Skip to content

Commit a388379

Browse files
committed
Fix test object overwriting in multiple repeats.
1 parent 51f1186 commit a388379

File tree

11 files changed

+32
-16
lines changed

11 files changed

+32
-16
lines changed

common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ public String getDescription() {
225225

226226
@Override
227227
public CompoundTest clone() throws CloneNotSupportedException {
228-
return (CompoundTest) super.clone();
228+
CompoundTest clone = (CompoundTest) super.clone();
229+
clone.tests = new Test[tests.length];
230+
for (int i = 0; i < tests.length; i++) {
231+
clone.tests[i] = tests[i].clone();
232+
}
233+
return clone;
229234
}
230235
}

reader/src/main/java/cz/crcs/ectester/reader/test/CardCofactorSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ protected void runTests() throws Exception {
5050
Test objectEcdh = CompoundTest.any(ExpectedValue.SUCCESS, CardUtil.getKATypeString(EC_Consts.KeyAgreement_ALG_EC_SVDP_DH) + " test with cofactor pubkey.", setPub, ecdh);
5151
Command ecdhCommand = new Command.ECDH_direct(this.card, CardConsts.KEYPAIR_LOCAL, CardConsts.EXPORT_FALSE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, pub.flatten());
5252
Test rawEcdh = CommandTest.expect(ecdhCommand, ExpectedValue.FAILURE, "Card correctly rejected point on non-generator subgroup.", "Card incorrectly accepted point on non-generator subgroup.");
53+
Test test = CompoundTest.all(ExpectedValue.SUCCESS, pub.getId() + " cofactor key test.", objectEcdh, rawEcdh);
5354
for (int i = 0; i < cfg.number; ++i) {
54-
ecdhTests.add(CompoundTest.all(ExpectedValue.SUCCESS, pub.getId() + " cofactor key test.", objectEcdh, rawEcdh));
55+
ecdhTests.add(test.clone());
5556
}
5657
}
5758
if (cfg.testShuffle)

reader/src/main/java/cz/crcs/ectester/reader/test/CardCompositeSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ protected void runTests() throws Exception {
4545
for (EC_Key key : curveKeys.getValue()) {
4646
Command ecdhCommand = new Command.ECDH_direct(this.card, CardConsts.KEYPAIR_LOCAL, CardConsts.EXPORT_FALSE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, key.flatten());
4747
Test ecdh = CommandTest.expect(ecdhCommand, ExpectedValue.FAILURE, "Card correctly rejected to do ECDH over a composite order curve.", "Card incorrectly does ECDH over a composite order curve, leaks bits of private key.");
48+
Test test = CompoundTest.greedyAllTry(ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", with " + key.getDesc(), ecdh);
4849
for (int i = 0; i < cfg.number; ++i) {
49-
tests.add(CompoundTest.greedyAllTry(ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", with " + key.getDesc(), ecdh));
50+
tests.add(test.clone());
5051
}
5152
}
5253
if (cfg.testShuffle)

reader/src/main/java/cz/crcs/ectester/reader/test/CardDegenerateSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ protected void runTests() throws Exception {
5050
Test objectEcdh = CompoundTest.any(Result.ExpectedValue.SUCCESS, CardUtil.getKATypeString(EC_Consts.KeyAgreement_ALG_EC_SVDP_DH) + " test with degenerate pubkey.", setPub, ecdh);
5151
Command ecdhCommand = new Command.ECDH_direct(this.card, CardConsts.KEYPAIR_LOCAL, CardConsts.EXPORT_TRUE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, pub.flatten());
5252
Test rawEcdh = CommandTest.expect(ecdhCommand, Result.ExpectedValue.FAILURE, "Card correctly rejected point on degenerate curve.", "Card incorrectly accepted point on degenerate curve.");
53+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " degenerate key test.", objectEcdh, rawEcdh);
5354
for (int i = 0; i < cfg.number; ++i) {
54-
ecdhTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " degenerate key test.", objectEcdh, rawEcdh));
55+
ecdhTests.add(test.clone());
5556
}
5657
//TODO: actually get the result of ECDH here, as well as export privkey and compare to exponentiation in Fp^*.
5758
}

