Interface IKem
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Kem
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Defines a Key Encapsulation Mechanism (KEM).
public interface IKem : IDisposable
- Inherited Members
Remarks
A KEM provides three operations: key generation, encapsulation, and decapsulation. Encapsulation produces a shared secret and a ciphertext that can be sent to the holder of the corresponding decapsulation key, who can recover the same shared secret.
Common KEM algorithms:
- ML-KEM-512 (FIPS 203, security category 1)
- ML-KEM-768 (FIPS 203, security category 3)
- ML-KEM-1024 (FIPS 203, security category 5)
Properties
AlgorithmName
Gets the algorithm name.
string AlgorithmName { get; }
Property Value
CiphertextSizeBytes
Gets the ciphertext size in bytes.
int CiphertextSizeBytes { get; }
Property Value
DecapsulationKeySizeBytes
Gets the decapsulation key size in bytes.
int DecapsulationKeySizeBytes { get; }
Property Value
EncapsulationKeySizeBytes
Gets the encapsulation key size in bytes.
int EncapsulationKeySizeBytes { get; }
Property Value
SharedSecretSizeBytes
Gets the shared secret size in bytes.
int SharedSecretSizeBytes { get; }
Property Value
Methods
Decapsulate(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>)
Decapsulates the shared secret from the ciphertext using the decapsulation key.
void Decapsulate(ReadOnlySpan<byte> decapsulationKey, ReadOnlySpan<byte> ciphertext, Span<byte> sharedSecret)
Parameters
decapsulationKeyReadOnlySpan<byte>The decapsulation (private) key.
ciphertextReadOnlySpan<byte>The ciphertext produced by encapsulation.
sharedSecretSpan<byte>The buffer to receive the shared secret.
Remarks
ML-KEM uses implicit rejection: if decapsulation fails, a pseudorandom value derived from the ciphertext and a secret value is returned instead of an error.
Exceptions
- ArgumentException
decapsulationKey,ciphertext, orsharedSecrethas an invalid size.
Encapsulate(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, Span<byte>)
Encapsulates a shared secret using the encapsulation key with a deterministic seed.
void Encapsulate(ReadOnlySpan<byte> encapsulationKey, ReadOnlySpan<byte> seed, Span<byte> ciphertext, Span<byte> sharedSecret)
Parameters
encapsulationKeyReadOnlySpan<byte>The encapsulation (public) key.
seedReadOnlySpan<byte>The 32-byte random seed (m) for deterministic encapsulation.
ciphertextSpan<byte>The buffer to receive the ciphertext.
sharedSecretSpan<byte>The buffer to receive the shared secret.
Exceptions
- ArgumentException
Any parameter has an invalid size.
Encapsulate(ReadOnlySpan<byte>, Span<byte>, Span<byte>)
Encapsulates a shared secret using the encapsulation key.
void Encapsulate(ReadOnlySpan<byte> encapsulationKey, Span<byte> ciphertext, Span<byte> sharedSecret)
Parameters
encapsulationKeyReadOnlySpan<byte>The encapsulation (public) key.
ciphertextSpan<byte>The buffer to receive the ciphertext.
sharedSecretSpan<byte>The buffer to receive the shared secret.
Exceptions
- ArgumentException
encapsulationKeyhas an invalid size, orciphertextorsharedSecretis too small.
GenerateKeyPair(ReadOnlySpan<byte>, Span<byte>, Span<byte>)
Generates an encapsulation key and a decapsulation key using the provided seed.
void GenerateKeyPair(ReadOnlySpan<byte> seed, Span<byte> encapsulationKey, Span<byte> decapsulationKey)
Parameters
seedReadOnlySpan<byte>The deterministic seed (d ‖ z) for key generation.
encapsulationKeySpan<byte>The buffer to receive the encapsulation (public) key.
decapsulationKeySpan<byte>The buffer to receive the decapsulation (private) key.
Exceptions
- ArgumentException
seed,encapsulationKey, ordecapsulationKeyhas an invalid size.
GenerateKeyPair(ReadOnlySpan<byte>, Span<byte>, Span<byte>, bool)
Generates a key pair from a seed, optionally skipping the pairwise consistency test.
void GenerateKeyPair(ReadOnlySpan<byte> seed, Span<byte> encapsulationKey, Span<byte> decapsulationKey, bool pairwiseConsistencyTest)
Parameters
seedReadOnlySpan<byte>The deterministic seed (d ‖ z) for key generation.
encapsulationKeySpan<byte>The buffer to receive the encapsulation (public) key.
decapsulationKeySpan<byte>The buffer to receive the decapsulation (private) key.
pairwiseConsistencyTestbool
Exceptions
- ArgumentException
A parameter has an invalid size.
GenerateKeyPair(Span<byte>, Span<byte>)
Generates an encapsulation key and a decapsulation key.
void GenerateKeyPair(Span<byte> encapsulationKey, Span<byte> decapsulationKey)
Parameters
encapsulationKeySpan<byte>The buffer to receive the encapsulation (public) key.
decapsulationKeySpan<byte>The buffer to receive the decapsulation (private) key.
Exceptions
- ArgumentException
encapsulationKeyordecapsulationKeyis too small.
GenerateKeyPair(Span<byte>, Span<byte>, bool)
Generates a key pair, optionally skipping the pairwise consistency test.
void GenerateKeyPair(Span<byte> encapsulationKey, Span<byte> decapsulationKey, bool pairwiseConsistencyTest)
Parameters
encapsulationKeySpan<byte>The buffer to receive the encapsulation (public) key.
decapsulationKeySpan<byte>The buffer to receive the decapsulation (private) key.
pairwiseConsistencyTestbooltrue to verify the generated key pair with an encapsulate/decapsulate round trip; false to skip it. See the remarks on the KEM type.
Exceptions
- ArgumentException
A buffer is too small.