Class KemMessageAgreementAdapter
java.lang.Object
zeroecho.core.alg.common.agreement.KemMessageAgreementAdapter
- All Implemented Interfaces:
Closeable,AutoCloseable,AgreementContext,CryptoContext,MessageAgreementContext
Adapter: using a KEM as a message-based agreement primitive
KemMessageAgreementAdapter adapts a KemContext into a
MessageAgreementContext, making KEMs usable in higher-level protocols
that expect a two-party message agreement API.
Roles
KemMessageAgreementAdapter.Role.INITIATOR- encapsulates to a peer’s public key, producing a ciphertext (peer message) and shared secret.KemMessageAgreementAdapter.Role.RESPONDER- receives a peer message (ciphertext), decapsulates with their private key, and derives the shared secret.
Lifecycle
- Create via
KemMessageAgreementAdapter.Builderwith a boundKemContext. - Initiator calls
getPeerMessage()to obtain ciphertext to transmit. - Responder calls
setPeerMessage(byte[])with received ciphertext. - Both parties call
deriveSecret()to obtain the agreed secret.
Thread-safety
Instances are not thread-safe; synchronize externally if sharing across threads.- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forKemMessageAgreementAdapter.static enumRole of the adapter: initiator or responder. -
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying algorithm descriptor.builder()Returns a new builder for constructing aKemMessageAgreementAdapter.voidclose()Closes the underlying KEM context if it is closeable.byte[]Derives the shared secret from this exchange.byte[]Returns the ciphertext produced by encapsulation.key()Returns the key bound to the underlying KEM context.voidsetPeerMessage(byte[] message) Stores the peer’s ciphertext for decapsulation.voidsetPeerPublic(PublicKey peer) No-op for KEM-based contexts.
-
Method Details
-
builder
Returns a new builder for constructing aKemMessageAgreementAdapter.- Returns:
- builder instance
-
setPeerMessage
public void setPeerMessage(byte[] message) Stores the peer’s ciphertext for decapsulation.- Specified by:
setPeerMessagein interfaceMessageAgreementContext- Parameters:
message- ciphertext received from initiator- Throws:
IllegalStateException- if called in initiator mode
-
getPeerMessage
public byte[] getPeerMessage()Returns the ciphertext produced by encapsulation.- Specified by:
getPeerMessagein interfaceMessageAgreementContext- Returns:
- defensive copy of ciphertext to send
- Throws:
IllegalStateException- if called in responder mode
-
setPeerPublic
No-op for KEM-based contexts.Unlike Diffie–Hellman, KEMs are already bound to the correct key at construction. This method exists for interface symmetry.
- Specified by:
setPeerPublicin interfaceAgreementContext- Parameters:
peer- ignored
-
deriveSecret
public byte[] deriveSecret()Derives the shared secret from this exchange.- Specified by:
deriveSecretin interfaceAgreementContext- Returns:
- defensive copy of the derived secret
- Throws:
UncheckedIOException- if encapsulation/decapsulation fails
-
algorithm
Returns the underlying algorithm descriptor.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- algorithm bound to this adapter
-
key
Returns the key bound to the underlying KEM context.- Specified by:
keyin interfaceCryptoContext- Returns:
- encapsulation (public) or decapsulation (private) key
-
close
Closes the underlying KEM context if it is closeable.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext- Throws:
IOException- if the wrapped context fails to close
-