ECNamedCurveTable.java revision 5db505e1f6a68c8d5dfdb0fed0b8607dea7bed96
1package org.bouncycastle.jce;
2
3import java.util.Enumeration;
4
5import org.bouncycastle.asn1.ASN1ObjectIdentifier;
6import org.bouncycastle.asn1.x9.X9ECParameters;
7import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
8
9/**
10 * a table of locally supported named curves.
11 */
12public class ECNamedCurveTable
13{
14    /**
15     * return a parameter spec representing the passed in named
16     * curve. The routine returns null if the curve is not present.
17     *
18     * @param name the name of the curve requested
19     * @return a parameter spec for the curve, null if it is not available.
20     */
21    public static ECNamedCurveParameterSpec getParameterSpec(
22        String  name)
23    {
24        X9ECParameters  ecP = org.bouncycastle.asn1.x9.ECNamedCurveTable.getByName(name);
25        if (ecP == null)
26        {
27            try
28            {
29                ecP = org.bouncycastle.asn1.x9.ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier(name));
30            }
31            catch (IllegalArgumentException e)
32            {
33                // ignore - not an oid
34            }
35        }
36
37        if (ecP == null)
38        {
39            return null;
40        }
41
42        return new ECNamedCurveParameterSpec(
43                                        name,
44                                        ecP.getCurve(),
45                                        ecP.getG(),
46                                        ecP.getN(),
47                                        ecP.getH(),
48                                        ecP.getSeed());
49    }
50
51    /**
52     * return an enumeration of the names of the available curves.
53     *
54     * @return an enumeration of the names of the available curves.
55     */
56    public static Enumeration getNames()
57    {
58        return org.bouncycastle.asn1.x9.ECNamedCurveTable.getNames();
59    }
60}
61