PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/keyhi.h

http://firefox-mac-pdf.googlecode.com/
C Header | 311 lines | 93 code | 51 blank | 167 comment | 2 complexity | ed5d3b1304ec259d4a170a4e8105419a 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 Stephen Henson <stephen.henson@gemplus.com>
  23. * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
  24. *
  25. * Alternatively, the contents of this file may be used under the terms of
  26. * either the GNU General Public License Version 2 or later (the "GPL"), or
  27. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. * in which case the provisions of the GPL or the LGPL are applicable instead
  29. * of those above. If you wish to allow use of your version of this file only
  30. * under the terms of either the GPL or the LGPL, and not to allow others to
  31. * use your version of this file under the terms of the MPL, indicate your
  32. * decision by deleting the provisions above and replace them with the notice
  33. * and other provisions required by the GPL or the LGPL. If you do not delete
  34. * the provisions above, a recipient may use your version of this file under
  35. * the terms of any one of the MPL, the GPL or the LGPL.
  36. *
  37. * ***** END LICENSE BLOCK ***** */
  38. /* $Id: keyhi.h,v 1.16 2006/05/31 23:54:51 wtchang%redhat.com Exp $ */
  39. #ifndef _KEYHI_H_
  40. #define _KEYHI_H_
  41. #include "plarena.h"
  42. #include "seccomon.h"
  43. #include "secoidt.h"
  44. #include "secdert.h"
  45. #include "keythi.h"
  46. #include "certt.h"
  47. /*#include "secpkcs5.h" */
  48. SEC_BEGIN_PROTOS
  49. /*
  50. ** Destroy a subject-public-key-info object.
  51. */
  52. extern void SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki);
  53. /*
  54. ** Copy subject-public-key-info "src" to "dst". "dst" is filled in
  55. ** appropriately (memory is allocated for each of the sub objects).
  56. */
  57. extern SECStatus SECKEY_CopySubjectPublicKeyInfo(PRArenaPool *arena,
  58. CERTSubjectPublicKeyInfo *dst,
  59. CERTSubjectPublicKeyInfo *src);
  60. /*
  61. ** Update the PQG parameters for a cert's public key.
  62. ** Only done for DSA and Fortezza certs
  63. */
  64. extern SECStatus
  65. SECKEY_UpdateCertPQG(CERTCertificate * subjectCert);
  66. /* Compare the KEA parameters of two public keys.
  67. * Only used by fortezza. */
  68. extern SECStatus
  69. SECKEY_KEAParamCompare(CERTCertificate *cert1,CERTCertificate *cert2);
  70. /*
  71. ** Return the strength of the public key in bytes
  72. */
  73. extern unsigned SECKEY_PublicKeyStrength(const SECKEYPublicKey *pubk);
  74. /*
  75. ** Return the strength of the public key in bits
  76. */
  77. extern unsigned SECKEY_PublicKeyStrengthInBits(const SECKEYPublicKey *pubk);
  78. /*
  79. ** Return the length of the signature in bytes
  80. */
  81. extern unsigned SECKEY_SignatureLen(const SECKEYPublicKey *pubk);
  82. /*
  83. ** Make a copy of the private key "privKey"
  84. */
  85. extern SECKEYPrivateKey *SECKEY_CopyPrivateKey(const SECKEYPrivateKey *privKey);
  86. /*
  87. ** Make a copy of the public key "pubKey"
  88. */
  89. extern SECKEYPublicKey *SECKEY_CopyPublicKey(const SECKEYPublicKey *pubKey);
  90. /*
  91. ** Convert a private key "privateKey" into a public key
  92. */
  93. extern SECKEYPublicKey *SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privateKey);
  94. /*
  95. * create a new RSA key pair. The private Key is returned...
  96. */
  97. SECKEYPrivateKey *SECKEY_CreateRSAPrivateKey(int keySizeInBits,
  98. SECKEYPublicKey **pubk, void *cx);
  99. /*
  100. * create a new DH key pair. The private Key is returned...
  101. */
  102. SECKEYPrivateKey *SECKEY_CreateDHPrivateKey(SECKEYDHParams *param,
  103. SECKEYPublicKey **pubk, void *cx);
  104. /*
  105. * create a new EC key pair. The private Key is returned...
  106. */
  107. SECKEYPrivateKey *SECKEY_CreateECPrivateKey(SECKEYECParams *param,
  108. SECKEYPublicKey **pubk, void *cx);
  109. /*
  110. ** Create a subject-public-key-info based on a public key.
  111. */
  112. extern CERTSubjectPublicKeyInfo *
  113. SECKEY_CreateSubjectPublicKeyInfo(SECKEYPublicKey *k);
  114. /*
  115. ** Decode a DER encoded public key into an SECKEYPublicKey structure.
  116. */
  117. extern SECKEYPublicKey *SECKEY_DecodeDERPublicKey(SECItem *pubkder);
  118. /*
  119. ** Convert a base64 ascii encoded DER public key to our internal format.
  120. */
  121. extern SECKEYPublicKey *SECKEY_ConvertAndDecodePublicKey(char *pubkstr);
  122. /*
  123. ** Convert a base64 ascii encoded DER public key and challenge to spki,
  124. ** and verify the signature and challenge data are correct
  125. */
  126. extern CERTSubjectPublicKeyInfo *
  127. SECKEY_ConvertAndDecodePublicKeyAndChallenge(char *pkacstr, char *challenge,
  128. void *cx);
  129. /*
  130. ** Encode a CERTSubjectPublicKeyInfo structure. into a
  131. ** DER encoded subject public key info.
  132. */
  133. SECItem *
  134. SECKEY_EncodeDERSubjectPublicKeyInfo(SECKEYPublicKey *pubk);
  135. /*
  136. ** Decode a DER encoded subject public key info into a
  137. ** CERTSubjectPublicKeyInfo structure.
  138. */
  139. extern CERTSubjectPublicKeyInfo *
  140. SECKEY_DecodeDERSubjectPublicKeyInfo(SECItem *spkider);
  141. /*
  142. ** Convert a base64 ascii encoded DER subject public key info to our
  143. ** internal format.
  144. */
  145. extern CERTSubjectPublicKeyInfo *
  146. SECKEY_ConvertAndDecodeSubjectPublicKeyInfo(char *spkistr);
  147. /*
  148. * extract the public key from a subject Public Key info structure.
  149. * (used by JSS).
  150. */
  151. extern SECKEYPublicKey *
  152. SECKEY_ExtractPublicKey(CERTSubjectPublicKeyInfo *);
  153. /*
  154. ** Destroy a private key object.
  155. ** "key" the object
  156. */
  157. extern void SECKEY_DestroyPrivateKey(SECKEYPrivateKey *key);
  158. /*
  159. ** Destroy a public key object.
  160. ** "key" the object
  161. */
  162. extern void SECKEY_DestroyPublicKey(SECKEYPublicKey *key);
  163. /* Destroy and zero out a private key info structure. for now this
  164. * function zero's out memory allocated in an arena for the key
  165. * since PORT_FreeArena does not currently do this.
  166. *
  167. * NOTE -- If a private key info is allocated in an arena, one should
  168. * not call this function with freeit = PR_FALSE. The function should
  169. * destroy the arena.
  170. */
  171. extern void
  172. SECKEY_DestroyPrivateKeyInfo(SECKEYPrivateKeyInfo *pvk, PRBool freeit);
  173. /* Destroy and zero out an encrypted private key info.
  174. *
  175. * NOTE -- If a encrypted private key info is allocated in an arena, one should
  176. * not call this function with freeit = PR_FALSE. The function should
  177. * destroy the arena.
  178. */
  179. extern void
  180. SECKEY_DestroyEncryptedPrivateKeyInfo(SECKEYEncryptedPrivateKeyInfo *epki,
  181. PRBool freeit);
  182. /* Copy private key info structure.
  183. * poolp is the arena into which the contents of from is to be copied.
  184. * NULL is a valid entry.
  185. * to is the destination private key info
  186. * from is the source private key info
  187. * if either from or to is NULL or an error occurs, SECFailure is
  188. * returned. otherwise, SECSuccess is returned.
  189. */
  190. extern SECStatus
  191. SECKEY_CopyPrivateKeyInfo(PRArenaPool *poolp,
  192. SECKEYPrivateKeyInfo *to,
  193. SECKEYPrivateKeyInfo *from);
  194. extern SECStatus
  195. SECKEY_CacheStaticFlags(SECKEYPrivateKey* key);
  196. /* Copy encrypted private key info structure.
  197. * poolp is the arena into which the contents of from is to be copied.
  198. * NULL is a valid entry.
  199. * to is the destination encrypted private key info
  200. * from is the source encrypted private key info
  201. * if either from or to is NULL or an error occurs, SECFailure is
  202. * returned. otherwise, SECSuccess is returned.
  203. */
  204. extern SECStatus
  205. SECKEY_CopyEncryptedPrivateKeyInfo(PRArenaPool *poolp,
  206. SECKEYEncryptedPrivateKeyInfo *to,
  207. SECKEYEncryptedPrivateKeyInfo *from);
  208. /*
  209. * Accessor functions for key type of public and private keys.
  210. */
  211. KeyType SECKEY_GetPrivateKeyType(SECKEYPrivateKey *privKey);
  212. KeyType SECKEY_GetPublicKeyType(SECKEYPublicKey *pubKey);
  213. /*
  214. * Creates a PublicKey from its DER encoding.
  215. * Currently only supports RSA and DSA keys.
  216. */
  217. SECKEYPublicKey*
  218. SECKEY_ImportDERPublicKey(SECItem *derKey, CK_KEY_TYPE type);
  219. SECKEYPrivateKeyList*
  220. SECKEY_NewPrivateKeyList(void);
  221. void
  222. SECKEY_DestroyPrivateKeyList(SECKEYPrivateKeyList *keys);
  223. void
  224. SECKEY_RemovePrivateKeyListNode(SECKEYPrivateKeyListNode *node);
  225. SECStatus
  226. SECKEY_AddPrivateKeyToListTail( SECKEYPrivateKeyList *list,
  227. SECKEYPrivateKey *key);
  228. #define PRIVKEY_LIST_HEAD(l) ((SECKEYPrivateKeyListNode*)PR_LIST_HEAD(&l->list))
  229. #define PRIVKEY_LIST_NEXT(n) ((SECKEYPrivateKeyListNode *)n->links.next)
  230. #define PRIVKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
  231. SECKEYPublicKeyList*
  232. SECKEY_NewPublicKeyList(void);
  233. void
  234. SECKEY_DestroyPublicKeyList(SECKEYPublicKeyList *keys);
  235. void
  236. SECKEY_RemovePublicKeyListNode(SECKEYPublicKeyListNode *node);
  237. SECStatus
  238. SECKEY_AddPublicKeyToListTail( SECKEYPublicKeyList *list,
  239. SECKEYPublicKey *key);
  240. #define PUBKEY_LIST_HEAD(l) ((SECKEYPublicKeyListNode*)PR_LIST_HEAD(&l->list))
  241. #define PUBKEY_LIST_NEXT(n) ((SECKEYPublicKeyListNode *)n->links.next)
  242. #define PUBKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
  243. /*
  244. * Length in bits of the EC's field size. This is also the length of
  245. * the x and y coordinates of EC points, such as EC public keys and
  246. * base points.
  247. *
  248. * Return 0 on failure (unknown EC domain parameters).
  249. */
  250. extern int SECKEY_ECParamsToKeySize(const SECItem *params);
  251. /*
  252. * Length in bits of the EC base point order, usually denoted n. This
  253. * is also the length of EC private keys and ECDSA signature components
  254. * r and s.
  255. *
  256. * Return 0 on failure (unknown EC domain parameters).
  257. */
  258. extern int SECKEY_ECParamsToBasePointOrderLen(const SECItem *params);
  259. SEC_END_PROTOS
  260. #endif /* _KEYHI_H_ */