Class HybridValueParameterSpec
java.lang.Object
org.bouncycastle.jcajce.spec.HybridValueParameterSpec
- All Implemented Interfaces:
AlgorithmParameterSpec, Destroyable
Parameter spec for the SP 800-56C Rev. 2 "hybrid" shared secret: the secret a
KeyAgreement derives keys from becomes Z' = Z || T, where Z is the agreement's own
shared secret and T is a secret established by some other scheme (SP 800-56C Rev. 2, Section
2). NIST IR 8547, Section 3.2.1, names this generic composite as the way to combine a
classical key agreement with a post-quantum KEM during the transition to post-quantum
cryptography: T can be the shared secret of an ML-KEM encapsulation, and the result stays
secure while either component does.
The spec is accepted by every DH, ECDH and XDH KeyAgreement of the BC provider that
applies a KDF (the "...withSHA256KDF", "...withSHA256CKDF", "...withSHA256HKDF" and similar
services): KeyAgreement.init(key, spec) then generateSecret(...) derives the
keying material from Z' rather than Z, and the base spec supplies what the KDF would otherwise
have been given (for example a UserKeyingMaterialSpec). By default T is appended; with
doPrepend set the spec calculates Z' = T || Z instead, which NIST IR 8547 states will
also be allowed. The two orders give different keys, so the order is part of the protocol
being implemented and both parties must fix it in advance.
// T from an ML-KEM encapsulation, Z from X25519
KeyAgreement agreement = KeyAgreement.getInstance("X25519withSHA256HKDF", "BC");
agreement.init(ourX25519Key, new HybridValueParameterSpec(mlkemSharedSecret, new UserKeyingMaterialSpec(ukm)));
agreement.doPhase(theirX25519Key, true);
SecretKey key = agreement.generateSecret("AES[256]");
Get methods throw IllegalStateException if destroy() is called.
-
Constructor Summary
ConstructorsConstructorDescriptionHybridValueParameterSpec(byte[] t, boolean doPrepend, AlgorithmParameterSpec baseSpec) Create a spec with T set to t and the spec for the KDF in the agreement to baseSpec, choosing which side of Z the value T goes on.HybridValueParameterSpec(byte[] t, AlgorithmParameterSpec baseSpec) Create a spec with T set to t and the spec for the KDF in the agreement to baseSpec. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Destroy this parameter spec, explicitly erasing its contents.Return the base parameter spec.byte[]getT()Return a reference to the T value.booleanReturn true if the destroy() method is called and the contents are erased.booleanReturn whether or not T should be prepended.
-
Constructor Details
-
HybridValueParameterSpec
Create a spec with T set to t and the spec for the KDF in the agreement to baseSpec. Note: the t value is not copied.- Parameters:
t- a shared secret to be concatenated with the agreement's Z value.baseSpec- the base spec for the agreements KDF.
-
HybridValueParameterSpec
Create a spec with T set to t and the spec for the KDF in the agreement to baseSpec, choosing which side of Z the value T goes on. Note: the t value is not copied.- Parameters:
t- a shared secret to be concatenated with the agreement's Z value.doPrepend- true to derive from T || Z, false to derive from Z || T.baseSpec- the base spec for the agreements KDF.
-
-
Method Details
-
isPrependedT
public boolean isPrependedT()Return whether or not T should be prepended.- Returns:
- true if T to be prepended, false otherwise.
-
getT
public byte[] getT()Return a reference to the T value.- Returns:
- a reference to T.
-
getBaseParameterSpec
Return the base parameter spec.- Returns:
- base spec to be applied to the KDF.
-
isDestroyed
public boolean isDestroyed()Return true if the destroy() method is called and the contents are erased.- Specified by:
isDestroyedin interfaceDestroyable- Returns:
- true if destroyed, false otherwise.
-
destroy
public void destroy()Destroy this parameter spec, explicitly erasing its contents.- Specified by:
destroyin interfaceDestroyable
-