mirrored from https://www.bouncycastle.org/repositories/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ECNamedCurveTable.java
96 lines (85 loc) · 2.5 KB
/
ECNamedCurveTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package org.bouncycastle.jce;
import java.util.Enumeration;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
/**
* a table of locally supported named curves.
*/
public class ECNamedCurveTable
{
/**
* return a parameter spec representing the passed in named
* curve. The routine returns null if the curve is not present.
*
* @param name the name of the curve requested
* @return a parameter spec for the curve, null if it is not available.
*/
public static ECNamedCurveParameterSpec getParameterSpec(
String name)
{
ASN1ObjectIdentifier oid;
try
{
oid = possibleOID(name) ? new ASN1ObjectIdentifier(name) : null;
}
catch (IllegalArgumentException e)
{
oid = null;
}
X9ECParameters ecP;
if (oid != null)
{
ecP = org.bouncycastle.crypto.ec.CustomNamedCurves.getByOID(oid);
}
else
{
ecP = org.bouncycastle.crypto.ec.CustomNamedCurves.getByName(name);
}
if (ecP == null)
{
if (oid != null)
{
ecP = org.bouncycastle.asn1.x9.ECNamedCurveTable.getByOID(oid);
}
else
{
ecP = org.bouncycastle.asn1.x9.ECNamedCurveTable.getByName(name);
}
}
if (ecP == null)
{
return null;
}
return new ECNamedCurveParameterSpec(
name,
ecP.getCurve(),
ecP.getG(),
ecP.getN(),
ecP.getH(),
ecP.getSeed());
}
/**
* return an enumeration of the names of the available curves.
*
* @return an enumeration of the names of the available curves.
*/
public static Enumeration getNames()
{
return org.bouncycastle.asn1.x9.ECNamedCurveTable.getNames();
}
private static boolean possibleOID(
String identifier)
{
if (identifier.length() < 3 || identifier.charAt(1) != '.')
{
return false;
}
char first = identifier.charAt(0);
if (first < '0' || first > '2')
{
return false;
}
return true;
}
}