Class FrodoKemContext

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

public final class FrodoKemContext extends Object implements KemContext

FrodoKEM runtime context

Implementation of KemContext for the Frodo post-quantum key encapsulation mechanism (KEM).

A FrodoKemContext is a lightweight binding of:

  • a CryptoAlgorithm descriptor,
  • 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
  • Constructor Details

    • FrodoKemContext

      public FrodoKemContext(CryptoAlgorithm algorithm, PublicKey k)
      Constructs a context bound to a public key for the KeyUsage.ENCAPSULATE role.
      Parameters:
      algorithm - algorithm descriptor, must not be null
      k - Frodo public key used to encapsulate the shared secret
      Throws:
      NullPointerException - if any argument is null
    • FrodoKemContext

      public FrodoKemContext(CryptoAlgorithm algorithm, PrivateKey k)
      Constructs a context bound to a private key for the KeyUsage.DECAPSULATE role.
      Parameters:
      algorithm - algorithm descriptor, must not be null
      k - Frodo private key used to decapsulate ciphertext
      Throws:
      NullPointerException - if any argument is null
  • Method Details

    • algorithm

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

      public Key key()
      Returns the key bound to this context.
      Specified by:
      key in interface CryptoContext
      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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CryptoContext
    • encapsulate

      public KemContext.KemResult encapsulate() throws IOException
      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 IllegalStateException is 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:
      encapsulate in interface KemContext
      Returns:
      result containing the encapsulated ciphertext and shared secret
      Throws:
      IllegalStateException - if this context is in decapsulation mode
      IOException - if encapsulation fails in the underlying provider
    • decapsulate

      public byte[] decapsulate(byte[] ciphertext) throws IOException
      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 IllegalStateException is thrown.

      Specified by:
      decapsulate in interface KemContext
      Parameters:
      ciphertext - encapsulated keying material received from the initiator
      Returns:
      the recovered shared secret
      Throws:
      IllegalStateException - if this context is in encapsulation mode
      IOException - if decapsulation fails in the underlying provider