...

Package eddilithium3

import "github.com/cloudflare/circl/sign/eddilithium3"
Overview
Index
Examples

Overview ▾

Package eddilithium3 implements the hybrid signature scheme Ed448-Dilithium3.

Example

Code:

// Generates a keypair.
pk, sk, err := eddilithium3.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 [eddilithium3.PrivateKeySize]byte
var packedPk [eddilithium3.PublicKeySize]byte
sk.Pack(&packedSk)
pk.Pack(&packedPk)

// Load it again
var sk2 eddilithium3.PrivateKey
var pk2 eddilithium3.PublicKey
sk2.Unpack(&packedSk)
pk2.Unpack(&packedPk)

// Creates a signature on our message with the generated private key.
msg := []byte("Some message")
var signature [eddilithium3.SignatureSize]byte
eddilithium3.SignTo(&sk2, msg, signature[:])

// Checks whether a signature is correct
if !eddilithium3.Verify(&pk2, msg, signature[:]) {
    panic("incorrect signature")
}

fmt.Printf("O.K.")

Output:

O.K.

Constants

const (
    // SeedSize is the length of the seed for NewKeyFromSeed
    SeedSize = ed448.SeedSize // > mode3.SeedSize

    // PublicKeySize is the length in bytes of the packed public key.
    PublicKeySize = mode3.PublicKeySize + ed448.PublicKeySize

    // PrivateKeySize is the length in bytes of the packed public key.
    PrivateKeySize = mode3.PrivateKeySize + ed448.SeedSize

    // SignatureSize is the length in bytes of the signatures.
    SignatureSize = mode3.SignatureSize + ed448.SignatureSize
)

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 Scheme

func Scheme() sign.Scheme

Scheme returns a signature interface.

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.

func Verify

func Verify(pk *PublicKey, msg []byte, signature []byte) bool

Verify checks whether the given signature by pk on msg is valid.

type PrivateKey

PrivateKey is the type of an EdDilithium3 private key.

type PrivateKey struct {
    // contains filtered or unexported fields
}

func (*PrivateKey) Bytes

func (sk *PrivateKey) Bytes() []byte

Bytes packs the private key.

func (*PrivateKey) Equal

func (sk *PrivateKey) Equal(other crypto.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() crypto.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

PublicKey is the type of an EdDilithium3 public key.

type PublicKey struct {
    // contains filtered or unexported fields
}

func (*PublicKey) Bytes

func (pk *PublicKey) Bytes() []byte

Bytes packs the public key.

func (*PublicKey) Equal

func (pk *PublicKey) Equal(other crypto.PublicKey) bool

func (*PublicKey) MarshalBinary

func (pk *PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary packs the public key.

func (*PublicKey) Pack

func (pk *PublicKey) Pack(buf *[PublicKeySize]byte)

Pack packs the public key into buf.

func (*PublicKey) Scheme

func (pk *PublicKey) Scheme() sign.Scheme

func (*PublicKey) UnmarshalBinary

func (pk *PublicKey) UnmarshalBinary(data []byte) error

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.