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