Class MLDSASignatureAlgorithm
java.lang.Object
tech.kwik.agent15.pqc.impl.MLDSASignatureAlgorithm
- All Implemented Interfaces:
SignatureAlgorithm
- Direct Known Subclasses:
MLDSA44SignatureAlgorithm, MLDSA65SignatureAlgorithm, MLDSA87SignatureAlgorithm
ML-DSA (FIPS 204), the post-quantum signature scheme
underlying the mldsa44/mldsa65/mldsa87 TLS signature schemes.
Unlike RSA-PSS/ECDSA, a single JCA algorithm name ("ML-DSA") handles signing and verifying for all three
parameter sets; the parameter set is carried by the key itself. So the only thing that differs per subclass is
keyMatchesScheme(PublicKey), which needs a way to tell an ML-DSA-44 key from an ML-DSA-65 or ML-DSA-87 one: the JDK's
getAlgorithm() reports "ML-DSA" for all three, but each parameter set's public key has a distinct, fixed
X.509-encoded length, which is what subclasses pass in here.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static intcomputePublicKeyEncodedLength(String algorithm) Generates a throwaway key pair for the given ML-DSA parameter set (e.g.booleankeyMatchesScheme(PublicKey publicKey) Checks whether the given public key can be used with this signature scheme; for EC keys this includes checking that the key's curve is the one the scheme requires.byte[]sign(byte[] content, PrivateKey certificatePrivateKey) Signs the given content with the given private key.booleanVerifies a signature over the given content with the given public key.
-
Constructor Details
-
MLDSASignatureAlgorithm
protected MLDSASignatureAlgorithm(int publicKeyEncodedLength)
-
-
Method Details
-
sign
Description copied from interface:SignatureAlgorithmSigns the given content with the given private key.- Specified by:
signin interfaceSignatureAlgorithm- Parameters:
content- the content to signcertificatePrivateKey- the private key associated with the certificate- Returns:
- the signature
- Throws:
InternalErrorAlert- when the private key cannot be used with this signature scheme
-
verify
Description copied from interface:SignatureAlgorithmVerifies a signature over the given content with the given public key. Note that this does not check that the public key matches this signature scheme; useSignatureAlgorithm.keyMatchesScheme(PublicKey)for that.- Specified by:
verifyin interfaceSignatureAlgorithm- Parameters:
content- the content that was signedsignature- the signature to verifycertificatePublicKey- the public key of the certificate that (supposedly) created the signature- Returns:
- whether the signature is valid
-
keyMatchesScheme
Description copied from interface:SignatureAlgorithmChecks whether the given public key can be used with this signature scheme; for EC keys this includes checking that the key's curve is the one the scheme requires.- Specified by:
keyMatchesSchemein interfaceSignatureAlgorithm- Parameters:
publicKey-- Returns:
-
computePublicKeyEncodedLength
Generates a throwaway key pair for the given ML-DSA parameter set (e.g. "ML-DSA-65") and returns its public key's X.509-encoded length, so subclasses don't have to hardcode a JDK/ASN.1-derived number.
-