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