diff options
Diffstat (limited to 'standalone/src')
9 files changed, 45 insertions, 48 deletions
diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java index 308ade7..6566a9c 100644 --- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java +++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyAgreementTestable.java @@ -18,11 +18,11 @@ public class KeyAgreementTestable extends StandaloneTestable<KeyAgreementTestabl private KeyAgreement ka; private ECPrivateKey privateKey; private ECPublicKey publicKey; - private KeyGeneratorTestable kgtPrivate; - private KeyGeneratorTestable kgtPublic; - private AlgorithmParameterSpec spec; - private String keyAlgo; - private SecureRandom random; + private final KeyGeneratorTestable kgtPrivate; + private final KeyGeneratorTestable kgtPublic; + private final AlgorithmParameterSpec spec; + private final String keyAlgo; + private final SecureRandom random; private byte[] secret; private SecretKey derived; @@ -204,13 +204,13 @@ public class KeyAgreementTestable extends StandaloneTestable<KeyAgreementTestabl public KeyAgreementTestable build() { if (ka == null) { - throw new NullPointerException("ka needs to be not-null."); + throw new NullPointerException("ka needs to be non-null."); } if ((privateKey == null) == (kgtPrivate == null)) { - throw new IllegalStateException("One of (but not both) privateKey or privateKgt needs to be not-null."); + throw new IllegalStateException("One of (but not both) privateKey or privateKgt needs to be non-null."); } if ((publicKey == null) == (kgtPublic == null)) { - throw new IllegalStateException("One of (but not both) publicKey or publicKgt needs to be not-null."); + throw new IllegalStateException("One of (but not both) publicKey or publicKgt needs to be non-null."); } return new KeyAgreementTestable(this); } diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java index 8865576..f9c84e1 100644 --- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java +++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/KeyGeneratorTestable.java @@ -28,26 +28,6 @@ public class KeyGeneratorTestable extends StandaloneTestable<KeyGeneratorTestabl this.spec = builder.spec; this.random = builder.random; } - /* - public KeyGeneratorTestable(KeyPairGenerator kpg) { - this.kpg = kpg; - } - - public KeyGeneratorTestable(KeyPairGenerator kpg, int keysize) { - this.kpg = kpg; - this.keysize = keysize; - } - - public KeyGeneratorTestable(KeyPairGenerator kpg, ECParameterSpec spec) { - this.kpg = kpg; - this.spec = spec; - } - - public KeyGeneratorTestable(KeyPairGenerator kpg, ECGenParameterSpec spec) { - this.kpg = kpg; - this.spec = spec; - } - */ public int getKeysize() { return keysize; @@ -143,6 +123,12 @@ public class KeyGeneratorTestable extends StandaloneTestable<KeyGeneratorTestabl } public KeyGeneratorTestable build() { + if (kpg == null) { + throw new NullPointerException("kpg mus be non-null."); + } + if (spec != null && keysize != 0) { + throw new IllegalStateException("Only one of spec and keysize can be set."); + } return new KeyGeneratorTestable(this); } } diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/SignatureTestable.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/SignatureTestable.java index 76074e4..5839497 100644 --- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/SignatureTestable.java +++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/base/SignatureTestable.java @@ -15,32 +15,32 @@ public class SignatureTestable extends StandaloneTestable<SignatureTestable.Sign private ECPrivateKey signKey; private ECPublicKey verifyKey; private KeyGeneratorTestable kgt; + private SecureRandom random; private byte[] data; private byte[] signature; private boolean verified; - public SignatureTestable(Signature sig, ECPrivateKey signKey, ECPublicKey verifyKey, byte[] data) { + public SignatureTestable(Signature sig, ECPrivateKey signKey, ECPublicKey verifyKey, byte[] data, SecureRandom random) { this.sig = sig; this.signKey = signKey; this.verifyKey = verifyKey; this.data = data; - if (data == null) { - SecureRandom random = new SecureRandom(); - this.data = new byte[64]; - random.nextBytes(this.data); - } + this.random = random; } - public SignatureTestable(Signature sig, ECPublicKey verifyKey, byte[] data, byte[] signature) { + public SignatureTestable(Signature sig, ECPublicKey verifyKey, byte[] data, byte[] signature, SecureRandom random) { this.sig = sig; this.verifyKey = verifyKey; this.data = data; this.signature = signature; + this.random = random; } - public SignatureTestable(Signature sig, KeyGeneratorTestable kgt, byte[] data) { - this(sig, (ECPrivateKey) null, null, data); + public SignatureTestable(Signature sig, KeyGeneratorTestable kgt, byte[] data, SecureRandom random) { + this.sig = sig; this.kgt = kgt; + this.data = data; + this.random = random; } public Signature getSig() { @@ -71,7 +71,11 @@ public class SignatureTestable extends StandaloneTestable<SignatureTestable.Sign if(signKey != null) { stage = SignatureStage.InitSign; try { - sig.initSign(signKey); + if (random != null) { + sig.initSign(signKey, random); + } else { + sig.initSign(signKey); + } } catch (InvalidKeyException e) { failOnException(e); return; 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 e1741e6..643e44e 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 @@ -56,7 +56,7 @@ public class StandaloneCofactorSuite extends StandaloneTestSuite { KeyPairGenerator kpg = kpgIdent.getInstance(cfg.selected.getProvider()); ECParameterSpec spec = curve.toSpec(); - KeyGeneratorTestable kgt = new KeyGeneratorTestable(kpg, spec); + KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(spec).build(); Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY); 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 92adc4f..f98dc3b 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 @@ -64,7 +64,7 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite { ECParameterSpec spec = curve.toSpec(); //Generate KeyPair - KeyGeneratorTestable kgt = new KeyGeneratorTestable(kpg, spec); + KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(spec).build(); Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY); //Perform KeyAgreement tests @@ -133,7 +133,7 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite { } //generate KeyPair - KeyGeneratorTestable kgt = new KeyGeneratorTestable(kpg, curve.toSpec()); + KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(curve.toSpec()).build(); Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY); //perform KeyAgreement tests @@ -154,7 +154,8 @@ public class StandaloneCompositeSuite extends StandaloneTestSuite { for (SignatureIdent sigIdent : cfg.selected.getSigs()) { if (sigAlgo == null || sigIdent.containsAny(sigTypes)) { Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); - SignatureTestable testable = new SignatureTestable(sig, kgt, null); + byte[] data = sigIdent.toString().getBytes(); + SignatureTestable testable = new SignatureTestable(sig, kgt, data, null); sigTests.add(SignatureTest.expectError(testable, dhValue)); } } diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java index 1ad1557..9fbc2ac 100644 --- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java +++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneDefaultSuite.java @@ -4,6 +4,7 @@ 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.Result; +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; @@ -79,7 +80,8 @@ public class StandaloneDefaultSuite extends StandaloneTestSuite { for (SignatureIdent sigIdent : cfg.selected.getSigs()) { if (sigAlgo == null || sigIdent.contains(sigAlgo)) { Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); - doTest(SignatureTest.expect(new SignatureTestable(sig, kgtOne, null), Result.ExpectedValue.SUCCESS)); + byte[] data = sigIdent.toString().getBytes(); + doTest(SignatureTest.expect(new SignatureTestable(sig, kgtOne, data, null), Result.ExpectedValue.SUCCESS)); } } } 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 c1c995b..d0d83e6 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 @@ -7,6 +7,7 @@ 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; @@ -101,7 +102,8 @@ public class StandaloneMiscSuite extends StandaloneTestSuite { for (SignatureIdent sigIdent : cfg.selected.getSigs()) { if (sigAlgo == null || sigIdent.containsAny(sigTypes)) { Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); - SignatureTestable testable = new SignatureTestable(sig, kgt, hashCurve(curve)); + byte[] data = sigIdent.toString().getBytes(); + SignatureTestable testable = new SignatureTestable(sig, kgt, data, null); sigTests.add(SignatureTest.expectError(testable, expected)); } } diff --git a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandalonePerformanceSuite.java b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandalonePerformanceSuite.java index bce9d39..e3a5969 100644 --- a/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandalonePerformanceSuite.java +++ b/standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandalonePerformanceSuite.java @@ -111,10 +111,12 @@ public class StandalonePerformanceSuite extends StandaloneTestSuite { for (SignatureIdent sigIdent : cfg.selected.getSigs()) { if (sigAlgo == null || sigIdent.containsAny(sigTypes)) { Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); - sigTests.add(PerformanceTest.repeat(new SignatureTestable(sig, kgtOne, null), cfg.selected, sigIdent.getName(), count)); + byte[] data = sigIdent.toString().getBytes(); + sigTests.add(PerformanceTest.repeat(new SignatureTestable(sig, kgtOne, data, null), cfg.selected, sigIdent.getName(), count)); + // TODO: The following will always fail as a runTest is not done at this point. if (kgtOne.getKeyPair() != null) { ECPrivateKey signKey = (ECPrivateKey) kgtOne.getKeyPair().getPrivate(); - sigTestsNoVerification.add(PerformanceTest.repeat(new SignatureTestable(sig, signKey, null, null), cfg.selected, sigIdent.getName(), count)); + sigTestsNoVerification.add(PerformanceTest.repeat(new SignatureTestable(sig, signKey, null, data, null), cfg.selected, sigIdent.getName(), count)); } } } 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 43feb23..81ed535 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 @@ -61,11 +61,11 @@ public class StandaloneSignatureSuite extends StandaloneTestSuite { byte[] data = sig.getSigData(); if (data == null) { - data = defaultData; + data = sigIdent.toString().getBytes(); } Signature signature = sigIdent.getInstance(cfg.selected.getProvider()); - SignatureTestable testable = new SignatureTestable(signature, ecpub, data, sig.getData(0)); + SignatureTestable testable = new SignatureTestable(signature, ecpub, data, sig.getData(0), null); doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, "ECDSA test of " + sig.getId() + ".", SignatureTest.expectError(testable, expected))); } } |
