mlkem768

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package mlkem768 implements the IND-CCA2 secure key encapsulation mechanism ML-KEM-768 as defined in FIPS203.

Index

Constants

View Source
const (
	// Size of seed for NewKeyFromSeed
	KeySeedSize = cpapke.KeySeedSize + 32

	// Size of seed for EncapsulateTo.
	EncapsulationSeedSize = 32

	// Size of the established shared key.
	SharedKeySize = 32

	// Size of the encapsulated shared key.
	CiphertextSize = cpapke.CiphertextSize

	// Size of a packed public key.
	PublicKeySize = cpapke.PublicKeySize

	// Size of a packed private key.
	PrivateKeySize = cpapke.PrivateKeySize + cpapke.PublicKeySize + 64
)

Variables

This section is empty.

Functions

func GenerateKeyPair

func GenerateKeyPair(rand io.Reader) (*PublicKey, *PrivateKey, error)

GenerateKeyPair generates public and private keys using entropy from rand. If rand is nil, crypto/rand.Reader will be used.

func NewKeyFromSeed

func NewKeyFromSeed(seed []byte) (*PublicKey, *PrivateKey)

NewKeyFromSeed derives a public/private keypair deterministically from the given seed.

Panics if seed is not of length KeySeedSize.

func Scheme

func Scheme() kem.Scheme

Scheme returns a KEM interface.

Types

type PrivateKey

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

Type of a ML-KEM-768 private key

func (*PrivateKey) DecapsulateTo

func (sk *PrivateKey) DecapsulateTo(ss, ct []byte)

DecapsulateTo computes the shared key which is encapsulated in ct for the private key.

Panics if ct or ss are not of length CiphertextSize and SharedKeySize respectively.

func (*PrivateKey) Equal

func (sk *PrivateKey) Equal(other kem.PrivateKey) bool

func (*PrivateKey) MarshalBinary

func (sk *PrivateKey) MarshalBinary() ([]byte, error)

func (*PrivateKey) Pack

func (sk *PrivateKey) Pack(buf []byte)

Packs sk to buf.

Panics if buf is not of size PrivateKeySize.

func (*PrivateKey) Public

func (sk *PrivateKey) Public() kem.PublicKey

func (*PrivateKey) Scheme

func (sk *PrivateKey) Scheme() kem.Scheme

func (*PrivateKey) Unpack

func (sk *PrivateKey) Unpack(buf []byte) error

Unpacks sk from buf.

Panics if buf is not of size PrivateKeySize.

Returns an error if buf is not of size PrivateKeySize, or private key doesn't pass the ML-KEM decapsulation key check.

type PublicKey

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

Type of a ML-KEM-768 public key

func (*PublicKey) EncapsulateTo

func (pk *PublicKey) EncapsulateTo(ct, ss []byte, seed []byte)

EncapsulateTo generates a shared key and ciphertext that contains it for the public key using randomness from seed and writes the shared key to ss and ciphertext to ct.

Panics if ss, ct or seed are not of length SharedKeySize, CiphertextSize and EncapsulationSeedSize respectively.

seed may be nil, in which case crypto/rand.Reader is used to generate one.

func (*PublicKey) Equal

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

func (*PublicKey) MarshalBinary

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

func (*PublicKey) Pack

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

Packs pk to buf.

Panics if buf is not of size PublicKeySize.

func (*PublicKey) Scheme

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

func (*PublicKey) Unpack

func (pk *PublicKey) Unpack(buf []byte) error

Unpacks pk from buf.

Returns an error if buf is not of size PublicKeySize, or the public key is not normalized.

Jump to

Keyboard shortcuts

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