Class SntruPrimeAlgorithm


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

Overview

This algorithm wrapper integrates Bouncy Castle's "SNTRUPrime" 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 SntruPrimeKeyGenSpec with sntrup1277 as the default variant. Additional import builders are provided for X.509-encoded public keys and PKCS#8-encoded private keys.

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
SntruPrimeAlgorithm alg = new SntruPrimeAlgorithm();
KeyPair kp = alg.asymmetricKeyPairGenerator(SntruPrimeKeyGenSpec.class)
                .generateKeyPair(SntruPrimeKeyGenSpec.sntrup761());

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

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

    • SntruPrimeAlgorithm

      public SntruPrimeAlgorithm()
      Creates a new algorithm wrapper for SNTRU Prime 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 SntruPrimeKeyGenSpec including the default sntrup1277 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