Interface KemContext
- All Superinterfaces:
AutoCloseable, Closeable, CryptoContext
- All Known Implementing Classes:
BikeKemContext, CmceKemContext, FrodoKemContext, HqcKemContext, KyberKemContext, NtruKemContext, NtrulPrimeKemContext, SaberKemContext, SntruPrimeKemContext, XWingKemContext
Context for performing key encapsulation and decapsulation (KEM) operations.
A KemContext encapsulates the state for algorithms that exchange
shared secrets using asymmetric primitives. KEMs are widely used in
post-quantum cryptography and hybrid key exchange protocols.
Lifecycle
- Create a context via
ZeroEchoSession#createContext(...)for theKeyUsage.ENCAPSULATEorKeyUsage.DECAPSULATErole. - Call
encapsulate()when acting as an initiator. The result includes both the ciphertext to send and the derived shared secret. - Call
decapsulate(byte[])when acting as a responder, supplying the received ciphertext to recover the same shared secret. - Dispose of the context with
CryptoContext.close()to release resources.
Security considerations
- The shared secret must be immediately fed into a key-derivation function (KDF). Applications should zeroize the byte array after use.
- Structural ciphertext validation is algorithm-specific. KEMs with implicit rejection may return a pseudorandom secret for an invalid, correctly sized ciphertext; a returned secret does not authenticate the peer.
- Contexts are not guaranteed to be thread-safe; use one instance per flow.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classEncapsulation result holding both ciphertext and shared secret. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decapsulate(byte[] ciphertext) Performs decapsulation of the given ciphertext to recover the shared secret.Performs encapsulation, generating both the encapsulated ciphertext and the derived shared secret.Methods inherited from interface CryptoContext
algorithm, close, key
-
Method Details
-
encapsulate
Performs encapsulation, generating both the encapsulated ciphertext and the derived shared secret.- Returns:
- a
KemContext.KemResultcontaining the ciphertext to transmit and the raw shared secret - Throws:
IOException- if encapsulation fails or the provider encounters an error
-
decapsulate
Performs decapsulation of the given ciphertext to recover the shared secret.- Parameters:
ciphertext- the peer’s encapsulation ciphertext- Returns:
- a new byte array containing the raw shared secret
- Throws:
IOException- if decapsulation fails or the input is invalid
-