Class XdhAlgorithm
KeyAgreement API.
This algorithm integrates the XDH family (currently X25519, optionally X448
in supporting providers) into the ZeroEcho registry. It exposes the
KeyUsage.AGREEMENT role and produces AgreementContext
instances using GenericJcaAgreementContext, which delegates to the
standard JCA KeyAgreement primitive (e.g., "XDH",
"X25519").
Behavior
- Context type:
AgreementContextconstructed as aGenericJcaAgreementContext. - Keys: Requires a local
PrivateKey; the peerPublicKeymust be supplied viaAgreementContext.setPeerPublic(java.security.PublicKey)before callingAgreementContext.deriveSecret(). - Secret material:
deriveSecret()returns the raw XDH shared secret. Protocols must apply a KDF before deriving symmetric keys or other session material. - Providers: The context uses the default JCA provider lookup unless
a provider is explicitly configured in
GenericJcaAgreementContext(this algorithm passesnull). - Default spec:
XdhSpec.X25519is used when no explicit spec is provided.
Key material and builders
- Asymmetric key pairs are generated or imported via
XdhKeyGenBuilder, parameterized byXdhSpec. - The default builder spec is
XdhSpec.X25519. - Additional asymmetric builders are registered for
XdhPublicKeySpecandXdhPrivateKeySpecto import encoded keys directly via the JCAKeyFactoryfor "XDH".
Example
// Discover the algorithm definition (via ServiceLoader or explicit construction)
CryptoAlgorithm xdh = new XdhAlgorithm();
// Generate key pairs
KeyPair a = xdh.asymmetricKeyPairGenerator(XdhSpec.class).generateKeyPair(XdhSpec.X25519);
KeyPair b = xdh.asymmetricKeyPairGenerator(XdhSpec.class).generateKeyPair(XdhSpec.X25519);
// Perform agreement on side A
AgreementContext ctxA = xdh.createContext(KeyUsage.AGREEMENT, a.getPrivate(), XdhSpec.X25519);
ctxA.setPeerPublic(b.getPublic());
byte[] secretA = ctxA.deriveSecret();
// Perform agreement on side B
AgreementContext ctxB = xdh.createContext(KeyUsage.AGREEMENT, b.getPrivate(), XdhSpec.X25519);
ctxB.setPeerPublic(a.getPublic());
byte[] secretB = ctxB.deriveSecret();
// secretA and secretB are equal; apply a KDF before using them
- Since:
- 1.0
-
Constructor Summary
Constructors -
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
-
XdhAlgorithm
public XdhAlgorithm()Creates a new XDH algorithm registration.This constructor performs the following registrations:
- Binds the
KeyUsage.AGREEMENTrole underAlgorithmFamily.AGREEMENTto produceAgreementContextinstances withPrivateKeykeys andXdhSpecspecs, backed byGenericJcaAgreementContextwith the JCA name fromXdhSpec.keyAgreementName(). - Registers the
XdhKeyGenBuilderfor key pair generation withXdhSpec, defaulting toXdhSpec.X25519. - Registers asymmetric key builders for
XdhPublicKeySpecandXdhPrivateKeySpecto allow direct key import usingKeyFactory("XDH").
The bound contexts use the platform’s default JCA provider (
provider = null). - Binds the
-
-
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
-