Class KyberAlgorithm


public final class KyberAlgorithm extends AbstractCryptoAlgorithm
Concrete CryptoAlgorithm implementation for the post-quantum key encapsulation mechanism (KEM) Kyber, standardized as ML-KEM.

Overview

Kyber provides IND-CCA2 security based on module-LWE. This implementation delegates cryptographic operations to the Bouncy Castle PQC provider and exposes Kyber through the unified CryptoAlgorithm API surface.

Declared capabilities

  • AlgorithmFamily.KEM:
    • KeyUsage.ENCAPSULATE with a PublicKey, returning a KemContext.
    • KeyUsage.DECAPSULATE with a PrivateKey, returning a KemContext.
  • AlgorithmFamily.AGREEMENT (message-based):
    • Initiator: given the recipient PublicKey, wraps a Kyber KEM context in a KemMessageAgreementAdapter to drive message agreement.
    • Responder: given the local PrivateKey, wraps a Kyber KEM context in the same adapter to decapsulate and agree the shared secret.

Key builders

  • KyberKeyGenSpec: key pair generation for variants KYBER512, KYBER768, and KYBER1024 via KeyPairGenerator configured with KyberParameterSpec.
  • KyberPublicKeySpec: import of Kyber public keys from X.509 SubjectPublicKeyInfo.
  • KyberPrivateKeySpec: import of Kyber private keys from PKCS#8 PrivateKeyInfo.

Provider dependency

All operations require the Bouncy Castle PQC provider to be present and registered in java.security.Security under the name provided by BouncyCastleProvider. The helper ensureProvider() validates availability before key generation or import.

Thread-safety

Instances of KyberAlgorithm are immutable and safe to share. Contexts created via the declared capabilities (KemContext, MessageAgreementContext) are not necessarily thread-safe.

Usage examples

// Register provider once during bootstrap:
Security.addProvider(new BouncyCastleProvider());

// Construct the algorithm:
KyberAlgorithm kyber = new KyberAlgorithm();

// Generate a Kyber-768 key pair:
KeyPair kp = kyber.asymmetricKeyPairGenerator(KyberKeyGenSpec.class)
                  .generateKeyPair(KyberKeyGenSpec.kyber768());

// Encapsulation by initiator (recipient public key known):
KemContext enc = kyber.createContext(KeyUsage.ENCAPSULATE, kp.getPublic(), VoidSpec.INSTANCE);

// Decapsulation by responder (own private key):
KemContext dec = kyber.createContext(KeyUsage.DECAPSULATE, kp.getPrivate(), VoidSpec.INSTANCE);

// Message-style agreement (initiator):
MessageAgreementContext initCtx =
    kyber.createContext(KeyUsage.AGREEMENT, kp.getPublic(), VoidSpec.INSTANCE);

// Message-style agreement (responder):
MessageAgreementContext respCtx =
    kyber.createContext(KeyUsage.AGREEMENT, kp.getPrivate(), VoidSpec.INSTANCE);
  • Constructor Details

    • KyberAlgorithm

      public KyberAlgorithm()
      Provides ML-KEM (Kyber) integration backed by the Bouncy Castle provider and registers capabilities and key builders required for KEM usage and message agreement.

      Overview

      This algorithm instance wires the following into the surrounding crypto framework:

      • KEM roles: ENCAPSULATE with PublicKey and DECAPSULATE with PrivateKey.
      • AGREEMENT role via KemMessageAgreementAdapter for initiator and responder flows, reusing the underlying KEM context.
      • Asymmetric key builders for KyberKeyGenSpec generation and X.509/PKCS#8 key import paths.

      Example

      Security.addProvider(new BouncyCastleProvider());
      KyberAlgorithm alg = new KyberAlgorithm();
      
      KeyPair kp = alg.asymmetricKeyPairGenerator(KyberKeyGenSpec.class)
                      .generateKeyPair(KyberKeyGenSpec.kyber768());
      
  • Method Details

    • parameterSets

      public List<ParameterSetDescriptor<? extends AlgorithmKeySpec>> parameterSets()
      Description copied from class: CryptoAlgorithm
      Returns the discoverable parameter sets (or parameterized templates) supported by this algorithm.

      Callers (UIs, provisioning tools, policy engines) use this list to present users with valid, named key-generation options without prior knowledge of the concrete algorithm. Each entry is either a pre-built ParameterSetDescriptor.Concrete (ready spec) or a ParameterSetDescriptor.Template (user-supplied arguments produce the spec).

      The default implementation returns an empty list. Algorithms with finite, enumerable parameter sets should override this method. Overrides must return immutable lists in stable order, with unique nonblank descriptor identifiers. Registry loading validates a snapshot; external providers remain responsible for maintaining the contract on subsequent calls. Implementations may use ParameterSetDescriptor.snapshot(List) to validate and copy their list.

      Overrides:
      parameterSets in class CryptoAlgorithm
      Returns:
      immutable list of parameter set descriptors; never null