pem.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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/pkcs7.h>
  64. #include <openssl/stack.h>
  65. #include <openssl/x509.h>
  66. // For compatibility with open-iscsi, which assumes that it can get
  67. // |OPENSSL_malloc| from pem.h or err.h
  68. #include <openssl/crypto.h>
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. #define PEM_BUFSIZE 1024
  73. #define PEM_STRING_X509_OLD "X509 CERTIFICATE"
  74. #define PEM_STRING_X509 "CERTIFICATE"
  75. #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
  76. #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
  77. #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
  78. #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
  79. #define PEM_STRING_X509_CRL "X509 CRL"
  80. #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
  81. #define PEM_STRING_PUBLIC "PUBLIC KEY"
  82. #define PEM_STRING_RSA "RSA PRIVATE KEY"
  83. #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
  84. #define PEM_STRING_DSA "DSA PRIVATE KEY"
  85. #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
  86. #define PEM_STRING_EC "EC PRIVATE KEY"
  87. #define PEM_STRING_PKCS7 "PKCS7"
  88. #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
  89. #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
  90. #define PEM_STRING_PKCS8INF "PRIVATE KEY"
  91. #define PEM_STRING_DHPARAMS "DH PARAMETERS"
  92. #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
  93. #define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
  94. #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
  95. #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
  96. #define PEM_STRING_CMS "CMS"
  97. // enc_type is one off
  98. #define PEM_TYPE_ENCRYPTED 10
  99. #define PEM_TYPE_MIC_ONLY 20
  100. #define PEM_TYPE_MIC_CLEAR 30
  101. #define PEM_TYPE_CLEAR 40
  102. // These macros make the PEM_read/PEM_write functions easier to maintain and
  103. // write. Now they are all implemented with either:
  104. // IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
  105. #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
  106. static void *pem_read_##name##_d2i(void **x, const unsigned char **inp, \
  107. long len) { \
  108. return d2i_##asn1((type **)x, inp, len); \
  109. } \
  110. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, \
  111. pem_password_cb *cb, void *u) { \
  112. return (type *)PEM_ASN1_read(pem_read_##name##_d2i, str, fp, (void **)x, \
  113. cb, u); \
  114. }
  115. #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
  116. static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \
  117. return i2d_##asn1((type *)x, outp); \
  118. } \
  119. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x) { \
  120. return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, NULL, NULL, 0, \
  121. NULL, NULL); \
  122. }
  123. #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
  124. static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \
  125. return i2d_##asn1((const type *)x, outp); \
  126. } \
  127. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x) { \
  128. return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, (void *)x, NULL, \
  129. NULL, 0, NULL, NULL); \
  130. }
  131. #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
  132. static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \
  133. return i2d_##asn1((type *)x, outp); \
  134. } \
  135. OPENSSL_EXPORT int PEM_write_##name( \
  136. FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  137. pem_password_cb *cb, void *u) { \
  138. return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, kstr, klen, \
  139. cb, u); \
  140. }
  141. #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
  142. static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \
  143. return i2d_##asn1((const type *)x, outp); \
  144. } \
  145. OPENSSL_EXPORT int PEM_write_##name( \
  146. FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  147. pem_password_cb *cb, void *u) { \
  148. return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, kstr, klen, \
  149. cb, u); \
  150. }
  151. #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  152. static void *pem_read_bio_##name##_d2i(void **x, const unsigned char **inp, \
  153. long len) { \
  154. return d2i_##asn1((type **)x, inp, len); \
  155. } \
  156. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, \
  157. pem_password_cb *cb, void *u) { \
  158. return (type *)PEM_ASN1_read_bio(pem_read_bio_##name##_d2i, str, bp, \
  159. (void **)x, cb, u); \
  160. }
  161. #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  162. static int pem_write_bio_##name##_i2d(const void *x, unsigned char **outp) { \
  163. return i2d_##asn1((type *)x, outp); \
  164. } \
  165. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x) { \
  166. return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, x, NULL, \
  167. NULL, 0, NULL, NULL); \
  168. }
  169. #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  170. static int pem_write_bio_##name##_i2d(const void *x, unsigned char **outp) { \
  171. return i2d_##asn1((const type *)x, outp); \
  172. } \
  173. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x) { \
  174. return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, (void *)x, \
  175. NULL, NULL, 0, NULL, NULL); \
  176. }
  177. #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  178. static int pem_write_bio_##name##_i2d(const void *x, unsigned char **outp) { \
  179. return i2d_##asn1((type *)x, outp); \
  180. } \
  181. OPENSSL_EXPORT int PEM_write_bio_##name( \
  182. BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  183. pem_password_cb *cb, void *u) { \
  184. return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, x, enc, \
  185. kstr, klen, cb, u); \
  186. }
  187. #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  188. static int pem_write_bio_##name##_i2d(const void *x, unsigned char **outp) { \
  189. return i2d_##asn1((const type *)x, outp); \
  190. } \
  191. OPENSSL_EXPORT int PEM_write_bio_##name( \
  192. BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  193. pem_password_cb *cb, void *u) { \
  194. return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, (void *)x, \
  195. enc, kstr, klen, cb, u); \
  196. }
  197. #define IMPLEMENT_PEM_write(name, type, str, asn1) \
  198. IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  199. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  200. #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
  201. IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  202. IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
  203. #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
  204. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  205. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  206. #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
  207. IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  208. IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
  209. #define IMPLEMENT_PEM_read(name, type, str, asn1) \
  210. IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  211. IMPLEMENT_PEM_read_fp(name, type, str, asn1)
  212. #define IMPLEMENT_PEM_rw(name, type, str, asn1) \
  213. IMPLEMENT_PEM_read(name, type, str, asn1) \
  214. IMPLEMENT_PEM_write(name, type, str, asn1)
  215. #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
  216. IMPLEMENT_PEM_read(name, type, str, asn1) \
  217. IMPLEMENT_PEM_write_const(name, type, str, asn1)
  218. #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
  219. IMPLEMENT_PEM_read(name, type, str, asn1) \
  220. IMPLEMENT_PEM_write_cb(name, type, str, asn1)
  221. // These are the same except they are for the declarations
  222. #define DECLARE_PEM_read_fp(name, type) \
  223. OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, \
  224. pem_password_cb *cb, void *u);
  225. #define DECLARE_PEM_write_fp(name, type) \
  226. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
  227. #define DECLARE_PEM_write_fp_const(name, type) \
  228. OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
  229. #define DECLARE_PEM_write_cb_fp(name, type) \
  230. OPENSSL_EXPORT int PEM_write_##name( \
  231. FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  232. pem_password_cb *cb, void *u);
  233. #define DECLARE_PEM_read_bio(name, type) \
  234. OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, \
  235. pem_password_cb *cb, void *u);
  236. #define DECLARE_PEM_write_bio(name, type) \
  237. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
  238. #define DECLARE_PEM_write_bio_const(name, type) \
  239. OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
  240. #define DECLARE_PEM_write_cb_bio(name, type) \
  241. OPENSSL_EXPORT int PEM_write_bio_##name( \
  242. BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
  243. pem_password_cb *cb, void *u);
  244. #define DECLARE_PEM_write(name, type) \
  245. DECLARE_PEM_write_bio(name, type) \
  246. DECLARE_PEM_write_fp(name, type)
  247. #define DECLARE_PEM_write_const(name, type) \
  248. DECLARE_PEM_write_bio_const(name, type) \
  249. DECLARE_PEM_write_fp_const(name, type)
  250. #define DECLARE_PEM_write_cb(name, type) \
  251. DECLARE_PEM_write_cb_bio(name, type) \
  252. DECLARE_PEM_write_cb_fp(name, type)
  253. #define DECLARE_PEM_read(name, type) \
  254. DECLARE_PEM_read_bio(name, type) \
  255. DECLARE_PEM_read_fp(name, type)
  256. #define DECLARE_PEM_rw(name, type) \
  257. DECLARE_PEM_read(name, type) \
  258. DECLARE_PEM_write(name, type)
  259. #define DECLARE_PEM_rw_const(name, type) \
  260. DECLARE_PEM_read(name, type) \
  261. DECLARE_PEM_write_const(name, type)
  262. #define DECLARE_PEM_rw_cb(name, type) \
  263. DECLARE_PEM_read(name, type) \
  264. DECLARE_PEM_write_cb(name, type)
  265. // "userdata": new with OpenSSL 0.9.4
  266. typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
  267. OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header,
  268. EVP_CIPHER_INFO *cipher);
  269. OPENSSL_EXPORT int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data,
  270. long *len, pem_password_cb *callback, void *u);
  271. // PEM_read_bio reads from |bp|, until the next PEM block. If one is found, it
  272. // returns one and sets |*name|, |*header|, and |*data| to newly-allocated
  273. // buffers containing the PEM type, the header block, and the decoded data,
  274. // respectively. |*name| and |*header| are NUL-terminated C strings, while
  275. // |*data| has |*len| bytes. The caller must release each of |*name|, |*header|,
  276. // and |*data| with |OPENSSL_free| when done. If no PEM block is found, this
  277. // function returns zero and pushes |PEM_R_NO_START_LINE| to the error queue. If
  278. // one is found, but there is an error decoding it, it returns zero and pushes
  279. // some other error to the error queue.
  280. OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header,
  281. unsigned char **data, long *len);
  282. // PEM_write_bio writes a PEM block to |bp|, containing |len| bytes from |data|
  283. // as data. |name| and |hdr| are NUL-terminated C strings containing the PEM
  284. // type and header block, respectively. This function returns zero on error and
  285. // the number of bytes written on success.
  286. OPENSSL_EXPORT int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
  287. const unsigned char *data, long len);
  288. OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen,
  289. char **pnm, const char *name, BIO *bp,
  290. pem_password_cb *cb, void *u);
  291. OPENSSL_EXPORT void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name,
  292. BIO *bp, void **x, pem_password_cb *cb,
  293. void *u);
  294. OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name,
  295. BIO *bp, void *x, const EVP_CIPHER *enc,
  296. unsigned char *kstr, int klen,
  297. pem_password_cb *cb, void *u);
  298. OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(
  299. BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
  300. OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi,
  301. EVP_CIPHER *enc, unsigned char *kstr,
  302. int klen, pem_password_cb *cd,
  303. void *u);
  304. OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header,
  305. unsigned char **data, long *len);
  306. OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr,
  307. const unsigned char *data, long len);
  308. OPENSSL_EXPORT void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp,
  309. void **x, pem_password_cb *cb, void *u);
  310. OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
  311. void *x, const EVP_CIPHER *enc,
  312. unsigned char *kstr, int klen,
  313. pem_password_cb *callback, void *u);
  314. OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp,
  315. STACK_OF(X509_INFO) *sk,
  316. pem_password_cb *cb,
  317. void *u);
  318. // PEM_def_callback treats |userdata| as a string and copies it into |buf|,
  319. // assuming its |size| is sufficient. Returns the length of the string, or 0
  320. // if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
  321. // returned. Note that this is different from OpenSSL, which prompts for a
  322. // password.
  323. OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag,
  324. void *userdata);
  325. OPENSSL_EXPORT void PEM_proc_type(char *buf, int type);
  326. OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len,
  327. char *str);
  328. DECLARE_PEM_rw(X509, X509)
  329. DECLARE_PEM_rw(X509_AUX, X509)
  330. DECLARE_PEM_rw(X509_REQ, X509_REQ)
  331. DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
  332. DECLARE_PEM_rw(X509_CRL, X509_CRL)
  333. DECLARE_PEM_rw(PKCS7, PKCS7)
  334. DECLARE_PEM_rw(PKCS8, X509_SIG)
  335. DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  336. DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
  337. DECLARE_PEM_rw_const(RSAPublicKey, RSA)
  338. DECLARE_PEM_rw(RSA_PUBKEY, RSA)
  339. #ifndef OPENSSL_NO_DSA
  340. DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
  341. DECLARE_PEM_rw(DSA_PUBKEY, DSA)
  342. DECLARE_PEM_rw_const(DSAparams, DSA)
  343. #endif
  344. DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
  345. DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
  346. DECLARE_PEM_rw_const(DHparams, DH)
  347. DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
  348. DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
  349. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x,
  350. int nid, char *kstr,
  351. int klen,
  352. pem_password_cb *cb,
  353. void *u);
  354. OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *,
  355. const EVP_CIPHER *, char *,
  356. int, pem_password_cb *,
  357. void *);
  358. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x,
  359. const EVP_CIPHER *enc, char *kstr,
  360. int klen, pem_password_cb *cb,
  361. void *u);
  362. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
  363. char *kstr, int klen,
  364. pem_password_cb *cb, void *u);
  365. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x,
  366. pem_password_cb *cb, void *u);
  367. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x,
  368. const EVP_CIPHER *enc, char *kstr,
  369. int klen, pem_password_cb *cb,
  370. void *u);
  371. OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
  372. char *kstr, int klen,
  373. pem_password_cb *cb, void *u);
  374. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
  375. char *kstr, int klen,
  376. pem_password_cb *cb, void *u);
  377. OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x,
  378. pem_password_cb *cb, void *u);
  379. OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x,
  380. const EVP_CIPHER *enc, char *kstr,
  381. int klen, pem_password_cb *cd,
  382. void *u);
  383. #ifdef __cplusplus
  384. }
  385. #endif
  386. #define PEM_R_BAD_BASE64_DECODE 100
  387. #define PEM_R_BAD_DECRYPT 101
  388. #define PEM_R_BAD_END_LINE 102
  389. #define PEM_R_BAD_IV_CHARS 103
  390. #define PEM_R_BAD_PASSWORD_READ 104
  391. #define PEM_R_CIPHER_IS_NULL 105
  392. #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 106
  393. #define PEM_R_NOT_DEK_INFO 107
  394. #define PEM_R_NOT_ENCRYPTED 108
  395. #define PEM_R_NOT_PROC_TYPE 109
  396. #define PEM_R_NO_START_LINE 110
  397. #define PEM_R_READ_KEY 111
  398. #define PEM_R_SHORT_HEADER 112
  399. #define PEM_R_UNSUPPORTED_CIPHER 113
  400. #define PEM_R_UNSUPPORTED_ENCRYPTION 114
  401. #endif // OPENSSL_HEADER_PEM_H