diff options
| author | J08nY | 2019-03-18 11:01:24 +0100 |
|---|---|---|
| committer | J08nY | 2019-03-18 11:01:24 +0100 |
| commit | 529ab9c66b20e4308f88b63ead3318fd52e47eab (patch) | |
| tree | 88b4fd80c4044b6febba2e28e6f1cdabdfceccb4 /src/cz/crcs/ectester/common/ec/EC_Curve.java | |
| parent | f535cb56d88e2bcc17dde1f15d021a17d1f1f511 (diff) | |
| parent | 648d8718af10186e5c585844f6bb8c32e244c3a0 (diff) | |
| download | ECTester-529ab9c66b20e4308f88b63ead3318fd52e47eab.tar.gz ECTester-529ab9c66b20e4308f88b63ead3318fd52e47eab.tar.zst ECTester-529ab9c66b20e4308f88b63ead3318fd52e47eab.zip | |
Merge branch 'devel'
Diffstat (limited to '')
| -rw-r--r-- | src/cz/crcs/ectester/common/ec/EC_Curve.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/cz/crcs/ectester/common/ec/EC_Curve.java b/src/cz/crcs/ectester/common/ec/EC_Curve.java index 6c0d060..d5d1516 100644 --- a/src/cz/crcs/ectester/common/ec/EC_Curve.java +++ b/src/cz/crcs/ectester/common/ec/EC_Curve.java @@ -3,6 +3,7 @@ package cz.crcs.ectester.common.ec; import cz.crcs.ectester.applet.EC_Consts; import cz.crcs.ectester.common.util.ByteUtil; import javacard.security.KeyPair; +import org.bouncycastle.math.ec.ECCurve; import java.math.BigInteger; import java.security.spec.*; @@ -64,7 +65,12 @@ public class EC_Curve extends EC_Params { int e1 = ByteUtil.getShort(fieldData[1], 0); int e2 = ByteUtil.getShort(fieldData[2], 0); int e3 = ByteUtil.getShort(fieldData[3], 0); - int[] powers = new int[]{e1, e2, e3}; + int[] powers; + if (e2 == 0 && e3 == 0) { + powers = new int[]{e1}; + } else { + powers = new int[]{e1, e2, e3}; + } field = new ECFieldF2m(m, powers); } @@ -74,6 +80,28 @@ public class EC_Curve extends EC_Params { return new EllipticCurve(field, a, b); } + public ECCurve toBCCurve() { + if (this.field == KeyPair.ALG_EC_FP) { + BigInteger p = new BigInteger(1, getParam(EC_Consts.PARAMETER_FP)[0]); + BigInteger a = new BigInteger(1, getParam(EC_Consts.PARAMETER_A)[0]); + BigInteger b = new BigInteger(1, getParam(EC_Consts.PARAMETER_B)[0]); + BigInteger r = new BigInteger(1, getParam(EC_Consts.PARAMETER_R)[0]); + BigInteger k = new BigInteger(1, getParam(EC_Consts.PARAMETER_K)[0]); + return new ECCurve.Fp(p, a, b, r, k); + } else { + byte[][] fieldData = getParam(EC_Consts.PARAMETER_F2M); + int m = ByteUtil.getShort(fieldData[0], 0); + int e1 = ByteUtil.getShort(fieldData[1], 0); + int e2 = ByteUtil.getShort(fieldData[2], 0); + int e3 = ByteUtil.getShort(fieldData[3], 0); + BigInteger a = new BigInteger(1, getParam(EC_Consts.PARAMETER_A)[0]); + BigInteger b = new BigInteger(1, getParam(EC_Consts.PARAMETER_B)[0]); + BigInteger r = new BigInteger(1, getParam(EC_Consts.PARAMETER_R)[0]); + BigInteger k = new BigInteger(1, getParam(EC_Consts.PARAMETER_K)[0]); + return new ECCurve.F2m(m, e1, e2, e3, a, b, r, k); + } + } + public ECParameterSpec toSpec() { EllipticCurve curve = toCurve(); |
