Involved Source Files Package mlkem768 implements the quantum-resistant key encapsulation method
ML-KEM (formerly known as Kyber).
Only the recommended ML-KEM-768 parameter set is provided.
The version currently implemented is the one specified by [NIST FIPS 203 ipd],
with the unintentional transposition of the matrix A reverted to match the
behavior of [Kyber version 3.0]. Future versions of this package might
introduce backwards incompatible changes to implement changes to FIPS 203.
[Kyber version 3.0]: https://pq-crystals.org/kyber/data/kyber-specification-round3-20210804.pdf
[NIST FIPS 203 ipd]: https://doi.org/10.6028/NIST.FIPS.203.ipd
Package-Level Type Names (total 6, in which 1 is exported)
/* sort exporteds by: | */
A DecapsulationKey is the secret key used to decapsulate a shared key from a
ciphertext. It includes various precomputed values. // A[i*k+j] = sampleNTT(ρ, j, i)decryptionKeydecryptionKey // ByteDecode₁₂(dk[:decryptionKeySize])dk[2400]byteencryptionKeyencryptionKey // ByteDecode₁₂(ek[:384k]) Bytes returns the extended encoding of the decapsulation key, according to
FIPS 203 (DRAFT). EncapsulationKey returns the public encapsulation key necessary to produce
ciphertexts.
func GenerateKey() (*DecapsulationKey, error)
func NewKeyFromExtendedEncoding(decapsulationKey []byte) (*DecapsulationKey, error)
func NewKeyFromSeed(seed []byte) (*DecapsulationKey, error)
func generateKey(dk *DecapsulationKey) (*DecapsulationKey, error)
func kemKeyGen(dk *DecapsulationKey, d, z *[32]byte) *DecapsulationKey
func newKeyFromExtendedEncoding(dk *DecapsulationKey, dkBytes []byte) (*DecapsulationKey, error)
func newKeyFromSeed(dk *DecapsulationKey, seed []byte) (*DecapsulationKey, error)
func Decapsulate(dk *DecapsulationKey, ciphertext []byte) (sharedKey []byte, err error)
func generateKey(dk *DecapsulationKey) (*DecapsulationKey, error)
func kemDecaps(dk *DecapsulationKey, c *[1088]byte) (K []byte)
func kemKeyGen(dk *DecapsulationKey, d, z *[32]byte) *DecapsulationKey
func newKeyFromExtendedEncoding(dk *DecapsulationKey, dkBytes []byte) (*DecapsulationKey, error)
func newKeyFromSeed(dk *DecapsulationKey, seed []byte) (*DecapsulationKey, error)
func crypto/tls.kyberDecapsulate(dk *DecapsulationKey, c []byte) ([]byte, error)
decryptionKey is the parsed and expanded form of a PKE decryption key. // ByteDecode₁₂(dk[:decryptionKeySize])
func parseDK(dx *decryptionKey, dkPKE []byte) error
func pkeDecrypt(dx *decryptionKey, c *[1088]byte) []byte
encryptionKey is the parsed and expanded form of a PKE encryption key. // A[i*k+j] = sampleNTT(ρ, j, i) // ByteDecode₁₂(ek[:384k])
func parseEK(ex *encryptionKey, ekPKE []byte) error
func pkeEncrypt(cc *[1088]byte, ex *encryptionKey, m *[32]byte, rnd []byte) []byte
fieldElement is an integer modulo q, an element of ℤ_q. It is always reduced.
func decompress(y uint16, d uint8) fieldElement
func fieldAdd(a, b fieldElement) fieldElement
func fieldAddMul(a, b, c, d fieldElement) fieldElement
func fieldCheckReduced(a uint16) (fieldElement, error)
func fieldMul(a, b fieldElement) fieldElement
func fieldMulSub(a, b, c fieldElement) fieldElement
func fieldReduce(a uint32) fieldElement
func fieldReduceOnce(a uint16) fieldElement
func fieldSub(a, b fieldElement) fieldElement
func compress(x fieldElement, d uint8) uint16
func fieldAdd(a, b fieldElement) fieldElement
func fieldAddMul(a, b, c, d fieldElement) fieldElement
func fieldMul(a, b fieldElement) fieldElement
func fieldMulSub(a, b, c fieldElement) fieldElement
func fieldSub(a, b fieldElement) fieldElement
nttElement is an NTT representation, an element of T_q, represented as an
array according to FIPS 203 (DRAFT), Section 2.4.
func ntt(f ringElement) nttElement
func nttMul(f, g nttElement) nttElement
func sampleNTT(rho []byte, ii, jj byte) nttElement
func inverseNTT(f nttElement) ringElement
func nttMul(f, g nttElement) nttElement
Package-Level Functions (total 42, in which 5 are exported)
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.
Encapsulate generates a shared key and an associated ciphertext from an
encapsulation key, drawing random bytes from crypto/rand.
If the encapsulation key is not valid, Encapsulate returns an error.
The shared key must be kept secret.
GenerateKey generates a new decapsulation key, drawing random bytes from
crypto/rand. The decapsulation key must be kept secret.
NewKeyFromExtendedEncoding parses a decapsulation key from its FIPS 203
(DRAFT) extended encoding.
NewKeyFromSeed deterministically generates a decapsulation key from a 64-byte
seed in the "d || z" form. The seed must be uniformly random.
compress maps a field element uniformly to the range 0 to 2ᵈ-1, according to
FIPS 203 (DRAFT), Definition 4.5.
decompress maps a number x between 0 and 2ᵈ-1 uniformly to the full range of
field elements, according to FIPS 203 (DRAFT), Definition 4.6.
inverseNTT maps a nttElement back to the ringElement it represents.
It implements NTT⁻¹, according to FIPS 203 (DRAFT), Algorithm 9.
kemDecaps produces a shared key from a ciphertext.
It implements ML-KEM.Decaps according to FIPS 203 (DRAFT), Algorithm 17.
kemEncaps generates a shared key and an associated ciphertext.
It implements ML-KEM.Encaps according to FIPS 203 (DRAFT), Algorithm 16.
kemKeyGen generates a decapsulation key.
It implements ML-KEM.KeyGen according to FIPS 203 (DRAFT), Algorithm 15, and
K-PKE.KeyGen according to FIPS 203 (DRAFT), Algorithm 12. The two are merged
to save copies and allocations.
ntt maps a ringElement to its nttElement representation.
It implements NTT, according to FIPS 203 (DRAFT), Algorithm 8.
nttMul multiplies two nttElements.
It implements MultiplyNTTs, according to FIPS 203 (DRAFT), Algorithm 10.
parseDK parses a decryption key from its encoded form.
It implements the computation of s from K-PKE.Decrypt according to FIPS 203
(DRAFT), Algorithm 14.
parseEK parses an encryption key from its encoded form.
It implements the initial stages of K-PKE.Encrypt according to FIPS 203
(DRAFT), Algorithm 13.
pkeDecrypt decrypts a ciphertext.
It implements K-PKE.Decrypt according to FIPS 203 (DRAFT), Algorithm 14,
although the computation of s is done in parseDK.
pkeEncrypt encrypt a plaintext message.
It implements K-PKE.Encrypt according to FIPS 203 (DRAFT), Algorithm 13,
although the computation of t and AT is done in parseEK.
Type Parameters:
T: ~[256]fieldElement polyAdd adds two ringElements or nttElements.
Type Parameters:
T: ~[256]fieldElement polyByteDecode decodes the 384-byte encoding of a polynomial, checking that
all the coefficients are properly reduced. This achieves the "Modulus check"
step of ML-KEM Encapsulation Input Validation.
polyByteDecode is also used in ML-KEM Decapsulation, where the input
validation is not required, but implicitly allowed by the specification.
It implements ByteDecode₁₂, according to FIPS 203 (DRAFT), Algorithm 5.
Type Parameters:
T: ~[256]fieldElement polyByteEncode appends the 384-byte encoding of f to b.
It implements ByteEncode₁₂, according to FIPS 203 (DRAFT), Algorithm 4.
Type Parameters:
T: ~[256]fieldElement polySub subtracts two ringElements or nttElements.
ringCompressAndEncode1 appends a 32-byte encoding of a ring element to s,
compressing one coefficients per bit.
It implements Compress₁, according to FIPS 203 (DRAFT), Definition 4.5,
followed by ByteEncode₁, according to FIPS 203 (DRAFT), Algorithm 4.
ringCompressAndEncode10 appends a 320-byte encoding of a ring element to s,
compressing four coefficients per five bytes.
It implements Compress₁₀, according to FIPS 203 (DRAFT), Definition 4.5,
followed by ByteEncode₁₀, according to FIPS 203 (DRAFT), Algorithm 4.
ringCompressAndEncode4 appends a 128-byte encoding of a ring element to s,
compressing two coefficients per byte.
It implements Compress₄, according to FIPS 203 (DRAFT), Definition 4.5,
followed by ByteEncode₄, according to FIPS 203 (DRAFT), Algorithm 4.
ringDecodeAndDecompress1 decodes a 32-byte slice to a ring element where each
bit is mapped to 0 or ⌈q/2⌋.
It implements ByteDecode₁, according to FIPS 203 (DRAFT), Algorithm 5,
followed by Decompress₁, according to FIPS 203 (DRAFT), Definition 4.6.
ringDecodeAndDecompress10 decodes a 320-byte encoding of a ring element where
each ten bits are mapped to an equidistant distribution.
It implements ByteDecode₁₀, according to FIPS 203 (DRAFT), Algorithm 5,
followed by Decompress₁₀, according to FIPS 203 (DRAFT), Definition 4.6.
ringDecodeAndDecompress4 decodes a 128-byte encoding of a ring element where
each four bits are mapped to an equidistant distribution.
It implements ByteDecode₄, according to FIPS 203 (DRAFT), Algorithm 5,
followed by Decompress₄, according to FIPS 203 (DRAFT), Definition 4.6.
sampleNTT draws a uniformly random nttElement from a stream of uniformly
random bytes generated by the XOF function, according to FIPS 203 (DRAFT),
Algorithm 6 and Definition 4.2.
samplePolyCBD draws a ringElement from the special Dη distribution given a
stream of random bytes generated by the PRF function, according to FIPS 203
(DRAFT), Algorithm 7 and Definition 4.1.
sliceForAppend takes a slice and a requested number of bytes. It returns a
slice with the contents of the given slice followed by that many bytes and a
second slice that aliases into it and contains only the extra bytes. If the
original slice has sufficient capacity then no allocation is performed.
Package-Level Variables (total 2, neither is exported)
gammas are the values ζ^2BitRev7(i)+1 mod q for each index i.
zetas are the values ζ^BitRev7(k) mod q for each index k.
Package-Level Constants (total 21, in which 5 are exported)
The pages are generated with Goldsv0.7.6. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.