kyber

package
v0.0.0-...-2a6ca2d Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: CC0-1.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SIZEZ             = 32
	SEEDBYTES         = 32
	Kyber512SizePK    = 800
	Kyber512SizeSK    = 1632
	Kyber512SizePKESK = 768
	Kyber512SizeC     = 768 //2*320 + 128

	Kyber768SizePK    = 1184
	Kyber768SizeSK    = 2400
	Kyber768SizePKESK = 1152
	Kyber768SizeC     = 1088 //3*320 + 128

	Kyber1024SizePK    = 1568
	Kyber1024SizeSK    = 3168
	Kyber1024SizePKESK = 1536
	Kyber1024SizeC     = 1568 //4*352 + 160
)

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 k.SIZEX() functions defined in keys.go

Variables

This section is empty.

Functions

This section is empty.

Types

type Kyber

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

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

func NewKyber1024

func NewKyber1024() *Kyber

NewKyber1024 defines a kyber instance with a very high security level.

func NewKyber512

func NewKyber512() *Kyber

NewKyber512 defines a kyber instance with a light security level.

func NewKyber768

func NewKyber768() *Kyber

NewKyber768 defines a kyber instance with a medium security level.

func NewKyberUnsafe

func NewKyberUnsafe(n, k, q, eta1, et2, du, dv int) *Kyber

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

func (*Kyber) Decaps

func (k *Kyber) Decaps(packedSK, c []byte) []byte

Decaps decryps a ciphertext given a secret key and checks its validity. The secret key and ciphertext must be give as packed byte array. The recovered shared secret is returned as byte array. If an error occurs durirng the decapsulation process, a nil shared secret is returned.

func (*Kyber) Decrypt

func (k *Kyber) Decrypt(packedSK, c []byte) []byte

Decrypt decrypts a ciphertext given a secret key. The secret key and ciphertext must be give as packed byte array. The recovered message is returned as byte array. If an error occurs durirng the decryption process (wrong key format for example), a nil message is returned.

func (*Kyber) Encaps

func (k *Kyber) Encaps(packedPK, coins []byte) ([]byte, []byte)

Encaps generates a shared secret and the encryption of said shared secret using a given public key. A 32 byte long seed can be given as argument (coins). If a nil seed is given, the seed is generated using Go crypto's random number generator. The shared secret and ciphertext returned are packed into byte arrays. If an error occurs during the encaps process, nil arrays are returned.

func (*Kyber) Encrypt

func (k *Kyber) Encrypt(packedPK, msg, r []byte) []byte

Encrypt generates the encryption of a message using a public key. A 32 byte long seed can be given as argument (r). If a nil seed is given, the seed is generated using Go crypto's random number generator. The ciphertext returned is packed into a byte array. If an error occurs during the encrpytion process, a nil array is returned.

func (*Kyber) KeyGen

func (k *Kyber) KeyGen(seed []byte) ([]byte, []byte)

KeyGen creates a public and private key pair. A 64 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 (*Kyber) PKEKeyGen

func (k *Kyber) PKEKeyGen(seed []byte) ([]byte, []byte)

PKEKeyGen 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 (*Kyber) PackPK

func (k *Kyber) PackPK(pk *PublicKey) []byte

PackPK packs a PublicKey into an array of bytes

func (*Kyber) PackPKESK

func (k *Kyber) PackPKESK(sk *PKEPrivateKey) []byte

PackPKESK packs a PKE PrivateKey into a byte array

func (*Kyber) PackSK

func (k *Kyber) PackSK(sk *PrivateKey) []byte

PackSK packs a PrivateKey into a byte array

func (*Kyber) SIZEC

func (k *Kyber) SIZEC() int

SIZEC returns the size in bytes of the ciphertext of a kyber instance

func (*Kyber) SIZEPK

func (k *Kyber) SIZEPK() int

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

func (*Kyber) SIZEPKESK

func (k *Kyber) SIZEPKESK() int

SIZEPKESK returns the size in bytes of the PKE secret key of a kyber instance

func (*Kyber) SIZESK

func (k *Kyber) SIZESK() int

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

func (*Kyber) UnpackPK

func (k *Kyber) UnpackPK(packedPK []byte) *PublicKey

UnpackPK reverses the packing operation and outputs a PublicKey struct

func (*Kyber) UnpackPKESK

func (k *Kyber) UnpackPKESK(psk []byte) *PKEPrivateKey

UnpackPKESK reverses the packing operation and outputs a PKEPrivateKey struct

func (*Kyber) UnpackSK

func (k *Kyber) UnpackSK(psk []byte) *PrivateKey

UnpackSK reverses the packing operation and outputs a PrivateKey struct

type Mat

type Mat []Vec

Mat is used to hold A

type PKEPrivateKey

type PKEPrivateKey struct {
	S Vec //NTT(s)
}

PKEPrivateKey holds the ak strct for Kyber's PKE scheme

type Poly

type Poly [n]int16

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

type PrivateKey

type PrivateKey struct {
	Z   []byte
	SkP []byte
	Pk  []byte
}

PrivateKey holds the sk struct

type PublicKey

type PublicKey struct {
	T   Vec    //NTT(t)
	Rho []byte //32
}

PublicKey holds the pk strct

type Vec

type Vec []Poly

Vec is an array of K polynomials

Jump to

Keyboard shortcuts

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