Class MldsaSignatureContext
java.lang.Object
zeroecho.core.alg.mldsa.MldsaSignatureContext
- All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, SignatureContext, TagEngine<Signature>
Streaming signature context for ML-DSA (FIPS 204).
MldsaSignatureContext adapts a JCA Signature engine for use
within the ZeroEcho streaming signature infrastructure. It supports both
signing and verification and delegates the low-level mechanics to
GenericJcaSignatureContext.
Provider and algorithm
- JCA algorithm:
"ML-DSA". - Provider:
"BC"(Bouncy Castle core provider).
Streaming contract
- SIGN: the wrapped stream emits the message body and appends a detached signature trailer at EOF.
- VERIFY: the wrapped stream emits the body only; verification is performed at EOF against a caller-supplied expected tag.
- Since:
- 1.0
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionMldsaSignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey) Creates a signing context bound to a private key.MldsaSignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey) Creates a verification context bound to a public key. -
Method Summary
Modifier and TypeMethodDescriptionReturns the parentCryptoAlgorithmassociated with this context.voidclose()Closes this context and releases any underlying resources.Returns the verification predicate core that can be used to select a mismatch handling strategy.key()Returns the key bound to this context.voidsetExpectedTag(byte[] expected) Supplies the expected signature (tag) for VERIFY mode.voidSets the verification approach used at EOF to compare the computed and expected signatures.intReturns the signature (tag) length in bytes for the parameter set in use.wrap(InputStream upstream) Wraps an input stream such that bytes read from the returned stream update the underlying signature engine.
-
Constructor Details
-
MldsaSignatureContext
public MldsaSignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey) throws GeneralSecurityException Creates a signing context bound to a private key.The produced signature length is resolved by probing the JCA engine via
GenericJcaSignatureContext.SignLengthResolver.probeWith(String, String).- Parameters:
algorithm- the parent algorithm instance; must not benullprivateKey- ML-DSA private key; must not benull- Throws:
GeneralSecurityException- if the JCA signature engine cannot be initialized
-
MldsaSignatureContext
public MldsaSignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey) throws GeneralSecurityException Creates a verification context bound to a public key.The expected signature length is derived from the public key parameter set via
MLDSAParameterSpec.getName()and canonical ML-DSA signature sizes.- Parameters:
algorithm- the parent algorithm instance; must not benullpublicKey- ML-DSA public key; must not benull- Throws:
GeneralSecurityException- if the key is invalid or the parameter set is unsupported
-
-
Method Details
-
algorithm
Returns the parentCryptoAlgorithmassociated with this context.- Specified by:
algorithmin interfaceCryptoContext- Returns:
- the algorithm instance
-
key
Returns the key bound to this context.- Specified by:
keyin interfaceCryptoContext- Returns:
- signing
PrivateKeyor verificationPublicKey
-
close
public void close()Closes this context and releases any underlying resources.Once closed, the context must not be reused.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCryptoContext
-
wrap
Wraps an input stream such that bytes read from the returned stream update the underlying signature engine.- Specified by:
wrapin interfaceTagEngine<Signature>- Parameters:
upstream- input stream providing message bytes; must not benull- Returns:
- wrapped stream that performs signing or verification as bytes are read
- Throws:
IOException- if wrapping fails
-
tagLength
-
setExpectedTag
public void setExpectedTag(byte[] expected) Supplies the expected signature (tag) for VERIFY mode.- Specified by:
setExpectedTagin interfaceTagEngine<Signature>- Parameters:
expected- expected signature bytes; must not benull
-
setVerificationApproach
public void setVerificationApproach(ThrowingBiPredicate.VerificationBiPredicate<Signature> strategy) Sets the verification approach used at EOF to compare the computed and expected signatures.- Specified by:
setVerificationApproachin interfaceTagEngine<Signature>- Parameters:
strategy- verification predicate; must not benull
-
getVerificationCore
Returns the verification predicate core that can be used to select a mismatch handling strategy.- Specified by:
getVerificationCorein interfaceTagEngine<Signature>- Returns:
- the verification predicate core
-