|
3 | 3 | import cz.crcs.ectester.common.cli.TreeCommandLine;
|
4 | 4 | import cz.crcs.ectester.common.ec.EC_Curve;
|
5 | 5 | import cz.crcs.ectester.common.output.TestWriter;
|
6 |
| -import cz.crcs.ectester.common.test.CompoundTest; |
7 | 6 | import cz.crcs.ectester.common.test.Result;
|
8 |
| -import cz.crcs.ectester.common.test.Test; |
9 |
| -import cz.crcs.ectester.common.util.ByteUtil; |
10 |
| -import cz.crcs.ectester.common.util.ECUtil; |
11 | 7 | import cz.crcs.ectester.data.EC_Store;
|
12 | 8 | import cz.crcs.ectester.standalone.ECTesterStandalone;
|
13 |
| -import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; |
14 | 9 | import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent;
|
15 |
| -import cz.crcs.ectester.standalone.consts.SignatureIdent; |
16 |
| -import cz.crcs.ectester.standalone.test.base.*; |
17 | 10 |
|
18 |
| -import javax.crypto.KeyAgreement; |
19 |
| -import java.security.KeyPair; |
20 | 11 | import java.security.KeyPairGenerator;
|
21 | 12 | import java.security.NoSuchAlgorithmException;
|
22 |
| -import java.security.Signature; |
23 |
| -import java.security.interfaces.ECPrivateKey; |
24 |
| -import java.security.interfaces.ECPublicKey; |
25 | 13 | import java.util.*;
|
26 | 14 |
|
27 |
| -import static cz.crcs.ectester.common.util.ECUtil.hashCurve; |
28 |
| - |
29 | 15 | /**
|
30 | 16 | * @author David Hofman
|
31 | 17 | */
|
@@ -76,49 +62,12 @@ protected void runTests() throws Exception {
|
76 | 62 | testCurves(bnCurves.values(), "Barreto-Naehrig", kpg, Result.ExpectedValue.SUCCESS);
|
77 | 63 | testCurves(mntCurves.values(), "MNT", kpg, Result.ExpectedValue.SUCCESS);
|
78 | 64 | testCurves(mCurves, "Montgomery", kpg, Result.ExpectedValue.SUCCESS);
|
79 |
| - testCurve(curve25519, "Montgomery", kpg, Result.ExpectedValue.SUCCESS); |
80 |
| - } |
81 |
| - |
82 |
| - private void testCurve(EC_Curve curve, String catName, KeyPairGenerator kpg, Result.ExpectedValue expected) throws NoSuchAlgorithmException { |
83 |
| - //generate KeyPair |
84 |
| - KeyGeneratorTestable kgt = KeyGeneratorTestable.builder().keyPairGenerator(kpg).spec(curve.toSpec()).random(getRandom()).build(); |
85 |
| - Test generate = KeyGeneratorTest.expectError(kgt, Result.ExpectedValue.ANY); |
86 |
| - |
87 |
| - //perform KeyAgreement tests |
88 |
| - List<Test> kaTests = new LinkedList<>(); |
89 |
| - for (KeyAgreementIdent kaIdent : cfg.selected.getKAs()) { |
90 |
| - if (kaAlgo == null || kaIdent.containsAny(kaTypes)) { |
91 |
| - KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider()); |
92 |
| - KeyAgreementTestable testable = KeyAgreementTestable.builder().ka(ka).publicKgt(kgt).privateKgt(kgt).random(getRandom()).build(); |
93 |
| - kaTests.add(KeyAgreementTest.expectError(testable, expected)); |
94 |
| - } |
95 |
| - } |
96 |
| - if (kaTests.isEmpty()) { |
97 |
| - kaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified KeyAgreement types is supported by the library.")); |
98 |
| - } |
99 |
| - |
100 |
| - //perform Signature tests |
101 |
| - List<Test> sigTests = new LinkedList<>(); |
102 |
| - for (SignatureIdent sigIdent : cfg.selected.getSigs()) { |
103 |
| - if (sigAlgo == null || sigIdent.containsAny(sigTypes)) { |
104 |
| - Signature sig = sigIdent.getInstance(cfg.selected.getProvider()); |
105 |
| - byte[] data = sigIdent.toString().getBytes(); |
106 |
| - SignatureTestable testable = new SignatureTestable(sig, kgt, data, getRandom()); |
107 |
| - sigTests.add(SignatureTest.expectError(testable, expected)); |
108 |
| - } |
109 |
| - } |
110 |
| - if (sigTests.isEmpty()) { |
111 |
| - sigTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "None of the specified Signature types is supported by the library.")); |
112 |
| - } |
113 |
| - |
114 |
| - Test performKeyAgreements = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified KeyAgreements.", kaTests.toArray(new Test[0])); |
115 |
| - Test performSignatures = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform specified Signatures.", sigTests.toArray(new Test[0])); |
116 |
| - doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Tests over " + curve.getBits() + "b " + catName + " curve: " + curve.getId() + ".", generate, performKeyAgreements, performSignatures)); |
| 65 | + testCurve(curve25519, kpg, Result.ExpectedValue.SUCCESS, "Tests over Curve25519.", kaAlgo, sigAlgo, kaTypes, sigTypes); |
117 | 66 | }
|
118 | 67 |
|
119 | 68 | private void testCurves(Collection<EC_Curve> curves, String catName, KeyPairGenerator kpg, Result.ExpectedValue expected) throws NoSuchAlgorithmException {
|
120 | 69 | for (EC_Curve curve : curves) {
|
121 |
| - testCurve(curve, catName, kpg, expected); |
| 70 | + testCurve(curve, kpg, expected, "Tests over " + curve.getBits() + "b " + catName + " curve: " + curve.getId() + ".", kaAlgo, sigAlgo, kaTypes, sigTypes); |
122 | 71 | }
|
123 | 72 | }
|
124 | 73 | }
|
0 commit comments