1*f9fbec18Smcpowers /* ***** BEGIN LICENSE BLOCK *****
2*f9fbec18Smcpowers * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3*f9fbec18Smcpowers *
4*f9fbec18Smcpowers * The contents of this file are subject to the Mozilla Public License Version
5*f9fbec18Smcpowers * 1.1 (the "License"); you may not use this file except in compliance with
6*f9fbec18Smcpowers * the License. You may obtain a copy of the License at
7*f9fbec18Smcpowers * http://www.mozilla.org/MPL/
8*f9fbec18Smcpowers *
9*f9fbec18Smcpowers * Software distributed under the License is distributed on an "AS IS" basis,
10*f9fbec18Smcpowers * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11*f9fbec18Smcpowers * for the specific language governing rights and limitations under the
12*f9fbec18Smcpowers * License.
13*f9fbec18Smcpowers *
14*f9fbec18Smcpowers * The Original Code is the Netscape security libraries.
15*f9fbec18Smcpowers *
16*f9fbec18Smcpowers * The Initial Developer of the Original Code is
17*f9fbec18Smcpowers * Netscape Communications Corporation.
18*f9fbec18Smcpowers * Portions created by the Initial Developer are Copyright (C) 1994-2000
19*f9fbec18Smcpowers * the Initial Developer. All Rights Reserved.
20*f9fbec18Smcpowers *
21*f9fbec18Smcpowers * Contributor(s):
22*f9fbec18Smcpowers * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
23*f9fbec18Smcpowers *
24*f9fbec18Smcpowers * Alternatively, the contents of this file may be used under the terms of
25*f9fbec18Smcpowers * either the GNU General Public License Version 2 or later (the "GPL"), or
26*f9fbec18Smcpowers * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27*f9fbec18Smcpowers * in which case the provisions of the GPL or the LGPL are applicable instead
28*f9fbec18Smcpowers * of those above. If you wish to allow use of your version of this file only
29*f9fbec18Smcpowers * under the terms of either the GPL or the LGPL, and not to allow others to
30*f9fbec18Smcpowers * use your version of this file under the terms of the MPL, indicate your
31*f9fbec18Smcpowers * decision by deleting the provisions above and replace them with the notice
32*f9fbec18Smcpowers * and other provisions required by the GPL or the LGPL. If you do not delete
33*f9fbec18Smcpowers * the provisions above, a recipient may use your version of this file under
34*f9fbec18Smcpowers * the terms of any one of the MPL, the GPL or the LGPL.
35*f9fbec18Smcpowers *
36*f9fbec18Smcpowers * ***** END LICENSE BLOCK ***** */
37*f9fbec18Smcpowers /*
38*f9fbec18Smcpowers * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
39*f9fbec18Smcpowers * Use is subject to license terms.
40*f9fbec18Smcpowers *
41*f9fbec18Smcpowers * Sun elects to use this software under the MPL license.
42*f9fbec18Smcpowers */
43*f9fbec18Smcpowers
44*f9fbec18Smcpowers #pragma ident "%Z%%M% %I% %E% SMI"
45*f9fbec18Smcpowers
46*f9fbec18Smcpowers #include <sys/types.h>
47*f9fbec18Smcpowers #include <sys/systm.h>
48*f9fbec18Smcpowers #include <sys/param.h>
49*f9fbec18Smcpowers #ifdef _KERNEL
50*f9fbec18Smcpowers #include <sys/kmem.h>
51*f9fbec18Smcpowers #else
52*f9fbec18Smcpowers #include <string.h>
53*f9fbec18Smcpowers #endif
54*f9fbec18Smcpowers #include "ec.h"
55*f9fbec18Smcpowers #include "ecl-curve.h"
56*f9fbec18Smcpowers #include "ecc_impl.h"
57*f9fbec18Smcpowers #include "secoidt.h"
58*f9fbec18Smcpowers
59*f9fbec18Smcpowers #define CERTICOM_OID 0x2b, 0x81, 0x04
60*f9fbec18Smcpowers #define SECG_OID CERTICOM_OID, 0x00
61*f9fbec18Smcpowers
62*f9fbec18Smcpowers #define ANSI_X962_OID 0x2a, 0x86, 0x48, 0xce, 0x3d
63*f9fbec18Smcpowers #define ANSI_X962_CURVE_OID ANSI_X962_OID, 0x03
64*f9fbec18Smcpowers #define ANSI_X962_GF2m_OID ANSI_X962_CURVE_OID, 0x00
65*f9fbec18Smcpowers #define ANSI_X962_GFp_OID ANSI_X962_CURVE_OID, 0x01
66*f9fbec18Smcpowers
67*f9fbec18Smcpowers #define CONST_OID static const unsigned char
68*f9fbec18Smcpowers
69*f9fbec18Smcpowers /* ANSI X9.62 prime curve OIDs */
70*f9fbec18Smcpowers /* NOTE: prime192v1 is the same as secp192r1, prime256v1 is the
71*f9fbec18Smcpowers * same as secp256r1
72*f9fbec18Smcpowers */
73*f9fbec18Smcpowers CONST_OID ansiX962prime192v1[] = { ANSI_X962_GFp_OID, 0x01 };
74*f9fbec18Smcpowers CONST_OID ansiX962prime192v2[] = { ANSI_X962_GFp_OID, 0x02 };
75*f9fbec18Smcpowers CONST_OID ansiX962prime192v3[] = { ANSI_X962_GFp_OID, 0x03 };
76*f9fbec18Smcpowers CONST_OID ansiX962prime239v1[] = { ANSI_X962_GFp_OID, 0x04 };
77*f9fbec18Smcpowers CONST_OID ansiX962prime239v2[] = { ANSI_X962_GFp_OID, 0x05 };
78*f9fbec18Smcpowers CONST_OID ansiX962prime239v3[] = { ANSI_X962_GFp_OID, 0x06 };
79*f9fbec18Smcpowers CONST_OID ansiX962prime256v1[] = { ANSI_X962_GFp_OID, 0x07 };
80*f9fbec18Smcpowers
81*f9fbec18Smcpowers /* SECG prime curve OIDs */
82*f9fbec18Smcpowers CONST_OID secgECsecp112r1[] = { SECG_OID, 0x06 };
83*f9fbec18Smcpowers CONST_OID secgECsecp112r2[] = { SECG_OID, 0x07 };
84*f9fbec18Smcpowers CONST_OID secgECsecp128r1[] = { SECG_OID, 0x1c };
85*f9fbec18Smcpowers CONST_OID secgECsecp128r2[] = { SECG_OID, 0x1d };
86*f9fbec18Smcpowers CONST_OID secgECsecp160k1[] = { SECG_OID, 0x09 };
87*f9fbec18Smcpowers CONST_OID secgECsecp160r1[] = { SECG_OID, 0x08 };
88*f9fbec18Smcpowers CONST_OID secgECsecp160r2[] = { SECG_OID, 0x1e };
89*f9fbec18Smcpowers CONST_OID secgECsecp192k1[] = { SECG_OID, 0x1f };
90*f9fbec18Smcpowers CONST_OID secgECsecp224k1[] = { SECG_OID, 0x20 };
91*f9fbec18Smcpowers CONST_OID secgECsecp224r1[] = { SECG_OID, 0x21 };
92*f9fbec18Smcpowers CONST_OID secgECsecp256k1[] = { SECG_OID, 0x0a };
93*f9fbec18Smcpowers CONST_OID secgECsecp384r1[] = { SECG_OID, 0x22 };
94*f9fbec18Smcpowers CONST_OID secgECsecp521r1[] = { SECG_OID, 0x23 };
95*f9fbec18Smcpowers
96*f9fbec18Smcpowers /* SECG characterisitic two curve OIDs */
97*f9fbec18Smcpowers CONST_OID secgECsect113r1[] = {SECG_OID, 0x04 };
98*f9fbec18Smcpowers CONST_OID secgECsect113r2[] = {SECG_OID, 0x05 };
99*f9fbec18Smcpowers CONST_OID secgECsect131r1[] = {SECG_OID, 0x16 };
100*f9fbec18Smcpowers CONST_OID secgECsect131r2[] = {SECG_OID, 0x17 };
101*f9fbec18Smcpowers CONST_OID secgECsect163k1[] = {SECG_OID, 0x01 };
102*f9fbec18Smcpowers CONST_OID secgECsect163r1[] = {SECG_OID, 0x02 };
103*f9fbec18Smcpowers CONST_OID secgECsect163r2[] = {SECG_OID, 0x0f };
104*f9fbec18Smcpowers CONST_OID secgECsect193r1[] = {SECG_OID, 0x18 };
105*f9fbec18Smcpowers CONST_OID secgECsect193r2[] = {SECG_OID, 0x19 };
106*f9fbec18Smcpowers CONST_OID secgECsect233k1[] = {SECG_OID, 0x1a };
107*f9fbec18Smcpowers CONST_OID secgECsect233r1[] = {SECG_OID, 0x1b };
108*f9fbec18Smcpowers CONST_OID secgECsect239k1[] = {SECG_OID, 0x03 };
109*f9fbec18Smcpowers CONST_OID secgECsect283k1[] = {SECG_OID, 0x10 };
110*f9fbec18Smcpowers CONST_OID secgECsect283r1[] = {SECG_OID, 0x11 };
111*f9fbec18Smcpowers CONST_OID secgECsect409k1[] = {SECG_OID, 0x24 };
112*f9fbec18Smcpowers CONST_OID secgECsect409r1[] = {SECG_OID, 0x25 };
113*f9fbec18Smcpowers CONST_OID secgECsect571k1[] = {SECG_OID, 0x26 };
114*f9fbec18Smcpowers CONST_OID secgECsect571r1[] = {SECG_OID, 0x27 };
115*f9fbec18Smcpowers
116*f9fbec18Smcpowers /* ANSI X9.62 characteristic two curve OIDs */
117*f9fbec18Smcpowers CONST_OID ansiX962c2pnb163v1[] = { ANSI_X962_GF2m_OID, 0x01 };
118*f9fbec18Smcpowers CONST_OID ansiX962c2pnb163v2[] = { ANSI_X962_GF2m_OID, 0x02 };
119*f9fbec18Smcpowers CONST_OID ansiX962c2pnb163v3[] = { ANSI_X962_GF2m_OID, 0x03 };
120*f9fbec18Smcpowers CONST_OID ansiX962c2pnb176v1[] = { ANSI_X962_GF2m_OID, 0x04 };
121*f9fbec18Smcpowers CONST_OID ansiX962c2tnb191v1[] = { ANSI_X962_GF2m_OID, 0x05 };
122*f9fbec18Smcpowers CONST_OID ansiX962c2tnb191v2[] = { ANSI_X962_GF2m_OID, 0x06 };
123*f9fbec18Smcpowers CONST_OID ansiX962c2tnb191v3[] = { ANSI_X962_GF2m_OID, 0x07 };
124*f9fbec18Smcpowers CONST_OID ansiX962c2onb191v4[] = { ANSI_X962_GF2m_OID, 0x08 };
125*f9fbec18Smcpowers CONST_OID ansiX962c2onb191v5[] = { ANSI_X962_GF2m_OID, 0x09 };
126*f9fbec18Smcpowers CONST_OID ansiX962c2pnb208w1[] = { ANSI_X962_GF2m_OID, 0x0a };
127*f9fbec18Smcpowers CONST_OID ansiX962c2tnb239v1[] = { ANSI_X962_GF2m_OID, 0x0b };
128*f9fbec18Smcpowers CONST_OID ansiX962c2tnb239v2[] = { ANSI_X962_GF2m_OID, 0x0c };
129*f9fbec18Smcpowers CONST_OID ansiX962c2tnb239v3[] = { ANSI_X962_GF2m_OID, 0x0d };
130*f9fbec18Smcpowers CONST_OID ansiX962c2onb239v4[] = { ANSI_X962_GF2m_OID, 0x0e };
131*f9fbec18Smcpowers CONST_OID ansiX962c2onb239v5[] = { ANSI_X962_GF2m_OID, 0x0f };
132*f9fbec18Smcpowers CONST_OID ansiX962c2pnb272w1[] = { ANSI_X962_GF2m_OID, 0x10 };
133*f9fbec18Smcpowers CONST_OID ansiX962c2pnb304w1[] = { ANSI_X962_GF2m_OID, 0x11 };
134*f9fbec18Smcpowers CONST_OID ansiX962c2tnb359v1[] = { ANSI_X962_GF2m_OID, 0x12 };
135*f9fbec18Smcpowers CONST_OID ansiX962c2pnb368w1[] = { ANSI_X962_GF2m_OID, 0x13 };
136*f9fbec18Smcpowers CONST_OID ansiX962c2tnb431r1[] = { ANSI_X962_GF2m_OID, 0x14 };
137*f9fbec18Smcpowers
138*f9fbec18Smcpowers #define OI(x) { siDEROID, (unsigned char *)x, sizeof x }
139*f9fbec18Smcpowers #ifndef SECOID_NO_STRINGS
140*f9fbec18Smcpowers #define OD(oid,tag,desc,mech,ext) { OI(oid), tag, desc, mech, ext }
141*f9fbec18Smcpowers #else
142*f9fbec18Smcpowers #define OD(oid,tag,desc,mech,ext) { OI(oid), tag, 0, mech, ext }
143*f9fbec18Smcpowers #endif
144*f9fbec18Smcpowers
145*f9fbec18Smcpowers #define CKM_INVALID_MECHANISM 0xffffffffUL
146*f9fbec18Smcpowers
147*f9fbec18Smcpowers /* XXX this is incorrect */
148*f9fbec18Smcpowers #define INVALID_CERT_EXTENSION 1
149*f9fbec18Smcpowers
150*f9fbec18Smcpowers #define CKM_ECDSA 0x00001041
151*f9fbec18Smcpowers #define CKM_ECDSA_SHA1 0x00001042
152*f9fbec18Smcpowers #define CKM_ECDH1_DERIVE 0x00001050
153*f9fbec18Smcpowers
154*f9fbec18Smcpowers static SECOidData ANSI_prime_oids[] = {
155*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
156*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
157*f9fbec18Smcpowers
158*f9fbec18Smcpowers OD( ansiX962prime192v1, ECCurve_NIST_P192,
159*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime192v1 (aka secp192r1, NIST P-192)",
160*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
161*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
162*f9fbec18Smcpowers OD( ansiX962prime192v2, ECCurve_X9_62_PRIME_192V2,
163*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime192v2",
164*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
165*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
166*f9fbec18Smcpowers OD( ansiX962prime192v3, ECCurve_X9_62_PRIME_192V3,
167*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime192v3",
168*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
169*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
170*f9fbec18Smcpowers OD( ansiX962prime239v1, ECCurve_X9_62_PRIME_239V1,
171*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime239v1",
172*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
173*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
174*f9fbec18Smcpowers OD( ansiX962prime239v2, ECCurve_X9_62_PRIME_239V2,
175*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime239v2",
176*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
177*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
178*f9fbec18Smcpowers OD( ansiX962prime239v3, ECCurve_X9_62_PRIME_239V3,
179*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime239v3",
180*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
181*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
182*f9fbec18Smcpowers OD( ansiX962prime256v1, ECCurve_NIST_P256,
183*f9fbec18Smcpowers "ANSI X9.62 elliptic curve prime256v1 (aka secp256r1, NIST P-256)",
184*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
185*f9fbec18Smcpowers INVALID_CERT_EXTENSION )
186*f9fbec18Smcpowers };
187*f9fbec18Smcpowers
188*f9fbec18Smcpowers static SECOidData SECG_oids[] = {
189*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
190*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
191*f9fbec18Smcpowers
192*f9fbec18Smcpowers OD( secgECsect163k1, ECCurve_NIST_K163,
193*f9fbec18Smcpowers "SECG elliptic curve sect163k1 (aka NIST K-163)",
194*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
195*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
196*f9fbec18Smcpowers OD( secgECsect163r1, ECCurve_SECG_CHAR2_163R1,
197*f9fbec18Smcpowers "SECG elliptic curve sect163r1",
198*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
199*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
200*f9fbec18Smcpowers OD( secgECsect239k1, ECCurve_SECG_CHAR2_239K1,
201*f9fbec18Smcpowers "SECG elliptic curve sect239k1",
202*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
203*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
204*f9fbec18Smcpowers OD( secgECsect113r1, ECCurve_SECG_CHAR2_113R1,
205*f9fbec18Smcpowers "SECG elliptic curve sect113r1",
206*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
207*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
208*f9fbec18Smcpowers OD( secgECsect113r2, ECCurve_SECG_CHAR2_113R2,
209*f9fbec18Smcpowers "SECG elliptic curve sect113r2",
210*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
211*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
212*f9fbec18Smcpowers OD( secgECsecp112r1, ECCurve_SECG_PRIME_112R1,
213*f9fbec18Smcpowers "SECG elliptic curve secp112r1",
214*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
215*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
216*f9fbec18Smcpowers OD( secgECsecp112r2, ECCurve_SECG_PRIME_112R2,
217*f9fbec18Smcpowers "SECG elliptic curve secp112r2",
218*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
219*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
220*f9fbec18Smcpowers OD( secgECsecp160r1, ECCurve_SECG_PRIME_160R1,
221*f9fbec18Smcpowers "SECG elliptic curve secp160r1",
222*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
223*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
224*f9fbec18Smcpowers OD( secgECsecp160k1, ECCurve_SECG_PRIME_160K1,
225*f9fbec18Smcpowers "SECG elliptic curve secp160k1",
226*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
227*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
228*f9fbec18Smcpowers OD( secgECsecp256k1, ECCurve_SECG_PRIME_256K1,
229*f9fbec18Smcpowers "SECG elliptic curve secp256k1",
230*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
231*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
232*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
233*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
234*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
235*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
236*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
237*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
238*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
239*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
240*f9fbec18Smcpowers OD( secgECsect163r2, ECCurve_NIST_B163,
241*f9fbec18Smcpowers "SECG elliptic curve sect163r2 (aka NIST B-163)",
242*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
243*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
244*f9fbec18Smcpowers OD( secgECsect283k1, ECCurve_NIST_K283,
245*f9fbec18Smcpowers "SECG elliptic curve sect283k1 (aka NIST K-283)",
246*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
247*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
248*f9fbec18Smcpowers OD( secgECsect283r1, ECCurve_NIST_B283,
249*f9fbec18Smcpowers "SECG elliptic curve sect283r1 (aka NIST B-283)",
250*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
251*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
252*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
253*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
254*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
255*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
256*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
257*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
258*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
259*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
260*f9fbec18Smcpowers OD( secgECsect131r1, ECCurve_SECG_CHAR2_131R1,
261*f9fbec18Smcpowers "SECG elliptic curve sect131r1",
262*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
263*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
264*f9fbec18Smcpowers OD( secgECsect131r2, ECCurve_SECG_CHAR2_131R2,
265*f9fbec18Smcpowers "SECG elliptic curve sect131r2",
266*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
267*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
268*f9fbec18Smcpowers OD( secgECsect193r1, ECCurve_SECG_CHAR2_193R1,
269*f9fbec18Smcpowers "SECG elliptic curve sect193r1",
270*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
271*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
272*f9fbec18Smcpowers OD( secgECsect193r2, ECCurve_SECG_CHAR2_193R2,
273*f9fbec18Smcpowers "SECG elliptic curve sect193r2",
274*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
275*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
276*f9fbec18Smcpowers OD( secgECsect233k1, ECCurve_NIST_K233,
277*f9fbec18Smcpowers "SECG elliptic curve sect233k1 (aka NIST K-233)",
278*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
279*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
280*f9fbec18Smcpowers OD( secgECsect233r1, ECCurve_NIST_B233,
281*f9fbec18Smcpowers "SECG elliptic curve sect233r1 (aka NIST B-233)",
282*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
283*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
284*f9fbec18Smcpowers OD( secgECsecp128r1, ECCurve_SECG_PRIME_128R1,
285*f9fbec18Smcpowers "SECG elliptic curve secp128r1",
286*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
287*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
288*f9fbec18Smcpowers OD( secgECsecp128r2, ECCurve_SECG_PRIME_128R2,
289*f9fbec18Smcpowers "SECG elliptic curve secp128r2",
290*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
291*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
292*f9fbec18Smcpowers OD( secgECsecp160r2, ECCurve_SECG_PRIME_160R2,
293*f9fbec18Smcpowers "SECG elliptic curve secp160r2",
294*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
295*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
296*f9fbec18Smcpowers OD( secgECsecp192k1, ECCurve_SECG_PRIME_192K1,
297*f9fbec18Smcpowers "SECG elliptic curve secp192k1",
298*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
299*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
300*f9fbec18Smcpowers OD( secgECsecp224k1, ECCurve_SECG_PRIME_224K1,
301*f9fbec18Smcpowers "SECG elliptic curve secp224k1",
302*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
303*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
304*f9fbec18Smcpowers OD( secgECsecp224r1, ECCurve_NIST_P224,
305*f9fbec18Smcpowers "SECG elliptic curve secp224r1 (aka NIST P-224)",
306*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
307*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
308*f9fbec18Smcpowers OD( secgECsecp384r1, ECCurve_NIST_P384,
309*f9fbec18Smcpowers "SECG elliptic curve secp384r1 (aka NIST P-384)",
310*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
311*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
312*f9fbec18Smcpowers OD( secgECsecp521r1, ECCurve_NIST_P521,
313*f9fbec18Smcpowers "SECG elliptic curve secp521r1 (aka NIST P-521)",
314*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
315*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
316*f9fbec18Smcpowers OD( secgECsect409k1, ECCurve_NIST_K409,
317*f9fbec18Smcpowers "SECG elliptic curve sect409k1 (aka NIST K-409)",
318*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
319*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
320*f9fbec18Smcpowers OD( secgECsect409r1, ECCurve_NIST_B409,
321*f9fbec18Smcpowers "SECG elliptic curve sect409r1 (aka NIST B-409)",
322*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
323*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
324*f9fbec18Smcpowers OD( secgECsect571k1, ECCurve_NIST_K571,
325*f9fbec18Smcpowers "SECG elliptic curve sect571k1 (aka NIST K-571)",
326*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
327*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
328*f9fbec18Smcpowers OD( secgECsect571r1, ECCurve_NIST_B571,
329*f9fbec18Smcpowers "SECG elliptic curve sect571r1 (aka NIST B-571)",
330*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
331*f9fbec18Smcpowers INVALID_CERT_EXTENSION )
332*f9fbec18Smcpowers };
333*f9fbec18Smcpowers
334*f9fbec18Smcpowers static SECOidData ANSI_oids[] = {
335*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
336*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
337*f9fbec18Smcpowers
338*f9fbec18Smcpowers /* ANSI X9.62 named elliptic curves (characteristic two field) */
339*f9fbec18Smcpowers OD( ansiX962c2pnb163v1, ECCurve_X9_62_CHAR2_PNB163V1,
340*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb163v1",
341*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
342*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
343*f9fbec18Smcpowers OD( ansiX962c2pnb163v2, ECCurve_X9_62_CHAR2_PNB163V2,
344*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb163v2",
345*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
346*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
347*f9fbec18Smcpowers OD( ansiX962c2pnb163v3, ECCurve_X9_62_CHAR2_PNB163V3,
348*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb163v3",
349*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
350*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
351*f9fbec18Smcpowers OD( ansiX962c2pnb176v1, ECCurve_X9_62_CHAR2_PNB176V1,
352*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb176v1",
353*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
354*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
355*f9fbec18Smcpowers OD( ansiX962c2tnb191v1, ECCurve_X9_62_CHAR2_TNB191V1,
356*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb191v1",
357*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
358*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
359*f9fbec18Smcpowers OD( ansiX962c2tnb191v2, ECCurve_X9_62_CHAR2_TNB191V2,
360*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb191v2",
361*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
362*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
363*f9fbec18Smcpowers OD( ansiX962c2tnb191v3, ECCurve_X9_62_CHAR2_TNB191V3,
364*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb191v3",
365*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
366*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
367*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
368*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
369*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
370*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
371*f9fbec18Smcpowers OD( ansiX962c2pnb208w1, ECCurve_X9_62_CHAR2_PNB208W1,
372*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb208w1",
373*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
374*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
375*f9fbec18Smcpowers OD( ansiX962c2tnb239v1, ECCurve_X9_62_CHAR2_TNB239V1,
376*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb239v1",
377*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
378*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
379*f9fbec18Smcpowers OD( ansiX962c2tnb239v2, ECCurve_X9_62_CHAR2_TNB239V2,
380*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb239v2",
381*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
382*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
383*f9fbec18Smcpowers OD( ansiX962c2tnb239v3, ECCurve_X9_62_CHAR2_TNB239V3,
384*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb239v3",
385*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
386*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
387*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
388*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
389*f9fbec18Smcpowers { { siDEROID, NULL, 0 }, ECCurve_noName,
390*f9fbec18Smcpowers "Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
391*f9fbec18Smcpowers OD( ansiX962c2pnb272w1, ECCurve_X9_62_CHAR2_PNB272W1,
392*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb272w1",
393*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
394*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
395*f9fbec18Smcpowers OD( ansiX962c2pnb304w1, ECCurve_X9_62_CHAR2_PNB304W1,
396*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb304w1",
397*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
398*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
399*f9fbec18Smcpowers OD( ansiX962c2tnb359v1, ECCurve_X9_62_CHAR2_TNB359V1,
400*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb359v1",
401*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
402*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
403*f9fbec18Smcpowers OD( ansiX962c2pnb368w1, ECCurve_X9_62_CHAR2_PNB368W1,
404*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2pnb368w1",
405*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
406*f9fbec18Smcpowers INVALID_CERT_EXTENSION ),
407*f9fbec18Smcpowers OD( ansiX962c2tnb431r1, ECCurve_X9_62_CHAR2_TNB431R1,
408*f9fbec18Smcpowers "ANSI X9.62 elliptic curve c2tnb431r1",
409*f9fbec18Smcpowers CKM_INVALID_MECHANISM,
410*f9fbec18Smcpowers INVALID_CERT_EXTENSION )
411*f9fbec18Smcpowers };
412*f9fbec18Smcpowers
413*f9fbec18Smcpowers SECOidData *
SECOID_FindOID(const SECItem * oid)414*f9fbec18Smcpowers SECOID_FindOID(const SECItem *oid)
415*f9fbec18Smcpowers {
416*f9fbec18Smcpowers SECOidData *po;
417*f9fbec18Smcpowers SECOidData *ret;
418*f9fbec18Smcpowers int i;
419*f9fbec18Smcpowers
420*f9fbec18Smcpowers if (oid->len == 8) {
421*f9fbec18Smcpowers if (oid->data[6] == 0x00) {
422*f9fbec18Smcpowers /* XXX bounds check */
423*f9fbec18Smcpowers po = &ANSI_oids[oid->data[7]];
424*f9fbec18Smcpowers if (memcmp(oid->data, po->oid.data, 8) == 0)
425*f9fbec18Smcpowers ret = po;
426*f9fbec18Smcpowers }
427*f9fbec18Smcpowers if (oid->data[6] == 0x01) {
428*f9fbec18Smcpowers /* XXX bounds check */
429*f9fbec18Smcpowers po = &ANSI_prime_oids[oid->data[7]];
430*f9fbec18Smcpowers if (memcmp(oid->data, po->oid.data, 8) == 0)
431*f9fbec18Smcpowers ret = po;
432*f9fbec18Smcpowers }
433*f9fbec18Smcpowers } else if (oid->len == 5) {
434*f9fbec18Smcpowers /* XXX bounds check */
435*f9fbec18Smcpowers po = &SECG_oids[oid->data[4]];
436*f9fbec18Smcpowers if (memcmp(oid->data, po->oid.data, 5) == 0)
437*f9fbec18Smcpowers ret = po;
438*f9fbec18Smcpowers } else {
439*f9fbec18Smcpowers ret = NULL;
440*f9fbec18Smcpowers }
441*f9fbec18Smcpowers return(ret);
442*f9fbec18Smcpowers }
443*f9fbec18Smcpowers
444*f9fbec18Smcpowers ECCurveName
SECOID_FindOIDTag(const SECItem * oid)445*f9fbec18Smcpowers SECOID_FindOIDTag(const SECItem *oid)
446*f9fbec18Smcpowers {
447*f9fbec18Smcpowers SECOidData *oiddata;
448*f9fbec18Smcpowers
449*f9fbec18Smcpowers oiddata = SECOID_FindOID (oid);
450*f9fbec18Smcpowers if (oiddata == NULL)
451*f9fbec18Smcpowers return ECCurve_noName;
452*f9fbec18Smcpowers
453*f9fbec18Smcpowers return oiddata->offset;
454*f9fbec18Smcpowers }
455