PageRenderTime 35ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/blapit.h

http://firefox-mac-pdf.googlecode.com/
C Header | 380 lines | 207 code | 50 blank | 123 comment | 2 complexity | 80d7509fea1de7884448ab5aebc11afb MD5 | raw file
  1. /*
  2. * blapit.h - public data structures for the crypto library
  3. *
  4. * ***** BEGIN LICENSE BLOCK *****
  5. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6. *
  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/
  11. *
  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
  15. * License.
  16. *
  17. * The Original Code is the Netscape security libraries.
  18. *
  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.
  23. *
  24. * Contributor(s):
  25. * Dr Vipul Gupta <vipul.gupta@sun.com> and
  26. * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
  27. *
  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.
  39. *
  40. * ***** END LICENSE BLOCK ***** */
  41. /* $Id: blapit.h,v 1.20 2007/02/28 19:47:37 rrelyea%redhat.com Exp $ */
  42. #ifndef _BLAPIT_H_
  43. #define _BLAPIT_H_
  44. #include "seccomon.h"
  45. #include "prlink.h"
  46. #include "plarena.h"
  47. #include "ecl-exp.h"
  48. /* RC2 operation modes */
  49. #define NSS_RC2 0
  50. #define NSS_RC2_CBC 1
  51. /* RC5 operation modes */
  52. #define NSS_RC5 0
  53. #define NSS_RC5_CBC 1
  54. /* DES operation modes */
  55. #define NSS_DES 0
  56. #define NSS_DES_CBC 1
  57. #define NSS_DES_EDE3 2
  58. #define NSS_DES_EDE3_CBC 3
  59. #define DES_KEY_LENGTH 8 /* Bytes */
  60. /* AES operation modes */
  61. #define NSS_AES 0
  62. #define NSS_AES_CBC 1
  63. /* Camellia operation modes */
  64. #define NSS_CAMELLIA 0
  65. #define NSS_CAMELLIA_CBC 1
  66. #define DSA_SIGNATURE_LEN 40 /* Bytes */
  67. #define DSA_SUBPRIME_LEN 20 /* Bytes */
  68. /* XXX We shouldn't have to hard code this limit. For
  69. * now, this is the quickest way to support ECDSA signature
  70. * processing (ECDSA signature lengths depend on curve
  71. * size). This limit is sufficient for curves upto
  72. * 576 bits.
  73. */
  74. #define MAX_ECKEY_LEN 72 /* Bytes */
  75. /*
  76. * Number of bytes each hash algorithm produces
  77. */
  78. #define MD2_LENGTH 16 /* Bytes */
  79. #define MD5_LENGTH 16 /* Bytes */
  80. #define SHA1_LENGTH 20 /* Bytes */
  81. #define SHA256_LENGTH 32 /* bytes */
  82. #define SHA384_LENGTH 48 /* bytes */
  83. #define SHA512_LENGTH 64 /* bytes */
  84. #define HASH_LENGTH_MAX SHA512_LENGTH
  85. /*
  86. * Input block size for each hash algorithm.
  87. */
  88. #define MD2_BLOCK_LENGTH 64 /* bytes */
  89. #define MD5_BLOCK_LENGTH 64 /* bytes */
  90. #define SHA1_BLOCK_LENGTH 64 /* bytes */
  91. #define SHA256_BLOCK_LENGTH 64 /* bytes */
  92. #define SHA384_BLOCK_LENGTH 128 /* bytes */
  93. #define SHA512_BLOCK_LENGTH 128 /* bytes */
  94. #define HASH_BLOCK_LENGTH_MAX SHA512_BLOCK_LENGTH
  95. #define AES_KEY_WRAP_IV_BYTES 8
  96. #define AES_KEY_WRAP_BLOCK_SIZE 8 /* bytes */
  97. #define AES_BLOCK_SIZE 16 /* bytes */
  98. #define CAMELLIA_BLOCK_SIZE 16 /* bytes */
  99. #define NSS_FREEBL_DEFAULT_CHUNKSIZE 2048
  100. /*
  101. * These values come from the initial key size limits from the PKCS #11
  102. * module. They may be arbitrarily adjusted to any value freebl supports.
  103. */
  104. #define RSA_MIN_MODULUS_BITS 128
  105. #define RSA_MAX_MODULUS_BITS 8192
  106. #define RSA_MAX_EXPONENT_BITS 64
  107. #define DH_MIN_P_BITS 128
  108. #define DH_MAX_P_BITS 2236
  109. /*
  110. * The FIPS 186 algorithm for generating primes P and Q allows only 9
  111. * distinct values for the length of P, and only one value for the
  112. * length of Q.
  113. * The algorithm uses a variable j to indicate which of the 9 lengths
  114. * of P is to be used.
  115. * The following table relates j to the lengths of P and Q in bits.
  116. *
  117. * j bits in P bits in Q
  118. * _ _________ _________
  119. * 0 512 160
  120. * 1 576 160
  121. * 2 640 160
  122. * 3 704 160
  123. * 4 768 160
  124. * 5 832 160
  125. * 6 896 160
  126. * 7 960 160
  127. * 8 1024 160
  128. *
  129. * The FIPS-186 compliant PQG generator takes j as an input parameter.
  130. */
  131. #define DSA_Q_BITS 160
  132. #define DSA_MAX_P_BITS 1024
  133. #define DSA_MIN_P_BITS 512
  134. /*
  135. * function takes desired number of bits in P,
  136. * returns index (0..8) or -1 if number of bits is invalid.
  137. */
  138. #define PQG_PBITS_TO_INDEX(bits) \
  139. (((bits) < 512 || (bits) > 1024 || (bits) % 64) ? \
  140. -1 : (int)((bits)-512)/64)
  141. /*
  142. * function takes index (0-8)
  143. * returns number of bits in P for that index, or -1 if index is invalid.
  144. */
  145. #define PQG_INDEX_TO_PBITS(j) (((unsigned)(j) > 8) ? -1 : (512 + 64 * (j)))
  146. /***************************************************************************
  147. ** Opaque objects
  148. */
  149. struct DESContextStr ;
  150. struct RC2ContextStr ;
  151. struct RC4ContextStr ;
  152. struct RC5ContextStr ;
  153. struct AESContextStr ;
  154. struct CamelliaContextStr ;
  155. struct MD2ContextStr ;
  156. struct MD5ContextStr ;
  157. struct SHA1ContextStr ;
  158. struct SHA256ContextStr ;
  159. struct SHA512ContextStr ;
  160. struct AESKeyWrapContextStr ;
  161. typedef struct DESContextStr DESContext;
  162. typedef struct RC2ContextStr RC2Context;
  163. typedef struct RC4ContextStr RC4Context;
  164. typedef struct RC5ContextStr RC5Context;
  165. typedef struct AESContextStr AESContext;
  166. typedef struct CamelliaContextStr CamelliaContext;
  167. typedef struct MD2ContextStr MD2Context;
  168. typedef struct MD5ContextStr MD5Context;
  169. typedef struct SHA1ContextStr SHA1Context;
  170. typedef struct SHA256ContextStr SHA256Context;
  171. typedef struct SHA512ContextStr SHA512Context;
  172. /* SHA384Context is really a SHA512ContextStr. This is not a mistake. */
  173. typedef struct SHA512ContextStr SHA384Context;
  174. typedef struct AESKeyWrapContextStr AESKeyWrapContext;
  175. /***************************************************************************
  176. ** RSA Public and Private Key structures
  177. */
  178. /* member names from PKCS#1, section 7.1 */
  179. struct RSAPublicKeyStr {
  180. PRArenaPool * arena;
  181. SECItem modulus;
  182. SECItem publicExponent;
  183. };
  184. typedef struct RSAPublicKeyStr RSAPublicKey;
  185. /* member names from PKCS#1, section 7.2 */
  186. struct RSAPrivateKeyStr {
  187. PRArenaPool * arena;
  188. SECItem version;
  189. SECItem modulus;
  190. SECItem publicExponent;
  191. SECItem privateExponent;
  192. SECItem prime1;
  193. SECItem prime2;
  194. SECItem exponent1;
  195. SECItem exponent2;
  196. SECItem coefficient;
  197. };
  198. typedef struct RSAPrivateKeyStr RSAPrivateKey;
  199. /***************************************************************************
  200. ** DSA Public and Private Key and related structures
  201. */
  202. struct PQGParamsStr {
  203. PRArenaPool *arena;
  204. SECItem prime; /* p */
  205. SECItem subPrime; /* q */
  206. SECItem base; /* g */
  207. /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
  208. };
  209. typedef struct PQGParamsStr PQGParams;
  210. struct PQGVerifyStr {
  211. PRArenaPool * arena; /* includes this struct, seed, & h. */
  212. unsigned int counter;
  213. SECItem seed;
  214. SECItem h;
  215. };
  216. typedef struct PQGVerifyStr PQGVerify;
  217. struct DSAPublicKeyStr {
  218. PQGParams params;
  219. SECItem publicValue;
  220. };
  221. typedef struct DSAPublicKeyStr DSAPublicKey;
  222. struct DSAPrivateKeyStr {
  223. PQGParams params;
  224. SECItem publicValue;
  225. SECItem privateValue;
  226. };
  227. typedef struct DSAPrivateKeyStr DSAPrivateKey;
  228. /***************************************************************************
  229. ** Diffie-Hellman Public and Private Key and related structures
  230. ** Structure member names suggested by PKCS#3.
  231. */
  232. struct DHParamsStr {
  233. PRArenaPool * arena;
  234. SECItem prime; /* p */
  235. SECItem base; /* g */
  236. };
  237. typedef struct DHParamsStr DHParams;
  238. struct DHPublicKeyStr {
  239. PRArenaPool * arena;
  240. SECItem prime;
  241. SECItem base;
  242. SECItem publicValue;
  243. };
  244. typedef struct DHPublicKeyStr DHPublicKey;
  245. struct DHPrivateKeyStr {
  246. PRArenaPool * arena;
  247. SECItem prime;
  248. SECItem base;
  249. SECItem publicValue;
  250. SECItem privateValue;
  251. };
  252. typedef struct DHPrivateKeyStr DHPrivateKey;
  253. /***************************************************************************
  254. ** Data structures used for elliptic curve parameters and
  255. ** public and private keys.
  256. */
  257. /*
  258. ** The ECParams data structures can encode elliptic curve
  259. ** parameters for both GFp and GF2m curves.
  260. */
  261. typedef enum { ec_params_explicit,
  262. ec_params_named
  263. } ECParamsType;
  264. typedef enum { ec_field_GFp = 1,
  265. ec_field_GF2m
  266. } ECFieldType;
  267. struct ECFieldIDStr {
  268. int size; /* field size in bits */
  269. ECFieldType type;
  270. union {
  271. SECItem prime; /* prime p for (GFp) */
  272. SECItem poly; /* irreducible binary polynomial for (GF2m) */
  273. } u;
  274. int k1; /* first coefficient of pentanomial or
  275. * the only coefficient of trinomial
  276. */
  277. int k2; /* two remaining coefficients of pentanomial */
  278. int k3;
  279. };
  280. typedef struct ECFieldIDStr ECFieldID;
  281. struct ECCurveStr {
  282. SECItem a; /* contains octet stream encoding of
  283. * field element (X9.62 section 4.3.3)
  284. */
  285. SECItem b;
  286. SECItem seed;
  287. };
  288. typedef struct ECCurveStr ECCurve;
  289. struct ECParamsStr {
  290. PRArenaPool * arena;
  291. ECParamsType type;
  292. ECFieldID fieldID;
  293. ECCurve curve;
  294. SECItem base;
  295. SECItem order;
  296. int cofactor;
  297. SECItem DEREncoding;
  298. ECCurveName name;
  299. SECItem curveOID;
  300. };
  301. typedef struct ECParamsStr ECParams;
  302. struct ECPublicKeyStr {
  303. ECParams ecParams;
  304. SECItem publicValue; /* elliptic curve point encoded as
  305. * octet stream.
  306. */
  307. };
  308. typedef struct ECPublicKeyStr ECPublicKey;
  309. struct ECPrivateKeyStr {
  310. ECParams ecParams;
  311. SECItem publicValue; /* encoded ec point */
  312. SECItem privateValue; /* private big integer */
  313. SECItem version; /* As per SEC 1, Appendix C, Section C.4 */
  314. };
  315. typedef struct ECPrivateKeyStr ECPrivateKey;
  316. typedef void * (*BLapiAllocateFunc)(void);
  317. typedef void (*BLapiDestroyContextFunc)(void *cx, PRBool freeit);
  318. typedef SECStatus (*BLapiInitContextFunc)(void *cx,
  319. const unsigned char *key,
  320. unsigned int keylen,
  321. const unsigned char *,
  322. int,
  323. unsigned int ,
  324. unsigned int );
  325. typedef SECStatus (*BLapiEncrypt)(void *cx, unsigned char *output,
  326. unsigned int *outputLen,
  327. unsigned int maxOutputLen,
  328. const unsigned char *input,
  329. unsigned int inputLen);
  330. #endif /* _BLAPIT_H_ */