NISTNamedCurves.java revision a198e1ecc615e26a167d0f2dca9fa7e5fc62de10
1package org.bouncycastle.asn1.nist;
2
3import java.util.Enumeration;
4import java.util.Hashtable;
5
6import org.bouncycastle.asn1.ASN1ObjectIdentifier;
7import org.bouncycastle.asn1.sec.SECNamedCurves;
8import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
9import org.bouncycastle.asn1.x9.X9ECParameters;
10import org.bouncycastle.util.Strings;
11
12/**
13 * Utility class for fetching curves using their NIST names as published in FIPS-PUB 186-3
14 */
15public class NISTNamedCurves
16{
17    static final Hashtable objIds = new Hashtable();
18    static final Hashtable names = new Hashtable();
19
20    static void defineCurve(String name, ASN1ObjectIdentifier oid)
21    {
22        objIds.put(name, oid);
23        names.put(oid, name);
24    }
25
26    static
27    {
28        defineCurve("B-571", SECObjectIdentifiers.sect571r1);
29        defineCurve("B-409", SECObjectIdentifiers.sect409r1);
30        defineCurve("B-283", SECObjectIdentifiers.sect283r1);
31        defineCurve("B-233", SECObjectIdentifiers.sect233r1);
32        defineCurve("B-163", SECObjectIdentifiers.sect163r2);
33        defineCurve("K-571", SECObjectIdentifiers.sect571k1);
34        defineCurve("K-409", SECObjectIdentifiers.sect409k1);
35        defineCurve("K-283", SECObjectIdentifiers.sect283k1);
36        defineCurve("K-233", SECObjectIdentifiers.sect233k1);
37        defineCurve("K-163", SECObjectIdentifiers.sect163k1);
38        defineCurve("P-521", SECObjectIdentifiers.secp521r1);
39        defineCurve("P-384", SECObjectIdentifiers.secp384r1);
40        defineCurve("P-256", SECObjectIdentifiers.secp256r1);
41        defineCurve("P-224", SECObjectIdentifiers.secp224r1);
42        defineCurve("P-192", SECObjectIdentifiers.secp192r1);
43    }
44
45    public static X9ECParameters getByName(
46        String  name)
47    {
48        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)objIds.get(Strings.toUpperCase(name));
49
50        if (oid != null)
51        {
52            return getByOID(oid);
53        }
54
55        return null;
56    }
57
58    /**
59     * return the X9ECParameters object for the named curve represented by
60     * the passed in object identifier. Null if the curve isn't present.
61     *
62     * @param oid an object identifier representing a named curve, if present.
63     */
64    public static X9ECParameters getByOID(
65        ASN1ObjectIdentifier  oid)
66    {
67        return SECNamedCurves.getByOID(oid);
68    }
69
70    /**
71     * return the object identifier signified by the passed in name. Null
72     * if there is no object identifier associated with name.
73     *
74     * @return the object identifier associated with name, if present.
75     */
76    public static ASN1ObjectIdentifier getOID(
77        String  name)
78    {
79        return (ASN1ObjectIdentifier)objIds.get(Strings.toUpperCase(name));
80    }
81
82    /**
83     * return the named curve name represented by the given object identifier.
84     */
85    public static String getName(
86        ASN1ObjectIdentifier  oid)
87    {
88        return (String)names.get(oid);
89    }
90
91    /**
92     * returns an enumeration containing the name strings for curves
93     * contained in this structure.
94     */
95    public static Enumeration getNames()
96    {
97        return objIds.keys();
98    }
99}
100