Kem class¶
- class crsyspqc.Kem¶
Key-Encapsulation Mechanism (KEM) functions.
- class Alg¶
Key-Encapsulation Mechanism (KEM) algorithms.
- ML_KEM_512 = 16¶
ML_KEM_512 from FIPS.203 (based on Kyber512)
- ML_KEM_768 = 17¶
ML_KEM_768 from FIPS.203 (based on Kyber768)
- ML_KEM_1024 = 18¶
ML_KEM_1024 from FIPS.203 (based on Kyber1024)
- static keygen(alg, params='')¶
Generate an encapsulation/decapsulation key pair (ek, dk).
- Parameters:
alg (Kem.Alg) – Kem algorithm.
params (str) – Optional parameter to pass known test random material of exactly 64 bytes (
d||z
) encoded in hexadecimal [default=add fresh randomness].
- Returns:
A key pair (ek, dk) both of type bytes.
- static encaps(alg, encapkey, params='')¶
Carry out the ML-KEM encapsulation algorithm.
- Parameters:
alg (Kem.Alg) – Kem algorithm.
encapkey (bytes) – Encapsulation key ek
params (str) – Optional parameter to pass known test random material of exactly 32 bytes (
m
) encoded in hexadecimal [default=add fresh randomness].
- Returns:
A pair (ss, ct). Secret shared key ss and ciphertext ct both of type bytes.
- static decaps(alg, ct, decapkey)¶
Carry out the ML-KEM decapsulation algorithm.
- Parameters:
alg (Kem.Alg) – Kem algorithm.
ct (bytes) – Ciphertext ct
decapkey (bytes) – Decapsulation key dk (in expanded or 64-byte “seed” form)
- Returns:
shared secret key, ss. On failure, ss will contain a pseudo-random value.
- Return type:
bytes
- static encapkey_size(alg)¶
Return length in bytes of encapsulation key (“public key”) for given algorithm.
- Parameters:
alg (Kem.Alg) – KEM algorithm.
- Returns:
length in bytes.
- Return type:
int
- static decapkey_size(alg)¶
Return length in bytes of expanded decapsulation key (“private key”) for given algorithm.
- Parameters:
alg (Kem.Alg) – KEM algorithm.
- Returns:
length in bytes.
- Return type:
int
- static ciphertext_size(alg)¶
Return length in bytes of ciphertext ct for given algorithm.
- Parameters:
alg (Kem.Alg) – KEM algorithm.
- Returns:
length in bytes.
- Return type:
int
Return length in bytes of shared secret key ss for given algorithm.
- Parameters:
alg (Kem.Alg) – KEM algorithm.
- Returns:
length in bytes.
- Return type:
int