comparison nss/lib/freebl/blapit.h @ 0:1e5118fa0cb1

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