summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2018-12-10 15:34:09 +0100
committerJ08nY2018-12-10 15:34:09 +0100
commit5848a64d506231bfa8de73b433a76b1017b4d33e (patch)
treedb7888681ef35afcab6a74cea6c4283bb0d7662c
parent0b69ee96a04d09ad81b03d67173b49658cfb2b9c (diff)
downloadECTester-5848a64d506231bfa8de73b433a76b1017b4d33e.tar.gz
ECTester-5848a64d506231bfa8de73b433a76b1017b4d33e.tar.zst
ECTester-5848a64d506231bfa8de73b433a76b1017b4d33e.zip
-rw-r--r--src/cz/crcs/ectester/data/degenerate/cofactor.xml122
-rw-r--r--src/cz/crcs/ectester/data/degenerate/keys.xml2
-rw-r--r--src/cz/crcs/ectester/reader/ECTesterReader.java14
-rw-r--r--src/cz/crcs/ectester/reader/test/CardDegenerateSuite.java9
4 files changed, 134 insertions, 13 deletions
diff --git a/src/cz/crcs/ectester/data/degenerate/cofactor.xml b/src/cz/crcs/ectester/data/degenerate/cofactor.xml
new file mode 100644
index 0000000..2ceaeb5
--- /dev/null
+++ b/src/cz/crcs/ectester/data/degenerate/cofactor.xml
@@ -0,0 +1,122 @@
+<pubkey>
+ <id>cofactor128p4/0</id>
+ <inline>0x00000000000000000000000000000000,0x94d9020b666fbb599609485472a9246e</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 2</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/1</id>
+ <inline>0x00000000000000000000000000000000,0x2d3a81f8b8d96e6db96a04fb6cf432de</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 3</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/2</id>
+ <inline>0x00000000000000000000000000000000,0x639272497e0865cea0e17677b6bc5575</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 7</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/3</id>
+ <inline>0x00000000000000000000000000000000,0x072aba3ae7aeb770332600a630e503d1</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 5297</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/4</id>
+ <inline>0x00000000000000000000000000000000,0x17b45a35afdff5c5150a7c0a7ee34825</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 31134053800693</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/5</id>
+ <inline>0x00000000000000000000000000000000,0x6fd5d6e491bf5a15eb1d38554caad86c</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>degenerate order = 28564500657606656383</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor128p4/gen</id>
+ <inline>0x00000000000000000000000000000000,0x00000000000000000000000000000005</inline>
+ <curve>cofactor/cofactor128p4</curve>
+ <desc>generator of Fp^*</desc>
+</pubkey>
+
+<pubkey>
+ <id>cofactor160p4/0</id>
+ <inline>0x0000000000000000000000000000000000000000,0x93ab454ad26dae3b521d5b61a48c94cab3c4aa9c</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 2</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/1</id>
+ <inline>0x0000000000000000000000000000000000000000,0xbad87d0931716ec918e43e76b57971cc613e153</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 4</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/2</id>
+ <inline>0x0000000000000000000000000000000000000000,0x4428069aa7ac1865eb52c5b4c885ec832d89b36d</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 3</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/3</id>
+ <inline>0x0000000000000000000000000000000000000000,0x6eb71aefce923ebf8b07c6f1f59b1c30d43b74ae</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 23</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/4</id>
+ <inline>0x0000000000000000000000000000000000000000,0x3c5ff8c94b31b46f92575e0b77b0366afe24dfc1</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 11443</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/5</id>
+ <inline>0x0000000000000000000000000000000000000000,0xd8e2287382e057de70e1f45f70d8dad85d27025</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 352281613501590816479</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/5</id>
+ <inline>0x0000000000000000000000000000000000000000,0x36911d265f6d795a2efd10c20aae0f3ec5f815f4</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>degenerate order = 757721821606925858951</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor160p4/gen</id>
+ <inline>0x0000000000000000000000000000000000000000,0x0000000000000000000000000000000000000002</inline>
+ <curve>cofactor/cofactor160p4</curve>
+ <desc>generator of Fp^*</desc>
+</pubkey>
+
+<pubkey>
+ <id>cofactor192p4/0</id>
+ <inline>0x000000000000000000000000000000000000000000000000,0x8cceb84c81521937bef0925a3aaf09195a59c3f99ae06134</inline>
+ <curve>cofactor/cofactor192p4</curve>
+ <desc>degenerate order = 2</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor192p4/1</id>
+ <inline>0x000000000000000000000000000000000000000000000000,0x63ca4f21e0e4f6a833f914468e00e4d817f472d54aca5a64</inline>
+ <curve>cofactor/cofactor192p4</curve>
+ <desc>degenerate order = 4</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor192p4/2</id>
+ <inline>0x000000000000000000000000000000000000000000000000,0x7ce088c401bfc705e70da9928c04ed6e1bf100c26b253028</inline>
+ <curve>cofactor/cofactor192p4</curve>
+ <desc>degenerate order = 5</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor192p4/3</id>
+ <inline>0x000000000000000000000000000000000000000000000000,0x000000000000000000000000000000000000000000100000</inline>
+ <curve>cofactor/cofactor192p4</curve>
+ <desc>degenerate order = 172629492300688965054638881592440218548130640356589228457</desc>
+</pubkey>
+<pubkey>
+ <id>cofactor192p4/gen</id>
+ <inline>0x000000000000000000000000000000000000000000000000,0x000000000000000000000000000000000000000000000002</inline>
+ <curve>cofactor/cofactor192p4</curve>
+ <desc>generator of Fp^*</desc>
+</pubkey>
diff --git a/src/cz/crcs/ectester/data/degenerate/keys.xml b/src/cz/crcs/ectester/data/degenerate/keys.xml
index b999ca0..498cf26 100644
--- a/src/cz/crcs/ectester/data/degenerate/keys.xml
+++ b/src/cz/crcs/ectester/data/degenerate/keys.xml
@@ -2,6 +2,7 @@
<!DOCTYPE keys [
<!ENTITY secg SYSTEM "degenerate/secg.xml">
<!ENTITY brainpool SYSTEM "degenerate/brainpool.xml">
+ <!ENTITY cofactor SYSTEM "degenerate/cofactor.xml">
]>
<keys xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../schema.xsd">
@@ -11,4 +12,5 @@
-->
&secg;
&brainpool;
+ &cofactor;
</keys> \ No newline at end of file
diff --git a/src/cz/crcs/ectester/reader/ECTesterReader.java b/src/cz/crcs/ectester/reader/ECTesterReader.java
index fe44709..9f0d8cc 100644
--- a/src/cz/crcs/ectester/reader/ECTesterReader.java
+++ b/src/cz/crcs/ectester/reader/ECTesterReader.java
@@ -42,10 +42,6 @@ import cz.crcs.ectester.reader.test.*;
import javacard.framework.ISO7816;
import javacard.security.KeyPair;
import org.apache.commons.cli.*;
-import org.bouncycastle.asn1.ASN1Integer;
-import org.bouncycastle.asn1.ASN1StreamParser;
-import org.bouncycastle.asn1.DERSequence;
-import org.bouncycastle.asn1.DERSequenceParser;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import javax.smartcardio.CardException;
@@ -603,8 +599,8 @@ public class ECTesterReader {
Response.Export export = new Command.Export(cardManager, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.KEY_BOTH, EC_Consts.PARAMETERS_KEYPAIR).send();
respWriter.outputResponse(export);
- byte pubkey_bytes[] = export.getParameter(pubkey, EC_Consts.PARAMETER_W);
- byte privkey_bytes[] = export.getParameter(privkey, EC_Consts.PARAMETER_S);
+ byte[] pubkey_bytes = export.getParameter(pubkey, EC_Consts.PARAMETER_W);
+ byte[] privkey_bytes = export.getParameter(privkey, EC_Consts.PARAMETER_S);
Response.ECDH perform = new Command.ECDH(cardManager, pubkey, privkey, ECTesterApplet.EXPORT_TRUE, EC_Consts.TRANSFORMATION_NONE, cfg.ECKAType).send();
respWriter.outputResponse(perform);
@@ -643,7 +639,7 @@ public class ECTesterReader {
*/
private void ecdsa() throws CardException, IOException {
//read file, if asked to sign
- byte[] data = null;
+ byte[] data;
if (cfg.input != null) {
File in = new File(cfg.input);
long len = in.length();
@@ -700,7 +696,7 @@ public class ECTesterReader {
Response.ECDSA sign = new Command.ECDSA_sign(cardManager, ECTesterApplet.KEYPAIR_LOCAL, cfg.ECDSAType, ECTesterApplet.EXPORT_TRUE, data).send();
respWriter.outputResponse(sign);
- if (!sign.successful() || ! sign.hasSignature()) {
+ if (!sign.successful() || !sign.hasSignature()) {
if (retry < 10) {
++retry;
continue;
@@ -737,7 +733,7 @@ public class ECTesterReader {
k = ByteUtil.bytesToHex(kValue.toByteArray(), false);
}
}
- out.write(String.format("%d;%d;%d;%s;%s;%s;%s;%s;%d\n", done, sign.getDuration() / 1000000, verify.getDuration() / 1000000, dataString, pub, priv, ByteUtil.bytesToHex(signature, false), k,verify.successful() ? 1 : 0));
+ out.write(String.format("%d;%d;%d;%s;%s;%s;%s;%s;%d\n", done, sign.getDuration() / 1000000, verify.getDuration() / 1000000, dataString, pub, priv, ByteUtil.bytesToHex(signature, false), k, verify.successful() ? 1 : 0));
}
++done;
diff --git a/src/cz/crcs/ectester/reader/test/CardDegenerateSuite.java b/src/cz/crcs/ectester/reader/test/CardDegenerateSuite.java
index f434d4d..87613fe 100644
--- a/src/cz/crcs/ectester/reader/test/CardDegenerateSuite.java
+++ b/src/cz/crcs/ectester/reader/test/CardDegenerateSuite.java
@@ -40,7 +40,7 @@ public class CardDegenerateSuite extends CardTestSuite {
Test set = CommandTest.expect(new Command.Set(this.card, ECTesterApplet.KEYPAIR_BOTH, EC_Consts.CURVE_external, curve.getParams(), curve.flatten()), Result.ExpectedValue.SUCCESS);
Test generate = CommandTest.expect(new Command.Generate(this.card, ECTesterApplet.KEYPAIR_LOCAL), Result.ExpectedValue.SUCCESS);
- Test prepare = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Prepare and generate keypair on " + curve.getId(), allocate, set, generate);
+ Test prepare = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Prepare and generate keypair on " + curve.getId() + ".", allocate, set, generate);
List<Test> ecdhTests = new LinkedList<>();
for (EC_Key.Public pub : keys) {
@@ -50,13 +50,14 @@ public class CardDegenerateSuite extends CardTestSuite {
Command ecdhCommand = new Command.ECDH_direct(this.card, ECTesterApplet.KEYPAIR_LOCAL, ECTesterApplet.EXPORT_FALSE, EC_Consts.TRANSFORMATION_NONE, EC_Consts.KeyAgreement_ALG_EC_SVDP_DH, pub.flatten());
Test rawEcdh = CommandTest.expect(ecdhCommand, Result.ExpectedValue.FAILURE, "Card correctly rejected point on degenerate curve.", "Card incorrectly accepted point on degenerate curve.");
ecdhTests.add(CompoundTest.all(Result.ExpectedValue.SUCCESS, pub.getId() + " degenerate key test.", objectEcdh, rawEcdh));
+ //TODO: actually get the result of ECDH here, as well as export privkey and compare to exponentiation in Fp^*.
}
- Test ecdh = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform ECDH with degenerate public points", ecdhTests.toArray(new Test[0]));
+ Test ecdh = CompoundTest.all(Result.ExpectedValue.SUCCESS, "Perform ECDH with degenerate public points.", ecdhTests.toArray(new Test[0]));
if (cfg.cleanup) {
Test cleanup = CommandTest.expect(new Command.Cleanup(this.card), Result.ExpectedValue.ANY);
- doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Degenerate curve test of " + curve.getId(), prepare, ecdh, cleanup));
+ doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Degenerate curve test of " + curve.getId() + ".", prepare, ecdh, cleanup));
} else {
- doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Degenerate curve test of " + curve.getId(), prepare, ecdh));
+ doTest(CompoundTest.greedyAllTry(Result.ExpectedValue.SUCCESS, "Degenerate curve test of " + curve.getId() + ".", prepare, ecdh));
}
}