Class BikeKemContext

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

public final class BikeKemContext extends Object implements KemContext

BIKE Key Encapsulation Mechanism context

Implements KemContext for the BIKE (Bit Flipping Key Encapsulation) post-quantum algorithm. Encapsulation and decapsulation flows are separated by constructor:
  • Construct with a PublicKey to create an encapsulation context.
  • Construct with a PrivateKey to create a decapsulation context.

Usage

BikeKemContext enc = new BikeKemContext(algo, recipientPubKey);
KemResult r = enc.encapsulate();

BikeKemContext dec = new BikeKemContext(algo, myPrivateKey);
byte[] secret = dec.decapsulate(r.ciphertext());
Since:
1.0
  • Constructor Details

    • BikeKemContext

      public BikeKemContext(CryptoAlgorithm algorithm, PublicKey k)
      Creates an encapsulation context bound to the recipient's public key.
      Parameters:
      algorithm - parent algorithm instance
      k - recipient's public key
      Throws:
      NullPointerException - if any argument is null
    • BikeKemContext

      public BikeKemContext(CryptoAlgorithm algorithm, PrivateKey k)
      Creates a decapsulation context bound to the holder's private key.
      Parameters:
      algorithm - parent algorithm instance
      k - private key for decapsulation
      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:
      parent algorithm
    • key

      public Key key()
      Returns the underlying key bound to this context.
      Specified by:
      key in interface CryptoContext
      Returns:
      public or private key depending on mode
    • close

      public void close()
      Releases resources associated with this context.

      No-op for BIKE; provided for API symmetry.

      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
      Generates a new shared secret and ciphertext using the recipient's public key.
      Specified by:
      encapsulate in interface KemContext
      Returns:
      encapsulation result containing ciphertext and shared secret
      Throws:
      IOException - if encapsulation fails
      IllegalStateException - if this context is not initialized for encapsulation
    • decapsulate

      public byte[] decapsulate(byte[] ciphertext) throws IOException
      Recovers the shared secret from a ciphertext using the holder's private key.
      Specified by:
      decapsulate in interface KemContext
      Parameters:
      ciphertext - encapsulated key material
      Returns:
      recovered shared secret bytes
      Throws:
      IOException - if decapsulation fails
      IllegalStateException - if this context is not initialized for decapsulation