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:
authorDavid Hook <dgh@cryptoworkshop.com>2014-01-05 09:40:11 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2014-01-05 09:40:11 +0400
commitc613629f8314220a85adbc2c5de175a7e2bd9b81 (patch)
tree6b236c8dcc3669621f7991c41e25a791eb553c15
parent38f988fa0d25149b597f2b53e47300a6536b1470 (diff)
moved SECCustomNamedCurves to CustomNamedCurves in crypto.ec
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/ec/CustomNamedCurves.java120
-rw-r--r--core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java4
-rw-r--r--core/src/test/java/org/bouncycastle/math/ec/test/ECPointPerformanceTest.java4
-rw-r--r--core/src/test/java/org/bouncycastle/math/ec/test/ECPointTest.java4
-rw-r--r--prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/EC5Util.java6
-rw-r--r--prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/ECUtil.java4
6 files changed, 131 insertions, 11 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/ec/CustomNamedCurves.java b/core/src/main/java/org/bouncycastle/crypto/ec/CustomNamedCurves.java
new file mode 100644
index 00000000..96039c6c
--- /dev/null
+++ b/core/src/main/java/org/bouncycastle/crypto/ec/CustomNamedCurves.java
@@ -0,0 +1,120 @@
+package org.bouncycastle.crypto.ec;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.bouncycastle.asn1.ASN1ObjectIdentifier;
+import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
+import org.bouncycastle.asn1.x9.X9ECParameters;
+import org.bouncycastle.asn1.x9.X9ECParametersHolder;
+import org.bouncycastle.math.ec.ECCurve;
+import org.bouncycastle.math.ec.ECPoint;
+import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve;
+import org.bouncycastle.math.ec.custom.sec.SecP256R1Curve;
+import org.bouncycastle.util.Strings;
+import org.bouncycastle.util.encoders.Hex;
+
+public class CustomNamedCurves
+{
+ private static ECCurve configureCurve(ECCurve curve)
+ {
+ return curve;
+ }
+
+ /*
+ * secp256k1
+ */
+ static X9ECParametersHolder secp256k1 = new X9ECParametersHolder()
+ {
+ protected X9ECParameters createParameters()
+ {
+ byte[] S = null;
+ ECCurve curve = configureCurve(new SecP256K1Curve());
+ ECPoint G = curve.decodePoint(Hex.decode("04"
+ + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
+ + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));
+ return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S);
+ }
+ };
+
+ /*
+ * secp256r1
+ */
+ static X9ECParametersHolder secp256r1 = new X9ECParametersHolder()
+ {
+ protected X9ECParameters createParameters()
+ {
+ byte[] S = Hex.decode("C49D360886E704936A6678E1139D26B7819F7E90");
+ ECCurve curve = configureCurve(new SecP256R1Curve());
+ ECPoint G = curve.decodePoint(Hex.decode("04"
+ + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
+ + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"));
+ return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S);
+ }
+ };
+
+ static final Hashtable objIds = new Hashtable();
+ static final Hashtable curves = new Hashtable();
+ static final Hashtable names = new Hashtable();
+
+ static void defineCurve(String name, ASN1ObjectIdentifier oid, X9ECParametersHolder holder)
+ {
+ objIds.put(name, oid);
+ names.put(oid, name);
+ curves.put(oid, holder);
+ }
+
+ static
+ {
+ defineCurve("secp256k1", SECObjectIdentifiers.secp256k1, secp256k1);
+ defineCurve("secp256r1", SECObjectIdentifiers.secp256r1, secp256r1);
+
+ objIds.put(Strings.toLowerCase("P-256"), SECObjectIdentifiers.secp256r1);
+ }
+
+ public static X9ECParameters getByName(String name)
+ {
+ ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(Strings.toLowerCase(name));
+ return oid == null ? null : getByOID(oid);
+ }
+
+ /**
+ * return the X9ECParameters object for the named curve represented by the passed in object
+ * identifier. Null if the curve isn't present.
+ *
+ * @param oid
+ * an object identifier representing a named curve, if present.
+ */
+ public static X9ECParameters getByOID(ASN1ObjectIdentifier oid)
+ {
+ X9ECParametersHolder holder = (X9ECParametersHolder)curves.get(oid);
+ return holder == null ? null : holder.getParameters();
+ }
+
+ /**
+ * return the object identifier signified by the passed in name. Null if there is no object
+ * identifier associated with name.
+ *
+ * @return the object identifier associated with name, if present.
+ */
+ public static ASN1ObjectIdentifier getOID(String name)
+ {
+ return (ASN1ObjectIdentifier)objIds.get(Strings.toLowerCase(name));
+ }
+
+ /**
+ * return the named curve name represented by the given object identifier.
+ */
+ public static String getName(ASN1ObjectIdentifier oid)
+ {
+ return (String)names.get(oid);
+ }
+
+ /**
+ * returns an enumeration containing the name strings for curves contained in this structure.
+ */
+ public static Enumeration getNames()
+ {
+ return objIds.keys();
+ }
+}
diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java b/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
index e2a99d87..5adf06cf 100644
--- a/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
+++ b/core/src/main/java/org/bouncycastle/crypto/tls/TlsECCUtils.java
@@ -8,11 +8,11 @@ import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Hashtable;
-import org.bouncycastle.asn1.sec.SECCustomNamedCurves;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
+import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.crypto.generators.ECKeyPairGenerator;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECKeyGenerationParameters;
@@ -153,7 +153,7 @@ public class TlsECCUtils
// Parameters are lazily created the first time a particular curve is accessed
- X9ECParameters ecP = SECCustomNamedCurves.getByName(curveName);
+ X9ECParameters ecP = CustomNamedCurves.getByName(curveName);
if (ecP == null)
{
ecP = ECNamedCurveTable.getByName(curveName);
diff --git a/core/src/test/java/org/bouncycastle/math/ec/test/ECPointPerformanceTest.java b/core/src/test/java/org/bouncycastle/math/ec/test/ECPointPerformanceTest.java
index c919c6bf..c1420051 100644
--- a/core/src/test/java/org/bouncycastle/math/ec/test/ECPointPerformanceTest.java
+++ b/core/src/test/java/org/bouncycastle/math/ec/test/ECPointPerformanceTest.java
@@ -4,9 +4,9 @@ import java.math.BigInteger;
import java.security.SecureRandom;
import junit.framework.TestCase;
-import org.bouncycastle.asn1.sec.SECCustomNamedCurves;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParameters;
+import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
@@ -30,7 +30,7 @@ public class ECPointPerformanceTest extends TestCase
randMult(curveName, spec);
}
- spec = SECCustomNamedCurves.getByName(curveName);
+ spec = CustomNamedCurves.getByName(curveName);
if (spec != null)
{
randMult(curveName + " (custom)", spec);
diff --git a/core/src/test/java/org/bouncycastle/math/ec/test/ECPointTest.java b/core/src/test/java/org/bouncycastle/math/ec/test/ECPointTest.java
index 2002da41..e2be2deb 100644
--- a/core/src/test/java/org/bouncycastle/math/ec/test/ECPointTest.java
+++ b/core/src/test/java/org/bouncycastle/math/ec/test/ECPointTest.java
@@ -7,9 +7,9 @@ import java.util.Enumeration;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.bouncycastle.asn1.sec.SECCustomNamedCurves;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
+import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
@@ -446,7 +446,7 @@ public class ECPointTest extends TestCase
X9ECParameters x9ECParameters = SECNamedCurves.getByName(name);
implAddSubtractMultiplyTwiceEncodingTest(x9ECParameters);
- x9ECParameters = SECCustomNamedCurves.getByName(name);
+ x9ECParameters = CustomNamedCurves.getByName(name);
if (x9ECParameters != null)
{
implAddSubtractMultiplyTwiceEncodingTest(x9ECParameters);
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/EC5Util.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/EC5Util.java
index a50ffa60..e409b978 100644
--- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/EC5Util.java
+++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/EC5Util.java
@@ -10,8 +10,8 @@ import java.security.spec.EllipticCurve;
import java.util.HashMap;
import java.util.Map;
-import org.bouncycastle.asn1.sec.SECCustomNamedCurves;
import org.bouncycastle.asn1.sec.SECNamedCurves;
+import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
import org.bouncycastle.jce.spec.ECNamedCurveSpec;
import org.bouncycastle.math.ec.ECCurve;
@@ -24,8 +24,8 @@ public class EC5Util
static
{
- customCurves.put(SECNamedCurves.getByName("secp256k1").getCurve(), SECCustomNamedCurves.getByName("secp256k1").getCurve());
- customCurves.put(SECNamedCurves.getByName("secp256r1").getCurve(), SECCustomNamedCurves.getByName("secp256r1").getCurve());
+ customCurves.put(SECNamedCurves.getByName("secp256k1").getCurve(), CustomNamedCurves.getByName("secp256k1").getCurve());
+ customCurves.put(SECNamedCurves.getByName("secp256r1").getCurve(), CustomNamedCurves.getByName("secp256r1").getCurve());
}
public static EllipticCurve convertCurve(
diff --git a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/ECUtil.java b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/ECUtil.java
index 10e92b61..4283273d 100644
--- a/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/ECUtil.java
+++ b/prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/util/ECUtil.java
@@ -8,12 +8,12 @@ import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
-import org.bouncycastle.asn1.sec.SECCustomNamedCurves;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x9.X962NamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
+import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
@@ -242,7 +242,7 @@ public class ECUtil
public static X9ECParameters getNamedCurveByOid(
ASN1ObjectIdentifier oid)
{
- X9ECParameters params = SECCustomNamedCurves.getByOID(oid);
+ X9ECParameters params = CustomNamedCurves.getByOID(oid);
if (params == null)
{