Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classMakes the key factories for one ML-KEM variant.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final KeyFactoryMLKEM-1024 key factory.static final KeyFactoryMLKEM-512 key factory.static final KeyFactoryMLKEM-768 key factory.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic byte[]Alice side.static byte[][]Bob side.static byte[][]generateKeys(EncType type) Alice side, raw key generation.static KeyPairAlice side, key generation.private static MLKEMParametersEncType to ML-KEM parameters.
Field Details
MLKEM512KeyFactory
MLKEM-512 key factory.MLKEM768KeyFactory
MLKEM-768 key factory.MLKEM1024KeyFactory
MLKEM-1024 key factory.
Constructor Details
MLKEM
private MLKEM()Utility class, not intended for instantiation.
Method Details
getKeys
Alice side, key generation.- Parameters:
type- must be one of the internal types MLKEM*_INT- Returns:
- the key pair, public key in [0] and private key in [1]
- Throws:
GeneralSecurityException- if the type is not an ML-KEM type
generateKeys
Alice side, raw key generation.- Parameters:
type- must be one of the internal types MLKEM*_INT- Returns:
- a two element array holding the encoded public key in [0] and the encoded private key in [1]
- Throws:
GeneralSecurityException- if the type is not an ML-KEM type
encaps
Bob side.Fails if the public key is not a well formed ML-KEM public key of the given parameter set, or if the type is not an ML-KEM type.
- Parameters:
type- the encryption typepub- the public key, of exactly the length for this parameter set- Returns:
- ciphertext and shared secret, both non-null
- Throws:
GeneralSecurityException- if the type is unsupported or the key is malformed
decaps
public static byte[] decaps(EncType type, byte[] ciphertext, byte[] decapkey) throws GeneralSecurityException Alice side.Decapsulation implements the implicit rejection required by FIPS 203 section 7.3: a ciphertext that is malformed, truncated, tampered with, or addressed to a different key never raises. Instead the shared secret is replaced by a pseudorandom value derived from the decapsulation key and the rejected ciphertext, so the result simply does not match the peer's. The replacement is deterministic, so retrying learns nothing.
A caller that needs to authenticate the peer must therefore compare the returned secret against the expected one, because no exception distinguishes a bad ciphertext. A mismatched 32 byte secret is the only signal of rejection.
- Parameters:
type- the encryption typeciphertext- the ciphertext to decryptdecapkey- the decapsulation key- Returns:
- the 32 byte shared secret, never null; a rejected ciphertext yields a pseudorandom value rather than an error
- Throws:
GeneralSecurityException- if the type is not an ML-KEM type
getParam
EncType to ML-KEM parameters.- Parameters:
type- the encryption type- Returns:
- the parameters for the parameter set named by the type
- Throws:
GeneralSecurityException- if the type is not an ML-KEM type