security/nss/lib/freebl/blapit.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial