mlkem

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: BSD-3-Clause Imports: 6 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// ML-KEM-512 (Level 1 security)
	MLKEM512PublicKeySize    = 800
	MLKEM512PrivateKeySize   = 1632
	MLKEM512CiphertextSize   = 768
	MLKEM512SharedSecretSize = 32

	// ML-KEM-768 (Level 3 security)
	MLKEM768PublicKeySize    = 1184
	MLKEM768PrivateKeySize   = 2400
	MLKEM768CiphertextSize   = 1088
	MLKEM768SharedSecretSize = 32

	// ML-KEM-1024 (Level 5 security)
	MLKEM1024PublicKeySize    = 1568
	MLKEM1024PrivateKeySize   = 3168
	MLKEM1024CiphertextSize   = 1568
	MLKEM1024SharedSecretSize = 32
)

Security parameters for ML-KEM (Module Lattice Key Encapsulation Mechanism)

Variables

This section is empty.

Functions

func DeserializeDRY

func DeserializeDRY(bytes []byte, expectedSize int, typeName string) ([]byte, error)

DeserializeDRY provides unified deserialization

func SerializeDRY

func SerializeDRY(data []byte, expectedSize int, typeName string) ([]byte, error)

SerializeDRY provides unified serialization

Types

type BatchKEM

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

Batch operations for better throughput

func NewBatchKEM

func NewBatchKEM(mode Mode, numKeys int) (*BatchKEM, error)

NewBatchKEM creates a batch KEM processor

func (*BatchKEM) EncapsulateBatch

func (b *BatchKEM) EncapsulateBatch(rand io.Reader) ([]*EncapsulationResult, error)

EncapsulateBatch performs batch encapsulation

type EncapsulationResult

type EncapsulationResult struct {
	Ciphertext   []byte
	SharedSecret []byte
}

EncapsulationResult contains the ciphertext and shared secret

type Mode

type Mode int

Mode represents the ML-KEM parameter set

const (
	MLKEM512 Mode = iota + 1
	MLKEM768
	MLKEM1024
)

type PrivateKey

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

PrivateKey represents an ML-KEM private key

func GenerateKeyPair

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

GenerateKeyPair generates a new ML-KEM key pair

func GenerateKeyPairDRY

func GenerateKeyPairDRY(random io.Reader, mode Mode) (*PrivateKey, error)

GenerateKeyPairDRY generates a key pair using DRY principles

func GenerateKeyPairOptimized

func GenerateKeyPairOptimized(rand io.Reader, mode Mode) (*PrivateKey, error)

Optimized key generation with pre-allocated buffers

func PrivateKeyFromBytes

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

PrivateKeyFromBytes reconstructs a private key from bytes

func (*PrivateKey) Bytes

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

Bytes returns the private key as bytes

func (*PrivateKey) Decapsulate

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

Decapsulate recovers the shared secret from ciphertext

func (*PrivateKey) DecapsulateDRY

func (priv *PrivateKey) DecapsulateDRY(ciphertext []byte) ([]byte, error)

DecapsulateDRY performs decapsulation using DRY principles

type PublicKey

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

PublicKey represents an ML-KEM public key

func PublicKeyFromBytes

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

PublicKeyFromBytes reconstructs a public key from bytes

func (*PublicKey) Bytes

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

Bytes returns the public key as bytes

func (*PublicKey) Encapsulate

func (pub *PublicKey) Encapsulate(rand io.Reader) (*EncapsulationResult, error)

Encapsulate generates a shared secret and ciphertext

func (*PublicKey) EncapsulateDRY

func (pub *PublicKey) EncapsulateDRY(random io.Reader) (*EncapsulationResult, error)

EncapsulateDRY performs encapsulation using DRY principles

Jump to

Keyboard shortcuts

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