You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

514 regels
19 KiB

  1. /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #ifndef OPENSSL_HEADER_PEM_H
  57. #define OPENSSL_HEADER_PEM_H
  58. #include <openssl/base64.h>
  59. #include <openssl/bio.h>
  60. #include <openssl/cipher.h>
  61. #include <openssl/digest.h>
  62. #include <openssl/evp.h>
  63. #include <openssl/stack.h>
  64. #include <openssl/x509.h>
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. #define PEM_BUFSIZE 1024
  69. #define PEM_OBJ_UNDEF 0
  70. #define PEM_OBJ_X509 1
  71. #define PEM_OBJ_X509_REQ 2
  72. #define PEM_OBJ_CRL 3
  73. #define PEM_OBJ_SSL_SESSION 4
  74. #define PEM_OBJ_PRIV_KEY 10
  75. #define PEM_OBJ_PRIV_RSA 11
  76. #define PEM_OBJ_PRIV_DSA 12
  77. #define PEM_OBJ_PRIV_DH 13
  78. #define PEM_OBJ_PUB_RSA 14
  79. #define PEM_OBJ_PUB_DSA 15
  80. #define PEM_OBJ_PUB_DH 16
  81. #define PEM_OBJ_DHPARAMS 17
  82. #define PEM_OBJ_DSAPARAMS 18
  83. #define PEM_OBJ_PRIV_RSA_PUBLIC 19
  84. #define PEM_OBJ_PRIV_ECDSA 20
  85. #define PEM_OBJ_PUB_ECDSA 21
  86. #define PEM_OBJ_ECPARAMETERS 22
  87. #define PEM_ERROR 30
  88. #define PEM_DEK_DES_CBC 40
  89. #define PEM_DEK_IDEA_CBC 45
  90. #define PEM_DEK_DES_EDE 50
  91. #define PEM_DEK_DES_ECB 60
  92. #define PEM_DEK_RSA 70
  93. #define PEM_DEK_RSA_MD2 80
  94. #define PEM_DEK_RSA_MD5 90
  95. #define PEM_MD_MD2 NID_md2
  96. #define PEM_MD_MD5 NID_md5
  97. #define PEM_MD_SHA NID_sha
  98. #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
  99. #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
  100. #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
  101. #define PEM_STRING_X509_OLD "X509 CERTIFICATE"
  102. #define PEM_STRING_X509 "CERTIFICATE"
  103. #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
  104. #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
  105. #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
  106. #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
  107. #define PEM_STRING_X509_CRL "X509 CRL"
  108. #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
  109. #define PEM_STRING_PUBLIC "PUBLIC KEY"
  110. #define PEM_STRING_RSA "RSA PRIVATE KEY"
  111. #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
  112. #define PEM_STRING_DSA "DSA PRIVATE KEY"
  113. #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
  114. #define PEM_STRING_EC "EC PRIVATE KEY"
  115. #define PEM_STRING_PKCS7 "PKCS7"
  116. #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
  117. #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
  118. #define PEM_STRING_PKCS8INF "PRIVATE KEY"
  119. #define PEM_STRING_DHPARAMS "DH PARAMETERS"
  120. #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
  121. #define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
  122. #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
  123. #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
  124. #define PEM_STRING_CMS "CMS"
  125. /* Note that this structure is initialised by PEM_SealInit and cleaned up
  126. by PEM_SealFinal (at least for now) */
  127. typedef struct PEM_Encode_Seal_st
  128. {
  129. EVP_ENCODE_CTX encode;
  130. EVP_MD_CTX md;
  131. EVP_CIPHER_CTX cipher;
  132. } PEM_ENCODE_SEAL_CTX;
  133. /* enc_type is one off */
  134. #define PEM_TYPE_ENCRYPTED 10
  135. #define PEM_TYPE_MIC_ONLY 20
  136. #define PEM_TYPE_MIC_CLEAR 30
  137. #define PEM_TYPE_CLEAR 40
  138. typedef struct pem_recip_st
  139. {
  140. char *name;
  141. X509_NAME *dn;
  142. int cipher;
  143. int key_enc;
  144. /* char iv[8]; unused and wrong size */
  145. } PEM_USER;
  146. typedef struct pem_ctx_st
  147. {
  148. int type; /* what type of object */
  149. struct {
  150. int version;
  151. int mode;
  152. } proc_type;
  153. char *domain;
  154. struct {
  155. int cipher;
  156. /* unused, and wrong size
  157. unsigned char iv[8]; */
  158. } DEK_info;
  159. PEM_USER *originator;
  160. int num_recipient;
  161. PEM_USER **recipient;
  162. EVP_MD *md; /* signature type */
  163. int md_enc; /* is the md encrypted or not? */
  164. int md_len; /* length of md_data */
  165. char *md_data; /* message digest, could be pkey encrypted */
  166. EVP_CIPHER *dec; /* date encryption cipher */
  167. int key_len; /* key length */
  168. unsigned char *key; /* key */
  169. /* unused, and wrong size
  170. unsigned char iv[8]; */
  171. int data_enc; /* is the data encrypted */
  172. int data_len;
  173. unsigned char *data;
  174. } PEM_CTX;
  175. /* These macros make the PEM_read/PEM_write functions easier to maintain and
  176. * write. Now they are all implemented with either:
  177. * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
  178. */
  179. #ifdef OPENSSL_NO_FP_API
  180. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
  181. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
  182. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
  183. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
  184. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
  185. #else
  186. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
  187. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
  188. { \
  189. return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
  190. }
  191. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
  192. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \
  193. { \
  194. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
  195. }
  196. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
  197. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \
  198. { \
  199. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
  200. }
  201. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
  202. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  203. unsigned char *kstr, int klen, pem_password_cb *cb, \
  204. void *u) \
  205. { \
  206. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  207. }
  208. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
  209. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  210. unsigned char *kstr, int klen, pem_password_cb *cb, \
  211. void *u) \
  212. { \
  213. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  214. }
  215. #endif
  216. #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  217. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
  218. { \
  219. return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
  220. }
  221. #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  222. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \
  223. { \
  224. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
  225. }
  226. #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  227. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \
  228. { \
  229. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
  230. }
  231. #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  232. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  233. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  234. { \
  235. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
  236. }
  237. #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  238. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  239. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  240. { \
  241. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
  242. }
  243. #define IMPLEMENT_PEM_write(name, type, str, asn1) \
  244. IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  245. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  246. #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
  247. IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  248. IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
  249. #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
  250. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  251. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  252. #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
  253. IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  254. IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
  255. #define IMPLEMENT_PEM_read(name, type, str, asn1) \
  256. IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  257. IMPLEMENT_PEM_read_fp(name, type, str, asn1)
  258. #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
  259. IMPLEMENT_PEM_read(name, type, str, asn1) \
  260. IMPLEMENT_PEM_write(name, type, str, asn1)
  261. #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
  262. IMPLEMENT_PEM_read(name, type, str, asn1) \
  263. IMPLEMENT_PEM_write_const(name, type, str, asn1)
  264. #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
  265. IMPLEMENT_PEM_read(name, type, str, asn1) \
  266. IMPLEMENT_PEM_write_cb(name, type, str, asn1)
  267. /* These are the same except they are for the declarations */
  268. #if defined(OPENSSL_NO_FP_API)
  269. #define DECLARE_PEM_read_fp(name, type) /**/
  270. #define DECLARE_PEM_write_fp(name, type) /**/
  271. #define DECLARE_PEM_write_cb_fp(name, type) /**/
  272. #else
  273. #define DECLARE_PEM_read_fp(name, type) \
  274. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
  275. #define DECLARE_PEM_write_fp(name, type) \
  276. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
  277. #define DECLARE_PEM_write_fp_const(name, type) \
  278. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
  279. #define DECLARE_PEM_write_cb_fp(name, type) \
  280. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  281. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  282. #endif
  283. #define DECLARE_PEM_read_bio(name, type) \
  284. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
  285. #define DECLARE_PEM_write_bio(name, type) \
  286. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
  287. #define DECLARE_PEM_write_bio_const(name, type) \
  288. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
  289. #define DECLARE_PEM_write_cb_bio(name, type) \
  290. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  291. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  292. #define DECLARE_PEM_write(name, type) \
  293. DECLARE_PEM_write_bio(name, type) \
  294. DECLARE_PEM_write_fp(name, type)
  295. #define DECLARE_PEM_write_const(name, type) \
  296. DECLARE_PEM_write_bio_const(name, type) \
  297. DECLARE_PEM_write_fp_const(name, type)
  298. #define DECLARE_PEM_write_cb(name, type) \
  299. DECLARE_PEM_write_cb_bio(name, type) \
  300. DECLARE_PEM_write_cb_fp(name, type)
  301. #define DECLARE_PEM_read(name, type) \
  302. DECLARE_PEM_read_bio(name, type) \
  303. DECLARE_PEM_read_fp(name, type)
  304. #define DECLARE_PEM_rw(name, type) \
  305. DECLARE_PEM_read(name, type) \
  306. DECLARE_PEM_write(name, type)
  307. #define DECLARE_PEM_rw_const(name, type) \
  308. DECLARE_PEM_read(name, type) \
  309. DECLARE_PEM_write_const(name, type)
  310. #define DECLARE_PEM_rw_cb(name, type) \
  311. DECLARE_PEM_read(name, type) \
  312. DECLARE_PEM_write_cb(name, type)
  313. /* "userdata": new with OpenSSL 0.9.4 */
  314. typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
  315. OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
  316. OPENSSL_EXPORT int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u);
  317. OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len);
  318. OPENSSL_EXPORT int PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
  319. OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, pem_password_cb *cb, void *u);
  320. OPENSSL_EXPORT void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u);
  321. OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, const EVP_CIPHER *enc,unsigned char *kstr,int klen, pem_password_cb *cb, void *u);
  322. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  323. OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
  324. OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len);
  325. OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len);
  326. OPENSSL_EXPORT void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u);
  327. OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, void *x,const EVP_CIPHER *enc,unsigned char *kstr, int klen,pem_password_cb *callback, void *u);
  328. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  329. OPENSSL_EXPORT int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk);
  330. OPENSSL_EXPORT void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl);
  331. OPENSSL_EXPORT int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv);
  332. OPENSSL_EXPORT void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
  333. OPENSSL_EXPORT void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
  334. OPENSSL_EXPORT int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey);
  335. /* PEM_def_callback treats |userdata| as a string and copies it into |buf|,
  336. * assuming its |size| is sufficient. Returns the length of the string, or 0
  337. * if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
  338. * returned. Note that this is different from OpenSSL, which prompts for a
  339. * password. */
  340. OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag, void *userdata);
  341. OPENSSL_EXPORT void PEM_proc_type(char *buf, int type);
  342. OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len, char *str);
  343. DECLARE_PEM_rw(X509, X509)
  344. DECLARE_PEM_rw(X509_AUX, X509)
  345. DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
  346. DECLARE_PEM_rw(X509_REQ, X509_REQ)
  347. DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
  348. DECLARE_PEM_rw(X509_CRL, X509_CRL)
  349. /* DECLARE_PEM_rw(PKCS7, PKCS7) */
  350. DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
  351. DECLARE_PEM_rw(PKCS8, X509_SIG)
  352. DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  353. DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
  354. DECLARE_PEM_rw_const(RSAPublicKey, RSA)
  355. DECLARE_PEM_rw(RSA_PUBKEY, RSA)
  356. #ifndef OPENSSL_NO_DSA
  357. DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
  358. DECLARE_PEM_rw(DSA_PUBKEY, DSA)
  359. DECLARE_PEM_rw_const(DSAparams, DSA)
  360. #endif
  361. DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
  362. DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
  363. DECLARE_PEM_rw_const(DHparams, DH)
  364. DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
  365. DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
  366. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  367. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *);
  368. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
  369. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  370. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  371. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u);
  372. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  373. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  374. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  375. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, char *kstr,int klen, pem_password_cb *cd, void *u);
  376. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
  377. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
  378. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
  379. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in);
  380. OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
  381. OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
  382. OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
  383. OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u);
  384. void ERR_load_PEM_strings(void);
  385. #ifdef __cplusplus
  386. }
  387. #endif
  388. #define PEM_R_BAD_BASE64_DECODE 100
  389. #define PEM_R_BAD_DECRYPT 101
  390. #define PEM_R_BAD_END_LINE 102
  391. #define PEM_R_BAD_IV_CHARS 103
  392. #define PEM_R_BAD_PASSWORD_READ 104
  393. #define PEM_R_CIPHER_IS_NULL 105
  394. #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106
  395. #define PEM_R_NOT_DEK_INFO 107
  396. #define PEM_R_NOT_ENCRYPTED 108
  397. #define PEM_R_NOT_PROC_TYPE 109
  398. #define PEM_R_NO_START_LINE 110
  399. #define PEM_R_READ_KEY 111
  400. #define PEM_R_SHORT_HEADER 112
  401. #define PEM_R_UNSUPPORTED_CIPHER 113
  402. #define PEM_R_UNSUPPORTED_ENCRYPTION 114
  403. #endif /* OPENSSL_HEADER_PEM_H */