aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/cz/crcs/ectester/common')
-rw-r--r--src/cz/crcs/ectester/common/cli/TreeCommandLine.java14
-rw-r--r--src/cz/crcs/ectester/common/ec/EC_Curve.java35
2 files changed, 42 insertions, 7 deletions
diff --git a/src/cz/crcs/ectester/common/cli/TreeCommandLine.java b/src/cz/crcs/ectester/common/cli/TreeCommandLine.java
index 39607dc..7de6ef1 100644
--- a/src/cz/crcs/ectester/common/cli/TreeCommandLine.java
+++ b/src/cz/crcs/ectester/common/cli/TreeCommandLine.java
@@ -3,7 +3,6 @@ package cz.crcs.ectester.common.cli;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
-import sun.reflect.generics.tree.Tree;
import java.util.Iterator;
import java.util.List;
@@ -150,20 +149,21 @@ public class TreeCommandLine extends CommandLine {
}
public boolean hasArg(int index) {
- if (next != null) {
- return next.hasArg(index);
- }
- return Math.abs(index) < cli.getArgs().length;
+ return getArg(index) != null;
}
public String getArg(int index) {
if (next != null) {
return next.getArg(index);
}
- if (index >= cli.getArgs().length) {
+ String[] args = cli.getArgs();
+ if (index >= args.length) {
+ return null;
+ }
+ if (index < 0 && -index > args.length) {
return null;
}
- return index < 0 ? cli.getArgs()[cli.getArgs().length + index] : cli.getArgs()[index];
+ return index < 0 ? args[args.length + index] : args[index];
}
@Override
diff --git a/src/cz/crcs/ectester/common/ec/EC_Curve.java b/src/cz/crcs/ectester/common/ec/EC_Curve.java
index 19cfe2d..478ce7d 100644
--- a/src/cz/crcs/ectester/common/ec/EC_Curve.java
+++ b/src/cz/crcs/ectester/common/ec/EC_Curve.java
@@ -1,8 +1,12 @@
package cz.crcs.ectester.common.ec;
import cz.crcs.ectester.applet.EC_Consts;
+import cz.crcs.ectester.common.Util;
import javacard.security.KeyPair;
+import java.math.BigInteger;
+import java.security.spec.*;
+
/**
* An Elliptic curve, contains parameters Fp/F2M, A, B, G, R, (K)?.
*
@@ -49,4 +53,35 @@ public class EC_Curve extends EC_Params {
public String toString() {
return "<" + getId() + "> " + (field == KeyPair.ALG_EC_FP ? "Prime" : "Binary") + " field Elliptic curve (" + String.valueOf(bits) + "b)" + (desc == null ? "" : ": " + desc);
}
+
+ public ECParameterSpec toSpec() {
+ ECField field;
+ if (this.field == KeyPair.ALG_EC_FP) {
+ field = new ECFieldFp(new BigInteger(1, getData(0)));
+ } else {
+ byte[][] fieldData = getParam(EC_Consts.PARAMETER_F2M);
+ int m = Util.getShort(fieldData[0], 0);
+ int e1 = Util.getShort(fieldData[1], 0);
+ int e2 = Util.getShort(fieldData[2], 0);
+ int e3 = Util.getShort(fieldData[3], 0);
+ int[] powers = new int[]{e1, e2, e3};
+ field = new ECFieldF2m(m, powers);
+ }
+
+ BigInteger a = new BigInteger(1, getParam(EC_Consts.PARAMETER_A)[0]);
+ BigInteger b = new BigInteger(1, getParam(EC_Consts.PARAMETER_B)[0]);
+
+ EllipticCurve curve = new EllipticCurve(field, a, b);
+
+ byte[][] G = getParam(EC_Consts.PARAMETER_G);
+ BigInteger gx = new BigInteger(1, G[0]);
+ BigInteger gy = new BigInteger(1, G[1]);
+ ECPoint generator = new ECPoint(gx, gy);
+
+ BigInteger n = new BigInteger(1, getParam(EC_Consts.PARAMETER_R)[0]);
+
+ int h = Util.getShort(getParam(EC_Consts.PARAMETER_K)[0], 0);
+
+ return new ECParameterSpec(curve, generator, n, h);
+ }
}