aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordavidhofman2021-08-16 18:30:44 +0200
committerGitHub2021-08-16 18:30:44 +0200
commit6f397b26eef8906c46878cd207492da59adff29b (patch)
treed2a25cddb6d18ea3ac8b3ce3fe15fe91a549843d /src
parent31747e95491eab3a7f3e9b9f6aad8e5e3a9bc7ea (diff)
downloadECTester-6f397b26eef8906c46878cd207492da59adff29b.tar.gz
ECTester-6f397b26eef8906c46878cd207492da59adff29b.tar.zst
ECTester-6f397b26eef8906c46878cd207492da59adff29b.zip
Diffstat (limited to 'src')
-rw-r--r--src/cz/crcs/ectester/data/test/results.xml89
-rw-r--r--src/cz/crcs/ectester/standalone/ECTesterStandalone.java17
-rw-r--r--src/cz/crcs/ectester/standalone/test/suites/StandaloneTestVectorSuite.java59
3 files changed, 163 insertions, 2 deletions
diff --git a/src/cz/crcs/ectester/data/test/results.xml b/src/cz/crcs/ectester/data/test/results.xml
index 64fa86a..fa43e4b 100644
--- a/src/cz/crcs/ectester/data/test/results.xml
+++ b/src/cz/crcs/ectester/data/test/results.xml
@@ -171,4 +171,93 @@
<onekey>test/p521-A</onekey>
<otherkey>test/p521-B</otherkey>
</kaResult>
+ <kaResult>
+ <id>secp160r1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>secg/secp160r1-dh-raw.csv</file>
+ <curve>secg/secp160r1</curve>
+ <onekey>test/secp160r1-U</onekey>
+ <otherkey>test/secp160r1-V</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>sect163k1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>secg/sect163k1-dh-raw.csv</file>
+ <curve>secg/sect163k1</curve>
+ <onekey>test/sect163k1-U</onekey>
+ <otherkey>test/sect163k1-V</otherkey>
+ </kaResult>
+
+ <kaResult>
+ <id>brainpoolP224r1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>brainpool/brainpoolP224r1-dh-raw.csv</file>
+ <curve>brainpool/brainpoolP224r1</curve>
+ <onekey>test/brainpoolP224r1-A</onekey>
+ <otherkey>test/brainpoolP224r1-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>brainpoolP256r1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>brainpool/brainpoolP256r1-dh-raw.csv</file>
+ <curve>brainpool/brainpoolP256r1</curve>
+ <onekey>test/brainpoolP256r1-A</onekey>
+ <otherkey>test/brainpoolP256r1-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>brainpoolP384r1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>brainpool/brainpoolP384r1-dh-raw.csv</file>
+ <curve>brainpool/brainpoolP384r1</curve>
+ <onekey>test/brainpoolP384r1-A</onekey>
+ <otherkey>test/brainpoolP384r1-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>brainpoolP512r1-dh-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>brainpool/brainpoolP512r1-dh-raw.csv</file>
+ <curve>brainpool/brainpoolP512r1</curve>
+ <onekey>test/brainpoolP512r1-A</onekey>
+ <otherkey>test/brainpoolP512r1-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>p192-dhc-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>nist/p192-dhc-raw.csv</file>
+ <curve>nist/P-192</curve>
+ <onekey>test/p192-A</onekey>
+ <otherkey>test/p192-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>p224-dhc-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>nist/p224-dhc-raw.csv</file>
+ <curve>nist/P-224</curve>
+ <onekey>test/p224-A</onekey>
+ <otherkey>test/p224-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>p256-dhc-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>nist/p256-dhc-raw.csv</file>
+ <curve>nist/P-256</curve>
+ <onekey>test/p256-A</onekey>
+ <otherkey>test/p256-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>p384-dhc-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>nist/p384-dhc-raw.csv</file>
+ <curve>nist/P-384</curve>
+ <onekey>test/p384-A</onekey>
+ <otherkey>test/p384-B</otherkey>
+ </kaResult>
+ <kaResult>
+ <id>p521-dhc-plain</id>
+ <ka>DH_PLAIN</ka>
+ <file>nist/p521-dhc-raw.csv</file>
+ <curve>nist/P-521</curve>
+ <onekey>test/p521-A</onekey>
+ <otherkey>test/p521-B</otherkey>
+ </kaResult>
</results> \ No newline at end of file
diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
index 65997c1..f5686b2 100644
--- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
+++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
@@ -41,6 +41,7 @@ import cz.crcs.ectester.standalone.output.XMLTestWriter;
import cz.crcs.ectester.standalone.output.YAMLTestWriter;
import cz.crcs.ectester.standalone.test.suites.StandaloneDefaultSuite;
import cz.crcs.ectester.standalone.test.suites.StandaloneTestSuite;
+import cz.crcs.ectester.standalone.test.suites.StandaloneTestVectorSuite;
import org.apache.commons.cli.*;
import javax.crypto.KeyAgreement;
@@ -311,7 +312,9 @@ public class ECTesterStandalone {
*
*/
private void listSuites() {
- StandaloneTestSuite[] suites = new StandaloneTestSuite[]{new StandaloneDefaultSuite(null, null, null)};
+ StandaloneTestSuite[] suites = new StandaloneTestSuite[]{
+ new StandaloneDefaultSuite(null, null, null),
+ new StandaloneTestVectorSuite(null, null, null)};
for (StandaloneTestSuite suite : suites) {
System.out.println(" - " + suite.getName());
for (String line : suite.getDescription()) {
@@ -739,7 +742,17 @@ public class ECTesterStandalone {
break;
}
- StandaloneTestSuite suite = new StandaloneDefaultSuite(writer, cfg, cli);
+ StandaloneTestSuite suite;
+
+ switch(cli.getArg(0).toLowerCase()) {
+ case "test-vectors":
+ suite = new StandaloneTestVectorSuite(writer, cfg, cli);
+ break;
+ case "default":
+ default:
+ suite = new StandaloneDefaultSuite(writer, cfg, cli);
+ }
+
suite.run();
}
diff --git a/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestVectorSuite.java b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestVectorSuite.java
new file mode 100644
index 0000000..c4a866b
--- /dev/null
+++ b/src/cz/crcs/ectester/standalone/test/suites/StandaloneTestVectorSuite.java
@@ -0,0 +1,59 @@
+package cz.crcs.ectester.standalone.test.suites;
+
+import cz.crcs.ectester.common.cli.TreeCommandLine;
+import cz.crcs.ectester.common.ec.*;
+import cz.crcs.ectester.common.output.TestWriter;
+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.test.base.KeyAgreementTest;
+import cz.crcs.ectester.standalone.test.base.KeyAgreementTestable;
+
+import javax.crypto.KeyAgreement;
+import java.io.IOException;
+import java.security.interfaces.ECPrivateKey;
+import java.security.interfaces.ECPublicKey;
+import java.util.Map;
+
+public class StandaloneTestVectorSuite extends StandaloneTestSuite {
+
+ public StandaloneTestVectorSuite(TestWriter writer, ECTesterStandalone.Config cfg, TreeCommandLine cli) {
+ super(writer, cfg, cli, "test-vectors", "The test-vectors suite contains a collection of test vectors which test basic ECDH correctness.");
+ }
+
+ @Override
+ protected void runTests() throws Exception {
+ Map<String, EC_KAResult> results = EC_Store.getInstance().getObjects(EC_KAResult.class, "test");
+ for (EC_KAResult result : results.values()) {
+
+ if(!"DH_PLAIN".equals(result.getKA())) {
+ continue;
+ }
+
+ EC_Params onekey = EC_Store.getInstance().getObject(EC_Keypair.class, result.getOneKey());
+ if (onekey == null) {
+ onekey = EC_Store.getInstance().getObject(EC_Key.Private.class, result.getOneKey());
+ }
+ EC_Params otherkey = EC_Store.getInstance().getObject(EC_Keypair.class, result.getOtherKey());
+ if (otherkey == null) {
+ otherkey = EC_Store.getInstance().getObject(EC_Key.Public.class, result.getOtherKey());
+ }
+ if (onekey == null || otherkey == null) {
+ throw new IOException("Test vector keys couldn't be located.");
+ }
+
+ ECPrivateKey privkey = onekey instanceof EC_Keypair ?
+ (ECPrivateKey) ECUtil.toKeyPair((EC_Keypair) onekey).getPrivate() :
+ ECUtil.toPrivateKey((EC_Key.Private) onekey);
+ ECPublicKey pubkey = otherkey instanceof EC_Keypair ?
+ (ECPublicKey) ECUtil.toKeyPair((EC_Keypair) otherkey).getPublic() :
+ ECUtil.toPublicKey((EC_Key.Public) otherkey);
+
+ KeyAgreementIdent kaIdent = KeyAgreementIdent.get("ECDH");
+ KeyAgreement ka = kaIdent.getInstance(cfg.selected.getProvider());
+ KeyAgreementTestable testable = new KeyAgreementTestable(ka, privkey, pubkey);
+ doTest(KeyAgreementTest.match(testable, result.getData(0)));
+ }
+ }
+}