2 * blapit.h - public data structures for the crypto library
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
17 * The Original Code is the Netscape security libraries.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1994-2000
22 * the Initial Developer. All Rights Reserved.
25 * Dr Vipul Gupta <vipul.gupta@sun.com> and
26 * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
41 /* $Id: blapit.h,v 1.20 2007/02/28 19:47:37 rrelyea%redhat.com Exp $ */
52 /* RC2 operation modes */
56 /* RC5 operation modes */
60 /* DES operation modes */
63 #define NSS_DES_EDE3 2
64 #define NSS_DES_EDE3_CBC 3
66 #define DES_KEY_LENGTH 8 /* Bytes */
68 /* AES operation modes */
72 /* Camellia operation modes */
73 #define NSS_CAMELLIA 0
74 #define NSS_CAMELLIA_CBC 1
76 #define DSA_SIGNATURE_LEN 40 /* Bytes */
77 #define DSA_SUBPRIME_LEN 20 /* Bytes */
79 /* XXX We shouldn't have to hard code this limit. For
80 * now, this is the quickest way to support ECDSA signature
81 * processing (ECDSA signature lengths depend on curve
82 * size). This limit is sufficient for curves upto
85 #define MAX_ECKEY_LEN 72 /* Bytes */
88 * Number of bytes each hash algorithm produces
90 #define MD2_LENGTH 16 /* Bytes */
91 #define MD5_LENGTH 16 /* Bytes */
92 #define SHA1_LENGTH 20 /* Bytes */
93 #define SHA256_LENGTH 32 /* bytes */
94 #define SHA384_LENGTH 48 /* bytes */
95 #define SHA512_LENGTH 64 /* bytes */
96 #define HASH_LENGTH_MAX SHA512_LENGTH
99 * Input block size for each hash algorithm.
102 #define MD2_BLOCK_LENGTH 64 /* bytes */
103 #define MD5_BLOCK_LENGTH 64 /* bytes */
104 #define SHA1_BLOCK_LENGTH 64 /* bytes */
105 #define SHA256_BLOCK_LENGTH 64 /* bytes */
106 #define SHA384_BLOCK_LENGTH 128 /* bytes */
107 #define SHA512_BLOCK_LENGTH 128 /* bytes */
108 #define HASH_BLOCK_LENGTH_MAX SHA512_BLOCK_LENGTH
110 #define AES_KEY_WRAP_IV_BYTES 8
111 #define AES_KEY_WRAP_BLOCK_SIZE 8 /* bytes */
112 #define AES_BLOCK_SIZE 16 /* bytes */
114 #define CAMELLIA_BLOCK_SIZE 16 /* bytes */
116 #define NSS_FREEBL_DEFAULT_CHUNKSIZE 2048
119 * These values come from the initial key size limits from the PKCS #11
120 * module. They may be arbitrarily adjusted to any value freebl supports.
122 #define RSA_MIN_MODULUS_BITS 128
123 #define RSA_MAX_MODULUS_BITS 8192
124 #define RSA_MAX_EXPONENT_BITS 64
125 #define DH_MIN_P_BITS 128
126 #define DH_MAX_P_BITS 2236
129 * The FIPS 186 algorithm for generating primes P and Q allows only 9
130 * distinct values for the length of P, and only one value for the
132 * The algorithm uses a variable j to indicate which of the 9 lengths
133 * of P is to be used.
134 * The following table relates j to the lengths of P and Q in bits.
136 * j bits in P bits in Q
137 * _ _________ _________
148 * The FIPS-186 compliant PQG generator takes j as an input parameter.
151 #define DSA_Q_BITS 160
152 #define DSA_MAX_P_BITS 1024
153 #define DSA_MIN_P_BITS 512
156 * function takes desired number of bits in P,
157 * returns index (0..8) or -1 if number of bits is invalid.
159 #define PQG_PBITS_TO_INDEX(bits) \
160 (((bits) < 512 || (bits) > 1024 || (bits) % 64) ? \
161 -1 : (int)((bits)-512)/64)
164 * function takes index (0-8)
165 * returns number of bits in P for that index, or -1 if index is invalid.
167 #define PQG_INDEX_TO_PBITS(j) (((unsigned)(j) > 8) ? -1 : (512 + 64 * (j)))
170 /***************************************************************************
174 struct DESContextStr
;
175 struct RC2ContextStr
;
176 struct RC4ContextStr
;
177 struct RC5ContextStr
;
178 struct AESContextStr
;
179 struct CamelliaContextStr
;
180 struct MD2ContextStr
;
181 struct MD5ContextStr
;
182 struct SHA1ContextStr
;
183 struct SHA256ContextStr
;
184 struct SHA512ContextStr
;
185 struct AESKeyWrapContextStr
;
187 typedef struct DESContextStr DESContext
;
188 typedef struct RC2ContextStr RC2Context
;
189 typedef struct RC4ContextStr RC4Context
;
190 typedef struct RC5ContextStr RC5Context
;
191 typedef struct AESContextStr AESContext
;
192 typedef struct CamelliaContextStr CamelliaContext
;
193 typedef struct MD2ContextStr MD2Context
;
194 typedef struct MD5ContextStr MD5Context
;
195 typedef struct SHA1ContextStr SHA1Context
;
196 typedef struct SHA256ContextStr SHA256Context
;
197 typedef struct SHA512ContextStr SHA512Context
;
198 /* SHA384Context is really a SHA512ContextStr. This is not a mistake. */
199 typedef struct SHA512ContextStr SHA384Context
;
200 typedef struct AESKeyWrapContextStr AESKeyWrapContext
;
202 /***************************************************************************
203 ** RSA Public and Private Key structures
206 /* member names from PKCS#1, section 7.1 */
207 struct RSAPublicKeyStr
{
210 SECItem publicExponent
;
212 typedef struct RSAPublicKeyStr RSAPublicKey
;
214 /* member names from PKCS#1, section 7.2 */
215 struct RSAPrivateKeyStr
{
219 SECItem publicExponent
;
220 SECItem privateExponent
;
227 typedef struct RSAPrivateKeyStr RSAPrivateKey
;
230 /***************************************************************************
231 ** DSA Public and Private Key and related structures
234 struct PQGParamsStr
{
236 SECItem prime
; /* p */
237 SECItem subPrime
; /* q */
238 SECItem base
; /* g */
239 /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
241 typedef struct PQGParamsStr PQGParams
;
243 struct PQGVerifyStr
{
244 PRArenaPool
* arena
; /* includes this struct, seed, & h. */
245 unsigned int counter
;
249 typedef struct PQGVerifyStr PQGVerify
;
251 struct DSAPublicKeyStr
{
255 typedef struct DSAPublicKeyStr DSAPublicKey
;
257 struct DSAPrivateKeyStr
{
260 SECItem privateValue
;
262 typedef struct DSAPrivateKeyStr DSAPrivateKey
;
264 /***************************************************************************
265 ** Diffie-Hellman Public and Private Key and related structures
266 ** Structure member names suggested by PKCS#3.
271 SECItem prime
; /* p */
272 SECItem base
; /* g */
274 typedef struct DHParamsStr DHParams
;
276 struct DHPublicKeyStr
{
282 typedef struct DHPublicKeyStr DHPublicKey
;
284 struct DHPrivateKeyStr
{
289 SECItem privateValue
;
291 typedef struct DHPrivateKeyStr DHPrivateKey
;
293 /***************************************************************************
294 ** Data structures used for elliptic curve parameters and
295 ** public and private keys.
299 ** The ECParams data structures can encode elliptic curve
300 ** parameters for both GFp and GF2m curves.
303 typedef enum { ec_params_explicit
,
307 typedef enum { ec_field_GFp
= 1,
311 struct ECFieldIDStr
{
312 int size
; /* field size in bits */
315 SECItem prime
; /* prime p for (GFp) */
316 SECItem poly
; /* irreducible binary polynomial for (GF2m) */
318 int k1
; /* first coefficient of pentanomial or
319 * the only coefficient of trinomial
321 int k2
; /* two remaining coefficients of pentanomial */
324 typedef struct ECFieldIDStr ECFieldID
;
327 SECItem a
; /* contains octet stream encoding of
328 * field element (X9.62 section 4.3.3)
333 typedef struct ECCurveStr ECCurve
;
347 typedef struct ECParamsStr ECParams
;
349 struct ECPublicKeyStr
{
351 SECItem publicValue
; /* elliptic curve point encoded as
355 typedef struct ECPublicKeyStr ECPublicKey
;
357 struct ECPrivateKeyStr
{
359 SECItem publicValue
; /* encoded ec point */
360 SECItem privateValue
; /* private big integer */
361 SECItem version
; /* As per SEC 1, Appendix C, Section C.4 */
363 typedef struct ECPrivateKeyStr ECPrivateKey
;
365 typedef void * (*BLapiAllocateFunc
)(void);
366 typedef void (*BLapiDestroyContextFunc
)(void *cx
, PRBool freeit
);
367 typedef SECStatus (*BLapiInitContextFunc
)(void *cx
,
368 const unsigned char *key
,
370 const unsigned char *,
374 typedef SECStatus (*BLapiEncrypt
)(void *cx
, unsigned char *output
,
375 unsigned int *outputLen
,
376 unsigned int maxOutputLen
,
377 const unsigned char *input
,
378 unsigned int inputLen
);
380 #endif /* _BLAPIT_H_ */