pq

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMLKEM1024 added in v1.0.1

func NewMLKEM1024() kem.KEM

NewMLKEM1024 returns a kem.KEM implementation for ML-KEM-1024 (Kyber-1024).

func NewMLKEM512 added in v1.0.1

func NewMLKEM512() kem.KEM

NewMLKEM512 returns a kem.KEM implementation for ML-KEM-512 (Kyber-512).

func NewMLKEM768 added in v1.0.1

func NewMLKEM768() kem.KEM

NewMLKEM768 returns a kem.KEM implementation for ML-KEM-768 (Kyber-768).

func Open

func Open(k kem.KEM, cipher aead.Aead, privateKey, associatedData, blob []byte) ([]byte, error)

Open reverses Seal by decapsulating the shared secret and decrypting the payload using the stored key schedule identifier.

func Seal

func Seal(k kem.KEM, cipher aead.Aead, publicKey, associatedData, plaintext []byte) ([]byte, error)

Seal performs KEM -> HKDF -> AEAD composition using the provided KEM and AEAD implementations. The returned blob encodes the encapsulated key, the chosen key schedule identifier, and the AEAD ciphertext (ciphertext || tag).

Types

type Hybrid

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

Hybrid implements a deployable hybrid key encapsulation mechanism that combines a classical ECDH exchange with an optional post-quantum KEM. The classical component is required to ensure callers can rely on the construction even before a post-quantum primitive is available. When a PQ KEM is supplied, Hybrid derives the final shared secret from both inputs using HKDF-SHA256 as described in draft-ietf-tls-hybrid-design-05.

The encoded public/private keys and ciphertexts follow a simple tagged format: version byte followed by 2-byte big-endian length prefixes for the classical and post-quantum components.

func NewHybrid

func NewHybrid(classical ecdh.KeyExchange, mlkem kem.KEM) (*Hybrid, error)

NewHybrid constructs a Hybrid KEM using the provided classical ECDH exchange and optional post-quantum KEM. The classical exchange must be non-nil.

func NewHybridX25519

func NewHybridX25519() *Hybrid

NewHybridX25519 returns a Hybrid instance backed by X25519 and without a post-quantum component. It is intended as an immediate, deployable hybrid construction until a vetted ML-KEM implementation is available.

func NewHybridX25519MLKEM1024 added in v1.0.1

func NewHybridX25519MLKEM1024() *Hybrid

NewHybridX25519MLKEM1024 returns a Hybrid instance backed by X25519 and ML-KEM-1024 (Kyber-1024).

func NewHybridX25519MLKEM512 added in v1.0.1

func NewHybridX25519MLKEM512() *Hybrid

NewHybridX25519MLKEM512 returns a Hybrid instance backed by X25519 and ML-KEM-512 (Kyber-512).

func NewHybridX25519MLKEM768 added in v1.0.1

func NewHybridX25519MLKEM768() *Hybrid

NewHybridX25519MLKEM768 returns a Hybrid instance backed by X25519 and ML-KEM-768 (Kyber-768).

func (*Hybrid) Decapsulate

func (h *Hybrid) Decapsulate(private, ciphertext []byte) ([]byte, error)

Decapsulate recovers the shared secret from ciphertext using the provided private key. It validates the key/ciphertext format and combines the classical and post-quantum secrets using HKDF-SHA256.

func (*Hybrid) Encapsulate

func (h *Hybrid) Encapsulate(public []byte) (ciphertext, sharedSecret []byte, err error)

Encapsulate performs hybrid encapsulation using the recipient's public key. The returned ciphertext embeds the ephemeral classical public key and, when available, the post-quantum ciphertext. The shared secret is derived from the concatenation of the classical and PQ secrets using HKDF-SHA256.

func (*Hybrid) GenerateKey

func (h *Hybrid) GenerateKey() (public, private []byte, err error)

GenerateKey creates a hybrid public/private key pair. When mlkem is nil only the classical component is produced, resulting in a format that still allows hybrid ciphertexts to be processed in the future.

Jump to

Keyboard shortcuts

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