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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -117,6 +117,14 @@ public class NamedParameterSpec implements AlgorithmParameterSpec {
public static final NamedParameterSpec ML_KEM_1024
= new NamedParameterSpec("ML-KEM-1024");

/**
* The LMS parameters
*
* @since 27
*/
public static final NamedParameterSpec LMS
= new NamedParameterSpec("LMS");

private final String name;

/**
Expand Down
87 changes: 87 additions & 0 deletions test/jdk/sun/security/provider/acvp/LMS_Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import jdk.test.lib.Asserts;
import jdk.test.lib.json.JSONValue;
import sun.security.util.RawKeySpec;

import java.security.*;

import static jdk.test.lib.Utils.toByteArray;

// JSON spec at https://pages.nist.gov/ACVP/draft-celi-acvp-lms.html
public class LMS_Test {

public static void run(JSONValue kat, Provider provider) throws Exception {

var mode = kat.get("mode").asString();
if (mode.equals("sigVer")) {
sigVerTest(kat, provider);
} else {
throw new UnsupportedOperationException("Unknown mode: " + mode);
}
}

static void sigVerTest(JSONValue kat, Provider p) throws Exception {
var s = p == null
? Signature.getInstance("HSS/LMS")
: Signature.getInstance("HSS/LMS", p);
for (var t : kat.get("testGroups").elements()) {
String pname = "HSS/LMS";
var pk = new PublicKey() {
public String getAlgorithm() { return pname; }
public String getFormat() { return "RAW"; }
// Convert to HSS key by prepending height of tree
// to the LMS public key.
public byte[] getEncoded() { return toByteArray(
"00000001" + t.get("publicKey").asString()); }
};
System.out.println(">> " + pname + " verify");

for (var c : t.get("tests").elements()) {
System.out.print(c.get("tcId").asInt() + " ");
var expected = c.get("testPassed").asBoolean();
var actual = true;

// build public key
PublicKey pk1;
RawKeySpec rks = new RawKeySpec(pk.getEncoded());
KeyFactory kf = p == null ? KeyFactory.getInstance("HSS/LMS") :
KeyFactory.getInstance("HSS/LMS", p);
pk1 = kf.generatePublic(rks);

try {
s.initVerify(pk1);
s.update(toByteArray(c.get("message").asString()));
// Convert to HSS signature by prepending
// Nspk value of 0.
actual = s.verify(toByteArray(
"00000000" + c.get("signature").asString()));
} catch (InvalidKeyException | SignatureException e) {
actual = false;
}
Asserts.assertEQ(expected, actual);
}
System.out.println();
}
}
}
7 changes: 6 additions & 1 deletion test/jdk/sun/security/provider/acvp/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -95,6 +95,7 @@ public class Launcher {
private static final String ACVP_BUNDLE_VERSION = "1.1.0.38";
// Zip archive entry name, do not update to use File.separator
private static final String[] TEST_FILES = {
"gen-val/json-files/LMS-sigVer-1.0/internalProjection.json",
"gen-val/json-files/ML-DSA-keyGen-FIPS204/internalProjection.json",
"gen-val/json-files/ML-DSA-sigGen-FIPS204/internalProjection.json",
"gen-val/json-files/ML-DSA-sigVer-FIPS204/internalProjection.json",
Expand Down Expand Up @@ -177,6 +178,10 @@ static void run(InputStream test) {
}
var alg = kat.get("algorithm").asString();
switch (alg) {
case "LMS" -> {
LMS_Test.run(kat, PROVIDER);
count++;
}
case "ML-DSA" -> {
ML_DSA_Test.run(kat, PROVIDER);
count++;
Expand Down