Documentation ¶
Overview ¶
Package eddilithium2 implements the hybrid signature scheme Ed25519-Dilithium2.
Example ¶
package main import ( "fmt" "github.com/karalef/circl/sign/eddilithium2" ) func main() { // Generates a keypair. pk, sk, err := eddilithium2.GenerateKey(nil) if err != nil { panic(err) } // (Alternatively one can derive a keypair from a seed, // see NewKeyFromSeed().) // Packs public and private key var packedSk [eddilithium2.PrivateKeySize]byte var packedPk [eddilithium2.PublicKeySize]byte sk.Pack(&packedSk) pk.Pack(&packedPk) // Load it again var sk2 eddilithium2.PrivateKey var pk2 eddilithium2.PublicKey sk2.Unpack(&packedSk) pk2.Unpack(&packedPk) // Creates a signature on our message with the generated private key. msg := []byte("Some message") var signature [eddilithium2.SignatureSize]byte eddilithium2.SignTo(&sk2, msg, signature[:]) // Checks whether a signature is correct if !eddilithium2.Verify(&pk2, msg, signature[:]) { panic("incorrect signature") } fmt.Printf("O.K.") }
Output: O.K.
Index ¶
- Constants
- func GenerateKey(rand io.Reader) (*PublicKey, *PrivateKey, error)
- func NewKeyFromSeed(seed *[SeedSize]byte) (*PublicKey, *PrivateKey)
- func Scheme() sign.Scheme
- func SignTo(sk *PrivateKey, msg []byte, signature []byte)
- func Verify(pk *PublicKey, msg []byte, signature []byte) bool
- type PrivateKey
- func (sk *PrivateKey) Bytes() []byte
- func (sk *PrivateKey) Equal(other sign.PrivateKey) bool
- func (sk *PrivateKey) MarshalBinary() ([]byte, error)
- func (sk *PrivateKey) Pack(buf *[PrivateKeySize]byte)
- func (sk *PrivateKey) Public() sign.PublicKey
- func (sk *PrivateKey) Scheme() sign.Scheme
- func (sk *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error)
- func (sk *PrivateKey) UnmarshalBinary(data []byte) error
- func (sk *PrivateKey) Unpack(buf *[PrivateKeySize]byte)
- type PublicKey
- func (pk *PublicKey) Bytes() []byte
- func (pk *PublicKey) Equal(other sign.PublicKey) bool
- func (pk *PublicKey) MarshalBinary() ([]byte, error)
- func (pk *PublicKey) Pack(buf *[PublicKeySize]byte)
- func (pk *PublicKey) Scheme() sign.Scheme
- func (pk *PublicKey) UnmarshalBinary(data []byte) error
- func (pk *PublicKey) Unpack(buf *[PublicKeySize]byte)
Examples ¶
Constants ¶
const ( // SeedSize is the length of the seed for NewKeyFromSeed SeedSize = mode2.SeedSize // = ed25519.SeedSize = 32 // PublicKeySize is the length in bytes of the packed public key. PublicKeySize = mode2.PublicKeySize + ed25519.PublicKeySize // PrivateKeySize is the length in bytes of the packed public key. PrivateKeySize = mode2.PrivateKeySize + ed25519.SeedSize // SignatureSize is the length in bytes of the signatures. SignatureSize = mode2.SignatureSize + ed25519.SignatureSize )
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
func GenerateKey(rand io.Reader) (*PublicKey, *PrivateKey, error)
GenerateKey generates a public/private key pair using entropy from rand. If rand is nil, crypto/rand.Reader will be used.
func NewKeyFromSeed ¶
func NewKeyFromSeed(seed *[SeedSize]byte) (*PublicKey, *PrivateKey)
NewKeyFromSeed derives a public/private key pair using the given seed.
func SignTo ¶
func SignTo(sk *PrivateKey, msg []byte, signature []byte)
SignTo signs the given message and writes the signature into signature. It will panic if signature is not of length at least SignatureSize.
Types ¶
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey is the type of an EdDilithium2 private key.
func (*PrivateKey) Equal ¶
func (sk *PrivateKey) Equal(other sign.PrivateKey) bool
func (*PrivateKey) MarshalBinary ¶
func (sk *PrivateKey) MarshalBinary() ([]byte, error)
MarshalBinary packs the private key.
func (*PrivateKey) Pack ¶
func (sk *PrivateKey) Pack(buf *[PrivateKeySize]byte)
Pack packs the private key into buf.
func (*PrivateKey) Public ¶
func (sk *PrivateKey) Public() sign.PublicKey
Public computes the public key corresponding to this private key.
Returns a *PublicKey. The type crypto.PublicKey is used to make PrivateKey implement the crypto.Signer interface.
func (*PrivateKey) Scheme ¶
func (sk *PrivateKey) Scheme() sign.Scheme
func (*PrivateKey) Sign ¶
func (sk *PrivateKey) Sign( rand io.Reader, msg []byte, opts crypto.SignerOpts, ) (signature []byte, err error)
Sign signs the given message.
opts.HashFunc() must return zero, which can be achieved by passing crypto.Hash(0) for opts. rand is ignored. Will only return an error if opts.HashFunc() is non-zero.
This function is used to make PrivateKey implement the crypto.Signer interface. The package-level SignTo function might be more convenient to use.
func (*PrivateKey) UnmarshalBinary ¶
func (sk *PrivateKey) UnmarshalBinary(data []byte) error
UnmarshalBinary unpacks the private key from data.
func (*PrivateKey) Unpack ¶
func (sk *PrivateKey) Unpack(buf *[PrivateKeySize]byte)
Unpack sets sk to the private key encoded in buf.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is the type of an EdDilithium2 public key.
func (*PublicKey) MarshalBinary ¶
MarshalBinary packs the public key.
func (*PublicKey) Pack ¶
func (pk *PublicKey) Pack(buf *[PublicKeySize]byte)
Pack packs the public key into buf.
func (*PublicKey) UnmarshalBinary ¶
UnmarshalBinary the public key from data.
func (*PublicKey) Unpack ¶
func (pk *PublicKey) Unpack(buf *[PublicKeySize]byte)
Unpack unpacks pk to the public key encoded in buf.