Class HqcKemContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, KemContext
HQC KEM Context
Implementation ofKemContext for the
post-quantum HQC (Hamming Quasi-Cyclic) key encapsulation mechanism.
An HqcKemContext binds an HQC key (public or private) and role
(encapsulation or decapsulation). It delegates to BouncyCastle's
HQCKEMGenerator and HQCKEMExtractor for cryptographic
operations. This context is created indirectly via HqcAlgorithm, not
by application code.
Roles
- Encapsulation: constructed with a
PublicKey. Providesencapsulate()to generate a ciphertext and shared secret. - Decapsulation: constructed with a
PrivateKey. Providesdecapsulate(byte[])to recover the shared secret from a ciphertext.
Thread-safety
Instances are not thread-safe. Each context should be used for a single encapsulation or decapsulation flow.
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface KemContext
KemContext.KemResult -
Constructor Summary
ConstructorsConstructorDescriptionHqcKemContext(CryptoAlgorithm algorithm, PrivateKey k) Constructs a decapsulation context using the recipient's private key.HqcKemContext(CryptoAlgorithm algorithm, PublicKey k) Constructs an encapsulation context using the recipient's public key. -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm that created this context.voidclose()Closes this context.byte[]decapsulate(byte[] ciphertext) Performs HQC decapsulation, recovering the shared secret from a ciphertext.Performs HQC encapsulation, generating a ciphertext and a shared secret.key()Returns the bound key (public or private) for this context.
-
Constructor Details
-
HqcKemContext
Constructs an encapsulation context using the recipient's public key.This role is for the initiator (Alice), who produces a ciphertext to send to the responder.
- Parameters:
algorithm- parent algorithm instancek- HQC public key of the recipient- Throws:
NullPointerException- if any argument isnull
-
HqcKemContext
Constructs a decapsulation context using the recipient's private key.This role is for the responder (Bob), who receives a ciphertext and recovers the shared secret.
- Parameters:
algorithm- parent algorithm instancek- HQC private key of the recipient- Throws:
NullPointerException- if any argument isnull
-
-
Method Details
-
algorithm
Returns the algorithm that created this context.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- associated
CryptoAlgorithm
-
key
Returns the bound key (public or private) for this context.- Specified by:
keyin interfaceCryptoContext- Returns:
- the underlying
Keyinstance
-
close
public void close()Closes this context. No-op for HQC, since no sensitive state is held beyond the key reference.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
encapsulate
Performs HQC encapsulation, generating a ciphertext and a shared secret.Requires that the context was constructed with a public key. On success, a
KemContext.KemResultcontaining the ciphertext and secret is returned.- Specified by:
encapsulatein interfaceKemContext- Returns:
- encapsulation result containing ciphertext and shared secret
- Throws:
IOException- if encapsulation fails due to provider errorIllegalStateException- if this context was initialized for decapsulation
-
decapsulate
Performs HQC decapsulation, recovering the shared secret from a ciphertext.Requires that the context was constructed with a private key. On success, the raw shared secret is returned.
- Specified by:
decapsulatein interfaceKemContext- Parameters:
ciphertext- the encapsulated key material produced byencapsulate()- Returns:
- the recovered shared secret
- Throws:
IOException- if decapsulation fails due to provider errorIllegalStateException- if this context was initialized for encapsulation
-