Skip to content

Commit

Permalink
typos, long lines, method renames, no more data/README
Browse files Browse the repository at this point in the history
  • Loading branch information
wangweij committed Nov 8, 2024
1 parent a7e2287 commit 34f9f8a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions test/jdk/sun/security/provider/acvp/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
/// The files are either put into the `data` directory or another
/// directory specified by the `test.acvp.data` test property.
/// The test walks through the directory recursively and looks for
/// file names equals to or ending with `internalProjection.json` and
/// runs test on them.
/// file names equal to or ending with `internalProjection.json` and
/// runs tests on them.
///
/// Set the `test.acvp.alg` test property to only test this algorithm.
/// Set the `test.acvp.alg` test property to only test the specified algorithm.
///
/// Sample files can be downloaded from
/// [https://github.com/usnistgov/ACVP-Server/tree/master/gen-val/json-files].
///
/// By default, the test uses system-preferred implementations.
/// If you want to test on a specific provider, set the
/// If you want to test a specific provider, set the
/// `test.acvp.provider` test property. The provider must be
/// registered.
///
Expand Down
18 changes: 10 additions & 8 deletions test/jdk/sun/security/provider/acvp/ML_DSA_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public class ML_DSA_Test {
public static void run(JSONValue kat, Provider provider) throws Exception {
var mode = kat.get("mode").asString();
switch (mode) {
case "keyGen" -> mldsaGen(kat, provider);
case "sigGen" -> mldsaSign(kat, provider);
case "sigVer" -> mldsaVerify(kat, provider);
case "keyGen" -> keyGenTest(kat, provider);
case "sigGen" -> sigGenTest(kat, provider);
case "sigVer" -> sigVerTest(kat, provider);
default -> throw new UnsupportedOperationException("Unknown mode: " + mode);
}
}

static void mldsaGen(JSONValue kat, Provider p) throws Exception {
static void keyGenTest(JSONValue kat, Provider p) throws Exception {
var g = p == null
? KeyPairGenerator.getInstance("ML-DSA")
: KeyPairGenerator.getInstance("ML-DSA", p);
Expand All @@ -67,7 +67,7 @@ static void mldsaGen(JSONValue kat, Provider p) throws Exception {
}
}

static void mldsaSign(JSONValue kat, Provider p) throws Exception {
static void sigGenTest(JSONValue kat, Provider p) throws Exception {
var s = p == null
? Signature.getInstance("ML-DSA")
: Signature.getInstance("ML-DSA", p);
Expand All @@ -82,17 +82,19 @@ static void mldsaSign(JSONValue kat, Provider p) throws Exception {
public String getFormat() { return "RAW"; }
public byte[] getEncoded() { return toByteArray(c.get("sk").asString()); }
};
var sr = new FixedSecureRandom(det ? new byte[32] : toByteArray(c.get("rnd").asString()));
var sr = new FixedSecureRandom(
det ? new byte[32] : toByteArray(c.get("rnd").asString()));
s.initSign(sk, sr);
s.update(toByteArray(c.get("message").asString()));
var sig = s.sign();
Asserts.assertEqualsByteArray(sig, toByteArray(c.get("signature").asString()));
Asserts.assertEqualsByteArray(
sig, toByteArray(c.get("signature").asString()));
}
System.out.println();
}
}

static void mldsaVerify(JSONValue kat, Provider p) throws Exception {
static void sigVerTest(JSONValue kat, Provider p) throws Exception {
var s = p == null
? Signature.getInstance("ML-DSA")
: Signature.getInstance("ML-DSA", p);
Expand Down
11 changes: 6 additions & 5 deletions test/jdk/sun/security/provider/acvp/ML_KEM_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public class ML_KEM_Test {
public static void run(JSONValue kat, Provider provider) throws Exception {
var mode = kat.get("mode").asString();
switch (mode) {
case "keyGen" -> mlkemGen(kat, provider);
case "encapDecap" -> mlkemEnc(kat, provider);
case "keyGen" -> keyGenTest(kat, provider);
case "encapDecap" -> encapDecapTest(kat, provider);
default -> throw new UnsupportedOperationException("Unknown mode: " + mode);
}
}

static void mlkemGen(JSONValue kat, Provider p) throws Exception {
static void keyGenTest(JSONValue kat, Provider p) throws Exception {
var g = p == null
? KeyPairGenerator.getInstance("ML-KEM")
: KeyPairGenerator.getInstance("ML-KEM", p);
Expand All @@ -68,7 +68,7 @@ static void mlkemGen(JSONValue kat, Provider p) throws Exception {
}
}

static void mlkemEnc(JSONValue kat, Provider p) throws Exception {
static void encapDecapTest(JSONValue kat, Provider p) throws Exception {
var g = p == null
? KEM.getInstance("ML-KEM")
: KEM.getInstance("ML-KEM", p);
Expand All @@ -87,7 +87,8 @@ static void mlkemEnc(JSONValue kat, Provider p) throws Exception {
var e = g.newEncapsulator(
ek, new FixedSecureRandom(toByteArray(c.get("m").asString())));
var enc = e.encapsulate();
Asserts.assertEqualsByteArray(enc.encapsulation(), toByteArray(c.get("c").asString()));
Asserts.assertEqualsByteArray(
enc.encapsulation(), toByteArray(c.get("c").asString()));
Asserts.assertEqualsByteArray(
enc.key().getEncoded(), toByteArray(c.get("k").asString()));
}
Expand Down
1 change: 0 additions & 1 deletion test/jdk/sun/security/provider/acvp/data/README

This file was deleted.

0 comments on commit 34f9f8a

Please sign in to comment.