aboutsummaryrefslogtreecommitdiff
path: root/standalone
diff options
context:
space:
mode:
authorJ08nY2025-02-27 16:12:12 +0100
committerJ08nY2025-02-27 16:12:12 +0100
commit51f118610d4d6b383b7b7b75201998b47ea5f972 (patch)
tree22978d4339f74e4a940aba7f523f83fc4ca8a64f /standalone
parent9946667069d6e297e2c35b2f4875d5c62f406e61 (diff)
downloadECTester-51f118610d4d6b383b7b7b75201998b47ea5f972.tar.gz
ECTester-51f118610d4d6b383b7b7b75201998b47ea5f972.tar.zst
ECTester-51f118610d4d6b383b7b7b75201998b47ea5f972.zip
Diffstat (limited to 'standalone')
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/ECTesterStandalone.java2
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java7
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java49
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java22
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java8
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneMiscSuite.java55
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneSignatureSuite.java16
-rw-r--r--standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java52
8 files changed, 108 insertions, 103 deletions
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/ECTesterStandalone.java b/standalone/src/main/java/cz/crcs/ectester/standalone/ECTesterStandalone.java
index 1f41f1c..96052f1 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/ECTesterStandalone.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/ECTesterStandalone.java
@@ -258,6 +258,8 @@ public class ECTesterStandalone {
testOpts.addOption(Option.builder("kt").longOpt("ka-type").desc("Set the KeyAgreement object [type].").hasArg().argName("type").optionalArg(false).build());
testOpts.addOption(Option.builder("st").longOpt("sig-type").desc("Set the Signature object [type].").hasArg().argName("type").optionalArg(false).build());
testOpts.addOption(Option.builder("f").longOpt("format").desc("Set the output format, one of text,yaml,xml.").hasArg().argName("format").optionalArg(false).build());
+ testOpts.addOption(Option.builder("n").longOpt("number").desc("Number of repeats during testing.").hasArg().argName("number").optionalArg(false).build());
+ testOpts.addOption(Option.builder("s").longOpt("shuffle").desc("Shuffle the test suite before running it.").build());
testOpts.addOption(Option.builder().longOpt("key-type").desc("Set the key [algorithm] for which the key should be derived in KeyAgreements with KDF. Default is \"AES\".").hasArg().argName("algorithm").optionalArg(false).build());
List<Argument> testArgs = new LinkedList<>();
testArgs.add(new Argument("test-suite", "The test suite to run.", true));
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java
index c97620d..ec11116 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java
@@ -71,9 +71,14 @@ public class StandaloneCofactorSuite extends StandaloneTestSuite {
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " cofactor key test (" + pub.getDesc() + ").", keyAgreement));
}
- allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with public points on non-generator subgroup.", specificKaTests.toArray(new Test[0])));
+ for (int i = 0; i < getNumRepeats(); i++) {
+ allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with public points on non-generator subgroup.", specificKaTests.toArray(new Test[0])));
+ }
}
}
+ if (cli.hasOption("test.shuffle")) {
+ Collections.shuffle(allKaTests);
+ }
if (allKaTests.isEmpty()) {
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified key agreement types is supported by the library."));
}
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java
index d838d20..2385cd3 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java
@@ -12,14 +12,10 @@ import cz.crcs.ectester.data.EC_Store;
import cz.crcs.ectester.standalone.ECTesterStandalone;
import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
-import cz.crcs.ectester.standalone.consts.SignatureIdent;
import cz.crcs.ectester.standalone.test.base.*;
import javax.crypto.KeyAgreement;
-import java.security.KeyPair;
import java.security.KeyPairGenerator;
-import java.security.Signature;
-import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECParameterSpec;
import java.util.*;
@@ -79,9 +75,14 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite {
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", with generated private key, " + pub.getDesc(), keyAgreement));
}
- allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with various public points.", specificKaTests.toArray(new Test[0])));
+ for (int i = 0; i < getNumRepeats(); i++) {
+ allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with various public points.", specificKaTests.toArray(new Test[0])));
+ }
}
}
+ if (cli.hasOption("test.shuffle")) {
+ Collections.shuffle(allKaTests);
+ }
if (allKaTests.isEmpty()) {
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified key agreement types is supported by the library."));
}
@@ -123,7 +124,7 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite {
testGroup(rg0Curves, kpg, null, Result.ExpectedValue.ANY);
}
- private void testGroup(List<EC_Curve> curves, KeyPairGenerator kpg, String testName, Result.ExpectedValue dhValue) throws Exception {
+ private void testGroup(List<EC_Curve> curves, KeyPairGenerator kpg, String testName, Result.ExpectedValue expected) throws Exception {
for (EC_Curve curve : curves) {
String description;
if (testName == null) {
@@ -131,41 +132,7 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite {
} else {
description = testName + " test of " + curve.getId() + ".";
}
-
- //generate KeyPair
- KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(curve.toSpec()).build();
- Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY);
-
- //perform KeyAgreement tests
- List<Test> kaTests = new LinkedList<>();
- for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) {
- if (kaAlgo == null || kaIdent.containsAny(kaTypes)) {
- KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider());
- KeyAgreementTestable testable = KeyAgreementTestable.builder().ka(ka).publicKgt(kgt).privateKgt(kgt).random(getRandom()).build();
- kaTests.add(KeyAgreementTest.expectError(testable, dhValue));
- }
- }
- if (kaTests.isEmpty()) {
- kaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified KeyAgreement types is supported by the library."));
- }
-
- //perform Signature tests
- List<Test> sigTests = new LinkedList<>();
- for (SignatureIdent sigIdent : cfg.selected.getSigs()) {
- if (sigAlgo == null || sigIdent.containsAny(sigTypes)) {
- Signature sig = sigIdent.getInstance(cfg.selected.getProvider());
- byte[] data = sigIdent.toString().getBytes();
- SignatureTestable testable = new SignatureTestable(sig, kgt, data, getRandom());
- sigTests.add(SignatureTest.expectError(testable, dhValue));
- }
- }
- if (sigTests.isEmpty()) {
- sigTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified Signature types is supported by the library."));
- }
-
- Test performKeyAgreements = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified KeyAgreements.", kaTests.toArray(new Test[0]));
- Test performSignatures = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified Signatures.", sigTests.toArray(new Test[0]));
- doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, description, generate, performKeyAgreements, performSignatures));
+ testCurve(curve, kpg, expected, description, kaAlgo, sigAlgo, kaTypes, sigTypes);
}
}
}
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java
index 12a9f16..c8841d0 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java
@@ -163,7 +163,7 @@ public class StandaloneEdgeCasesSuite extends StandaloneTestSuite {
Test fullS = ecdhTest(kgt, full, spec, "ECDH with S = 111111111...11111 (but < r).", Result.ExpectedValue.SUCCESS);
Test smallerS = ecdhTest(kgt, smaller, spec, "ECDH with S < r.", Result.ExpectedValue.SUCCESS);
Test exactS = ecdhTest(kgt, R, spec, "ECDH with S = r.", Result.ExpectedValue.FAILURE);
- Test largeS = ecdhTest(kgt, larger, spec, "ECDH with S > r.", Result.ExpectedValue.ANY);
+ Test largerS = ecdhTest(kgt, larger, spec, "ECDH with S > r.", Result.ExpectedValue.ANY);
Test rm1S = ecdhTest(kgt, rm1, spec, "ECDH with S = r - 1.", Result.ExpectedValue.SUCCESS);
Test rp1S = ecdhTest(kgt, rp1, spec, "ECDH with S = r + 1.", Result.ExpectedValue.ANY);
@@ -179,8 +179,15 @@ public class StandaloneEdgeCasesSuite extends StandaloneTestSuite {
Test krm1S = ecdhTest(kgt, krm1, spec, "ECDH with S = (k * r) - 1.", kExpected);
Test krp1S = ecdhTest(kgt, krp1, spec, "ECDH with S = (k * r) + 1.", Result.ExpectedValue.ANY);
+ List<Test> tests = new LinkedList<>();
+ for (int i = 0; i < getNumRepeats(); ++i) {
+ tests.addAll(Arrays.asList(zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largerS, rm1S, rp1S, krS, krm1S, krp1S));
+ }
+ if (cli.hasOption("test.shuffle"))
+ Collections.shuffle(tests);
+ tests.add(0, generate);
doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, "Tests with edge-case private key values over " + curve.getId() + ".",
- generate, zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largeS, rm1S, rp1S, krS, krm1S, krp1S));
+ generate, zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largerS, rm1S, rp1S, krS, krm1S, krp1S));
}
EC_Curve secp160r1 = EC_Store.getInstance().getObject(EC_Curve.class, "secg/secp160r1");
@@ -241,7 +248,16 @@ public class StandaloneEdgeCasesSuite extends StandaloneTestSuite {
}
}
Test rTest = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Near r.", rTests);
- doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, "Test private key values near zero, near p and near/larger than the order.", generate, zeroTest, pTest, rTest));
+
+ List<Test> tests160 = new LinkedList<>();
+ for (int j = 0; j < getNumRepeats(); ++j) {
+ tests160.addAll(Arrays.asList(zeroTest, pTest, rTest));
+ }
+ if (cli.hasOption("test.shuffle"))
+ Collections.shuffle(tests160);
+ tests160.add(0, generate);
+
+ doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, "Test private key values near zero, near p and near/larger than the order.", tests160.toArray(new Test[0])));
}
private Test ecdhTest(KeyGeneratorTestable kgt, BigInteger SParam, ECParameterSpec spec, String desc, Result.ExpectedValue expect) throws NoSuchAlgorithmException {
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java
index da5d19a..c533789 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java
@@ -39,6 +39,7 @@ public abstract class StandaloneForeignSuite extends StandaloneTestSuite {
protected void runTests() throws Exception {
String kpgAlgo = cli.getOptionValue("test.kpg-type");
String kaAlgo = cli.getOptionValue("test.ka-type");
+
List<String> kaTypes = kaAlgo != null ? Arrays.asList(kaAlgo.split(",")) : new ArrayList<>();
KeyPairGeneratorIdent kpgIdent = getKeyPairGeneratorIdent(kpgAlgo);
@@ -160,9 +161,14 @@ public abstract class StandaloneForeignSuite extends StandaloneTestSuite {
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " invalid key test.", keyAgreement));
}
- allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with invalid public points.", specificKaTests.toArray(new Test[0])));
+ for (int i = 0; i < getNumRepeats(); i++) {
+ allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with invalid public points.", specificKaTests.toArray(new Test[0])));
+ }
}
}
+ if (cli.hasOption("test.shuffle")) {
+ Collections.shuffle(allKaTests);
+ }
if (allKaTests.isEmpty()) {
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified key agreement types is supported by the library."));
}
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneMiscSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneMiscSuite.java
index 87ad0b3..1944f9d 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneMiscSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneMiscSuite.java
@@ -3,29 +3,15 @@ package cz.crcs.ectester.standalone.test.suites;
import cz.crcs.ectester.common.cli.TreeCommandLine;
import cz.crcs.ectester.common.ec.EC_Curve;
import cz.crcs.ectester.common.output.TestWriter;
-import cz.crcs.ectester.common.test.CompoundTest;
import cz.crcs.ectester.common.test.Result;
-import cz.crcs.ectester.common.test.Test;
-import cz.crcs.ectester.common.util.ByteUtil;
-import cz.crcs.ectester.common.util.ECUtil;
import cz.crcs.ectester.data.EC_Store;
import cz.crcs.ectester.standalone.ECTesterStandalone;
-import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
-import cz.crcs.ectester.standalone.consts.SignatureIdent;
-import cz.crcs.ectester.standalone.test.base.*;
-import javax.crypto.KeyAgreement;
-import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
-import java.security.Signature;
-import java.security.interfaces.ECPrivateKey;
-import java.security.interfaces.ECPublicKey;
import java.util.*;
-import static cz.crcs.ectester.common.util.ECUtil.hashCurve;
-
/**
* @author David Hofman
*/
@@ -76,49 +62,12 @@ public class StandaloneMiscSuite extends StandaloneTestSuite {
testCurves(bnCurves.values(), "Barreto-Naehrig", kpg, Result.ExpectedValue.SUCCESS);
testCurves(mntCurves.values(), "MNT", kpg, Result.ExpectedValue.SUCCESS);
testCurves(mCurves, "Montgomery", kpg, Result.ExpectedValue.SUCCESS);
- testCurve(curve25519, "Montgomery", kpg, Result.ExpectedValue.SUCCESS);
- }
-
- private void testCurve(EC_Curve curve, String catName, KeyPairGenerator kpg, Result.ExpectedValue expected) throws NoSuchAlgorithmException {
- //generate KeyPair
- KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(curve.toSpec()).random(getRandom()).build();
- Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY);
-
- //perform KeyAgreement tests
- List<Test> kaTests = new LinkedList<>();
- for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) {
- if (kaAlgo == null || kaIdent.containsAny(kaTypes)) {
- KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider());
- KeyAgreementTestable testable = KeyAgreementTestable.builder().ka(ka).publicKgt(kgt).privateKgt(kgt).random(getRandom()).build();
- kaTests.add(KeyAgreementTest.expectError(testable, expected));
- }
- }
- if (kaTests.isEmpty()) {
- kaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified KeyAgreement types is supported by the library."));
- }
-
- //perform Signature tests
- List<Test> sigTests = new LinkedList<>();
- for (SignatureIdent sigIdent : cfg.selected.getSigs()) {
- if (sigAlgo == null || sigIdent.containsAny(sigTypes)) {
- Signature sig = sigIdent.getInstance(cfg.selected.getProvider());
- byte[] data = sigIdent.toString().getBytes();
- SignatureTestable testable = new SignatureTestable(sig, kgt, data, getRandom());
- sigTests.add(SignatureTest.expectError(testable, expected));
- }
- }
- if (sigTests.isEmpty()) {
- sigTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified Signature types is supported by the library."));
- }
-
- Test performKeyAgreements = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified KeyAgreements.", kaTests.toArray(new Test[0]));
- Test performSignatures = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified Signatures.", sigTests.toArray(new Test[0]));
- doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Tests over " + curve.getBits() + "b " + catName + " curve: " + curve.getId() + ".", generate, performKeyAgreements, performSignatures));
+ testCurve(curve25519, kpg, Result.ExpectedValue.SUCCESS, "Tests over Curve25519.", kaAlgo, sigAlgo, kaTypes, sigTypes);
}
private void testCurves(Collection<EC_Curve> curves, String catName, KeyPairGenerator kpg, Result.ExpectedValue expected) throws NoSuchAlgorithmException {
for (EC_Curve curve : curves) {
- testCurve(curve, catName, kpg, expected);
+ testCurve(curve, kpg, expected, "Tests over " + curve.getBits() + "b " + catName + " curve: " + curve.getId() + ".", kaAlgo, sigAlgo, kaTypes, sigTypes);
}
}
}
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneSignatureSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneSignatureSuite.java
index 740dca7..633462e 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneSignatureSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneSignatureSuite.java
@@ -42,13 +42,21 @@ public class StandaloneSignatureSuite extends StandaloneTestSuite {
List<EC_SigResult> nok = groups.entrySet().stream().filter((e) -> e.getKey().equals("nok")).findFirst().get().getValue();
byte[] data = "Some stuff that is not the actual data".getBytes();
- for (EC_SigResult sig : nok) {
- ecdsaTest(sig, sigIdent, Result.ExpectedValue.FAILURE, data);
+ for (int i = 0; i < getNumRepeats(); ++i) {
+ if (cli.hasOption("test.shuffle"))
+ Collections.shuffle(nok);
+ for (EC_SigResult sig : nok) {
+ ecdsaTest(sig, sigIdent, Result.ExpectedValue.FAILURE, data);
+ }
}
List<EC_SigResult> ok = groups.entrySet().stream().filter((e) -> e.getKey().equals("ok")).findFirst().get().getValue();
- for (EC_SigResult sig : ok) {
- ecdsaTest(sig, sigIdent, Result.ExpectedValue.SUCCESS, null);
+ for (int i = 0; i < getNumRepeats(); ++i) {
+ if (cli.hasOption("test.shuffle"))
+ Collections.shuffle(ok);
+ for (EC_SigResult sig : ok) {
+ ecdsaTest(sig, sigIdent, Result.ExpectedValue.SUCCESS, null);
+ }
}
}
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java
index bfea628..f02b85d 100644
--- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java
+++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneTestSuite.java
@@ -1,7 +1,11 @@
package cz.crcs.ectester.standalone.test.suites;
import cz.crcs.ectester.common.cli.TreeCommandLine;
+import cz.crcs.ectester.common.ec.EC_Curve;
import cz.crcs.ectester.common.output.TestWriter;
+import cz.crcs.ectester.common.test.CompoundTest;
+import cz.crcs.ectester.common.test.Result;
+import cz.crcs.ectester.common.test.Test;
import cz.crcs.ectester.common.test.TestSuite;
import cz.crcs.ectester.common.util.ByteUtil;
import cz.crcs.ectester.common.util.Util;
@@ -11,8 +15,15 @@ import cz.crcs.ectester.standalone.consts.KeyAgreementIdent;
import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
import cz.crcs.ectester.standalone.consts.SignatureIdent;
import cz.crcs.ectester.standalone.libs.ProviderECLibrary;
+import cz.crcs.ectester.standalone.test.base.*;
+import javax.crypto.KeyAgreement;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.security.Signature;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -50,6 +61,10 @@ public abstract class StandaloneTestSuite extends TestSuite {
return this.random;
}
+ public int getNumRepeats() {
+ return Integer.parseInt(cli.getOptionValue("test.number", "1"));
+ }
+
private <T extends Ident> T getIdent(Set<T> options, String choice, String identName, String defaultChoice) {
T ident;
if (choice == null) {
@@ -89,4 +104,41 @@ public abstract class StandaloneTestSuite extends TestSuite {
SignatureIdent getSignatureIdent(String sigAlgo) {
return getIdent(cfg.selected.getSigs(), sigAlgo, "Signature", "ECDSA");
}
+
+ public void testCurve(EC_Curve curve, KeyPairGenerator kpg, Result.ExpectedValue expected, String description, String kaAlgo, String sigAlgo, List<String> kaTypes, List<String> sigTypes) throws NoSuchAlgorithmException {
+ //generate KeyPair
+ KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(curve.toSpec()).random(getRandom()).build();
+ Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY);
+
+ //perform KeyAgreement tests
+ List<Test> kaTests = new LinkedList<>();
+ for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) {
+ if (kaAlgo == null || kaIdent.containsAny(kaTypes)) {
+ KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider());
+ KeyAgreementTestable testable = KeyAgreementTestable.builder().ka(ka).publicKgt(kgt).privateKgt(kgt).random(getRandom()).build();
+ kaTests.add(KeyAgreementTest.expectError(testable, expected));
+ }
+ }
+ if (kaTests.isEmpty()) {
+ kaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified KeyAgreement types is supported by the library."));
+ }
+
+ //perform Signature tests
+ List<Test> sigTests = new LinkedList<>();
+ for (SignatureIdent sigIdent : cfg.selected.getSigs()) {
+ if (sigAlgo == null || sigIdent.containsAny(sigTypes)) {
+ Signature sig = sigIdent.getInstance(cfg.selected.getProvider());
+ byte[] data = sigIdent.toString().getBytes();
+ SignatureTestable testable = new SignatureTestable(sig, kgt, data, getRandom());
+ sigTests.add(SignatureTest.expectError(testable, expected));
+ }
+ }
+ if (sigTests.isEmpty()) {
+ sigTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified Signature types is supported by the library."));
+ }
+
+ Test performKeyAgreements = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified KeyAgreements.", kaTests.toArray(new Test[0]));
+ Test performSignatures = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified Signatures.", sigTests.toArray(new Test[0]));
+ doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, description, generate, performKeyAgreements, performSignatures));
+ }
}