diff options
| author | J08nY | 2018-05-27 23:44:37 +0200 |
|---|---|---|
| committer | J08nY | 2018-05-27 23:44:37 +0200 |
| commit | 47e0465f1260e249016b512363b8625418a35ac3 (patch) | |
| tree | d9fdd2eba609ac2836d86f870ca552fd7c1f84ba | |
| parent | d22fb876d79dd16cb1f762a732ba8acb6c8b401c (diff) | |
| download | ECTester-47e0465f1260e249016b512363b8625418a35ac3.tar.gz ECTester-47e0465f1260e249016b512363b8625418a35ac3.tar.zst ECTester-47e0465f1260e249016b512363b8625418a35ac3.zip | |
| -rw-r--r-- | docs/LIBS.md | 8 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/common/test/CompoundTest.java | 75 | ||||
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java | 14 |
3 files changed, 47 insertions, 50 deletions
diff --git a/docs/LIBS.md b/docs/LIBS.md index a1395bc..5c132f7 100644 --- a/docs/LIBS.md +++ b/docs/LIBS.md @@ -1,6 +1,6 @@ # Libraries with ECC support -Libraries with at least some ECC support: +Popular libraries with at least some ECC support: - [Crypto++](https://cryptopp.com/) - [libgcrypt](https://www.gnupg.org/related_software/libgcrypt/) @@ -20,9 +20,9 @@ Libraries with at least some ECC support: - [Botan](https://botan.randombit.net/) - C++ - Uses blinded(randomized) Montgomery ladder. - - https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-1998-cmo-2 - - https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-1986-cc - - https://eprint.iacr.org/2015/657 + - <https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-1998-cmo-2> + - <https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-1986-cc> + - <https://eprint.iacr.org/2015/657> - ECTester supports v2.4.0 and up. - [libtomcrypt](http://www.libtom.net/LibTomCrypt/) - C diff --git a/src/cz/crcs/ectester/common/test/CompoundTest.java b/src/cz/crcs/ectester/common/test/CompoundTest.java index 2c851b2..607dadb 100644 --- a/src/cz/crcs/ectester/common/test/CompoundTest.java +++ b/src/cz/crcs/ectester/common/test/CompoundTest.java @@ -22,6 +22,24 @@ public class CompoundTest extends Test { } }; + private final static Consumer<Test[]> RUN_GREEDY_ALL = tests -> { + for (Test t : tests) { + t.run(); + if (!t.ok()) { + break; + } + } + }; + + private final static Consumer<Test[]> RUN_GREEDY_ANY = tests -> { + for (Test t : tests) { + t.run(); + if (t.ok()) { + break; + } + } + }; + private CompoundTest(Function<Test[], Result> resultCallback, Consumer<Test[]> runCallback, Test... tests) { this.resultCallback = resultCallback; this.runCallback = runCallback; @@ -49,7 +67,7 @@ public class CompoundTest extends Test { return new CompoundTest(callback, runCallback, description, tests); } - public static CompoundTest all(Result.ExpectedValue what, Test... all) { + private static CompoundTest expectAll(Result.ExpectedValue what, Consumer<Test[]> runCallback, Test[] all) { return new CompoundTest((tests) -> { for (Test test : tests) { if (!Result.Value.fromExpected(what, test.ok()).ok()) { @@ -57,7 +75,11 @@ public class CompoundTest extends Test { } } return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result."); - }, RUN_ALL, all); + }, runCallback, all); + } + + public static CompoundTest all(Result.ExpectedValue what, Test... all) { + return expectAll(what, RUN_ALL, all); } public static CompoundTest all(Result.ExpectedValue what, String description, Test... all) { @@ -67,21 +89,7 @@ public class CompoundTest extends Test { } public static CompoundTest greedyAll(Result.ExpectedValue what, Test... all) { - return new CompoundTest((tests) -> { - for (Test test : tests) { - if (!Result.Value.fromExpected(what, test.ok()).ok()) { - return new Result(Result.Value.FAILURE, "Some sub-tests did not have the expected result."); - } - } - return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result."); - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (!t.ok()) { - break; - } - } - }, all); + return expectAll(what, RUN_GREEDY_ALL, all); } public static CompoundTest greedyAll(Result.ExpectedValue what, String description, Test... all) { @@ -111,14 +119,7 @@ public class CompoundTest extends Test { } else { return new Result(Result.Value.SUCCESS, "All considered sub-tests had the expected result."); } - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (!t.ok()) { - break; - } - } - }, all); + }, RUN_GREEDY_ALL, all); } public static CompoundTest greedyAllTry(Result.ExpectedValue what, String description, Test... all) { @@ -127,7 +128,7 @@ public class CompoundTest extends Test { return result; } - public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) { + private static CompoundTest expectAny(Result.ExpectedValue what, Consumer<Test[]> runCallback, Test[] any) { return new CompoundTest((tests) -> { for (Test test : tests) { if (Result.Value.fromExpected(what, test.ok()).ok()) { @@ -135,14 +136,11 @@ public class CompoundTest extends Test { } } return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result."); - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (t.ok()) { - break; - } - } - }, any); + }, runCallback, any); + } + + public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) { + return expectAny(what, RUN_GREEDY_ANY, any); } public static CompoundTest greedyAny(Result.ExpectedValue what, String description, Test... any) { @@ -152,14 +150,7 @@ public class CompoundTest extends Test { } public static CompoundTest any(Result.ExpectedValue what, Test... any) { - return new CompoundTest((tests) -> { - for (Test test : tests) { - if (Result.Value.fromExpected(what, test.ok()).ok()) { - return new Result(Result.Value.SUCCESS, "Some sub-tests did have the expected result."); - } - } - return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result."); - }, RUN_ALL, any); + return expectAny(what, RUN_ALL, any); } public static CompoundTest any(Result.ExpectedValue what, String description, Test... any) { diff --git a/src/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java b/src/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java index ae18f77..0a4515a 100644 --- a/src/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java +++ b/src/cz/crcs/ectester/reader/test/CardEdgeCasesSuite.java @@ -39,6 +39,8 @@ public class CardEdgeCasesSuite extends CardTestSuite { String description = null; switch (e.getKey()) { case "addsub": + description = "Tests for addition-subtraction chains."; + break; case "cve_2017_10176": description = "Tests for CVE-2017-10176."; break; @@ -55,8 +57,7 @@ public class CardEdgeCasesSuite extends CardTestSuite { List<Test> curveTests = new LinkedList<>(); Test allocate = CommandTest.expect(new Command.Allocate(this.card, ECTesterApplet.KEYPAIR_BOTH, curve.getBits(), curve.getField()), Result.ExpectedValue.SUCCESS); Test set = CommandTest.expect(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), Result.ExpectedValue.SUCCESS); - curveTests.add(allocate); - curveTests.add(set); + Test prepareCurve = CompoundTest.greedyAll(Result.ExpectedValue.SUCCESS, "Prepare curve", allocate, set); List<EC_KAResult> values = c.getValue(); for (EC_KAResult value : values) { @@ -91,10 +92,15 @@ public class CardEdgeCasesSuite extends CardTestSuite { } }); - Test one = CompoundTest.greedyAll(Result.ExpectedValue.SUCCESS, "Test " + id + ".", setPrivkey, setPubkey, ecdhPreTest, ecdh); + Test prepare = CompoundTest.greedyAll(Result.ExpectedValue.SUCCESS, "Prepare", setPrivkey, setPubkey); + Test ka = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Do", ecdhPreTest, ecdh); + + Test one = CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Test " + id + ".", prepare, ka); curveTests.add(one); } - groupTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, "Tests on " + curve.getId() + ".", curveTests.toArray(new Test[0]))); + + Test curveTest = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Tests", curveTests.toArray(new Test[0])); + groupTests.add(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Tests on " + curve.getId() + ".", prepareCurve, curveTest)); } doTest(CompoundTest.all(Result.ExpectedValue.SUCCESS, description, groupTests.toArray(new Test[0]))); } |
