Class MLDSASignatureAlgorithm

java.lang.Object
tech.kwik.agent15.pqc.impl.MLDSASignatureAlgorithm
All Implemented Interfaces:
SignatureAlgorithm
Direct Known Subclasses:
MLDSA44SignatureAlgorithm, MLDSA65SignatureAlgorithm, MLDSA87SignatureAlgorithm

public abstract class MLDSASignatureAlgorithm extends Object implements SignatureAlgorithm
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
    Modifier
    Constructor
    Description
    protected
    MLDSASignatureAlgorithm(int publicKeyEncodedLength)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static int
    Generates a throwaway key pair for the given ML-DSA parameter set (e.g.
    boolean
    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.
    boolean
    verify(byte[] content, byte[] signature, PublicKey certificatePublicKey)
    Verifies a signature over the given content with the given public key.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MLDSASignatureAlgorithm

      protected MLDSASignatureAlgorithm(int publicKeyEncodedLength)
  • Method Details

    • sign

      public byte[] sign(byte[] content, PrivateKey certificatePrivateKey) throws InternalErrorAlert
      Description copied from interface: SignatureAlgorithm
      Signs the given content with the given private key.
      Specified by:
      sign in interface SignatureAlgorithm
      Parameters:
      content - the content to sign
      certificatePrivateKey - the private key associated with the certificate
      Returns:
      the signature
      Throws:
      InternalErrorAlert - when the private key cannot be used with this signature scheme
    • verify

      public boolean verify(byte[] content, byte[] signature, PublicKey certificatePublicKey)
      Description copied from interface: SignatureAlgorithm
      Verifies 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; use SignatureAlgorithm.keyMatchesScheme(PublicKey) for that.
      Specified by:
      verify in interface SignatureAlgorithm
      Parameters:
      content - the content that was signed
      signature - the signature to verify
      certificatePublicKey - the public key of the certificate that (supposedly) created the signature
      Returns:
      whether the signature is valid
    • keyMatchesScheme

      public boolean keyMatchesScheme(PublicKey publicKey)
      Description copied from interface: SignatureAlgorithm
      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.
      Specified by:
      keyMatchesScheme in interface SignatureAlgorithm
      Parameters:
      publicKey -
      Returns:
    • computePublicKeyEncodedLength

      protected static int computePublicKeyEncodedLength(String algorithm)
      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.