dilithium

package
v0.0.0-...-01484a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: CC0-1.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SEEDBYTES = 32

	Dilithium2SizePK  = 1312
	Dilihtium2SizeSK  = 2528
	Dilithium2SizeSig = 2420

	Dilithium3SizePK  = 1952
	Dilihtium3SizeSK  = 4000
	Dilithium3SizeSig = 3293

	Dilithium5SizePK  = 2592
	Dilihtium5SizeSK  = 4864
	Dilithium5SizeSig = 4595
)

The first block of constants define internal parameters. SEEDBYTES holds the lenght in byte of the random number to give as input, if wanted. The remaining constants are exported to allow for fixed-lenght array instantiation. For a given security level, the consts are the same as the output of the d.SIZEX() functions defined in keys.go

Variables

This section is empty.

Functions

This section is empty.

Types

type Dilithium

type Dilithium struct {
	Name string
	// contains filtered or unexported fields
}

Dilithium struct defines the internal parameters to be used given a security level

func NewDilithium2

func NewDilithium2(randomized ...bool) *Dilithium

NewDilithium2 defines a dilithium instance with a light security level. The signature is randomized expect if a false boolean is given as argument.

func NewDilithium3

func NewDilithium3(randomized ...bool) *Dilithium

NewDilithium3 defines a dilithium instance with a medium security level. The signature is randomized expect if a false boolean is given as argument.

func NewDilithium5

func NewDilithium5(randomized ...bool) *Dilithium

NewDilithium5 defines a dilithium instance with a very high security level. The signature is randomized expect if a false boolean is given as argument.

func NewDilithiumUnsafe

func NewDilithiumUnsafe(q, d, tau, gamma1, gamma2, k, l, eta, omega int) *Dilithium

NewDilithiumUnsafe is a skeleton function to be used for research purposes when wanting to use a dilithium instance with parameters that differ from the recommended ones.

func (*Dilithium) KeyGen

func (d *Dilithium) KeyGen(seed []byte) ([]byte, []byte)

KeyGen creates a public and private key pair. A 32 byte long seed can be given as argument. If a nil seed is given, the seed is generated using Go crypto's random number generator. The keys returned are packed into byte arrays.

func (*Dilithium) PackPK

func (d *Dilithium) PackPK(pk PublicKey) []byte

PackPK packs a PublicKey into an array of bytes

func (*Dilithium) PackSK

func (d *Dilithium) PackSK(sk PrivateKey) []byte

PackSK packs a PrivateKey into a byte array

func (*Dilithium) PackSig

func (d *Dilithium) PackSig(z Vec, h Vec, hc []byte) []byte

PackSig packs a dilithium signature into a byte array

func (*Dilithium) SIZEPK

func (d *Dilithium) SIZEPK() int

SIZEPK returns the size in bytes of the public key of a dilithium instance

func (*Dilithium) SIZESIG

func (d *Dilithium) SIZESIG() int

SIZESIG returns the size in bytes of the signature of a dilithium instance

func (*Dilithium) SIZESK

func (d *Dilithium) SIZESK() int

SIZESK returns the size in bytes of the secret key of a dilithium instance

func (*Dilithium) Sign

func (d *Dilithium) Sign(packedSK, msg []byte) []byte

Sign produces a signature on the given msg using the secret signing key. The signing key must be given as packed byte array. The message should also be a byte array. The returned signature is packed into a byte array. If an error occurs during the signature process, a nil signature is returned.

func (*Dilithium) UnpackPK

func (d *Dilithium) UnpackPK(packedPK []byte) PublicKey

UnpackPK reverses the packing operation and outputs a PublicKey struct

func (*Dilithium) UnpackSK

func (d *Dilithium) UnpackSK(packedSK []byte) PrivateKey

UnpackSK reverses the packing operation and outputs a PrivateKey struct

func (*Dilithium) UnpackSig

func (d *Dilithium) UnpackSig(sig []byte) (Vec, Vec, []byte)

UnpackSig unpacks a byte array into a signature. If the format is incorrect, nil objects are returned.

func (*Dilithium) Verify

func (d *Dilithium) Verify(packedPK, msg, sig []byte) bool

Verify uses the verification key to verify a signature given a msg. The public key and signature must be given as packed byte arrays. The message should be a byte array. The result of the verificatino is returned as a boolean, true is the verificatino succeeded, false otherwise. If an error occurs during the verification, a false is returned.

type Mat

type Mat []Vec

Mat is used to hold the matrix A

type Poly

type Poly [n]int32

Poly represents a polynomial of deg n with coefs in [0, Q)

type PrivateKey

type PrivateKey struct {
	S1  Vec //L
	S2  Vec //K
	Rho [SEEDBYTES]byte
	Key [SEEDBYTES]byte
	Tr  [SEEDBYTES]byte
	T0  Vec //K
}

PrivateKey holds the sk struct

type PublicKey

type PublicKey struct {
	T1  Vec //K
	Rho [SEEDBYTES]byte
}

PublicKey holds the pk strct

type Vec

type Vec []Poly

Vec holds L or K polynomials

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL