Home | History | Annotate | Download | only in jce
      1 package org.bouncycastle.jce;
      2 
      3 import org.bouncycastle.asn1.DERObjectIdentifier;
      4 import org.bouncycastle.asn1.nist.NISTNamedCurves;
      5 import org.bouncycastle.asn1.sec.SECNamedCurves;
      6 // BEGIN android-removed
      7 // import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
      8 // END android-removed
      9 import org.bouncycastle.asn1.x9.X962NamedCurves;
     10 import org.bouncycastle.asn1.x9.X9ECParameters;
     11 import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
     12 
     13 import java.util.Enumeration;
     14 import java.util.Vector;
     15 
     16 /**
     17  * a table of locally supported named curves.
     18  */
     19 public class ECNamedCurveTable
     20 {
     21     /**
     22      * return a parameter spec representing the passed in named
     23      * curve. The routine returns null if the curve is not present.
     24      *
     25      * @param name the name of the curve requested
     26      * @return a parameter spec for the curve, null if it is not available.
     27      */
     28     public static ECNamedCurveParameterSpec getParameterSpec(
     29         String  name)
     30     {
     31         X9ECParameters  ecP = X962NamedCurves.getByName(name);
     32         if (ecP == null)
     33         {
     34             try
     35             {
     36                 ecP = X962NamedCurves.getByOID(new DERObjectIdentifier(name));
     37             }
     38             catch (IllegalArgumentException e)
     39             {
     40                 // ignore - not an oid
     41             }
     42         }
     43 
     44         if (ecP == null)
     45         {
     46             ecP = SECNamedCurves.getByName(name);
     47             if (ecP == null)
     48             {
     49                 try
     50                 {
     51                     ecP = SECNamedCurves.getByOID(new DERObjectIdentifier(name));
     52                 }
     53                 catch (IllegalArgumentException e)
     54                 {
     55                     // ignore - not an oid
     56                 }
     57             }
     58         }
     59 
     60         // BEGIN android-removed
     61         // if (ecP == null)
     62         // {
     63         //     ecP = TeleTrusTNamedCurves.getByName(name);
     64         //     if (ecP == null)
     65         //     {
     66         //         try
     67         //         {
     68         //             ecP = TeleTrusTNamedCurves.getByOID(new DERObjectIdentifier(name));
     69         //         }
     70         //         catch (IllegalArgumentException e)
     71         //         {
     72         //             // ignore - not an oid
     73         //         }
     74         //     }
     75         // }
     76         // END android-removed
     77 
     78         if (ecP == null)
     79         {
     80             ecP = NISTNamedCurves.getByName(name);
     81         }
     82 
     83         if (ecP == null)
     84         {
     85             return null;
     86         }
     87 
     88         return new ECNamedCurveParameterSpec(
     89                                         name,
     90                                         ecP.getCurve(),
     91                                         ecP.getG(),
     92                                         ecP.getN(),
     93                                         ecP.getH(),
     94                                         ecP.getSeed());
     95     }
     96 
     97     /**
     98      * return an enumeration of the names of the available curves.
     99      *
    100      * @return an enumeration of the names of the available curves.
    101      */
    102     public static Enumeration getNames()
    103     {
    104         Vector v = new Vector();
    105 
    106         addEnumeration(v, X962NamedCurves.getNames());
    107         addEnumeration(v, SECNamedCurves.getNames());
    108         addEnumeration(v, NISTNamedCurves.getNames());
    109         // BEGIN android-removed
    110         // addEnumeration(v, TeleTrusTNamedCurves.getNames());
    111         // END android-removed
    112 
    113         return v.elements();
    114     }
    115 
    116     private static void addEnumeration(
    117         Vector v,
    118         Enumeration e)
    119     {
    120         while (e.hasMoreElements())
    121         {
    122             v.addElement(e.nextElement());
    123         }
    124     }
    125 }
    126