Class NtrulPrimeAlgorithm


public final class NtrulPrimeAlgorithm extends AbstractCryptoAlgorithm
Configures and exposes the NTRU LPRime post-quantum KEM and a message-agreement adapter backed by the Bouncy Castle PQC provider.

Overview

This algorithm wrapper wires Bouncy Castle's "NTRULPRime" implementation into the ZeroEcho capability model. It registers two KEM capabilities (encapsulation and decapsulation) and maps them to an agreement-style API via a lightweight adapter so that callers can use a single MessageAgreementContext for both initiator and responder roles.

Capabilities

  • AlgorithmFamily.KEM / KeyUsage.ENCAPSULATE - creates a KemContext bound to a recipient public key.
  • AlgorithmFamily.KEM / KeyUsage.DECAPSULATE - creates a KemContext bound to a holder's private key.
  • AlgorithmFamily.AGREEMENT / KeyUsage.AGREEMENT - provides a MessageAgreementContext that delegates to a KemContext for initiator and responder roles.

Key material

A default asymmetric key builder is registered for NtrulPrimeKeyGenSpec with ntrulpr1277 as the default variant. Additional import builders are provided for X.509-encoded public keys and PKCS#8-encoded private keys of the same algorithm.

Provider requirements

All key operations rely on BouncyCastlePQCProvider. The provider must be installed in the current JVM before use, otherwise key generation and import will fail with a NoSuchProviderException. See ensureProvider().

Example

// Initialize the algorithm and generate a key pair
NtrulPrimeAlgorithm alg = new NtrulPrimeAlgorithm();
KeyPair kp = alg.asymmetricKeyPairGenerator(NtrulPrimeKeyGenSpec.class)
                .generateKeyPair(NtrulPrimeKeyGenSpec.ntrulpr761());

// Initiator (Alice) encapsulates to Bob's public key
MessageAgreementContext alice =
    alg.createContext(KeyUsage.AGREEMENT, kp.getPublic(), VoidSpec.INSTANCE);

// Responder (Bob) decapsulates with his private key
MessageAgreementContext bob =
    alg.createContext(KeyUsage.AGREEMENT, kp.getPrivate(), VoidSpec.INSTANCE);
See Also:
  • Constructor Details

    • NtrulPrimeAlgorithm

      public NtrulPrimeAlgorithm()
      Creates a new algorithm wrapper for NTRU LPRime and registers its KEM and agreement capabilities, together with key builders for generation and import.

      The constructor:

      • Declares the algorithm names used by the provider.
      • Registers KEM encapsulation and decapsulation capabilities.
      • Registers agreement capabilities that delegate to a KEM-based adapter.
      • Registers an asymmetric key builder for NtrulPrimeKeyGenSpec including the default variant.
      • Registers import builders for X.509 public keys and PKCS#8 private keys.
  • 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