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