Class HybridValueParameterSpec

java.lang.Object
org.bouncycastle.jcajce.spec.HybridValueParameterSpec
All Implemented Interfaces:
AlgorithmParameterSpec, Destroyable

public class HybridValueParameterSpec extends Object implements 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 Details

    • HybridValueParameterSpec

      public HybridValueParameterSpec(byte[] t, AlgorithmParameterSpec baseSpec)
      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

      public HybridValueParameterSpec(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. 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

      public AlgorithmParameterSpec 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:
      isDestroyed in interface Destroyable
      Returns:
      true if destroyed, false otherwise.
    • destroy

      public void destroy()
      Destroy this parameter spec, explicitly erasing its contents.
      Specified by:
      destroy in interface Destroyable