Blame SOURCES/jss-ECC_keygen_byCurveName.patch

b93447
diff -up jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java.fix jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java
b93447
--- jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java.fix	2010-10-20 09:54:35.189680000 -0700
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGenerator.java	2010-10-20 10:54:53.154835000 -0700
b93447
@@ -196,7 +196,10 @@ public class KeyPairGenerator {
b93447
         engine.setKeyPairUsages(usages,usages_mask);
b93447
     }
b93447
    
b93447
-
b93447
+    public int getCurveCodeByName(String curveName)
b93447
+        throws InvalidParameterException {
b93447
+        return engine.getCurveCodeByName(curveName);
b93447
+    }
b93447
 
b93447
 
b93447
 
b93447
diff -up jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java.fix jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java
b93447
--- jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java.fix	2010-10-20 09:54:52.393628000 -0700
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/crypto/KeyPairGeneratorSpi.java	2010-10-20 10:55:39.441698000 -0700
b93447
@@ -94,4 +94,6 @@ public abstract class KeyPairGeneratorSp
b93447
 
b93447
     public abstract void setKeyPairUsages(KeyPairGeneratorSpi.Usage[] usages, 
b93447
                                           KeyPairGeneratorSpi.Usage[] usages_mask);
b93447
+
b93447
+    public abstract int getCurveCodeByName(String curveName) throws InvalidParameterException;
b93447
 }
b93447
diff -up jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java.fix jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java
b93447
--- jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java.fix	2010-10-15 10:30:57.832196000 -0700
b93447
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/pkcs11/PK11KeyPairGenerator.java	2010-10-20 11:09:30.523208000 -0700
b93447
@@ -44,6 +44,7 @@ import java.security.*;
b93447
 import java.security.SecureRandom;
b93447
 import java.security.spec.AlgorithmParameterSpec;
b93447
 import java.security.spec.DSAParameterSpec;
b93447
+import java.util.Hashtable;
b93447
 
b93447
 
