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.
 
 
 
 
 
 

518 lines
20 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. /* For compatibility with open-iscsi, which assumes that it can get
  66. * |OPENSSL_malloc| from pem.h or err.h */
  67. #include <openssl/crypto.h>
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71. #define PEM_BUFSIZE 1024
  72. #define PEM_OBJ_UNDEF 0
  73. #define PEM_OBJ_X509 1
  74. #define PEM_OBJ_X509_REQ 2
  75. #define PEM_OBJ_CRL 3
  76. #define PEM_OBJ_SSL_SESSION 4
  77. #define PEM_OBJ_PRIV_KEY 10
  78. #define PEM_OBJ_PRIV_RSA 11
  79. #define PEM_OBJ_PRIV_DSA 12
  80. #define PEM_OBJ_PRIV_DH 13
  81. #define PEM_OBJ_PUB_RSA 14
  82. #define PEM_OBJ_PUB_DSA 15
  83. #define PEM_OBJ_PUB_DH 16
  84. #define PEM_OBJ_DHPARAMS 17
  85. #define PEM_OBJ_DSAPARAMS 18
  86. #define PEM_OBJ_PRIV_RSA_PUBLIC 19
  87. #define PEM_OBJ_PRIV_ECDSA 20
  88. #define PEM_OBJ_PUB_ECDSA 21
  89. #define PEM_OBJ_ECPARAMETERS 22
  90. #define PEM_ERROR 30
  91. #define PEM_DEK_DES_CBC 40
  92. #define PEM_DEK_IDEA_CBC 45
  93. #define PEM_DEK_DES_EDE 50
  94. #define PEM_DEK_DES_ECB 60
  95. #define PEM_DEK_RSA 70
  96. #define PEM_DEK_RSA_MD2 80
  97. #define PEM_DEK_RSA_MD5 90
  98. #define PEM_MD_MD2 NID_md2
  99. #define PEM_MD_MD5 NID_md5
  100. #define PEM_MD_SHA NID_sha
  101. #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
  102. #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
  103. #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
  104. #define PEM_STRING_X509_OLD "X509 CERTIFICATE"
  105. #define PEM_STRING_X509 "CERTIFICATE"
  106. #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
  107. #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
  108. #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
  109. #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
  110. #define PEM_STRING_X509_CRL "X509 CRL"
  111. #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
  112. #define PEM_STRING_PUBLIC "PUBLIC KEY"
  113. #define PEM_STRING_RSA "RSA PRIVATE KEY"
  114. #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
  115. #define PEM_STRING_DSA "DSA PRIVATE KEY"
  116. #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
  117. #define PEM_STRING_EC "EC PRIVATE KEY"
  118. #define PEM_STRING_PKCS7 "PKCS7"
  119. #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
  120. #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
  121. #define PEM_STRING_PKCS8INF "PRIVATE KEY"
  122. #define PEM_STRING_DHPARAMS "DH PARAMETERS"
  123. #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
  124. #define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
  125. #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
  126. #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
  127. #define PEM_STRING_CMS "CMS"
  128. /* Note that this structure is initialised by PEM_SealInit and cleaned up
  129. by PEM_SealFinal (at least for now) */
  130. typedef struct PEM_Encode_Seal_st
  131. {
  132. EVP_ENCODE_CTX encode;
  133. EVP_MD_CTX md;
  134. EVP_CIPHER_CTX cipher;
  135. } PEM_ENCODE_SEAL_CTX;
  136. /* enc_type is one off */
  137. #define PEM_TYPE_ENCRYPTED 10
  138. #define PEM_TYPE_MIC_ONLY 20
  139. #define PEM_TYPE_MIC_CLEAR 30
  140. #define PEM_TYPE_CLEAR 40
  141. typedef struct pem_recip_st
  142. {
  143. char *name;
  144. X509_NAME *dn;
  145. int cipher;
  146. int key_enc;
  147. /* char iv[8]; unused and wrong size */
  148. } PEM_USER;
  149. typedef struct pem_ctx_st
  150. {
  151. int type; /* what type of object */
  152. struct {
  153. int version;
  154. int mode;
  155. } proc_type;
  156. char *domain;
  157. struct {
  158. int cipher;
  159. /* unused, and wrong size
  160. unsigned char iv[8]; */
  161. } DEK_info;
  162. PEM_USER *originator;
  163. int num_recipient;
  164. PEM_USER **recipient;
  165. EVP_MD *md; /* signature type */
  166. int md_enc; /* is the md encrypted or not? */
  167. int md_len; /* length of md_data */
  168. char *md_data; /* message digest, could be pkey encrypted */
  169. EVP_CIPHER *dec; /* date encryption cipher */
  170. int key_len; /* key length */
  171. unsigned char *key; /* key */
  172. /* unused, and wrong size
  173. unsigned char iv[8]; */
  174. int data_enc; /* is the data encrypted */
  175. int data_len;
  176. unsigned char *data;
  177. } PEM_CTX;
  178. /* These macros make the PEM_read/PEM_write functions easier to maintain and
  179. * write. Now they are all implemented with either:
  180. * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
  181. */
  182. #ifdef OPENSSL_NO_FP_API
  183. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
  184. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
  185. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
  186. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
  187. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
  188. #else
  189. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
  190. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
  191. { \
  192. return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \
  193. }
  194. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
  195. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) \
  196. { \
  197. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \
  198. }
  199. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
  200. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) \
  201. { \
  202. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \
  203. }
  204. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
  205. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  206. unsigned char *kstr, int klen, pem_password_cb *cb, \
  207. void *u) \
  208. { \
  209. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  210. }
  211. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
  212. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  213. unsigned char *kstr, int klen, pem_password_cb *cb, \
  214. void *u) \
  215. { \
  216. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \
  217. }
  218. #endif
  219. #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  220. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
  221. { \
  222. return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \
  223. }
  224. #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  225. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) \
  226. { \
  227. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \
  228. }
  229. #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  230. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) \
  231. { \
  232. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \
  233. }
  234. #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  235. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  236. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  237. { \
  238. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \
  239. }
  240. #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  241. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  242. unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
  243. { \
  244. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \
  245. }
  246. #define IMPLEMENT_PEM_write(name, type, str, asn1) \
  247. IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  248. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  249. #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
  250. IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  251. IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
  252. #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
  253. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  254. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  255. #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
  256. IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  257. IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
  258. #define IMPLEMENT_PEM_read(name, type, str, asn1) \
  259. IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  260. IMPLEMENT_PEM_read_fp(name, type, str, asn1)
  261. #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
  262. IMPLEMENT_PEM_read(name, type, str, asn1) \
  263. IMPLEMENT_PEM_write(name, type, str, asn1)
  264. #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
  265. IMPLEMENT_PEM_read(name, type, str, asn1) \
  266. IMPLEMENT_PEM_write_const(name, type, str, asn1)
  267. #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
  268. IMPLEMENT_PEM_read(name, type, str, asn1) \
  269. IMPLEMENT_PEM_write_cb(name, type, str, asn1)
  270. /* These are the same except they are for the declarations */
  271. #if defined(OPENSSL_NO_FP_API)
  272. #define DECLARE_PEM_read_fp(name, type) /**/
  273. #define DECLARE_PEM_write_fp(name, type) /**/
  274. #define DECLARE_PEM_write_cb_fp(name, type) /**/
  275. #else
  276. #define DECLARE_PEM_read_fp(name, type) \
  277. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
  278. #define DECLARE_PEM_write_fp(name, type) \
  279. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
  280. #define DECLARE_PEM_write_fp_const(name, type) \
  281. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
  282. #define DECLARE_PEM_write_cb_fp(name, type) \
  283. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
  284. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  285. #endif
  286. #define DECLARE_PEM_read_bio(name, type) \
  287. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
  288. #define DECLARE_PEM_write_bio(name, type) \
  289. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
  290. #define DECLARE_PEM_write_bio_const(name, type) \
  291. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
  292. #define DECLARE_PEM_write_cb_bio(name, type) \
  293. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
  294. unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
  295. #define DECLARE_PEM_write(name, type) \
  296. DECLARE_PEM_write_bio(name, type) \
  297. DECLARE_PEM_write_fp(name, type)
  298. #define DECLARE_PEM_write_const(name, type) \
  299. DECLARE_PEM_write_bio_const(name, type) \
  300. DECLARE_PEM_write_fp_const(name, type)
  301. #define DECLARE_PEM_write_cb(name, type) \
  302. DECLARE_PEM_write_cb_bio(name, type) \
  303. DECLARE_PEM_write_cb_fp(name, type)
  304. #define DECLARE_PEM_read(name, type) \
  305. DECLARE_PEM_read_bio(name, type) \
  306. DECLARE_PEM_read_fp(name, type)
  307. #define DECLARE_PEM_rw(name, type) \
  308. DECLARE_PEM_read(name, type) \
  309. DECLARE_PEM_write(name, type)
  310. #define DECLARE_PEM_rw_const(name, type) \
  311. DECLARE_PEM_read(name, type) \
  312. DECLARE_PEM_write_const(name, type)
  313. #define DECLARE_PEM_rw_cb(name, type) \
  314. DECLARE_PEM_read(name, type) \
  315. DECLARE_PEM_write_cb(name, type)
  316. /* "userdata": new with OpenSSL 0.9.4 */
  317. typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
  318. OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
  319. OPENSSL_EXPORT int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u);
  320. OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len);
  321. OPENSSL_EXPORT int PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
  322. 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);
  323. OPENSSL_EXPORT void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u);
  324. 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);
  325. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  326. 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);
  327. OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len);
  328. OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len);
  329. OPENSSL_EXPORT void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u);
  330. 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);
  331. OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  332. 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);
  333. OPENSSL_EXPORT void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl);
  334. OPENSSL_EXPORT int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, unsigned char *out, int *outl, EVP_PKEY *priv);
  335. OPENSSL_EXPORT void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
  336. OPENSSL_EXPORT void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
  337. OPENSSL_EXPORT int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, EVP_PKEY *pkey);
  338. /* PEM_def_callback treats |userdata| as a string and copies it into |buf|,
  339. * assuming its |size| is sufficient. Returns the length of the string, or 0
  340. * if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
  341. * returned. Note that this is different from OpenSSL, which prompts for a
  342. * password. */
  343. OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag, void *userdata);
  344. OPENSSL_EXPORT void PEM_proc_type(char *buf, int type);
  345. OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len, char *str);
  346. DECLARE_PEM_rw(X509, X509)
  347. DECLARE_PEM_rw(X509_AUX, X509)
  348. DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
  349. DECLARE_PEM_rw(X509_REQ, X509_REQ)
  350. DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
  351. DECLARE_PEM_rw(X509_CRL, X509_CRL)
  352. /* DECLARE_PEM_rw(PKCS7, PKCS7) */
  353. DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
  354. DECLARE_PEM_rw(PKCS8, X509_SIG)
  355. DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  356. DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
  357. DECLARE_PEM_rw_const(RSAPublicKey, RSA)
  358. DECLARE_PEM_rw(RSA_PUBKEY, RSA)
  359. #ifndef OPENSSL_NO_DSA
  360. DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
  361. DECLARE_PEM_rw(DSA_PUBKEY, DSA)
  362. DECLARE_PEM_rw_const(DSAparams, DSA)
  363. #endif
  364. DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
  365. DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
  366. DECLARE_PEM_rw_const(DHparams, DH)
  367. DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
  368. DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
  369. 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);
  370. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *);
  371. 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);
  372. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  373. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  374. 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);
  375. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  376. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u);
  377. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u);
  378. 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);
  379. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
  380. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
  381. OPENSSL_EXPORT EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
  382. OPENSSL_EXPORT EVP_PKEY *b2i_PublicKey_bio(BIO *in);
  383. OPENSSL_EXPORT int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk);
  384. OPENSSL_EXPORT int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk);
  385. OPENSSL_EXPORT EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
  386. OPENSSL_EXPORT int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u);
  387. void ERR_load_PEM_strings(void);
  388. #ifdef __cplusplus
  389. }
  390. #endif
  391. #define PEM_R_BAD_BASE64_DECODE 100
  392. #define PEM_R_BAD_DECRYPT 101
  393. #define PEM_R_BAD_END_LINE 102
  394. #define PEM_R_BAD_IV_CHARS 103
  395. #define PEM_R_BAD_PASSWORD_READ 104
  396. #define PEM_R_CIPHER_IS_NULL 105
  397. #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106
  398. #define PEM_R_NOT_DEK_INFO 107
  399. #define PEM_R_NOT_ENCRYPTED 108
  400. #define PEM_R_NOT_PROC_TYPE 109
  401. #define PEM_R_NO_START_LINE 110
  402. #define PEM_R_READ_KEY 111
  403. #define PEM_R_SHORT_HEADER 112
  404. #define PEM_R_UNSUPPORTED_CIPHER 113
  405. #define PEM_R_UNSUPPORTED_ENCRYPTION 114
  406. #endif /* OPENSSL_HEADER_PEM_H */