Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: mozilla/security/nss/lib/freebl/blapit.h

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * blapit.h - public data structures for the crypto library
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* $Id: blapit.h,v 1.30 2012/09/28 22:46:32 rrelyea%redhat.com Exp $ */
8
9 #ifndef _BLAPIT_H_
10 #define _BLAPIT_H_
11
12 #include "seccomon.h"
13 #include "prlink.h"
14 #include "plarena.h"
15 #include "ecl-exp.h"
16
17
18 /* RC2 operation modes */
19 #define NSS_RC2 0
20 #define NSS_RC2_CBC 1
21
22 /* RC5 operation modes */
23 #define NSS_RC5 0
24 #define NSS_RC5_CBC 1
25
26 /* DES operation modes */
27 #define NSS_DES 0
28 #define NSS_DES_CBC 1
29 #define NSS_DES_EDE3 2
30 #define NSS_DES_EDE3_CBC 3
31
32 #define DES_KEY_LENGTH 8 /* Bytes */
33
34 /* AES operation modes */
35 #define NSS_AES 0
36 #define NSS_AES_CBC 1
37 #define NSS_AES_CTS 2
38 #define NSS_AES_CTR 3
39 #define NSS_AES_GCM 4
40
41 /* Camellia operation modes */
42 #define NSS_CAMELLIA 0
43 #define NSS_CAMELLIA_CBC 1
44
45 /* SEED operation modes */
46 #define NSS_SEED 0
47 #define NSS_SEED_CBC 1
48
49 #define DSA1_SUBPRIME_LEN 20 /* Bytes */
50 #define DSA1_SIGNATURE_LEN (DSA1_SUBPRIME_LEN*2) /* Bytes */
51 #define DSA_MAX_SUBPRIME_LEN 32 /* Bytes */
52 #define DSA_MAX_SIGNATURE_LEN (DSA_MAX_SUBPRIME_LEN*2)/* Bytes */
53
54 /*
55 * Mark the old defines as deprecated. This will warn code that expected
56 * DSA1 only that they need to change if the are to support DSA2.
57 */
58 #if defined(__GNUC__) && (__GNUC__ > 3)
59 /* make GCC warn when we use these #defines */
60 typedef int __BLAPI_DEPRECATED __attribute__((deprecated));
61 #define DSA_SUBPRIME_LEN ((__BLAPI_DEPRECATED)DSA1_SUBPRIME_LEN)
62 #define DSA_SIGNATURE_LEN ((__BLAPI_DEPRECATED)DSA1_SIGNATURE_LEN)
63 #define DSA_Q_BITS ((__BLAPI_DEPRECATED)(DSA1_SUBPRIME_LEN*8))
64 #else
65 #ifdef _WIN32
66 /* This magic gets the windows compiler to give us a deprecation
67 * warning */
68 #pragma deprecated(DSA_SUBPRIME_LEN, DSA_SIGNATURE_LEN, DSA_QBITS)
69 #endif
70 #define DSA_SUBPRIME_LEN DSA1_SUBPRIME_LEN
71 #define DSA_SIGNATURE_LEN DSA1_SIGNATURE_LEN
72 #define DSA_Q_BITS (DSA1_SUBPRIME_LEN*8)
73 #endif
74
75
76 /* XXX We shouldn't have to hard code this limit. For
77 * now, this is the quickest way to support ECDSA signature
78 * processing (ECDSA signature lengths depend on curve
79 * size). This limit is sufficient for curves upto
80 * 576 bits.
81 */
82 #define MAX_ECKEY_LEN 72 /* Bytes */
83
84 /* EC point compression format */
85 #define EC_POINT_FORM_COMPRESSED_Y0 0x02
86 #define EC_POINT_FORM_COMPRESSED_Y1 0x03
87 #define EC_POINT_FORM_UNCOMPRESSED 0x04
88 #define EC_POINT_FORM_HYBRID_Y0 0x06
89 #define EC_POINT_FORM_HYBRID_Y1 0x07
90
91 /*
92 * Number of bytes each hash algorithm produces
93 */
94 #define MD2_LENGTH 16 /* Bytes */
95 #define MD5_LENGTH 16 /* Bytes */
96 #define SHA1_LENGTH 20 /* Bytes */
97 #define SHA256_LENGTH 32 /* bytes */
98 #define SHA384_LENGTH 48 /* bytes */
99 #define SHA512_LENGTH 64 /* bytes */
100 #define HASH_LENGTH_MAX SHA512_LENGTH
101
102 /*
103 * Input block size for each hash algorithm.
104 */
105
106 #define MD2_BLOCK_LENGTH 64 /* bytes */
107 #define MD5_BLOCK_LENGTH 64 /* bytes */
108 #define SHA1_BLOCK_LENGTH 64 /* bytes */
109 #define SHA224_BLOCK_LENGTH 64 /* bytes */
110 #define SHA256_BLOCK_LENGTH 64 /* bytes */
111 #define SHA384_BLOCK_LENGTH 128 /* bytes */
112 #define SHA512_BLOCK_LENGTH 128 /* bytes */
113 #define HASH_BLOCK_LENGTH_MAX SHA512_BLOCK_LENGTH
114
115 #define AES_KEY_WRAP_IV_BYTES 8
116 #define AES_KEY_WRAP_BLOCK_SIZE 8 /* bytes */
117 #define AES_BLOCK_SIZE 16 /* bytes */
118
119 #define AES_128_KEY_LENGTH 16 /* bytes */
120 #define AES_192_KEY_LENGTH 24 /* bytes */
121 #define AES_256_KEY_LENGTH 32 /* bytes */
122
123 #define CAMELLIA_BLOCK_SIZE 16 /* bytes */
124
125 #define SEED_BLOCK_SIZE 16 /* bytes */
126 #define SEED_KEY_LENGTH 16 /* bytes */
127
128 #define NSS_FREEBL_DEFAULT_CHUNKSIZE 2048
129
130 /*
131 * These values come from the initial key size limits from the PKCS #11
132 * module. They may be arbitrarily adjusted to any value freebl supports.
133 */
134 #define RSA_MIN_MODULUS_BITS 128
135 #define RSA_MAX_MODULUS_BITS 16384
136 #define RSA_MAX_EXPONENT_BITS 64
137 #define DH_MIN_P_BITS 128
138 #define DH_MAX_P_BITS 16384
139
140 /*
141 * The FIPS 186-1 algorithm for generating primes P and Q allows only 9
142 * distinct values for the length of P, and only one value for the
143 * length of Q.
144 * The algorithm uses a variable j to indicate which of the 9 lengths
145 * of P is to be used.
146 * The following table relates j to the lengths of P and Q in bits.
147 *
148 * j bits in P bits in Q
149 * _ _________ _________
150 * 0 512 160
151 * 1 576 160
152 * 2 640 160
153 * 3 704 160
154 * 4 768 160
155 * 5 832 160
156 * 6 896 160
157 * 7 960 160
158 * 8 1024 160
159 *
160 * The FIPS-186-1 compliant PQG generator takes j as an input parameter.
161 *
162 * FIPS 186-3 algorithm specifies 4 distinct P and Q sizes:
163 *
164 * bits in P bits in Q
165 * _________ _________
166 * 1024 160
167 * 2048 224
168 * 2048 256
169 * 3072 256
170 *
171 * The FIPS-186-3 complaiant PQG generator (PQG V2) takes arbitrary p and q
172 * lengths as input and returns an error if they aren't in this list.
173 */
174
175 #define DSA1_Q_BITS 160
176 #define DSA_MAX_P_BITS 3072
177 #define DSA_MIN_P_BITS 512
178 #define DSA_MAX_Q_BITS 256
179 #define DSA_MIN_Q_BITS 160
180
181 #if DSA_MAX_Q_BITS != DSA_MAX_SUBPRIME_LEN*8
182 #error "Inconsistent declaration of DSA SUBPRIME/Q parameters in blapit.h"
183 #endif
184
185
186 /*
187 * function takes desired number of bits in P,
188 * returns index (0..8) or -1 if number of bits is invalid.
189 */
190 #define PQG_PBITS_TO_INDEX(bits) \
191 (((bits) < 512 || (bits) > 1024 || (bits) % 64) ? \
192 -1 : (int)((bits)-512)/64)
193
194 /*
195 * function takes index (0-8)
196 * returns number of bits in P for that index, or -1 if index is invalid.
197 */
198 #define PQG_INDEX_TO_PBITS(j) (((unsigned)(j) > 8) ? -1 : (512 + 64 * (j)))
199
200
201 /***************************************************************************
202 ** Opaque objects
203 */
204
205 struct DESContextStr ;
206 struct RC2ContextStr ;
207 struct RC4ContextStr ;
208 struct RC5ContextStr ;
209 struct AESContextStr ;
210 struct CamelliaContextStr ;
211 struct MD2ContextStr ;
212 struct MD5ContextStr ;
213 struct SHA1ContextStr ;
214 struct SHA256ContextStr ;
215 struct SHA512ContextStr ;
216 struct AESKeyWrapContextStr ;
217 struct SEEDContextStr ;
218
219 typedef struct DESContextStr DESContext;
220 typedef struct RC2ContextStr RC2Context;
221 typedef struct RC4ContextStr RC4Context;
222 typedef struct RC5ContextStr RC5Context;
223 typedef struct AESContextStr AESContext;
224 typedef struct CamelliaContextStr CamelliaContext;
225 typedef struct MD2ContextStr MD2Context;
226 typedef struct MD5ContextStr MD5Context;
227 typedef struct SHA1ContextStr SHA1Context;
228 typedef struct SHA256ContextStr SHA256Context;
229 /* SHA224Context is really a SHA256ContextStr. This is not a mistake. */
230 typedef struct SHA256ContextStr SHA224Context;
231 typedef struct SHA512ContextStr SHA512Context;
232 /* SHA384Context is really a SHA512ContextStr. This is not a mistake. */
233 typedef struct SHA512ContextStr SHA384Context;
234 typedef struct AESKeyWrapContextStr AESKeyWrapContext;
235 typedef struct SEEDContextStr SEEDContext;
236
237 /***************************************************************************
238 ** RSA Public and Private Key structures
239 */
240
241 /* member names from PKCS#1, section 7.1 */
242 struct RSAPublicKeyStr {
243 PLArenaPool * arena;
244 SECItem modulus;
245 SECItem publicExponent;
246 };
247 typedef struct RSAPublicKeyStr RSAPublicKey;
248
249 /* member names from PKCS#1, section 7.2 */
250 struct RSAPrivateKeyStr {
251 PLArenaPool * arena;
252 SECItem version;
253 SECItem modulus;
254 SECItem publicExponent;
255 SECItem privateExponent;
256 SECItem prime1;
257 SECItem prime2;
258 SECItem exponent1;
259 SECItem exponent2;
260 SECItem coefficient;
261 };
262 typedef struct RSAPrivateKeyStr RSAPrivateKey;
263
264
265 /***************************************************************************
266 ** DSA Public and Private Key and related structures
267 */
268
269 struct PQGParamsStr {
270 PLArenaPool *arena;
271 SECItem prime; /* p */
272 SECItem subPrime; /* q */
273 SECItem base; /* g */
274 /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2 459 7.3.2) */
275 };
276 typedef struct PQGParamsStr PQGParams;
277
278 struct PQGVerifyStr {
279 PLArenaPool * arena; /* includes this struct, seed, & h. */
280 unsigned int counter;
281 SECItem seed;
282 SECItem h;
283 };
284 typedef struct PQGVerifyStr PQGVerify;
285
286 struct DSAPublicKeyStr {
287 PQGParams params;
288 SECItem publicValue;
289 };
290 typedef struct DSAPublicKeyStr DSAPublicKey;
291
292 struct DSAPrivateKeyStr {
293 PQGParams params;
294 SECItem publicValue;
295 SECItem privateValue;
296 };
297 typedef struct DSAPrivateKeyStr DSAPrivateKey;
298
299 /***************************************************************************
300 ** Diffie-Hellman Public and Private Key and related structures
301 ** Structure member names suggested by PKCS#3.
302 */
303
304 struct DHParamsStr {
305 PLArenaPool * arena;
306 SECItem prime; /* p */
307 SECItem base; /* g */
308 };
309 typedef struct DHParamsStr DHParams;
310
311 struct DHPublicKeyStr {
312 PLArenaPool * arena;
313 SECItem prime;
314 SECItem base;
315 SECItem publicValue;
316 };
317 typedef struct DHPublicKeyStr DHPublicKey;
318
319 struct DHPrivateKeyStr {
320 PLArenaPool * arena;
321 SECItem prime;
322 SECItem base;
323 SECItem publicValue;
324 SECItem privateValue;
325 };
326 typedef struct DHPrivateKeyStr DHPrivateKey;
327
328 /***************************************************************************
329 ** Data structures used for elliptic curve parameters and
330 ** public and private keys.
331 */
332
333 /*
334 ** The ECParams data structures can encode elliptic curve
335 ** parameters for both GFp and GF2m curves.
336 */
337
338 typedef enum { ec_params_explicit,
339 ec_params_named
340 } ECParamsType;
341
342 typedef enum { ec_field_GFp = 1,
343 ec_field_GF2m
344 } ECFieldType;
345
346 struct ECFieldIDStr {
347 int size; /* field size in bits */
348 ECFieldType type;
349 union {
350 SECItem prime; /* prime p for (GFp) */
351 SECItem poly; /* irreducible binary polynomial for (GF2m) */
352 } u;
353 int k1; /* first coefficient of pentanomial or
354 * the only coefficient of trinomial
355 */
356 int k2; /* two remaining coefficients of pentanomial */
357 int k3;
358 };
359 typedef struct ECFieldIDStr ECFieldID;
360
361 struct ECCurveStr {
362 SECItem a; /* contains octet stream encoding of
363 * field element (X9.62 section 4.3.3)
364 */
365 SECItem b;
366 SECItem seed;
367 };
368 typedef struct ECCurveStr ECCurve;
369
370 struct ECParamsStr {
371 PLArenaPool * arena;
372 ECParamsType type;
373 ECFieldID fieldID;
374 ECCurve curve;
375 SECItem base;
376 SECItem order;
377 int cofactor;
378 SECItem DEREncoding;
379 ECCurveName name;
380 SECItem curveOID;
381 };
382 typedef struct ECParamsStr ECParams;
383
384 struct ECPublicKeyStr {
385 ECParams ecParams;
386 SECItem publicValue; /* elliptic curve point encoded as
387 * octet stream.
388 */
389 };
390 typedef struct ECPublicKeyStr ECPublicKey;
391
392 struct ECPrivateKeyStr {
393 ECParams ecParams;
394 SECItem publicValue; /* encoded ec point */
395 SECItem privateValue; /* private big integer */
396 SECItem version; /* As per SEC 1, Appendix C, Section C.4 */
397 };
398 typedef struct ECPrivateKeyStr ECPrivateKey;
399
400 typedef void * (*BLapiAllocateFunc)(void);
401 typedef void (*BLapiDestroyContextFunc)(void *cx, PRBool freeit);
402 typedef SECStatus (*BLapiInitContextFunc)(void *cx,
403 const unsigned char *key,
404 unsigned int keylen,
405 const unsigned char *,
406 int,
407 unsigned int ,
408 unsigned int );
409 typedef SECStatus (*BLapiEncrypt)(void *cx, unsigned char *output,
410 unsigned int *outputLen,
411 unsigned int maxOutputLen,
412 const unsigned char *input,
413 unsigned int inputLen);
414
415 #endif /* _BLAPIT_H_ */
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/freebl/blapii.h ('k') | mozilla/security/nss/lib/freebl/build_config_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698