core/crypto/mlkem
mlkem
Types
3Decapsulation_Key
Decapsulation_Key :: Decapsulation_KeySourceDecapsulation_Key is a ML-KEM decapsulation (aka "private") key. This implementation opts to include the encapsulation (aka "public") key as well for cases where the decapsulation key is reused (eg: HPKE with X-Wing).
Encapsulation_Key
Encapsulation_Key :: Encapsulation_KeySourceEncapsulation_Key is a ML-KEM encapsulation (aka "public") key.
Parameters
Parameters :: enum int {
Invalid = 0,
ML_KEM_512 = 1,
ML_KEM_768 = 2,
ML_KEM_1024 = 3,
}SourceParameters are the supported ML-KEM parameter sets.
Constants
2DECAPSULATION_KEY_SEED_SIZE
DECAPSULATION_KEY_SEED_SIZE :: 64SourceDECAPSULATION_KEY_SEED_SIZE is the size of a Decapsulation key in bytes.
SHARED_SECRET_SIZE
SHARED_SECRET_SIZE :: 32SourceSHARED_SECRET_SIZE is the size of the final shared secret in bytes.
Variables
3CIPHERTEXT_SIZES
CIPHERTEXT_SIZES :: [4]int = [Parameters]int {
.Invalid = 0,
.ML_KEM_512 = _mlkem.CIPHERTEXTBYTES_512, // 768-bytes
.ML_KEM_768 = _mlkem.CIPHERTEXTBYTES_768, // 1088-bytes
.ML_KEM_1024 = _mlkem.CIPHERTEXTBYTES_1024, // 1568-bytes
}SourceCIPHERTEXT_SIZES are the per-parameter set sizes of the ciphertext in bytes.
DECAPSULATION_KEY_EXPANDED_SIZES
DECAPSULATION_KEY_EXPANDED_SIZES :: [4]int = [Parameters]int {
.Invalid = 0,
.ML_KEM_512 = _mlkem.DECAPSKEYBYTES_512, // 1632-bytes
.ML_KEM_768 = _mlkem.DECAPSKEYBYTES_768, // 2400-bytes
.ML_KEM_1024 = _mlkem.DECAPSKEYBYTES_1024, // 3168-bytes
}SourceDECAPSULATION_KEY_EXPANDED_SIZES are the per-parameter sizes of the decapsulation key in bytes.
ENCAPSULATION_KEY_SIZES
ENCAPSULATION_KEY_SIZES :: [4]int = [Parameters]int {
.Invalid = 0,
.ML_KEM_512 = _mlkem.ENCAPSKEYBYTES_512, // 800-bytes
.ML_KEM_768 = _mlkem.ENCAPSKEYBYTES_768, // 1184-bytes
.ML_KEM_1024 = _mlkem.ENCAPSKEYBYTES_1024, // 1568-bytes
}SourceENCAPSULATION_KEY_SIZES are the per-parameter sizes of the encapsulation key in bytes.
Procedures
15decaps
decaps :: proc(dk: ^Decapsulation_Key, ciphertext: []u8, shared_secret: []u8) -> (bool)Sourcedecaps uses the decapsulation key to generate a shared secret from a ciphertext. Due to ML-KEM's implicit rejection mechanism, this function will only return false if and only if (⟺) the lengths of the inputs are invalid or the decapsulation key is uninitialized.
This routine returning true does not guarantee that the shared secret matches that generated by the peer.
decapsulation_key_bytes
decapsulation_key_bytes :: proc(dk: ^Decapsulation_Key, dst: []u8)Sourcedecapsulation_key_bytes sets dst to byte-encoding of dk in the (d, z) "seed" format.
decapsulation_key_clear
decapsulation_key_clear :: proc(dk: ^Decapsulation_Key)Sourcedecapsulation_key_clear clears dk to the uninitialized state.
decapsulation_key_encaps_bytes
decapsulation_key_encaps_bytes :: proc(dk: ^Decapsulation_Key, dst: []u8)Sourcedecapsulation_key_encaps_bytes sets dst to the byte-encoding of the encasulation key corresponding to dk.
decapsulation_key_expanded_bytes
decapsulation_key_expanded_bytes :: proc(dk: ^Decapsulation_Key, dst: []u8)Sourcedecapsulation_key_expanded_bytes sets dst to the byte-encoding of dk. in the expanded FIPS 203 format. This primarily exists for export purposes.
decapsulation_key_generate
decapsulation_key_generate :: proc(dk: ^Decapsulation_Key, params: Parameters) -> (bool)Sourcedecapsulation_key_generate uses the system entropy source to generate a decapsulation key. This will only fail if and only if (⟺) the system entropy source is missing or broken.
decapsulation_key_set_bytes
decapsulation_key_set_bytes :: proc(dk: ^Decapsulation_Key, params: Parameters, seed: []u8) -> (bool)Sourcedecapsulation_key_set_bytes decodes a byte-encoded decapsulation key in (d, z) "seed" format, and returns true if and only if (⟺) the operation was successful.
encaps_ek
encaps_ek :: proc(ek: ^Encapsulation_Key, shared_secret: []u8, ciphertext: []u8) -> (bool)Sourceencaps_ek uses the encapsulation key to generate a shared secret and an associated ciphertext. This routine will fail if the system entropy source is unavailable.
encaps_ek_raw_bytes
encaps_ek_raw_bytes :: proc(params: Parameters, raw_ek: []u8, shared_secret: []u8, ciphertext: []u8) -> (bool)Sourceencaps_raw_ek_bytes uses the byte encoded encapsulation key to generate a shared secret and an associated ciphertext. This routine will fail if the system entropy source is unavailable, or of the encapsulation key is invalid.
encapsulation_key_bytes
encapsulation_key_bytes :: proc(ek: ^Encapsulation_Key, dst: []u8)Sourceencapsulation_key_encaps_bytes sets dst to the byte-encoding of ek.
encapsulation_key_clear
encapsulation_key_clear :: proc(ek: ^Encapsulation_Key)Sourceencapsulation_key_clear clears ek to the uninitialized state.
encapsulation_key_set_bytes
encapsulation_key_set_bytes :: proc(ek: ^Encapsulation_Key, params: Parameters, b: []u8) -> (bool)Sourceencapsulation_key_set_bytes decodes a byte-encoded encapsulation key, and returns true if and only if (⟺) the operation was successful.
encapsulation_key_set_decaps
encapsulation_key_set_decaps :: proc(ek: ^Encapsulation_Key, dk: ^Decapsulation_Key)Sourceencapsulation_key_set_decaps sets ek to the encapsulation key corresponding to dk.
key_size
key_size :: proc(k: ^T) -> (int)Sourcekey_size returns the key size of a Decapsulation_Key or Encapsulation_Key in bytes.
params
params :: proc(k: ^T) -> (Parameters)Sourceparams returns the Parameters used by a Decapsulation_Key or Encapsulation_Key instance.
Procedure Groups
1encaps
encaps :: proc{encaps_ek, encaps_ek_raw_bytes}Source