b93447
 /**
b93447
@@ -55,6 +56,246 @@ public final class PK11KeyPairGenerator
b93447
     extends org.mozilla.jss.crypto.KeyPairGeneratorSpi
b93447
 {
b93447
 
b93447
+    // curve code for getting the actual EC curve
b93447
+    private enum ECCurve_Code {
b93447
+      // NIST, SEC2 Prime curves
b93447
+        secp521r1 , // == nistp521
b93447
+        nistp521 ,
b93447
+        secp384r1 , // == nistp384
b93447
+        nistp384 ,
b93447
+        secp256r1 , // == nistp256
b93447
+        nistp256 ,
b93447
+        secp256k1 ,
b93447
+        secp224r1 , // == nistp224
b93447
+        nistp224 ,
b93447
+        secp224k1 ,
b93447
+        secp192r1 , // == nistp192
b93447
+        nistp192 ,
b93447
+        secp192k1 ,
b93447
+        secp160r2 ,
b93447
+        secp160r1 ,
b93447
+        secp160k1 ,
b93447
+        secp128r2 ,
b93447
+        secp128r1 ,
b93447
+        secp112r2 ,
b93447
+        secp112r1 ,
b93447
+      // NIST, SEC2 Binary curves
b93447
+        sect571r1 , // == nistb571
b93447
+        nistb571 ,
b93447
+        sect571k1 , // == nistk571
b93447
+        nistk571 ,
b93447
+        sect409r1 , // == nistb409
b93447
+        nistb409 ,
b93447
+        sect409k1 , // == nistk409
b93447
+        nistk409 ,
b93447
+        sect283r1 , // == nistb283
b93447
+        nistb283 ,
b93447
+        sect283k1 , // == nistk283
b93447
+        nistk283 ,
b93447
+        sect239k1 ,
b93447
+        sect233r1 , // == nistb233
b93447
+        nistb233 ,
b93447
+        sect233k1 , // == nistk233
b93447
+        nistk233 ,
b93447
+        sect193r2 ,
b93447
+        sect193r1 ,
b93447
+        nistb163 ,
b93447
+        sect163r2 , // == nistb163
b93447
+        sect163r1 ,
b93447
+        sect163k1 , // == nistk163
b93447
+        nistk163 ,
b93447
+        sect131r2 ,
b93447
+        sect131r1 ,
b93447
+        sect113r2 ,
b93447
+        sect113r1 ,
b93447
+      // ANSI X9.62 Prime curves
b93447
+        prime239v3 ,
b93447
+        prime239v2 ,
b93447
+        prime239v1 ,
b93447
+        prime192v3 ,
b93447
+        prime192v2 ,
b93447
+        prime192v1 , // == nistp192
b93447
+        // prime256v1 == nistp256
b93447
+      // ANSI X9.62 Binary curves
b93447
+        c2pnb163v1 ,
b93447
+        c2pnb163v2 ,
b93447
+        c2pnb163v3 ,
b93447
+        c2pnb176v1 ,
b93447
+        c2tnb191v1 ,
b93447
+        c2tnb191v2 ,
b93447
+        c2tnb191v3 ,
b93447
+        //c2onb191v4 ,
b93447
+        //c2onb191v5 ,
b93447
+        c2pnb208w1 ,
b93447
+        c2tnb239v1 ,
b93447
+        c2tnb239v2 ,
b93447
+        c2tnb239v3 ,
b93447
+        //c2onb239v4 ,
b93447
+        //c2onb239v5 ,
b93447
+        c2pnb272w1 ,
b93447
+        c2pnb304w1 ,
b93447
+        c2tnb359v1 ,
b93447
+        c2pnb368w1 ,
b93447
+        c2tnb431r1
b93447
+        // no WTLS curves fo now
b93447
+    };
b93447
+
b93447
+    private static Hashtable ECCurve_NameToCode = new Hashtable();
b93447
+    static {
b93447
+      // NIST, SEC2 Prime curves
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp521r1", ECCurve_Code.secp521r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistp521", ECCurve_Code.nistp521);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp384r1", ECCurve_Code.secp384r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistp384", ECCurve_Code.nistp384);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp256r1", ECCurve_Code.secp256r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistp256", ECCurve_Code.nistp256);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp256k1", ECCurve_Code.secp256k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp224r1", ECCurve_Code.secp224r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistp224", ECCurve_Code.nistp224);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp224k1", ECCurve_Code.secp224k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp192r1", ECCurve_Code.secp192r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistp192", ECCurve_Code.nistp192);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp192k1", ECCurve_Code.secp192k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp160r2", ECCurve_Code.secp160r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp160r1", ECCurve_Code.secp160r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp160k1", ECCurve_Code.secp160k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp128r2", ECCurve_Code.secp128r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp128r1", ECCurve_Code.secp128r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp112r2", ECCurve_Code.secp112r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "secp112r1", ECCurve_Code.secp112r1);
b93447
+      // NIST, SEC2 Binary curves
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect571r1", ECCurve_Code.sect571r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistb571", ECCurve_Code.nistb571);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect571k1", ECCurve_Code.sect571k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistk571", ECCurve_Code.nistk571);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect409r1", ECCurve_Code.sect409r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistb409", ECCurve_Code.nistb409);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect409k1", ECCurve_Code.sect409k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistk409", ECCurve_Code.nistk409);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect283r1", ECCurve_Code.sect283r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistb283", ECCurve_Code.nistb283);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect283k1", ECCurve_Code.sect283k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistk283", ECCurve_Code.nistk283);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect239k1", ECCurve_Code.sect239k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect233r1", ECCurve_Code.sect233r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistb233", ECCurve_Code.nistb233);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect233k1", ECCurve_Code.sect233k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistk233", ECCurve_Code.nistk233);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect193r2", ECCurve_Code.sect193r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect193r1", ECCurve_Code.sect193r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistb163", ECCurve_Code.nistb163);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect163r2", ECCurve_Code.sect163r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect163r1", ECCurve_Code.sect163r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect163k1", ECCurve_Code.sect163k1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "nistk163", ECCurve_Code.nistk163);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect131r2", ECCurve_Code.sect131r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect131r1", ECCurve_Code.sect131r1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect113r2", ECCurve_Code.sect113r2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "sect113r1", ECCurve_Code.sect113r1);
b93447
+      // ANSI Prime curves
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime239v3", ECCurve_Code.prime239v3);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime239v2", ECCurve_Code.prime239v2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime239v1", ECCurve_Code.prime239v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime192v3", ECCurve_Code.prime192v3);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime192v2", ECCurve_Code.prime192v2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "prime192v1", ECCurve_Code.prime192v1);
b93447
+      // ANSI Binary curves
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb163v1", ECCurve_Code.c2pnb163v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb163v2", ECCurve_Code.c2pnb163v2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb163v3", ECCurve_Code.c2pnb163v3);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb176v1", ECCurve_Code.c2pnb176v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb191v1", ECCurve_Code.c2tnb191v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb191v2", ECCurve_Code.c2tnb191v2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb191v3", ECCurve_Code.c2tnb191v3);
b93447
+        //ECCurve_NameToCode.put(
b93447
+        //    "c2onb191v4", ECCurve_Code.c2onb191v4);
b93447
+        //ECCurve_NameToCode.put(
b93447
+        //    "c2onb191v5", ECCurve_Code.c2onb191v5);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb208w1", ECCurve_Code.c2pnb208w1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb239v1", ECCurve_Code.c2tnb239v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb239v2", ECCurve_Code.c2tnb239v2);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb239v3", ECCurve_Code.c2tnb239v3);
b93447
+        //ECCurve_NameToCode.put(
b93447
+        //    "c2onb239v4", ECCurve_Code.c2onb239v4);
b93447
+        //ECCurve_NameToCode.put(
b93447
+        //    "c2onb239v5", ECCurve_Code.c2onb239v5);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb272w1", ECCurve_Code.c2pnb272w1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb304w1", ECCurve_Code.c2pnb304w1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb359v1", ECCurve_Code.c2tnb359v1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2pnb368w1", ECCurve_Code.c2pnb368w1);
b93447
+        ECCurve_NameToCode.put(
b93447
+            "c2tnb431r1", ECCurve_Code.c2tnb431r1);
b93447
+    }
b93447
+
b93447
     // opFlag constants: each of these flags specifies a crypto operation
b93447
     // the key will support.  Their values must match the same-named C
b93447
     // preprocessor macros defined in the PKCS #11 header pkcs11t.h.
b93447
@@ -165,7 +406,15 @@ public final class PK11KeyPairGenerator
b93447
             }
b93447
         } else {
b93447
             Assert._assert( algorithm == KeyPairAlgorithm.EC );
b93447
-            params = getCurve(strength);
b93447
+            if (strength < 112) {
b93447
+                // for EC, "strength" is actually a code for curves defined in 
b93447
+                //   ECCurve_Code
b93447
+                params = getECCurve(strength);
b93447
+            } else {
b93447
+                // this is the old method of strength to curve mapping,
b93447
+                // which is somewhat defective
b93447
+                params = getCurve(strength);
b93447
+            }
b93447
         }
b93447
     }
b93447
 
b93447
@@ -642,6 +891,189 @@ public final class PK11KeyPairGenerator
b93447
     static final OBJECT_IDENTIFIER CURVE_SECG_T571R1
b93447
 	= SECG_EC_CURVE.subBranch(39);
b93447
 
b93447
+    // the EC curvecode to oid hash table
b93447
+    private static Hashtable mECCurve_CodeToCurve = new Hashtable();
b93447
+    static {
b93447
+      // SEG Prime curves
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp521r1.ordinal(), (Object) CURVE_SECG_P521R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistp521.ordinal(), (Object) CURVE_SECG_P521R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp384r1.ordinal(), (Object) CURVE_SECG_P384R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistp384.ordinal(), (Object) CURVE_SECG_P384R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp256r1.ordinal(), (Object) CURVE_ANSI_P256V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistp256.ordinal(), (Object) CURVE_ANSI_P256V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp256k1.ordinal(), (Object) CURVE_SECG_P256K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp224r1.ordinal(), (Object) CURVE_SECG_P224R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistp224.ordinal(), (Object) CURVE_SECG_P224R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp224k1.ordinal(), (Object) CURVE_SECG_P224K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp192r1.ordinal(), (Object) CURVE_ANSI_P192V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistp192.ordinal(), (Object) CURVE_ANSI_P192V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp192k1.ordinal(), (Object) CURVE_SECG_P192K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp160r2.ordinal(), (Object) CURVE_SECG_P160R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp160r1.ordinal(), (Object) CURVE_SECG_P160R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp160k1.ordinal(), (Object) CURVE_SECG_P160K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp128r2.ordinal(), (Object) CURVE_SECG_P128R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp128r1.ordinal(), (Object) CURVE_SECG_P128R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp112r2.ordinal(), (Object) CURVE_SECG_P112R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.secp112r1.ordinal(), (Object) CURVE_SECG_P112R1);
b93447
+      // SEG Binary curves
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect571r1.ordinal(), (Object) CURVE_SECG_T571R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistb571.ordinal(), (Object) CURVE_SECG_T571R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect571k1.ordinal(), (Object) CURVE_SECG_T571K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistk571.ordinal(), (Object) CURVE_SECG_T571K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect409r1.ordinal(), (Object) CURVE_SECG_T409R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistb409.ordinal(), (Object) CURVE_SECG_T409R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect409k1.ordinal(), (Object) CURVE_SECG_T409K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistk409.ordinal(), (Object) CURVE_SECG_T409K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect283r1.ordinal(), (Object) CURVE_SECG_T283R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistb283.ordinal(), (Object) CURVE_SECG_T283R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect283k1.ordinal(), (Object) CURVE_SECG_T283K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistk283.ordinal(), (Object) CURVE_SECG_T283K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect239k1.ordinal(), (Object) CURVE_SECG_T239K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect233r1.ordinal(), (Object) CURVE_SECG_T233R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistb233.ordinal(), (Object) CURVE_SECG_T233R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect233k1.ordinal(), (Object) CURVE_SECG_T233K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistk233.ordinal(), (Object) CURVE_SECG_T233K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect193r2.ordinal(), (Object) CURVE_SECG_T193R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect193r1.ordinal(), (Object) CURVE_SECG_T193R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistb163.ordinal(), (Object) CURVE_SECG_T163K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect163r2.ordinal(), (Object) CURVE_SECG_T163R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect163r1.ordinal(), (Object) CURVE_SECG_T163R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect163k1.ordinal(), (Object) CURVE_SECG_T163K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.nistk163.ordinal(), (Object) CURVE_SECG_T163K1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect131r2.ordinal(), (Object) CURVE_SECG_T131R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect131r1.ordinal(), (Object) CURVE_SECG_T131R1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect113r2.ordinal(), (Object) CURVE_SECG_T113R2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.sect113r1.ordinal(), (Object) CURVE_SECG_T113R1);
b93447
+      // ANSI Prime curves
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime239v3.ordinal(), (Object) CURVE_ANSI_P239V3);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime239v2.ordinal(), (Object) CURVE_ANSI_P239V2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime239v1.ordinal(), (Object) CURVE_ANSI_P239V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime192v3.ordinal(), (Object) CURVE_ANSI_P192V3);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime192v2.ordinal(), (Object) CURVE_ANSI_P192V2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.prime192v1.ordinal(), (Object) CURVE_ANSI_P192V1);
b93447
+      // ANSI Binary curves
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb163v1.ordinal(), (Object) CURVE_ANSI_PNB163V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb163v2.ordinal(), (Object) CURVE_ANSI_PNB163V2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb163v3.ordinal(), (Object) CURVE_ANSI_PNB163V3);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb176v1.ordinal(), (Object) CURVE_ANSI_PNB176V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb191v1.ordinal(), (Object) CURVE_ANSI_TNB191V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb191v2.ordinal(), (Object) CURVE_ANSI_TNB191V2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb191v3.ordinal(), (Object) CURVE_ANSI_TNB191V3);
b93447
+        //mECCurve_CodeToCurve.put(
b93447
+        //    ECCurve_Code.c2onb191v4.ordinal(), (Object) CURVE_ANSI_ONB191V4);
b93447
+        //mECCurve_CodeToCurve.put(
b93447
+        //    ECCurve_Code.c2onb191v5.ordinal(), (Object) CURVE_ANSI_ONB191V5);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb208w1.ordinal(), (Object) CURVE_ANSI_PNB208W1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb239v1.ordinal(), (Object) CURVE_ANSI_TNB239V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb239v2.ordinal(), (Object) CURVE_ANSI_TNB239V2);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb239v3.ordinal(), (Object) CURVE_ANSI_TNB239V3);
b93447
+        //mECCurve_CodeToCurve.put(
b93447
+        //    ECCurve_Code.c2onb239v4.ordinal(), (Object) CURVE_ANSI_ONB239V4);
b93447
+        //mECCurve_CodeToCurve.put(
b93447
+        //    ECCurve_Code.c2onb239v5.ordinal(), (Object) CURVE_ANSI_ONB239V5);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb272w1.ordinal(), (Object) CURVE_ANSI_PNB272W1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb304w1.ordinal(), (Object) CURVE_ANSI_PNB304W1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb359v1.ordinal(), (Object) CURVE_ANSI_TNB359V1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2pnb368w1.ordinal(), (Object) CURVE_ANSI_PNB368W1);
b93447
+        mECCurve_CodeToCurve.put(
b93447
+            ECCurve_Code.c2tnb431r1.ordinal(), (Object) CURVE_ANSI_TNB431R1);
b93447
+    }
b93447
+
b93447
+    public int getCurveCodeByName(String curveName)
b93447
+        throws InvalidParameterException {
b93447
+        if (curveName == null)
b93447
+            throw new InvalidParameterException();
b93447
+        ECCurve_Code c = (ECCurve_Code) ECCurve_NameToCode.get(curveName);
b93447
+        if (c == null)
b93447
+            throw new InvalidParameterException(curveName);
b93447
+        return c.ordinal();
b93447
+    }
b93447
+
b93447
+    /*
b93447
+     * getECCurve
b93447
+     *     maps curvecode to the actual oid of the curve and
b93447
+     *     returns the PK11ParameterSpec
b93447
+     */
b93447
+    private AlgorithmParameterSpec getECCurve(int curvecode)
b93447
+        throws InvalidParameterException
b93447
+    {
b93447
+        OBJECT_IDENTIFIER oid;
b93447
+
b93447
+        oid = (OBJECT_IDENTIFIER) mECCurve_CodeToCurve.get(curvecode);
b93447
+        if (oid == null)
b93447
+            throw new IllegalArgumentException("curvecode ="+curvecode);
b93447
+        return new PK11ParameterSpec(ASN1Util.encode(oid));
b93447
+    }
b93447
+
b93447
     private AlgorithmParameterSpec getCurve(int strength) 
b93447
         throws InvalidParameterException
b93447
     {