Class HybridKexBuilder
The builder supports the two practical hybrid variants:
- CLASSIC_AGREEMENT + KEM_ADAPTER (classic peer public is provided out-of-band)
- PAIR_MESSAGE + KEM_ADAPTER (classic public key is carried in the hybrid message)
The builder also supports transcript binding and optional policy enforcement before returning the context.
Usage sketch
HybridKexContext ctx = HybridKexBuilder.builder()
.profile(HybridKexProfile.defaultProfile(32))
.transcript(new HybridKexTranscript().addUtf8("suite", "X25519+MLKEM768"))
.policy(new HybridKexPolicy(128, 192, 32))
.classicAgreement()
.algorithm("Xdh").spec(XdhSpec.X25519)
.privateKey(alicePriv).peerPublic(bobPub)
.pqcKem()
.algorithm("ML-KEM").peerPublic(bobPqcPub)
.buildInitiator();
Instances are mutable and not thread-safe.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigurator for the classic leg inHybridKexBuilder.ClassicMode.CLASSIC_AGREEMENTmode.static final classConfigurator for the classic leg inHybridKexBuilder.ClassicMode.PAIR_MESSAGEmode.static final classConfigurator for the PQC leg (KEM adapter). -
Method Summary
Modifier and TypeMethodDescriptionstatic HybridKexBuilderbuilder(ZeroEchoSession session) Creates a new builder instance.Builds initiator-side context.Builds responder-side context.Selects the classic leg inHybridKexBuilder.ClassicMode.CLASSIC_AGREEMENTmode.Selects the classic leg inHybridKexBuilder.ClassicMode.PAIR_MESSAGEmode.exporterFromOkm(byte[] okm) Creates an exporter seeded from a derived OKM value.policy(HybridKexPolicy policy) Optional hybrid policy enforcement.pqcKem()Selects configuration of the post-quantum leg (KEM adapter).profile(HybridKexProfile profile) Sets the hybrid profile (HKDF salt/info/output length).transcript(HybridKexTranscript transcript) Optional transcript used to bind HKDFinfo.
-
Method Details
-
builder
Creates a new builder instance.- Parameters:
session- explicit runtime configuration- Returns:
- new builder
- Throws:
NullPointerException- ifsessionisnull
-
profile
Sets the hybrid profile (HKDF salt/info/output length).- Parameters:
profile- profile (must not be null)- Returns:
- this builder
-
transcript
Optional transcript used to bind HKDFinfo.If provided, its bytes are concatenated to the profile
hkdfInfowith a single zero byte separator. This preserves the profile label as a domain separator while incorporating handshake context.- Parameters:
transcript- transcript (may be null to clear)- Returns:
- this builder
-
policy
Optional hybrid policy enforcement.- Parameters:
policy- policy (may be null to clear)- Returns:
- this builder
-
classicAgreement
Selects the classic leg inHybridKexBuilder.ClassicMode.CLASSIC_AGREEMENTmode.In this mode, the classic peer public key is assumed to be available out-of-band (for example via a certificate, a directory, or a higher-level handshake message). The hybrid wire message therefore typically carries only the PQC payload (KEM ciphertext), while the classic leg is configured via
AgreementContext.setPeerPublic(PublicKey).Calling this method resets any previously configured
PAIR_MESSAGEinputs (classicKeyPair) to prevent ambiguous configuration.- Returns:
- classic agreement configurator
- Since:
- 1.0
-
classicPairMessage
Selects the classic leg inHybridKexBuilder.ClassicMode.PAIR_MESSAGEmode.In this mode, the classic leg is message-capable: the public key is carried as an explicit classic message (typically an SPKI encoding) and becomes part of the hybrid peer message. This enables a fully message-oriented handshake where both legs contribute to the wire payload (classic public-key message + PQC ciphertext).
Calling this method resets any previously configured
CLASSIC_AGREEMENTinputs (classicPrivateandclassicPeerPublic) to prevent ambiguous configuration.- Returns:
- classic pair-message configurator
- Since:
- 1.0
-
pqcKem
Selects configuration of the post-quantum leg (KEM adapter).The PQC leg is always treated as a message-based agreement:
- Initiator is created from the recipient's PQC
PublicKeyand produces a message (typically a ciphertext) viaMessageAgreementContext.getPeerMessage(). - Responder is created from the recipient's PQC
PrivateKeyand consumes the peer message viaMessageAgreementContext.setPeerMessage(byte[]).
- Returns:
- PQC KEM configurator
- Since:
- 1.0
- Initiator is created from the recipient's PQC
-
buildInitiator
-
buildResponder
-
exporterFromOkm
Creates an exporter seeded from a derived OKM value.- Parameters:
okm- derived OKM (for exampleHybridKexContext.deriveSecret())- Returns:
- exporter
-