Class HqcKemContext

java.lang.Object
zeroecho.core.alg.hqc.HqcKemContext
All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, KemContext

public final class HqcKemContext extends Object implements KemContext

HQC KEM Context

Implementation of KemContext 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

Thread-safety

Instances are not thread-safe. Each context should be used for a single encapsulation or decapsulation flow.

Since:
1.0
  • Constructor Details

    • HqcKemContext

      public HqcKemContext(CryptoAlgorithm algorithm, PublicKey k)
      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 instance
      k - HQC public key of the recipient
      Throws:
      NullPointerException - if any argument is null
    • HqcKemContext

      public HqcKemContext(CryptoAlgorithm algorithm, PrivateKey k)
      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 instance
      k - HQC private key of the recipient
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • algorithm

      public CryptoAlgorithm algorithm()
      Returns the algorithm that created this context.
      Specified by:
      algorithm in interface CryptoContext
      Returns:
      associated CryptoAlgorithm
    • key

      public Key key()
      Returns the bound key (public or private) for this context.
      Specified by:
      key in interface CryptoContext
      Returns:
      the underlying Key instance
    • close

      public void close()
      Closes this context. No-op for HQC, since no sensitive state is held beyond the key reference.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CryptoContext
    • encapsulate

      public KemContext.KemResult encapsulate() throws IOException
      Performs HQC encapsulation, generating a ciphertext and a shared secret.

      Requires that the context was constructed with a public key. On success, a KemContext.KemResult containing the ciphertext and secret is returned.

      Specified by:
      encapsulate in interface KemContext
      Returns:
      encapsulation result containing ciphertext and shared secret
      Throws:
      IOException - if encapsulation fails due to provider error
      IllegalStateException - if this context was initialized for decapsulation
    • decapsulate

      public byte[] decapsulate(byte[] ciphertext) throws IOException
      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:
      decapsulate in interface KemContext
      Parameters:
      ciphertext - the encapsulated key material produced by encapsulate()
      Returns:
      the recovered shared secret
      Throws:
      IOException - if decapsulation fails due to provider error
      IllegalStateException - if this context was initialized for encapsulation