Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-05 16:43:46 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-05 16:43:46 +0400
commitbe94317db1e607063a9fd17bee364889997f90c3 (patch)
tree2cc93b36a914f1a9ca1ae205391e30abaca5965f
parentaad3520281888f8228bb4da67d23d1cd0e9cd9f8 (diff)
Replace more instanceof checks for curve type
-rw-r--r--core/src/main/java/org/bouncycastle/asn1/ua/DSTU4145ECBinary.java24
-rw-r--r--prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java24
-rw-r--r--prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java24
3 files changed, 29 insertions, 43 deletions
diff --git a/core/src/main/java/org/bouncycastle/asn1/ua/DSTU4145ECBinary.java b/core/src/main/java/org/bouncycastle/asn1/ua/DSTU4145ECBinary.java
index 11c2af48..dc9f74c0 100644
--- a/core/src/main/java/org/bouncycastle/asn1/ua/DSTU4145ECBinary.java
+++ b/core/src/main/java/org/bouncycastle/asn1/ua/DSTU4145ECBinary.java
@@ -12,15 +12,15 @@ import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
-import org.bouncycastle.asn1.x9.X9IntegerConverter;
import org.bouncycastle.crypto.params.ECDomainParameters;
+import org.bouncycastle.math.ec.ECAlgorithms;
import org.bouncycastle.math.ec.ECCurve;
+import org.bouncycastle.math.field.PolynomialExtensionField;
import org.bouncycastle.util.Arrays;
public class DSTU4145ECBinary
extends ASN1Object
{
-
BigInteger version = BigInteger.valueOf(0);
DSTU4145BinaryField f;
@@ -31,17 +31,27 @@ public class DSTU4145ECBinary
public DSTU4145ECBinary(ECDomainParameters params)
{
- if (!(params.getCurve() instanceof ECCurve.F2m))
+ ECCurve curve = params.getCurve();
+ if (!ECAlgorithms.isF2mCurve(curve))
{
throw new IllegalArgumentException("only binary domain is possible");
}
// We always use big-endian in parameter encoding
- ECCurve.F2m curve = (ECCurve.F2m)params.getCurve();
- f = new DSTU4145BinaryField(curve.getM(), curve.getK1(), curve.getK2(), curve.getK3());
+
+ PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
+ int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
+ if (exponents.length == 3)
+ {
+ f = new DSTU4145BinaryField(exponents[2], exponents[1]);
+ }
+ else if (exponents.length == 5)
+ {
+ f = new DSTU4145BinaryField(exponents[4], exponents[1], exponents[2], exponents[3]);
+ }
+
a = new ASN1Integer(curve.getA().toBigInteger());
- X9IntegerConverter converter = new X9IntegerConverter();
- b = new DEROctetString(converter.integerToBytes(curve.getB().toBigInteger(), converter.getByteLength(curve)));
+ b = new DEROctetString(curve.getB().getEncoded());
n = new ASN1Integer(params.getN());
bp = new DEROctetString(DSTU4145PointEncoder.encodePoint(params.getG()));
}
diff --git a/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java b/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java
index 5eeb1b18..7d83cc19 100644
--- a/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java
+++ b/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ec/BCECPrivateKey.java
@@ -235,26 +235,14 @@ public class BCECPrivateKey
}
else
{
- ECParameterSpec p = (ECParameterSpec)ecSpec;
- ECCurve curve = p.getG().getCurve();
- ECPoint generator;
-
- if (curve instanceof ECCurve.Fp)
- {
- generator = new ECPoint.Fp(curve, p.getG().getX(), p.getG().getY(), withCompression);
- }
- else if (curve instanceof ECCurve.F2m)
- {
- generator = new ECPoint.F2m(curve, p.getG().getX(), p.getG().getY(), withCompression);
- }
- else
- {
- throw new UnsupportedOperationException("Subclass of ECPoint " + curve.getClass().toString() + "not supported");
- }
-
+ ECParameterSpec p = (ECParameterSpec)ecSpec;
+
+ ECPoint pG = p.getG().normalize();
+ ECPoint g = pG.getCurve().createPoint(pG.getXCoord(), pG.getYCoord(), withCompression);
+
X9ECParameters ecP = new X9ECParameters(
p.getCurve(),
- generator,
+ g,
p.getN(),
p.getH(),
p.getSeed());
diff --git a/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java b/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java
index 9392d10a..32529f91 100644
--- a/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java
+++ b/prov/src/main/jdk1.4/org/bouncycastle/jcajce/provider/asymmetric/ecgost/BCECGOST3410PrivateKey.java
@@ -209,26 +209,14 @@ public class BCECGOST3410PrivateKey
}
else
{
- ECParameterSpec p = (ECParameterSpec)ecSpec;
- ECCurve curve = p.getG().getCurve();
- ECPoint generator;
-
- if (curve instanceof ECCurve.Fp)
- {
- generator = new ECPoint.Fp(curve, p.getG().getX(), p.getG().getY(), withCompression);
- }
- else if (curve instanceof ECCurve.F2m)
- {
- generator = new ECPoint.F2m(curve, p.getG().getX(), p.getG().getY(), withCompression);
- }
- else
- {
- throw new UnsupportedOperationException("Subclass of ECPoint " + curve.getClass().toString() + "not supported");
- }
-
+ ECParameterSpec p = (ECParameterSpec)ecSpec;
+
+ ECPoint pG = p.getG().normalize();
+ ECPoint g = pG.getCurve().createPoint(pG.getXCoord(), pG.getYCoord(), withCompression);
+
X9ECParameters ecP = new X9ECParameters(
p.getCurve(),
- generator,
+ g,
p.getN(),
p.getH(),
p.getSeed());