Class KyberAlgorithm
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, andKYBER1024via 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 Summary
ConstructorsConstructorDescriptionProvides ML-KEM (Kyber) integration backed by the Bouncy Castle provider and registers capabilities and key builders required for KEM usage and message agreement. -
Method Summary
Modifier and TypeMethodDescriptionList<ParameterSetDescriptor<? extends AlgorithmKeySpec>> Returns the discoverable parameter sets (or parameterized templates) supported by this algorithm.Methods inherited from class AbstractCryptoAlgorithm
capabilityMethods inherited from class CryptoAlgorithm
addCapability, asymmetricKeyPairGenerator, bindContext, createContext, displayName, id, keyOperations, listCapabilities, priority, privateKeyImporter, providerName, publicKeyImporter, registerAsymmetricKeyPairGenerator, registerPrivateKeyImporter, registerPublicKeyImporter, registerSymmetricKeyGenerator, registerSymmetricKeyImporter, requiresStatefulSigning, roles, supports, symmetricKeyGenerator, symmetricKeyImporter
-
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
PublicKeyand DECAPSULATE withPrivateKey. - AGREEMENT role via
KemMessageAgreementAdapterfor initiator and responder flows, reusing the underlying KEM context. - Asymmetric key builders for
KyberKeyGenSpecgeneration 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()); - KEM roles: ENCAPSULATE with
-
-
Method Details
-
parameterSets
Description copied from class:CryptoAlgorithmReturns 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 aParameterSetDescriptor.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:
parameterSetsin classCryptoAlgorithm- Returns:
- immutable list of parameter set descriptors; never
null
-