mlkem

package
v1.17.28 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: BSD-3-Clause Imports: 7 Imported by: 8

Documentation

Overview

Package mlkem provides a wrapper around github.com/cloudflare/circl/kem/mlkem for ML-KEM (Module-Lattice-based Key Encapsulation Mechanism) support.

Index

Constants

View Source
const (
	MLKEM512PublicKeySize  = mlkem512.PublicKeySize
	MLKEM512PrivateKeySize = mlkem512.PrivateKeySize
	MLKEM512CiphertextSize = mlkem512.CiphertextSize
	MLKEM512SharedKeySize  = mlkem512.SharedKeySize
)

Key size constants for ML-KEM-512

View Source
const (
	MLKEM768PublicKeySize  = mlkem768.PublicKeySize
	MLKEM768PrivateKeySize = mlkem768.PrivateKeySize
	MLKEM768CiphertextSize = mlkem768.CiphertextSize
	MLKEM768SharedKeySize  = mlkem768.SharedKeySize
)

Key size constants for ML-KEM-768

View Source
const (
	MLKEM1024PublicKeySize  = mlkem1024.PublicKeySize
	MLKEM1024PrivateKeySize = mlkem1024.PrivateKeySize
	MLKEM1024CiphertextSize = mlkem1024.CiphertextSize
	MLKEM1024SharedKeySize  = mlkem1024.SharedKeySize
)

Key size constants for ML-KEM-1024

Variables

View Source
var ErrInvalidCiphertextSize = errors.New("invalid ciphertext size")

ErrInvalidCiphertextSize is returned when a ciphertext has an incorrect size

View Source
var ErrInvalidKeySize = errors.New("invalid key size")

ErrInvalidKeySize is returned when a key has an incorrect size

Functions

func GenerateKey added in v1.4.18

func GenerateKey(mode Mode) (*PublicKey, *PrivateKey, error)

GenerateKey generates a new ML-KEM key pair using crypto/rand

func GenerateKeyPair

func GenerateKeyPair(reader io.Reader, mode Mode) (*PublicKey, *PrivateKey, error)

GenerateKeyPair generates a new ML-KEM key pair with a specific reader

func GetCiphertextSize added in v1.4.18

func GetCiphertextSize(mode Mode) int

GetCiphertextSize returns the size of a ciphertext for the given mode

func GetPrivateKeySize added in v1.4.18

func GetPrivateKeySize(mode Mode) int

GetPrivateKeySize returns the size of a private key for the given mode

func GetPublicKeySize added in v1.4.18

func GetPublicKeySize(mode Mode) int

GetPublicKeySize returns the size of a public key for the given mode

Types

type Mode

type Mode int

Mode represents different security levels of ML-KEM

const (
	// MLKEM512 provides 128-bit security
	MLKEM512 Mode = iota
	// MLKEM768 provides 192-bit security
	MLKEM768
	// MLKEM1024 provides 256-bit security
	MLKEM1024
)

func (Mode) String added in v1.4.16

func (m Mode) String() string

String returns the string representation of the mode

type PrivateKey

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

PrivateKey represents a ML-KEM private key

func PrivateKeyFromBytes

func PrivateKeyFromBytes(data []byte, mode Mode) (*PrivateKey, error)

PrivateKeyFromBytes creates a private key from its byte representation

func (*PrivateKey) Bytes

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

Bytes returns the byte representation of the private key

func (*PrivateKey) Decapsulate

func (sk *PrivateKey) Decapsulate(ciphertext []byte) ([]byte, error)

Decapsulate recovers the shared secret from a ciphertext

func (*PrivateKey) Equal added in v1.4.18

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

Equal reports whether sk and other represent the same private key

func (*PrivateKey) PublicKey

func (sk *PrivateKey) PublicKey() *PublicKey

PublicKey returns the public key corresponding to this private key

type PublicKey

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

PublicKey represents a ML-KEM public key

func PublicKeyFromBytes

func PublicKeyFromBytes(data []byte, mode Mode) (*PublicKey, error)

PublicKeyFromBytes creates a public key from its byte representation

func (*PublicKey) Bytes

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

Bytes returns the byte representation of the public key

func (*PublicKey) Encapsulate

func (pk *PublicKey) Encapsulate(reader ...io.Reader) ([]byte, []byte, error)

Encapsulate generates a shared secret and ciphertext

func (*PublicKey) Equal added in v1.4.18

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

Equal reports whether pk and other represent the same public key

Jump to

Keyboard shortcuts

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