reader/src/main/java/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Result apply(CommandTestable testable) {
9898

9999
Test one = CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Test " + id + ".", prepare, ka);
100100
for (int i = 0; i < cfg.number; ++i) {
101-
curveTests.add(one);
101+
curveTests.add(one.clone());
102102
}
103103
}
104104
if (cfg.testShuffle)
@@ -235,7 +235,9 @@ public Result apply(CommandTestable testable) {
235235

236236
List<Test> tests = new LinkedList<>();
237237
for (int i = 0; i < cfg.number; ++i) {
238-
tests.addAll(Arrays.asList(zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largerS, rm1S, rp1S, krS, krm1S, krp1S));
238+
tests.addAll(Arrays.asList(zeroS.clone(), oneS.clone(), alternateS.clone(), alternateOtherS.clone(),
239+
fullS.clone(), smallerS.clone(), exactS.clone(), largerS.clone(), rm1S.clone(), rp1S.clone(),
240+
krS.clone(), krm1S.clone(), krp1S.clone()));
239241
}
240242
if (cfg.testShuffle)
241243
Collections.shuffle(tests);
@@ -312,7 +314,7 @@ public Result apply(CommandTestable testable) {
312314

313315
List<Test> tests160 = new LinkedList<>();
314316
for (int j = 0; j < cfg.number; ++j) {
315-
tests160.addAll(Arrays.asList(zeroTest, pTest, rTest));
317+
tests160.addAll(Arrays.asList(zeroTest.clone(), pTest.clone(), rTest.clone()));
316318
}
317319
if (cfg.testShuffle)
318320
Collections.shuffle(tests160);

reader/src/main/java/cz/crcs/ectester/reader/test/CardInvalidSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ protected void runTests() throws Exception {
5454
Test objectEcdh = CompoundTest.any(Result.ExpectedValue.SUCCESS, CardUtil.getKATypeString(EC_Consts.KeyAgreement_ALG_EC_SVDP_DH) + " test with invalid pubkey.", setPub, ecdh);
5555
Command ecdhCommand = new Command.ECDH_direct(this.card, CardConsts.KEYPAIR_LOCAL, CardConsts.EXPORT_FALSE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, pub.flatten());
5656
Test rawEcdh = CommandTest.expect(ecdhCommand, ExpectedValue.FAILURE, "Card correctly rejected point on invalid curve.", "Card incorrectly accepted point on invalid curve.");
57+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " invalid key test.", objectEcdh, rawEcdh);
5758
for (int i = 0; i < cfg.number; ++i) {
58-
ecdhTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " invalid key test.", objectEcdh, rawEcdh));
59+
ecdhTests.add(test.clone());
5960
}
6061
}
6162
if (cfg.testShuffle)

reader/src/main/java/cz/crcs/ectester/reader/test/CardTwistSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ protected void runTests() throws Exception {
4848
Test objectEcdh = CompoundTest.any(Result.ExpectedValue.SUCCESS, CardUtil.getKATypeString(EC_Consts.KeyAgreement_ALG_EC_SVDP_DH) + " test with twist pubkey.", setPub, ecdh);
4949
Command ecdhCommand = new Command.ECDH_direct(this.card, CardConsts.KEYPAIR_LOCAL, CardConsts.EXPORT_FALSE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, pub.flatten());
5050
Test rawEcdh = CommandTest.expect(ecdhCommand, Result.ExpectedValue.FAILURE, "Card correctly rejected point on twist.", "Card incorrectly accepted point on twist.");
51+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " twist key test.", objectEcdh, rawEcdh);
5152
for (int i = 0; i < cfg.number; ++i) {
52-
ecdhTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " twist key test.", objectEcdh, rawEcdh));
53+
ecdhTests.add(test.clone());
5354
}
5455
}
5556
if (cfg.testShuffle)

standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCofactorSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ protected void runTests() throws Exception {
7171
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
7272
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " cofactor key test (" + pub.getDesc() + ").", keyAgreement));
7373
}
74+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with public points on non-generator subgroup.", specificKaTests.toArray(new Test[0]));
7475
for (int i = 0; i < getNumRepeats(); i++) {
75-
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with public points on non-generator subgroup.", specificKaTests.toArray(new Test[0])));
76+
allKaTests.add(test.clone());
7677
}
7778
}
7879
}

standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneCompositeSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ protected void runTests() throws Exception {
7575
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
7676
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Composite test of " + curve.getId() + ", with generated private key, " + pub.getDesc(), keyAgreement));
7777
}
78+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with various public points.", specificKaTests.toArray(new Test[0]));
7879
for (int i = 0; i < getNumRepeats(); i++) {
79-
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with various public points.", specificKaTests.toArray(new Test[0])));
80+
allKaTests.add(test.clone());
8081
}
8182
}
8283
}

standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneEdgeCasesSuite.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,14 @@ public Result apply(KeyAgreementTestable testable) {
181181

182182
List<Test> tests = new LinkedList<>();
183183
for (int i = 0; i < getNumRepeats(); ++i) {
184-
tests.addAll(Arrays.asList(zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largerS, rm1S, rp1S, krS, krm1S, krp1S));
184+
tests.addAll(Arrays.asList(zeroS.clone(), oneS.clone(), alternateS.clone(), alternateOtherS.clone(),
185+
fullS.clone(), smallerS.clone(), exactS.clone(), largerS.clone(), rm1S.clone(), rp1S.clone(),
186+
krS.clone(), krm1S.clone(), krp1S.clone()));
185187
}
186188
if (cli.hasOption("test.shuffle"))
187189
Collections.shuffle(tests);
188190
tests.add(0, generate);
189-
doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, "Tests with edge-case private key values over " + curve.getId() + ".",
190-
generate, zeroS, oneS, alternateS, alternateOtherS, fullS, smallerS, exactS, largerS, rm1S, rp1S, krS, krm1S, krp1S));
191+
doTest(CompoundTest.function(CompoundTest.EXPECT_ALL_SUCCESS, CompoundTest.RUN_ALL_IF_FIRST, "Tests with edge-case private key values over " + curve.getId() + ".", tests.toArray(new Test[0])));
191192
}
192193

193194
EC_Curve secp160r1 = EC_Store.getInstance().getObject(EC_Curve.class, "secg/secp160r1");
@@ -251,7 +252,7 @@ public Result apply(KeyAgreementTestable testable) {
251252

252253
List<Test> tests160 = new LinkedList<>();
253254
for (int j = 0; j < getNumRepeats(); ++j) {
254-
tests160.addAll(Arrays.asList(zeroTest, pTest, rTest));
255+
tests160.addAll(Arrays.asList(zeroTest.clone(), pTest.clone(), rTest.clone()));
255256
}
256257
if (cli.hasOption("test.shuffle"))
257258
Collections.shuffle(tests160);

standalone/src/main/java/cz/crcs/ectester/standalone/test/suites/StandaloneForeignSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ public int getKeysize() {
161161
Test keyAgreement = KeyAgreementTest.expectError(testable, Result.ExpectedValue.FAILURE);
162162
specificKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " invalid key test.", keyAgreement));
163163
}
164+
Test test = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with invalid public points.", specificKaTests.toArray(new Test[0]));
164165
for (int i = 0; i < getNumRepeats(); i++) {
165-
allKaTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform " + kaIdent.getName() + " with invalid public points.", specificKaTests.toArray(new Test[0])));
166+
allKaTests.add(test.clone());
166167
}
167168
}
168169
}

0 commit comments

Comments
 (0)