Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,12 @@
<version>${bcprov.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>${bcprov.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract class AbstractDOMSignatureMethod extends DOMStructure
implements SignatureMethod {

// denotes the type of signature algorithm
enum Type { DSA, RSA, ECDSA, EDDSA, HMAC }
enum Type { DSA, RSA, ECDSA, EDDSA, MLDSA, HMAC }

/**
* Verifies the passed-in signature with the specified key, using the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public abstract class DOMSignatureMethod extends AbstractDOMSignatureMethod {
"http://www.w3.org/2021/04/xmldsig-more#eddsa-ed25519";
static final String ED448 =
"http://www.w3.org/2021/04/xmldsig-more#eddsa-ed448";

// Provisional URIs for ML-DSA (FIPS 204) per draft-eastlake-rfc9231bis-xmlsec-uris
// section 3.3.15. These use the draft's "tbd" placeholder namespace and will need
// to be updated once final URIs are assigned (see SANTUARIO-634).
static final String ML_DSA_44 =
"http://www.w3.org/tbd#ml-dsa-44";
static final String ML_DSA_65 =
"http://www.w3.org/tbd#ml-dsa-65";
static final String ML_DSA_87 =
"http://www.w3.org/tbd#ml-dsa-87";
static final String ECDSA_SHA3_224 =
"http://www.w3.org/2021/04/xmldsig-more#ecdsa-sha3-224";
static final String ECDSA_SHA3_256 =
Expand Down Expand Up @@ -269,6 +279,12 @@ static SignatureMethod unmarshal(Element smElem) throws MarshalException {
return new EDDSA_ED25519(smElem);
} else if (alg.equals(ED448)) {
return new EDDSA_ED448(smElem);
} else if (alg.equals(ML_DSA_44)) {
return new MLDSA_44(smElem);
} else if (alg.equals(ML_DSA_65)) {
return new MLDSA_65(smElem);
} else if (alg.equals(ML_DSA_87)) {
return new MLDSA_87(smElem);
} else {
throw new MarshalException
("unsupported SignatureMethod algorithm: " + alg);
Expand Down Expand Up @@ -1291,4 +1307,87 @@ String getJCAAlgorithm() {
return "Ed448";
}
}

abstract static class AbstractMLDSASignatureMethod extends DOMSignatureMethod {

AbstractMLDSASignatureMethod(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
super(params);
}

AbstractMLDSASignatureMethod(Element dmElem) throws MarshalException {
super(dmElem);
}

/** ML-DSA signatures are raw bytes; no reformatting needed. */
@Override
byte[] postSignFormat(Key key, byte[] sig) {
return sig;
}

/** ML-DSA signatures are raw bytes; no reformatting needed. */
@Override
byte[] preVerifyFormat(Key key, byte[] sig) {
return sig;
}

@Override
Type getAlgorithmType() {
return Type.MLDSA;
}
}

static final class MLDSA_44 extends AbstractMLDSASignatureMethod {
MLDSA_44(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
super(params);
}
MLDSA_44(Element dmElem) throws MarshalException {
super(dmElem);
}
@Override
public String getAlgorithm() {
return ML_DSA_44;
}
@Override
String getJCAAlgorithm() {
return "ML-DSA-44";
}
}

static final class MLDSA_65 extends AbstractMLDSASignatureMethod {
MLDSA_65(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
super(params);
}
MLDSA_65(Element dmElem) throws MarshalException {
super(dmElem);
}
@Override
public String getAlgorithm() {
return ML_DSA_65;
}
@Override
String getJCAAlgorithm() {
return "ML-DSA-65";
}
}

static final class MLDSA_87 extends AbstractMLDSASignatureMethod {
MLDSA_87(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
super(params);
}
MLDSA_87(Element dmElem) throws MarshalException {
super(dmElem);
}
@Override
public String getAlgorithm() {
return ML_DSA_87;
}
@Override
String getJCAAlgorithm() {
return "ML-DSA-87";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,13 @@ public SignatureMethod newSignatureMethod(String algorithm,
return new DOMSignatureMethod.EDDSA_ED25519(params);
} else if (algorithm.equals(DOMSignatureMethod.ED448)) {
return new DOMSignatureMethod.EDDSA_ED448(params);
}else {
} else if (algorithm.equals(DOMSignatureMethod.ML_DSA_44)) {
return new DOMSignatureMethod.MLDSA_44(params);
} else if (algorithm.equals(DOMSignatureMethod.ML_DSA_65)) {
return new DOMSignatureMethod.MLDSA_65(params);
} else if (algorithm.equals(DOMSignatureMethod.ML_DSA_87)) {
return new DOMSignatureMethod.MLDSA_87(params);
} else {
throw new NoSuchAlgorithmException("unsupported algorithm");
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/apache/xml/security/algorithms/JCEMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.signature.XMLSignature;
import org.apache.xml.security.utils.EncryptionConstants;
import org.apache.xml.security.utils.JavaUtils;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -233,6 +234,18 @@ public static void registerDefaultAlgorithms() {
XMLSignature.ALGO_ID_SIGNATURE_EDDSA_ED448,
new Algorithm("Ed448", "Ed448", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_44,
new Algorithm("ML-DSA-44", "ML-DSA-44", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_65,
new Algorithm("ML-DSA-65", "ML-DSA-65", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_87,
new Algorithm("ML-DSA-87", "ML-DSA-87", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5,
new Algorithm("", "HmacMD5", "Mac", 0, 0)
Expand Down Expand Up @@ -318,6 +331,22 @@ public static void registerDefaultAlgorithms() {
XMLCipher.RSA_OAEP_11,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put(
EncryptionConstants.ALGO_ID_KEYTRANSPORT_MLKEM_512,
new Algorithm("ML-KEM-512", "ML-KEM-512", "KeyTransport")
);
algorithmsMap.put(
EncryptionConstants.ALGO_ID_KEYTRANSPORT_MLKEM_768,
new Algorithm("ML-KEM-768", "ML-KEM-768", "KeyTransport")
);
algorithmsMap.put(
EncryptionConstants.ALGO_ID_KEYTRANSPORT_MLKEM_1024,
new Algorithm("ML-KEM-1024", "ML-KEM-1024", "KeyTransport")
);
algorithmsMap.put(
EncryptionConstants.ALGO_ID_KEYTRANSPORT_GENERIC_HYBRID,
new Algorithm("", "", "KeyTransport")
);
algorithmsMap.put(
XMLCipher.DIFFIE_HELLMAN,
new Algorithm("", "", "KeyAgreement")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.xml.security.algorithms.implementations.SignatureDSA;
import org.apache.xml.security.algorithms.implementations.SignatureECDSA;
import org.apache.xml.security.algorithms.implementations.SignatureEDDSA;
import org.apache.xml.security.algorithms.implementations.SignatureMLDSA;
import org.apache.xml.security.exceptions.AlgorithmAlreadyRegisteredException;
import org.apache.xml.security.exceptions.XMLSecurityException;
import org.apache.xml.security.signature.XMLSignature;
Expand Down Expand Up @@ -513,6 +514,15 @@ public static void registerDefaultAlgorithms() {
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_EDDSA_ED448, SignatureEDDSA.SignatureEd448.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_44, SignatureMLDSA.SignatureMLDSA44.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_65, SignatureMLDSA.SignatureMLDSA65.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_MLDSA_87, SignatureMLDSA.SignatureMLDSA87.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, IntegrityHmac.IntegrityHmacMD5.class
);
Expand Down
Loading
Loading