01: package org.bouncycastle.asn1.nist;
02:
03: import org.bouncycastle.asn1.DERObjectIdentifier;
04: import org.bouncycastle.asn1.sec.SECNamedCurves;
05: import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
06: import org.bouncycastle.asn1.x9.X9ECParameters;
07: import org.bouncycastle.util.Strings;
08:
09: import java.util.Enumeration;
10: import java.util.Hashtable;
11:
12: /**
13: * Utility class for fetching curves using their NIST names as published in FIPS-PUB 186-2
14: */
15: public class NISTNamedCurves {
16: static final Hashtable objIds = new Hashtable();
17: static final Hashtable names = new Hashtable();
18:
19: static void defineCurve(String name, DERObjectIdentifier oid) {
20: objIds.put(name, oid);
21: names.put(oid, name);
22: }
23:
24: static {
25: defineCurve("B-571", SECObjectIdentifiers.sect571r1);
26: defineCurve("B-409", SECObjectIdentifiers.sect409r1);
27: defineCurve("B-283", SECObjectIdentifiers.sect283r1);
28: defineCurve("B-233", SECObjectIdentifiers.sect233r1);
29: defineCurve("B-163", SECObjectIdentifiers.sect163r2);
30: defineCurve("P-521", SECObjectIdentifiers.secp521r1);
31: defineCurve("P-256", SECObjectIdentifiers.secp256r1);
32: defineCurve("P-224", SECObjectIdentifiers.secp224r1);
33: defineCurve("P-384", SECObjectIdentifiers.secp384r1);
34: }
35:
36: public static X9ECParameters getByName(String name) {
37: DERObjectIdentifier oid = (DERObjectIdentifier) objIds
38: .get(Strings.toUpperCase(name));
39:
40: if (oid != null) {
41: return getByOID(oid);
42: }
43:
44: return null;
45: }
46:
47: /**
48: * return the X9ECParameters object for the named curve represented by
49: * the passed in object identifier. Null if the curve isn't present.
50: *
51: * @param oid an object identifier representing a named curve, if present.
52: */
53: public static X9ECParameters getByOID(DERObjectIdentifier oid) {
54: return SECNamedCurves.getByOID(oid);
55: }
56:
57: /**
58: * return the object identifier signified by the passed in name. Null
59: * if there is no object identifier associated with name.
60: *
61: * @return the object identifier associated with name, if present.
62: */
63: public static DERObjectIdentifier getOID(String name) {
64: return (DERObjectIdentifier) objIds.get(Strings
65: .toUpperCase(name));
66: }
67:
68: /**
69: * return the named curve name represented by the given object identifier.
70: */
71: public static String getName(DERObjectIdentifier oid) {
72: return (String) names.get(oid);
73: }
74:
75: /**
76: * returns an enumeration containing the name strings for curves
77: * contained in this structure.
78: */
79: public static Enumeration getNames() {
80: return objIds.keys();
81: }
82: }
|