Class XWingKemContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, KemContext
X-Wing combines X25519 (classical) and ML-KEM-768 (post-quantum) into a single hybrid KEM as specified in draft-connolly-cfrg-xwing-kem. It provides security if either component is secure.
Because there is no JCA provider binding for X-Wing in BouncyCastle 1.86,
this context uses the low-level BC API (pqc.crypto.xwing.*) directly.
The keys must therefore be instances of XWingPublicKey (encapsulate
mode) or XWingPrivateKey (decapsulate mode) as produced by
XWingAlgorithm.
Thread-safety
Instances are not thread-safe. Sequential operations in the configured role are supported while the borrowed key remains usable; no single-use guard is maintained. Closing this context does not destroy the borrowed key.
- Since:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface KemContext
KemContext.KemResult -
Constructor Summary
ConstructorsConstructorDescriptionXWingKemContext(CryptoAlgorithm algorithm, PrivateKey k) Creates a context in decapsulation role bound to the given private key.XWingKemContext(CryptoAlgorithm algorithm, PublicKey k) Creates a context in encapsulation role bound to the given public key. -
Method Summary
Modifier and TypeMethodDescriptionReturns the algorithm that created this context.voidclose()Completes the context's implementation-specific cleanup.byte[]decapsulate(byte[] ciphertext) Decapsulates an X-Wing ciphertext using the bound private key.Encapsulates a fresh shared secret to the recipient's X-Wing public key.key()Returns the key bound to this context.
-
Constructor Details
-
XWingKemContext
Creates a context in encapsulation role bound to the given public key.- Parameters:
algorithm- the owning algorithm instance; must not benullk- anXWingPublicKey; must not benull- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- if the key is not an imported or generated X-Wing public key
-
XWingKemContext
Creates a context in decapsulation role bound to the given private key.- Parameters:
algorithm- the owning algorithm instance; must not benullk- anXWingPrivateKey; must not benull- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- if the key is not an imported or generated X-Wing private keyIllegalStateException- if the private key was destroyed
-
-
Method Details
-
algorithm
Description copied from interface:CryptoContextReturns the algorithm that created this context.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- the algorithm definition that owns this context
-
key
Description copied from interface:CryptoContextReturns the key bound to this context.For unkeyed contexts such as digests, this may be
NullKey.INSTANCE.- Specified by:
keyin interfaceCryptoContext- Returns:
- the cryptographic key or sentinel bound to this context
-
close
public void close()Description copied from interface:CryptoContextCompletes the context's implementation-specific cleanup.Implementations release resources they explicitly own; cleanup can be a no-op for contexts holding only borrowed or garbage-collected state. The bound key remains caller-owned: closing a context never destroys the key. Callers that own a destroyable key must destroy it explicitly after all contexts and other consumers have released it. Streams returned by the context have independent lifecycles: callers must complete and close those streams before closing the context. This method does not promise to finalize stream output or verify authentication tags.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
encapsulate
Encapsulates a fresh shared secret to the recipient's X-Wing public key.- Specified by:
encapsulatein interfaceKemContext- Returns:
- ciphertext and shared secret
- Throws:
IllegalStateException- if this context is in decapsulation modeIOException- if encapsulation fails
-
decapsulate
Decapsulates an X-Wing ciphertext using the bound private key.- Specified by:
decapsulatein interfaceKemContext- Parameters:
ciphertext- the encapsulated bytes produced by the peer'sencapsulate()call- Returns:
- the recovered shared secret
- Throws:
IllegalStateException- if this context is in encapsulation modeIOException- if decapsulation failsIllegalArgumentException- if the ciphertext is null or not exactly 1120 bytes
-