Class FrodoKemContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, KemContext
FrodoKEM runtime context
Implementation ofKemContext for the Frodo
post-quantum key encapsulation mechanism (KEM).
A FrodoKemContext is a lightweight binding of:
- a
CryptoAlgorithmdescriptor, - a key (public for encapsulation or private for decapsulation), and
- a role indicator (encapsulate or decapsulate).
Contexts are created by FrodoAlgorithm when binding roles such as
KeyUsage.ENCAPSULATE or
KeyUsage.DECAPSULATE. They provide the runtime entry
points to encapsulate a secret or decapsulate a received ciphertext.
Thread-safety
Instances are not thread-safe. A context is intended for single-operation or short-lived use within a single thread.
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface KemContext
KemContext.KemResult -
Constructor Summary
ConstructorsConstructorDescriptionFrodoKemContext(CryptoAlgorithm algorithm, PrivateKey k) Constructs a context bound to a private key for theKeyUsage.DECAPSULATErole.FrodoKemContext(CryptoAlgorithm algorithm, PublicKey k) Constructs a context bound to a public key for theKeyUsage.ENCAPSULATErole. -
Method Summary
Modifier and TypeMethodDescriptionReturns the associated algorithm descriptor.voidclose()Closes the context and releases any held resources.byte[]decapsulate(byte[] ciphertext) Decapsulates a ciphertext to recover the shared secret.Encapsulates a fresh shared secret to the recipient’s public key.key()Returns the key bound to this context.
-
Constructor Details
-
FrodoKemContext
Constructs a context bound to a public key for theKeyUsage.ENCAPSULATErole.- Parameters:
algorithm- algorithm descriptor, must not benullk- Frodo public key used to encapsulate the shared secret- Throws:
NullPointerException- if any argument isnull
-
FrodoKemContext
Constructs a context bound to a private key for theKeyUsage.DECAPSULATErole.- Parameters:
algorithm- algorithm descriptor, must not benullk- Frodo private key used to decapsulate ciphertext- Throws:
NullPointerException- if any argument isnull
-
-
Method Details
-
algorithm
Returns the associated algorithm descriptor.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- algorithm instance that created this context
-
key
Returns the key bound to this context.- Specified by:
keyin interfaceCryptoContext- Returns:
- public key (for encapsulate) or private key (for decapsulate)
-
close
public void close()Closes the context and releases any held resources.For FrodoKEM this is a no-op, but the method is present for consistency with other context types.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
encapsulate
Encapsulates a fresh shared secret to the recipient’s public key.This method is only valid if the context was constructed with a public key (encapsulation role). Otherwise an
IllegalStateExceptionis thrown.A new random secret and ciphertext are generated using BouncyCastle’s FrodoKEM implementation. The ciphertext is transmitted to the recipient, while the secret is retained locally as the agreed keying material.
- Specified by:
encapsulatein interfaceKemContext- Returns:
- result containing the encapsulated ciphertext and shared secret
- Throws:
IllegalStateException- if this context is in decapsulation modeIOException- if encapsulation fails in the underlying provider
-
decapsulate
Decapsulates a ciphertext to recover the shared secret.This method is only valid if the context was constructed with a private key (decapsulation role). Otherwise an
IllegalStateExceptionis thrown.- Specified by:
decapsulatein interfaceKemContext- Parameters:
ciphertext- encapsulated keying material received from the initiator- Returns:
- the recovered shared secret
- Throws:
IllegalStateException- if this context is in encapsulation modeIOException- if decapsulation fails in the underlying provider
-