Class SaberKemContext
java.lang.Object
zeroecho.core.alg.saber.SaberKemContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, KemContext
KEM context for SABER supporting encapsulation with a public key and
decapsulation with a private key.
A SaberKemContext is created in one of two roles:
- Encapsulator: constructed with a
PublicKey, it produces an encapsulation ciphertext and a fresh shared secret. - Decapsulator: constructed with a
PrivateKey, it derives the shared secret from a received encapsulation ciphertext.
Lifecycle and thread-safety
Instances are single-use per operation style and not thread-safe. Callers
should not share a context across threads without external synchronization.
close() is a no-op because this context maintains no stream
resources.
Usage example
// Encapsulator side
KemContext enc = new SaberKemContext(algo, recipientPublicKey);
KemContext.KemResult r = enc.encapsulate();
byte[] ciphertext = r.ciphertext();
byte[] shared = r.sharedSecret();
// Decapsulator side
KemContext dec = new SaberKemContext(algo, myPrivateKey);
byte[] shared2 = dec.decapsulate(ciphertext);
-
Nested Class Summary
Nested classes/interfaces inherited from interface KemContext
KemContext.KemResult -
Constructor Summary
ConstructorsConstructorDescriptionSaberKemContext(CryptoAlgorithm algorithm, PrivateKey k) Creates a decapsulation context bound to ourPrivateKey.SaberKemContext(CryptoAlgorithm algorithm, PublicKey k) Creates an encapsulation context bound to the recipient'sPublicKey. -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm that created this context.voidclose()Closes the context and releases resources.byte[]decapsulate(byte[] ciphertext) Performs SABER decapsulation and returns the shared secret derived fromciphertext.Performs SABER encapsulation and returns the ciphertext and shared secret.key()Returns the key bound to this context.
-
Constructor Details
-
SaberKemContext
Creates an encapsulation context bound to the recipient'sPublicKey.- Parameters:
algorithm- the owning algorithm used for metadata and provider identityk- recipient public key for SABER encapsulation- Throws:
NullPointerException- ifalgorithmorkisnull
-
SaberKemContext
Creates a decapsulation context bound to ourPrivateKey.- Parameters:
algorithm- the owning algorithm used for metadata and provider identityk- private key for SABER decapsulation- Throws:
NullPointerException- ifalgorithmorkisnull
-
-
Method Details
-
algorithm
Returns the algorithm that created this context.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- the associated
CryptoAlgorithm
-
key
Returns the key bound to this context.For encapsulation this is a
PublicKey. For decapsulation this is aPrivateKey.- Specified by:
keyin interfaceCryptoContext- Returns:
- the bound
Key
-
close
public void close()Closes the context and releases resources.This implementation holds no stream resources, so the method is a no-op.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
encapsulate
Performs SABER encapsulation and returns the ciphertext and shared secret.This method is valid only when the context was constructed with a
PublicKey. The returnedKemContext.KemResultcontains the encapsulation to transmit and the derived shared secret.- Specified by:
encapsulatein interfaceKemContext- Returns:
- a
KemContext.KemResultholding the encapsulation and shared secret - Throws:
IllegalStateException- if the context was initialized for decapsulationIOException- if the underlying SABER operation fails
-
decapsulate
Performs SABER decapsulation and returns the shared secret derived fromciphertext.This method is valid only when the context was constructed with a
PrivateKey.- Specified by:
decapsulatein interfaceKemContext- Parameters:
ciphertext- the peer's encapsulation ciphertext- Returns:
- the derived shared secret bytes
- Throws:
IllegalStateException- if the context was initialized for encapsulationIOException- if the underlying SABER operation fails or input is invalid
-