xref: /titanic_50/usr/src/common/crypto/ecc/oid.c (revision c39526b769298791ff5b0b6c5e761f49aabaeb4e)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
45 
46 #include <sys/types.h>
47 #include <sys/systm.h>
48 #include <sys/param.h>
49 #ifdef _KERNEL
50 #include <sys/kmem.h>
51 #else
52 #include <string.h>
53 #endif
54 #include "ec.h"
55 #include "ecl-curve.h"
56 #include "ecc_impl.h"
57 #include "secoidt.h"
58 
59 #define CERTICOM_OID            0x2b, 0x81, 0x04
60 #define SECG_OID                CERTICOM_OID, 0x00
61 
62 #define ANSI_X962_OID           0x2a, 0x86, 0x48, 0xce, 0x3d
63 #define ANSI_X962_CURVE_OID     ANSI_X962_OID, 0x03
64 #define ANSI_X962_GF2m_OID      ANSI_X962_CURVE_OID, 0x00
65 #define ANSI_X962_GFp_OID       ANSI_X962_CURVE_OID, 0x01
66 
67 #define CONST_OID static const unsigned char
68 
69 /* ANSI X9.62 prime curve OIDs */
70 /* NOTE: prime192v1 is the same as secp192r1, prime256v1 is the
71  * same as secp256r1
72  */
73 CONST_OID ansiX962prime192v1[] = { ANSI_X962_GFp_OID, 0x01 };
74 CONST_OID ansiX962prime192v2[] = { ANSI_X962_GFp_OID, 0x02 };
75 CONST_OID ansiX962prime192v3[] = { ANSI_X962_GFp_OID, 0x03 };
76 CONST_OID ansiX962prime239v1[] = { ANSI_X962_GFp_OID, 0x04 };
77 CONST_OID ansiX962prime239v2[] = { ANSI_X962_GFp_OID, 0x05 };
78 CONST_OID ansiX962prime239v3[] = { ANSI_X962_GFp_OID, 0x06 };
79 CONST_OID ansiX962prime256v1[] = { ANSI_X962_GFp_OID, 0x07 };
80 
81 /* SECG prime curve OIDs */
82 CONST_OID secgECsecp112r1[] = { SECG_OID, 0x06 };
83 CONST_OID secgECsecp112r2[] = { SECG_OID, 0x07 };
84 CONST_OID secgECsecp128r1[] = { SECG_OID, 0x1c };
85 CONST_OID secgECsecp128r2[] = { SECG_OID, 0x1d };
86 CONST_OID secgECsecp160k1[] = { SECG_OID, 0x09 };
87 CONST_OID secgECsecp160r1[] = { SECG_OID, 0x08 };
88 CONST_OID secgECsecp160r2[] = { SECG_OID, 0x1e };
89 CONST_OID secgECsecp192k1[] = { SECG_OID, 0x1f };
90 CONST_OID secgECsecp224k1[] = { SECG_OID, 0x20 };
91 CONST_OID secgECsecp224r1[] = { SECG_OID, 0x21 };
92 CONST_OID secgECsecp256k1[] = { SECG_OID, 0x0a };
93 CONST_OID secgECsecp384r1[] = { SECG_OID, 0x22 };
94 CONST_OID secgECsecp521r1[] = { SECG_OID, 0x23 };
95 
96 /* SECG characterisitic two curve OIDs */
97 CONST_OID secgECsect113r1[] = {SECG_OID, 0x04 };
98 CONST_OID secgECsect113r2[] = {SECG_OID, 0x05 };
99 CONST_OID secgECsect131r1[] = {SECG_OID, 0x16 };
100 CONST_OID secgECsect131r2[] = {SECG_OID, 0x17 };
101 CONST_OID secgECsect163k1[] = {SECG_OID, 0x01 };
102 CONST_OID secgECsect163r1[] = {SECG_OID, 0x02 };
103 CONST_OID secgECsect163r2[] = {SECG_OID, 0x0f };
104 CONST_OID secgECsect193r1[] = {SECG_OID, 0x18 };
105 CONST_OID secgECsect193r2[] = {SECG_OID, 0x19 };
106 CONST_OID secgECsect233k1[] = {SECG_OID, 0x1a };
107 CONST_OID secgECsect233r1[] = {SECG_OID, 0x1b };
108 CONST_OID secgECsect239k1[] = {SECG_OID, 0x03 };
109 CONST_OID secgECsect283k1[] = {SECG_OID, 0x10 };
110 CONST_OID secgECsect283r1[] = {SECG_OID, 0x11 };
111 CONST_OID secgECsect409k1[] = {SECG_OID, 0x24 };
112 CONST_OID secgECsect409r1[] = {SECG_OID, 0x25 };
113 CONST_OID secgECsect571k1[] = {SECG_OID, 0x26 };
114 CONST_OID secgECsect571r1[] = {SECG_OID, 0x27 };
115 
116 /* ANSI X9.62 characteristic two curve OIDs */
117 CONST_OID ansiX962c2pnb163v1[] = { ANSI_X962_GF2m_OID, 0x01 };
118 CONST_OID ansiX962c2pnb163v2[] = { ANSI_X962_GF2m_OID, 0x02 };
119 CONST_OID ansiX962c2pnb163v3[] = { ANSI_X962_GF2m_OID, 0x03 };
120 CONST_OID ansiX962c2pnb176v1[] = { ANSI_X962_GF2m_OID, 0x04 };
121 CONST_OID ansiX962c2tnb191v1[] = { ANSI_X962_GF2m_OID, 0x05 };
122 CONST_OID ansiX962c2tnb191v2[] = { ANSI_X962_GF2m_OID, 0x06 };
123 CONST_OID ansiX962c2tnb191v3[] = { ANSI_X962_GF2m_OID, 0x07 };
124 CONST_OID ansiX962c2onb191v4[] = { ANSI_X962_GF2m_OID, 0x08 };
125 CONST_OID ansiX962c2onb191v5[] = { ANSI_X962_GF2m_OID, 0x09 };
126 CONST_OID ansiX962c2pnb208w1[] = { ANSI_X962_GF2m_OID, 0x0a };
127 CONST_OID ansiX962c2tnb239v1[] = { ANSI_X962_GF2m_OID, 0x0b };
128 CONST_OID ansiX962c2tnb239v2[] = { ANSI_X962_GF2m_OID, 0x0c };
129 CONST_OID ansiX962c2tnb239v3[] = { ANSI_X962_GF2m_OID, 0x0d };
130 CONST_OID ansiX962c2onb239v4[] = { ANSI_X962_GF2m_OID, 0x0e };
131 CONST_OID ansiX962c2onb239v5[] = { ANSI_X962_GF2m_OID, 0x0f };
132 CONST_OID ansiX962c2pnb272w1[] = { ANSI_X962_GF2m_OID, 0x10 };
133 CONST_OID ansiX962c2pnb304w1[] = { ANSI_X962_GF2m_OID, 0x11 };
134 CONST_OID ansiX962c2tnb359v1[] = { ANSI_X962_GF2m_OID, 0x12 };
135 CONST_OID ansiX962c2pnb368w1[] = { ANSI_X962_GF2m_OID, 0x13 };
136 CONST_OID ansiX962c2tnb431r1[] = { ANSI_X962_GF2m_OID, 0x14 };
137 
138 #define OI(x) { siDEROID, (unsigned char *)x, sizeof x }
139 #ifndef SECOID_NO_STRINGS
140 #define OD(oid,tag,desc,mech,ext) { OI(oid), tag, desc, mech, ext }
141 #else
142 #define OD(oid,tag,desc,mech,ext) { OI(oid), tag, 0, mech, ext }
143 #endif
144 
145 #define	CKM_INVALID_MECHANISM 0xffffffffUL
146 
147 /* XXX this is incorrect */
148 #define	INVALID_CERT_EXTENSION 1
149 
150 #define CKM_ECDSA                      0x00001041
151 #define CKM_ECDSA_SHA1                 0x00001042
152 #define CKM_ECDH1_DERIVE               0x00001050
153 
154 static SECOidData ANSI_prime_oids[] = {
155     { { siDEROID, NULL, 0 }, ECCurve_noName,
156 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
157 
158     OD( ansiX962prime192v1, ECCurve_NIST_P192,
159 	"ANSI X9.62 elliptic curve prime192v1 (aka secp192r1, NIST P-192)",
160 	CKM_INVALID_MECHANISM,
161 	INVALID_CERT_EXTENSION ),
162     OD( ansiX962prime192v2, ECCurve_X9_62_PRIME_192V2,
163 	"ANSI X9.62 elliptic curve prime192v2",
164 	CKM_INVALID_MECHANISM,
165 	INVALID_CERT_EXTENSION ),
166     OD( ansiX962prime192v3, ECCurve_X9_62_PRIME_192V3,
167 	"ANSI X9.62 elliptic curve prime192v3",
168 	CKM_INVALID_MECHANISM,
169 	INVALID_CERT_EXTENSION ),
170     OD( ansiX962prime239v1, ECCurve_X9_62_PRIME_239V1,
171 	"ANSI X9.62 elliptic curve prime239v1",
172 	CKM_INVALID_MECHANISM,
173 	INVALID_CERT_EXTENSION ),
174     OD( ansiX962prime239v2, ECCurve_X9_62_PRIME_239V2,
175 	"ANSI X9.62 elliptic curve prime239v2",
176 	CKM_INVALID_MECHANISM,
177 	INVALID_CERT_EXTENSION ),
178     OD( ansiX962prime239v3, ECCurve_X9_62_PRIME_239V3,
179 	"ANSI X9.62 elliptic curve prime239v3",
180 	CKM_INVALID_MECHANISM,
181 	INVALID_CERT_EXTENSION ),
182     OD( ansiX962prime256v1, ECCurve_NIST_P256,
183 	"ANSI X9.62 elliptic curve prime256v1 (aka secp256r1, NIST P-256)",
184 	CKM_INVALID_MECHANISM,
185 	INVALID_CERT_EXTENSION )
186 };
187 
188 static SECOidData SECG_oids[] = {
189     { { siDEROID, NULL, 0 }, ECCurve_noName,
190 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
191 
192     OD( secgECsect163k1, ECCurve_NIST_K163,
193 	"SECG elliptic curve sect163k1 (aka NIST K-163)",
194 	CKM_INVALID_MECHANISM,
195 	INVALID_CERT_EXTENSION ),
196     OD( secgECsect163r1, ECCurve_SECG_CHAR2_163R1,
197 	"SECG elliptic curve sect163r1",
198 	CKM_INVALID_MECHANISM,
199 	INVALID_CERT_EXTENSION ),
200     OD( secgECsect239k1, ECCurve_SECG_CHAR2_239K1,
201 	"SECG elliptic curve sect239k1",
202 	CKM_INVALID_MECHANISM,
203 	INVALID_CERT_EXTENSION ),
204     OD( secgECsect113r1, ECCurve_SECG_CHAR2_113R1,
205 	"SECG elliptic curve sect113r1",
206 	CKM_INVALID_MECHANISM,
207 	INVALID_CERT_EXTENSION ),
208     OD( secgECsect113r2, ECCurve_SECG_CHAR2_113R2,
209 	"SECG elliptic curve sect113r2",
210 	CKM_INVALID_MECHANISM,
211 	INVALID_CERT_EXTENSION ),
212     OD( secgECsecp112r1, ECCurve_SECG_PRIME_112R1,
213 	"SECG elliptic curve secp112r1",
214 	CKM_INVALID_MECHANISM,
215 	INVALID_CERT_EXTENSION ),
216     OD( secgECsecp112r2, ECCurve_SECG_PRIME_112R2,
217 	"SECG elliptic curve secp112r2",
218 	CKM_INVALID_MECHANISM,
219 	INVALID_CERT_EXTENSION ),
220     OD( secgECsecp160r1, ECCurve_SECG_PRIME_160R1,
221 	"SECG elliptic curve secp160r1",
222 	CKM_INVALID_MECHANISM,
223 	INVALID_CERT_EXTENSION ),
224     OD( secgECsecp160k1, ECCurve_SECG_PRIME_160K1,
225 	"SECG elliptic curve secp160k1",
226 	CKM_INVALID_MECHANISM,
227 	INVALID_CERT_EXTENSION ),
228     OD( secgECsecp256k1, ECCurve_SECG_PRIME_256K1,
229 	"SECG elliptic curve secp256k1",
230 	CKM_INVALID_MECHANISM,
231 	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     { { siDEROID, NULL, 0 }, ECCurve_noName,
239 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
240     OD( secgECsect163r2, ECCurve_NIST_B163,
241 	"SECG elliptic curve sect163r2 (aka NIST B-163)",
242 	CKM_INVALID_MECHANISM,
243 	INVALID_CERT_EXTENSION ),
244     OD( secgECsect283k1, ECCurve_NIST_K283,
245 	"SECG elliptic curve sect283k1 (aka NIST K-283)",
246 	CKM_INVALID_MECHANISM,
247 	INVALID_CERT_EXTENSION ),
248     OD( secgECsect283r1, ECCurve_NIST_B283,
249 	"SECG elliptic curve sect283r1 (aka NIST B-283)",
250 	CKM_INVALID_MECHANISM,
251 	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     { { siDEROID, NULL, 0 }, ECCurve_noName,
259 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
260     OD( secgECsect131r1, ECCurve_SECG_CHAR2_131R1,
261 	"SECG elliptic curve sect131r1",
262 	CKM_INVALID_MECHANISM,
263 	INVALID_CERT_EXTENSION ),
264     OD( secgECsect131r2, ECCurve_SECG_CHAR2_131R2,
265 	"SECG elliptic curve sect131r2",
266 	CKM_INVALID_MECHANISM,
267 	INVALID_CERT_EXTENSION ),
268     OD( secgECsect193r1, ECCurve_SECG_CHAR2_193R1,
269 	"SECG elliptic curve sect193r1",
270 	CKM_INVALID_MECHANISM,
271 	INVALID_CERT_EXTENSION ),
272     OD( secgECsect193r2, ECCurve_SECG_CHAR2_193R2,
273 	"SECG elliptic curve sect193r2",
274 	CKM_INVALID_MECHANISM,
275 	INVALID_CERT_EXTENSION ),
276     OD( secgECsect233k1, ECCurve_NIST_K233,
277 	"SECG elliptic curve sect233k1 (aka NIST K-233)",
278 	CKM_INVALID_MECHANISM,
279 	INVALID_CERT_EXTENSION ),
280     OD( secgECsect233r1, ECCurve_NIST_B233,
281 	"SECG elliptic curve sect233r1 (aka NIST B-233)",
282 	CKM_INVALID_MECHANISM,
283 	INVALID_CERT_EXTENSION ),
284     OD( secgECsecp128r1, ECCurve_SECG_PRIME_128R1,
285 	"SECG elliptic curve secp128r1",
286 	CKM_INVALID_MECHANISM,
287 	INVALID_CERT_EXTENSION ),
288     OD( secgECsecp128r2, ECCurve_SECG_PRIME_128R2,
289 	"SECG elliptic curve secp128r2",
290 	CKM_INVALID_MECHANISM,
291 	INVALID_CERT_EXTENSION ),
292     OD( secgECsecp160r2, ECCurve_SECG_PRIME_160R2,
293 	"SECG elliptic curve secp160r2",
294 	CKM_INVALID_MECHANISM,
295 	INVALID_CERT_EXTENSION ),
296     OD( secgECsecp192k1, ECCurve_SECG_PRIME_192K1,
297 	"SECG elliptic curve secp192k1",
298 	CKM_INVALID_MECHANISM,
299 	INVALID_CERT_EXTENSION ),
300     OD( secgECsecp224k1, ECCurve_SECG_PRIME_224K1,
301 	"SECG elliptic curve secp224k1",
302 	CKM_INVALID_MECHANISM,
303 	INVALID_CERT_EXTENSION ),
304     OD( secgECsecp224r1, ECCurve_NIST_P224,
305 	"SECG elliptic curve secp224r1 (aka NIST P-224)",
306 	CKM_INVALID_MECHANISM,
307 	INVALID_CERT_EXTENSION ),
308     OD( secgECsecp384r1, ECCurve_NIST_P384,
309 	"SECG elliptic curve secp384r1 (aka NIST P-384)",
310 	CKM_INVALID_MECHANISM,
311 	INVALID_CERT_EXTENSION ),
312     OD( secgECsecp521r1, ECCurve_NIST_P521,
313 	"SECG elliptic curve secp521r1 (aka NIST P-521)",
314 	CKM_INVALID_MECHANISM,
315 	INVALID_CERT_EXTENSION ),
316     OD( secgECsect409k1, ECCurve_NIST_K409,
317 	"SECG elliptic curve sect409k1 (aka NIST K-409)",
318 	CKM_INVALID_MECHANISM,
319 	INVALID_CERT_EXTENSION ),
320     OD( secgECsect409r1, ECCurve_NIST_B409,
321 	"SECG elliptic curve sect409r1 (aka NIST B-409)",
322 	CKM_INVALID_MECHANISM,
323 	INVALID_CERT_EXTENSION ),
324     OD( secgECsect571k1, ECCurve_NIST_K571,
325 	"SECG elliptic curve sect571k1 (aka NIST K-571)",
326 	CKM_INVALID_MECHANISM,
327 	INVALID_CERT_EXTENSION ),
328     OD( secgECsect571r1, ECCurve_NIST_B571,
329 	"SECG elliptic curve sect571r1 (aka NIST B-571)",
330 	CKM_INVALID_MECHANISM,
331 	INVALID_CERT_EXTENSION )
332 };
333 
334 static SECOidData ANSI_oids[] = {
335     { { siDEROID, NULL, 0 }, ECCurve_noName,
336 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
337 
338     /* ANSI X9.62 named elliptic curves (characteristic two field) */
339     OD( ansiX962c2pnb163v1, ECCurve_X9_62_CHAR2_PNB163V1,
340 	"ANSI X9.62 elliptic curve c2pnb163v1",
341 	CKM_INVALID_MECHANISM,
342 	INVALID_CERT_EXTENSION ),
343     OD( ansiX962c2pnb163v2, ECCurve_X9_62_CHAR2_PNB163V2,
344 	"ANSI X9.62 elliptic curve c2pnb163v2",
345 	CKM_INVALID_MECHANISM,
346 	INVALID_CERT_EXTENSION ),
347     OD( ansiX962c2pnb163v3, ECCurve_X9_62_CHAR2_PNB163V3,
348 	"ANSI X9.62 elliptic curve c2pnb163v3",
349 	CKM_INVALID_MECHANISM,
350 	INVALID_CERT_EXTENSION ),
351     OD( ansiX962c2pnb176v1, ECCurve_X9_62_CHAR2_PNB176V1,
352 	"ANSI X9.62 elliptic curve c2pnb176v1",
353 	CKM_INVALID_MECHANISM,
354 	INVALID_CERT_EXTENSION ),
355     OD( ansiX962c2tnb191v1, ECCurve_X9_62_CHAR2_TNB191V1,
356 	"ANSI X9.62 elliptic curve c2tnb191v1",
357 	CKM_INVALID_MECHANISM,
358 	INVALID_CERT_EXTENSION ),
359     OD( ansiX962c2tnb191v2, ECCurve_X9_62_CHAR2_TNB191V2,
360 	"ANSI X9.62 elliptic curve c2tnb191v2",
361 	CKM_INVALID_MECHANISM,
362 	INVALID_CERT_EXTENSION ),
363     OD( ansiX962c2tnb191v3, ECCurve_X9_62_CHAR2_TNB191V3,
364 	"ANSI X9.62 elliptic curve c2tnb191v3",
365 	CKM_INVALID_MECHANISM,
366 	INVALID_CERT_EXTENSION ),
367     { { siDEROID, NULL, 0 }, ECCurve_noName,
368 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
369     { { siDEROID, NULL, 0 }, ECCurve_noName,
370 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
371     OD( ansiX962c2pnb208w1, ECCurve_X9_62_CHAR2_PNB208W1,
372 	"ANSI X9.62 elliptic curve c2pnb208w1",
373 	CKM_INVALID_MECHANISM,
374 	INVALID_CERT_EXTENSION ),
375     OD( ansiX962c2tnb239v1, ECCurve_X9_62_CHAR2_TNB239V1,
376 	"ANSI X9.62 elliptic curve c2tnb239v1",
377 	CKM_INVALID_MECHANISM,
378 	INVALID_CERT_EXTENSION ),
379     OD( ansiX962c2tnb239v2, ECCurve_X9_62_CHAR2_TNB239V2,
380 	"ANSI X9.62 elliptic curve c2tnb239v2",
381 	CKM_INVALID_MECHANISM,
382 	INVALID_CERT_EXTENSION ),
383     OD( ansiX962c2tnb239v3, ECCurve_X9_62_CHAR2_TNB239V3,
384 	"ANSI X9.62 elliptic curve c2tnb239v3",
385 	CKM_INVALID_MECHANISM,
386 	INVALID_CERT_EXTENSION ),
387     { { siDEROID, NULL, 0 }, ECCurve_noName,
388 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
389     { { siDEROID, NULL, 0 }, ECCurve_noName,
390 	"Unknown OID", CKM_INVALID_MECHANISM, INVALID_CERT_EXTENSION },
391     OD( ansiX962c2pnb272w1, ECCurve_X9_62_CHAR2_PNB272W1,
392 	"ANSI X9.62 elliptic curve c2pnb272w1",
393 	CKM_INVALID_MECHANISM,
394 	INVALID_CERT_EXTENSION ),
395     OD( ansiX962c2pnb304w1, ECCurve_X9_62_CHAR2_PNB304W1,
396 	"ANSI X9.62 elliptic curve c2pnb304w1",
397 	CKM_INVALID_MECHANISM,
398 	INVALID_CERT_EXTENSION ),
399     OD( ansiX962c2tnb359v1, ECCurve_X9_62_CHAR2_TNB359V1,
400 	"ANSI X9.62 elliptic curve c2tnb359v1",
401 	CKM_INVALID_MECHANISM,
402 	INVALID_CERT_EXTENSION ),
403     OD( ansiX962c2pnb368w1, ECCurve_X9_62_CHAR2_PNB368W1,
404 	"ANSI X9.62 elliptic curve c2pnb368w1",
405 	CKM_INVALID_MECHANISM,
406 	INVALID_CERT_EXTENSION ),
407     OD( ansiX962c2tnb431r1, ECCurve_X9_62_CHAR2_TNB431R1,
408 	"ANSI X9.62 elliptic curve c2tnb431r1",
409 	CKM_INVALID_MECHANISM,
410 	INVALID_CERT_EXTENSION )
411 };
412 
413 SECOidData *
414 SECOID_FindOID(const SECItem *oid)
415 {
416     SECOidData *po;
417     SECOidData *ret;
418     int i;
419 
420     if (oid->len == 8) {
421 	if (oid->data[6] == 0x00) {
422 		/* XXX bounds check */
423 		po = &ANSI_oids[oid->data[7]];
424 		if (memcmp(oid->data, po->oid.data, 8) == 0)
425 			ret = po;
426 	}
427 	if (oid->data[6] == 0x01) {
428 		/* XXX bounds check */
429 		po = &ANSI_prime_oids[oid->data[7]];
430 		if (memcmp(oid->data, po->oid.data, 8) == 0)
431 			ret = po;
432 	}
433     } else if (oid->len == 5) {
434 	/* XXX bounds check */
435 	po = &SECG_oids[oid->data[4]];
436 	if (memcmp(oid->data, po->oid.data, 5) == 0)
437 		ret = po;
438     } else {
439 	ret = NULL;
440     }
441     return(ret);
442 }
443 
444 ECCurveName
445 SECOID_FindOIDTag(const SECItem *oid)
446 {
447     SECOidData *oiddata;
448 
449     oiddata = SECOID_FindOID (oid);
450     if (oiddata == NULL)
451 	return ECCurve_noName;
452 
453     return oiddata->offset;
454 }
455