PageRenderTime 39ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/gecko_api/include/keythi.h

http://firefox-mac-pdf.googlecode.com/
C Header | 258 lines | 150 code | 34 blank | 74 comment | 4 complexity | 6b4564f84e36cea4c2a7083a18d55e2e MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the Netscape security libraries.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 1994-2000
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef _KEYTHI_H_
  38. #define _KEYTHI_H_ 1
  39. #include "plarena.h"
  40. #include "pkcs11t.h"
  41. #include "secmodt.h"
  42. #include "prclist.h"
  43. typedef enum {
  44. nullKey = 0,
  45. rsaKey = 1,
  46. dsaKey = 2,
  47. fortezzaKey = 3,
  48. dhKey = 4,
  49. keaKey = 5,
  50. ecKey = 6
  51. } KeyType;
  52. /*
  53. ** Template Definitions
  54. **/
  55. SEC_BEGIN_PROTOS
  56. extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[];
  57. extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[];
  58. extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[];
  59. extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[];
  60. extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[];
  61. extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[];
  62. /* Windows DLL accessor functions */
  63. extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_DSAPublicKeyTemplate;
  64. extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_RSAPublicKeyTemplate;
  65. SEC_END_PROTOS
  66. /*
  67. ** RSA Public Key structures
  68. ** member names from PKCS#1, section 7.1
  69. */
  70. struct SECKEYRSAPublicKeyStr {
  71. PRArenaPool * arena;
  72. SECItem modulus;
  73. SECItem publicExponent;
  74. };
  75. typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey;
  76. /*
  77. ** DSA Public Key and related structures
  78. */
  79. struct SECKEYPQGParamsStr {
  80. PRArenaPool *arena;
  81. SECItem prime; /* p */
  82. SECItem subPrime; /* q */
  83. SECItem base; /* g */
  84. /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
  85. };
  86. typedef struct SECKEYPQGParamsStr SECKEYPQGParams;
  87. struct SECKEYDSAPublicKeyStr {
  88. SECKEYPQGParams params;
  89. SECItem publicValue;
  90. };
  91. typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey;
  92. /*
  93. ** Diffie-Hellman Public Key structure
  94. ** Structure member names suggested by PKCS#3.
  95. */
  96. struct SECKEYDHParamsStr {
  97. PRArenaPool * arena;
  98. SECItem prime; /* p */
  99. SECItem base; /* g */
  100. };
  101. typedef struct SECKEYDHParamsStr SECKEYDHParams;
  102. struct SECKEYDHPublicKeyStr {
  103. PRArenaPool * arena;
  104. SECItem prime;
  105. SECItem base;
  106. SECItem publicValue;
  107. };
  108. typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey;
  109. /*
  110. ** Elliptic curve Public Key structure
  111. ** The PKCS#11 layer needs DER encoding of ANSI X9.62
  112. ** parameters value
  113. */
  114. typedef SECItem SECKEYECParams;
  115. struct SECKEYECPublicKeyStr {
  116. SECKEYECParams DEREncodedParams;
  117. int size; /* size in bits */
  118. SECItem publicValue; /* encoded point */
  119. /* XXX Even though the PKCS#11 interface takes encoded parameters,
  120. * we may still wish to decode them above PKCS#11 for things like
  121. * printing key information. For named curves, which is what
  122. * we initially support, we ought to have the curve name at the
  123. * very least.
  124. */
  125. };
  126. typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey;
  127. /*
  128. ** FORTEZZA Public Key structures
  129. */
  130. struct SECKEYFortezzaPublicKeyStr {
  131. int KEAversion;
  132. int DSSversion;
  133. unsigned char KMID[8];
  134. SECItem clearance;
  135. SECItem KEApriviledge;
  136. SECItem DSSpriviledge;
  137. SECItem KEAKey;
  138. SECItem DSSKey;
  139. SECKEYPQGParams params;
  140. SECKEYPQGParams keaParams;
  141. };
  142. typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey;
  143. struct SECKEYDiffPQGParamsStr {
  144. SECKEYPQGParams DiffKEAParams;
  145. SECKEYPQGParams DiffDSAParams;
  146. };
  147. typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams;
  148. struct SECKEYPQGDualParamsStr {
  149. SECKEYPQGParams CommParams;
  150. SECKEYDiffPQGParams DiffParams;
  151. };
  152. typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams;
  153. struct SECKEYKEAParamsStr {
  154. PLArenaPool *arena;
  155. SECItem hash;
  156. };
  157. typedef struct SECKEYKEAParamsStr SECKEYKEAParams;
  158. struct SECKEYKEAPublicKeyStr {
  159. SECKEYKEAParams params;
  160. SECItem publicValue;
  161. };
  162. typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey;
  163. /*
  164. ** A Generic public key object.
  165. */
  166. struct SECKEYPublicKeyStr {
  167. PLArenaPool *arena;
  168. KeyType keyType;
  169. PK11SlotInfo *pkcs11Slot;
  170. CK_OBJECT_HANDLE pkcs11ID;
  171. union {
  172. SECKEYRSAPublicKey rsa;
  173. SECKEYDSAPublicKey dsa;
  174. SECKEYDHPublicKey dh;
  175. SECKEYKEAPublicKey kea;
  176. SECKEYFortezzaPublicKey fortezza;
  177. SECKEYECPublicKey ec;
  178. } u;
  179. };
  180. typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
  181. #define CachedAttribute(attribute,setbit) \
  182. static const PRUint32 SECKEY_##attribute = 1 << setbit;
  183. /* bit flag definitions for staticflags */
  184. #define SECKEY_Attributes_Cached 0x1 /* bit 0 states
  185. whether attributes are cached */
  186. CachedAttribute(CKA_PRIVATE,1) /* bit 1 is the value of CKA_PRIVATE */
  187. #define SECKEY_ATTRIBUTES_CACHED(key) \
  188. (0 != (key->staticflags & SECKEY_Attributes_Cached))
  189. #define SECKEY_ATTRIBUTE_VALUE(key,attribute) \
  190. (0 != (key->staticflags & SECKEY_##attribute))
  191. #define SECKEY_HAS_ATTRIBUTE_SET(key,attribute) \
  192. (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \
  193. (0 != (key->staticflags & SECKEY_##attribute)) : \
  194. PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute)
  195. /*
  196. ** A generic key structure
  197. */
  198. struct SECKEYPrivateKeyStr {
  199. PLArenaPool *arena;
  200. KeyType keyType;
  201. PK11SlotInfo *pkcs11Slot; /* pkcs11 slot this key lives in */
  202. CK_OBJECT_HANDLE pkcs11ID; /* ID of pkcs11 object */
  203. PRBool pkcs11IsTemp; /* temp pkcs11 object, delete it when done */
  204. void *wincx; /* context for errors and pw prompts */
  205. PRUint32 staticflags; /* bit flag of cached PKCS#11 attributes */
  206. };
  207. typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
  208. typedef struct {
  209. PRCList links;
  210. SECKEYPrivateKey *key;
  211. } SECKEYPrivateKeyListNode;
  212. typedef struct {
  213. PRCList list;
  214. PRArenaPool *arena;
  215. } SECKEYPrivateKeyList;
  216. typedef struct {
  217. PRCList links;
  218. SECKEYPublicKey *key;
  219. } SECKEYPublicKeyListNode;
  220. typedef struct {
  221. PRCList list;
  222. PRArenaPool *arena;
  223. } SECKEYPublicKeyList;
  224. #endif /* _KEYTHI_H_ */