Class XmssSignatureContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, SignatureContext, TagEngine<Signature>
XMSS is a stateful hash-based signature scheme standardized in RFC 8391. Unlike SLH-DSA/SPHINCS+, XMSS maintains a leaf index in the private key and each signing operation advances that index irreversibly.
This generic context cannot sign; freshly enrolled keys may use
StatefulSigner. Private-key construction fails before provider initialization or
signature-size discovery and never consumes a leaf. Verification remains available.
Usage — verification
XmssSignatureContext vctx = new XmssSignatureContext(alg, publicKey);
vctx.setExpectedTag(signature);
try (InputStream in = vctx.wrap(bodyWithoutTrailer)) {
in.transferTo(OutputStream.nullOutputStream());
}
Signature length formula
For a digest output length of n bytes and tree height h:
- n = 32 (SHA-256 / SHAKE-128):
sig_len = 4 + 32 * (68 + h) - n = 64 (SHA-512 / SHAKE-256):
sig_len = 4 + 64 * (132 + h)
The values 68 = 1 + 67 (index + WOTS+ p) and 132 = 1 + 131 reflect the Winternitz parameter counts p for w = 16 (the value used in the BC implementation for these parameter sets).
Thread-safety
Instances are stateful and not thread-safe. Use one instance per signing or verification operation.
- Since:
- 1.0
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionXmssSignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey) Rejects XMSS signing without using or changing the private key.XmssSignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey) Creates an XMSS verification context 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.Returns the current verification approach.key()Returns the key bound to this context.voidsetExpectedTag(byte[] expected) Supplies the expected tag for verify mode.voidSets the verification approach used to compare computed and expected tags.intReturns the fixed length in bytes of the final authentication tag.wrap(InputStream upstream) Wraps the given upstream stream with a filtering stream that both passes bytes through and updates the tag engine state.
-
Constructor Details
-
XmssSignatureContext
public XmssSignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey) throws GeneralSecurityException Rejects XMSS signing without using or changing the private key.- Parameters:
algorithm- owning algorithm descriptorprivateKey- private key- Throws:
UnsupportedRoleException- always; use the explicit durable capabilityGeneralSecurityException- retained for source compatibility
-
XmssSignatureContext
public XmssSignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey) throws GeneralSecurityException Creates an XMSS verification context bound to the given public key.The expected signature length is derived from key parameters without any signing operation.
- Parameters:
algorithm- owning algorithm descriptor; must not benullpublicKey- an XMSS public key (XMSSKey); must not benull- Throws:
GeneralSecurityException- if the key type is unrecognized or the JCA engine cannot be initialized
-
-
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
-
wrap
Description copied from interface:TagEngineWraps the given upstream stream with a filtering stream that both passes bytes through and updates the tag engine state.In produce mode, the wrapper emits the original data followed by the generated tag trailer when EOF is reached. In verify mode, the wrapper validates the expected tag either immediately or at EOF, depending on the engine and the configured verification approach.
- Specified by:
wrapin interfaceTagEngine<Signature>- Parameters:
upstream- source of plaintext or ciphertext; must not benull- Returns:
- a new stream that applies tag computation or verification
- Throws:
IOException- if wrapping fails or the engine cannot allocate required resources
-
tagLength
public int tagLength()Description copied from interface:TagEngineReturns the fixed length in bytes of the final authentication tag.Higher layers use this value to strip or append trailers during stream processing.
-
setExpectedTag
public void setExpectedTag(byte[] expected) Description copied from interface:TagEngineSupplies the expected tag for verify mode.Engines may verify immediately if the computed tag is already known, or they may defer verification until EOF. This method is invoked at most once per wrapped stream.
The default implementation throws
UnsupportedOperationException. Engines that support verification must override this method.- Specified by:
setExpectedTagin interfaceTagEngine<Signature>- Parameters:
expected- expected tag value; implementations may defensively copy this array
-
setVerificationApproach
public void setVerificationApproach(ThrowingBiPredicate.VerificationBiPredicate<Signature> strategy) Description copied from interface:TagEngineSets the verification approach used to compare computed and expected tags.Typical implementations will default to a constant-time comparison for
byte[]values. Callers may replace or decorate the strategy, for example withThrowingBiPredicate.VerificationBiPredicate.getThrowOnMismatch()to raise an exception on mismatch, orThrowingBiPredicate.VerificationBiPredicate.getFlagOkInCtx(conflux.CtxInterface, conflux.Key)to record the outcome in a context.- Specified by:
setVerificationApproachin interfaceTagEngine<Signature>- Parameters:
strategy- the verification predicate to use; must not benull
-
getVerificationCore
Description copied from interface:TagEngineReturns the current verification approach.- Specified by:
getVerificationCorein interfaceTagEngine<Signature>- Returns:
- the verification predicate in use; never
nullafter initialization
-