package mlkem

Import Path
	crypto/mlkem (on go.dev)

Dependency Relation
	imports one package, and imported by 0 packages

Involved Source Files Package mlkem implements the quantum-resistant key encapsulation method ML-KEM (formerly known as Kyber), as specified in [NIST FIPS 203]. Most applications should use the ML-KEM-768 parameter set, as implemented by [DecapsulationKey768] and [EncapsulationKey768].
Code Examples package main import ( "crypto/mlkem" "log" ) func main() { // Alice generates a new key pair and sends the encapsulation key to Bob. dk, err := mlkem.GenerateKey768() if err != nil { log.Fatal(err) } encapsulationKey := dk.EncapsulationKey().Bytes() // Bob uses the encapsulation key to encapsulate a shared secret, and sends // back the ciphertext to Alice. ciphertext := Bob(encapsulationKey) // Alice decapsulates the shared secret from the ciphertext. sharedSecret, err := dk.Decapsulate(ciphertext) if err != nil { log.Fatal(err) } // Alice and Bob now share a secret. _ = sharedSecret } func Bob(encapsulationKey []byte) (ciphertext []byte) { // Bob encapsulates a shared secret using the encapsulation key. ek, err := mlkem.NewEncapsulationKey768(encapsulationKey) if err != nil { log.Fatal(err) } sharedSecret, ciphertext := ek.Encapsulate() // Alice and Bob now share a secret. _ = sharedSecret // Bob sends the ciphertext to Alice. return ciphertext }
Package-Level Type Names (total 4)
/* sort by: | */
DecapsulationKey1024 is the secret key used to decapsulate a shared key from a ciphertext. It includes various precomputed values. Bytes returns the decapsulation key as a 64-byte seed in the "d || z" form. The decapsulation key must be kept secret. Decapsulate generates a shared key from a ciphertext and a decapsulation key. If the ciphertext is not valid, Decapsulate returns an error. The shared key must be kept secret. EncapsulationKey returns the public encapsulation key necessary to produce ciphertexts. func GenerateKey1024() (*DecapsulationKey1024, error) func NewDecapsulationKey1024(seed []byte) (*DecapsulationKey1024, error)
DecapsulationKey768 is the secret key used to decapsulate a shared key from a ciphertext. It includes various precomputed values. Bytes returns the decapsulation key as a 64-byte seed in the "d || z" form. The decapsulation key must be kept secret. Decapsulate generates a shared key from a ciphertext and a decapsulation key. If the ciphertext is not valid, Decapsulate returns an error. The shared key must be kept secret. EncapsulationKey returns the public encapsulation key necessary to produce ciphertexts. func GenerateKey768() (*DecapsulationKey768, error) func NewDecapsulationKey768(seed []byte) (*DecapsulationKey768, error)
An EncapsulationKey1024 is the public key used to produce ciphertexts to be decapsulated by the corresponding DecapsulationKey1024. Bytes returns the encapsulation key as a byte slice. Encapsulate generates a shared key and an associated ciphertext from an encapsulation key, drawing random bytes from the default crypto/rand source. The shared key must be kept secret. func NewEncapsulationKey1024(encapsulationKey []byte) (*EncapsulationKey1024, error) func (*DecapsulationKey1024).EncapsulationKey() *EncapsulationKey1024
An EncapsulationKey768 is the public key used to produce ciphertexts to be decapsulated by the corresponding DecapsulationKey768. Bytes returns the encapsulation key as a byte slice. Encapsulate generates a shared key and an associated ciphertext from an encapsulation key, drawing random bytes from the default crypto/rand source. The shared key must be kept secret. func NewEncapsulationKey768(encapsulationKey []byte) (*EncapsulationKey768, error) func (*DecapsulationKey768).EncapsulationKey() *EncapsulationKey768
Package-Level Functions (total 6)
GenerateKey1024 generates a new decapsulation key, drawing random bytes from the default crypto/rand source. The decapsulation key must be kept secret.
GenerateKey768 generates a new decapsulation key, drawing random bytes from the default crypto/rand source. The decapsulation key must be kept secret.
NewDecapsulationKey1024 expands a decapsulation key from a 64-byte seed in the "d || z" form. The seed must be uniformly random.
NewDecapsulationKey768 expands a decapsulation key from a 64-byte seed in the "d || z" form. The seed must be uniformly random.
NewEncapsulationKey1024 parses an encapsulation key from its encoded form. If the encapsulation key is not valid, NewEncapsulationKey1024 returns an error.
NewEncapsulationKey768 parses an encapsulation key from its encoded form. If the encapsulation key is not valid, NewEncapsulationKey768 returns an error.
Package-Level Constants (total 6)
CiphertextSize1024 is the size of a ciphertext produced by ML-KEM-1024.
CiphertextSize768 is the size of a ciphertext produced by ML-KEM-768.
EncapsulationKeySize1024 is the size of an ML-KEM-1024 encapsulation key.
EncapsulationKeySize768 is the size of an ML-KEM-768 encapsulation key.
SeedSize is the size of a seed used to generate a decapsulation key.
SharedKeySize is the size of a shared key produced by ML-KEM.