01: package org.bouncycastle.jce;
02:
03: import org.bouncycastle.asn1.DERObjectIdentifier;
04: import org.bouncycastle.asn1.nist.NISTNamedCurves;
05: import org.bouncycastle.asn1.sec.SECNamedCurves;
06: import org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves;
07: import org.bouncycastle.asn1.x9.X962NamedCurves;
08: import org.bouncycastle.asn1.x9.X9ECParameters;
09: import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
10:
11: import java.util.Enumeration;
12: import java.util.Vector;
13:
14: /**
15: * a table of locally supported named curves.
16: */
17: public class ECNamedCurveTable {
18: /**
19: * return a parameter spec representing the passed in named
20: * curve. The routine returns null if the curve is not present.
21: *
22: * @param name the name of the curve requested
23: * @return a parameter spec for the curve, null if it is not available.
24: */
25: public static ECNamedCurveParameterSpec getParameterSpec(String name) {
26: X9ECParameters ecP = X962NamedCurves.getByName(name);
27: if (ecP == null) {
28: try {
29: ecP = X962NamedCurves.getByOID(new DERObjectIdentifier(
30: name));
31: } catch (IllegalArgumentException e) {
32: // ignore - not an oid
33: }
34: }
35:
36: if (ecP == null) {
37: ecP = SECNamedCurves.getByName(name);
38: if (ecP == null) {
39: try {
40: ecP = SECNamedCurves
41: .getByOID(new DERObjectIdentifier(name));
42: } catch (IllegalArgumentException e) {
43: // ignore - not an oid
44: }
45: }
46: }
47:
48: if (ecP == null) {
49: ecP = TeleTrusTNamedCurves.getByName(name);
50: if (ecP == null) {
51: try {
52: ecP = TeleTrusTNamedCurves
53: .getByOID(new DERObjectIdentifier(name));
54: } catch (IllegalArgumentException e) {
55: // ignore - not an oid
56: }
57: }
58: }
59:
60: if (ecP == null) {
61: ecP = NISTNamedCurves.getByName(name);
62: }
63:
64: if (ecP == null) {
65: return null;
66: }
67:
68: return new ECNamedCurveParameterSpec(name, ecP.getCurve(), ecP
69: .getG(), ecP.getN(), ecP.getH(), ecP.getSeed());
70: }
71:
72: /**
73: * return an enumeration of the names of the available curves.
74: *
75: * @return an enumeration of the names of the available curves.
76: */
77: public static Enumeration getNames() {
78: Vector v = new Vector();
79:
80: addEnumeration(v, X962NamedCurves.getNames());
81: addEnumeration(v, SECNamedCurves.getNames());
82: addEnumeration(v, NISTNamedCurves.getNames());
83: addEnumeration(v, TeleTrusTNamedCurves.getNames());
84:
85: return v.elements();
86: }
87:
88: private static void addEnumeration(Vector v, Enumeration e) {
89: while (e.hasMoreElements()) {
90: v.addElement(e.nextElement());
91: }
92: }
93: }
|