pem.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /*
  2. * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OPENSSL_PEM_H
  10. # define OPENSSL_PEM_H
  11. # pragma once
  12. # include <openssl/macros.h>
  13. # ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define HEADER_PEM_H
  15. # endif
  16. # include <openssl/e_os2.h>
  17. # include <openssl/bio.h>
  18. # include <openssl/safestack.h>
  19. # include <openssl/evp.h>
  20. # include <openssl/x509.h>
  21. # include <openssl/pemerr.h>
  22. # ifndef OPENSSL_NO_STDIO
  23. # include <stdio.h>
  24. # endif
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. # define PEM_BUFSIZE 1024
  29. # define PEM_STRING_X509_OLD "X509 CERTIFICATE"
  30. # define PEM_STRING_X509 "CERTIFICATE"
  31. # define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
  32. # define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
  33. # define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
  34. # define PEM_STRING_X509_CRL "X509 CRL"
  35. # define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
  36. # define PEM_STRING_PUBLIC "PUBLIC KEY"
  37. # define PEM_STRING_RSA "RSA PRIVATE KEY"
  38. # define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
  39. # define PEM_STRING_DSA "DSA PRIVATE KEY"
  40. # define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
  41. # define PEM_STRING_PKCS7 "PKCS7"
  42. # define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
  43. # define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
  44. # define PEM_STRING_PKCS8INF "PRIVATE KEY"
  45. # define PEM_STRING_DHPARAMS "DH PARAMETERS"
  46. # define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS"
  47. # define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
  48. # define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
  49. # define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
  50. # define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
  51. # define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
  52. # define PEM_STRING_PARAMETERS "PARAMETERS"
  53. # define PEM_STRING_CMS "CMS"
  54. # define PEM_TYPE_ENCRYPTED 10
  55. # define PEM_TYPE_MIC_ONLY 20
  56. # define PEM_TYPE_MIC_CLEAR 30
  57. # define PEM_TYPE_CLEAR 40
  58. /*
  59. * These macros make the PEM_read/PEM_write functions easier to maintain and
  60. * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or
  61. * IMPLEMENT_PEM_rw_cb(...)
  62. */
  63. # define PEM_read_cb_fnsig(name, type, INTYPE, readname) \
  64. type *PEM_##readname##_##name(INTYPE *out, type **x, \
  65. pem_password_cb *cb, void *u)
  66. # define PEM_read_cb_ex_fnsig(name, type, INTYPE, readname) \
  67. type *PEM_##readname##_##name##_ex(INTYPE *out, type **x, \
  68. pem_password_cb *cb, void *u, \
  69. OSSL_LIB_CTX *libctx, \
  70. const char *propq)
  71. # define PEM_write_fnsig(name, type, OUTTYPE, writename) \
  72. int PEM_##writename##_##name(OUTTYPE *out, const type *x)
  73. # define PEM_write_cb_fnsig(name, type, OUTTYPE, writename) \
  74. int PEM_##writename##_##name(OUTTYPE *out, const type *x, \
  75. const EVP_CIPHER *enc, \
  76. const unsigned char *kstr, int klen, \
  77. pem_password_cb *cb, void *u)
  78. # define PEM_write_ex_fnsig(name, type, OUTTYPE, writename) \
  79. int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \
  80. OSSL_LIB_CTX *libctx, \
  81. const char *propq)
  82. # define PEM_write_cb_ex_fnsig(name, type, OUTTYPE, writename) \
  83. int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \
  84. const EVP_CIPHER *enc, \
  85. const unsigned char *kstr, int klen, \
  86. pem_password_cb *cb, void *u, \
  87. OSSL_LIB_CTX *libctx, \
  88. const char *propq)
  89. # ifdef OPENSSL_NO_STDIO
  90. # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
  91. # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
  92. # ifndef OPENSSL_NO_DEPRECATED_3_0
  93. # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
  94. # endif
  95. # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
  96. # ifndef OPENSSL_NO_DEPRECATED_3_0
  97. # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
  98. # endif
  99. # else
  100. # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
  101. type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u) \
  102. { \
  103. return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str, fp, \
  104. (void **)x, cb, u); \
  105. }
  106. # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
  107. PEM_write_fnsig(name, type, FILE, write) \
  108. { \
  109. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
  110. x, NULL, NULL, 0, NULL, NULL); \
  111. }
  112. # ifndef OPENSSL_NO_DEPRECATED_3_0
  113. # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
  114. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  115. # endif
  116. # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
  117. PEM_write_cb_fnsig(name, type, FILE, write) \
  118. { \
  119. return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
  120. x, enc, kstr, klen, cb, u); \
  121. }
  122. # ifndef OPENSSL_NO_DEPRECATED_3_0
  123. # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
  124. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  125. # endif
  126. # endif
  127. # define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  128. type *PEM_read_bio_##name(BIO *bp, type **x, \
  129. pem_password_cb *cb, void *u) \
  130. { \
  131. return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str, bp, \
  132. (void **)x, cb, u); \
  133. }
  134. # define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  135. PEM_write_fnsig(name, type, BIO, write_bio) \
  136. { \
  137. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
  138. x, NULL,NULL,0,NULL,NULL); \
  139. }
  140. # ifndef OPENSSL_NO_DEPRECATED_3_0
  141. # define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  142. IMPLEMENT_PEM_write_bio(name, type, str, asn1)
  143. # endif
  144. # define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  145. PEM_write_cb_fnsig(name, type, BIO, write_bio) \
  146. { \
  147. return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
  148. x, enc, kstr, klen, cb, u); \
  149. }
  150. # ifndef OPENSSL_NO_DEPRECATED_3_0
  151. # define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  152. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)
  153. # endif
  154. # define IMPLEMENT_PEM_write(name, type, str, asn1) \
  155. IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
  156. IMPLEMENT_PEM_write_fp(name, type, str, asn1)
  157. # ifndef OPENSSL_NO_DEPRECATED_3_0
  158. # define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
  159. IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
  160. IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
  161. # endif
  162. # define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
  163. IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
  164. IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
  165. # ifndef OPENSSL_NO_DEPRECATED_3_0
  166. # define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
  167. IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
  168. IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
  169. # endif
  170. # define IMPLEMENT_PEM_read(name, type, str, asn1) \
  171. IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
  172. IMPLEMENT_PEM_read_fp(name, type, str, asn1)
  173. # define IMPLEMENT_PEM_rw(name, type, str, asn1) \
  174. IMPLEMENT_PEM_read(name, type, str, asn1) \
  175. IMPLEMENT_PEM_write(name, type, str, asn1)
  176. # ifndef OPENSSL_NO_DEPRECATED_3_0
  177. # define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
  178. IMPLEMENT_PEM_read(name, type, str, asn1) \
  179. IMPLEMENT_PEM_write_const(name, type, str, asn1)
  180. # endif
  181. # define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
  182. IMPLEMENT_PEM_read(name, type, str, asn1) \
  183. IMPLEMENT_PEM_write_cb(name, type, str, asn1)
  184. /* These are the same except they are for the declarations */
  185. /*
  186. * The mysterious 'extern' that's passed to some macros is innocuous,
  187. * and is there to quiet pre-C99 compilers that may complain about empty
  188. * arguments in macro calls.
  189. */
  190. # if defined(OPENSSL_NO_STDIO)
  191. # define DECLARE_PEM_read_fp_attr(attr, name, type) /**/
  192. # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) /**/
  193. # define DECLARE_PEM_write_fp_attr(attr, name, type) /**/
  194. # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) /**/
  195. # ifndef OPENSSL_NO_DEPRECATED_3_0
  196. # define DECLARE_PEM_write_fp_const_attr(attr, name, type) /**/
  197. # endif
  198. # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) /**/
  199. # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) /**/
  200. # else
  201. # define DECLARE_PEM_read_fp_attr(attr, name, type) \
  202. attr PEM_read_cb_fnsig(name, type, FILE, read);
  203. # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) \
  204. attr PEM_read_cb_fnsig(name, type, FILE, read); \
  205. attr PEM_read_cb_ex_fnsig(name, type, FILE, read);
  206. # define DECLARE_PEM_write_fp_attr(attr, name, type) \
  207. attr PEM_write_fnsig(name, type, FILE, write);
  208. # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) \
  209. attr PEM_write_fnsig(name, type, FILE, write); \
  210. attr PEM_write_ex_fnsig(name, type, FILE, write);
  211. # ifndef OPENSSL_NO_DEPRECATED_3_0
  212. # define DECLARE_PEM_write_fp_const_attr(attr, name, type) \
  213. attr PEM_write_fnsig(name, type, FILE, write);
  214. # endif
  215. # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) \
  216. attr PEM_write_cb_fnsig(name, type, FILE, write);
  217. # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) \
  218. attr PEM_write_cb_fnsig(name, type, FILE, write); \
  219. attr PEM_write_cb_ex_fnsig(name, type, FILE, write);
  220. # endif
  221. # define DECLARE_PEM_read_fp(name, type) \
  222. DECLARE_PEM_read_fp_attr(extern, name, type)
  223. # define DECLARE_PEM_write_fp(name, type) \
  224. DECLARE_PEM_write_fp_attr(extern, name, type)
  225. # ifndef OPENSSL_NO_DEPRECATED_3_0
  226. # define DECLARE_PEM_write_fp_const(name, type) \
  227. DECLARE_PEM_write_fp_const_attr(extern, name, type)
  228. # endif
  229. # define DECLARE_PEM_write_cb_fp(name, type) \
  230. DECLARE_PEM_write_cb_fp_attr(extern, name, type)
  231. # define DECLARE_PEM_read_bio_attr(attr, name, type) \
  232. attr PEM_read_cb_fnsig(name, type, BIO, read_bio);
  233. # define DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
  234. attr PEM_read_cb_fnsig(name, type, BIO, read_bio); \
  235. attr PEM_read_cb_ex_fnsig(name, type, BIO, read_bio);
  236. # define DECLARE_PEM_read_bio(name, type) \
  237. DECLARE_PEM_read_bio_attr(extern, name, type)
  238. # define DECLARE_PEM_read_bio_ex(name, type) \
  239. DECLARE_PEM_read_bio_ex_attr(extern, name, type)
  240. # define DECLARE_PEM_write_bio_attr(attr, name, type) \
  241. attr PEM_write_fnsig(name, type, BIO, write_bio);
  242. # define DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
  243. attr PEM_write_fnsig(name, type, BIO, write_bio); \
  244. attr PEM_write_ex_fnsig(name, type, BIO, write_bio);
  245. # define DECLARE_PEM_write_bio(name, type) \
  246. DECLARE_PEM_write_bio_attr(extern, name, type)
  247. # define DECLARE_PEM_write_bio_ex(name, type) \
  248. DECLARE_PEM_write_bio_ex_attr(extern, name, type)
  249. # ifndef OPENSSL_NO_DEPRECATED_3_0
  250. # define DECLARE_PEM_write_bio_const_attr(attr, name, type) \
  251. attr PEM_write_fnsig(name, type, BIO, write_bio);
  252. # define DECLARE_PEM_write_bio_const(name, type) \
  253. DECLARE_PEM_write_bio_const_attr(extern, name, type)
  254. # endif
  255. # define DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
  256. attr PEM_write_cb_fnsig(name, type, BIO, write_bio);
  257. # define DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
  258. attr PEM_write_cb_fnsig(name, type, BIO, write_bio); \
  259. attr PEM_write_cb_ex_fnsig(name, type, BIO, write_bio);
  260. # define DECLARE_PEM_write_cb_bio(name, type) \
  261. DECLARE_PEM_write_cb_bio_attr(extern, name, type)
  262. # define DECLARE_PEM_write_cb_ex_bio(name, type) \
  263. DECLARE_PEM_write_cb_bio_ex_attr(extern, name, type)
  264. # define DECLARE_PEM_write_attr(attr, name, type) \
  265. DECLARE_PEM_write_bio_attr(attr, name, type) \
  266. DECLARE_PEM_write_fp_attr(attr, name, type)
  267. # define DECLARE_PEM_write_ex_attr(attr, name, type) \
  268. DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
  269. DECLARE_PEM_write_fp_ex_attr(attr, name, type)
  270. # define DECLARE_PEM_write(name, type) \
  271. DECLARE_PEM_write_attr(extern, name, type)
  272. # define DECLARE_PEM_write_ex(name, type) \
  273. DECLARE_PEM_write_ex_attr(extern, name, type)
  274. # ifndef OPENSSL_NO_DEPRECATED_3_0
  275. # define DECLARE_PEM_write_const_attr(attr, name, type) \
  276. DECLARE_PEM_write_bio_const_attr(attr, name, type) \
  277. DECLARE_PEM_write_fp_const_attr(attr, name, type)
  278. # define DECLARE_PEM_write_const(name, type) \
  279. DECLARE_PEM_write_const_attr(extern, name, type)
  280. # endif
  281. # define DECLARE_PEM_write_cb_attr(attr, name, type) \
  282. DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
  283. DECLARE_PEM_write_cb_fp_attr(attr, name, type)
  284. # define DECLARE_PEM_write_cb_ex_attr(attr, name, type) \
  285. DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
  286. DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type)
  287. # define DECLARE_PEM_write_cb(name, type) \
  288. DECLARE_PEM_write_cb_attr(extern, name, type)
  289. # define DECLARE_PEM_write_cb_ex(name, type) \
  290. DECLARE_PEM_write_cb_ex_attr(extern, name, type)
  291. # define DECLARE_PEM_read_attr(attr, name, type) \
  292. DECLARE_PEM_read_bio_attr(attr, name, type) \
  293. DECLARE_PEM_read_fp_attr(attr, name, type)
  294. # define DECLARE_PEM_read_ex_attr(attr, name, type) \
  295. DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
  296. DECLARE_PEM_read_fp_ex_attr(attr, name, type)
  297. # define DECLARE_PEM_read(name, type) \
  298. DECLARE_PEM_read_attr(extern, name, type)
  299. # define DECLARE_PEM_read_ex(name, type) \
  300. DECLARE_PEM_read_ex_attr(extern, name, type)
  301. # define DECLARE_PEM_rw_attr(attr, name, type) \
  302. DECLARE_PEM_read_attr(attr, name, type) \
  303. DECLARE_PEM_write_attr(attr, name, type)
  304. # define DECLARE_PEM_rw_ex_attr(attr, name, type) \
  305. DECLARE_PEM_read_ex_attr(attr, name, type) \
  306. DECLARE_PEM_write_ex_attr(attr, name, type)
  307. # define DECLARE_PEM_rw(name, type) \
  308. DECLARE_PEM_rw_attr(extern, name, type)
  309. # define DECLARE_PEM_rw_ex(name, type) \
  310. DECLARE_PEM_rw_ex_attr(extern, name, type)
  311. # ifndef OPENSSL_NO_DEPRECATED_3_0
  312. # define DECLARE_PEM_rw_const_attr(attr, name, type) \
  313. DECLARE_PEM_read_attr(attr, name, type) \
  314. DECLARE_PEM_write_const_attr(attr, name, type)
  315. # define DECLARE_PEM_rw_const(name, type) \
  316. DECLARE_PEM_rw_const_attr(extern, name, type)
  317. # endif
  318. # define DECLARE_PEM_rw_cb_attr(attr, name, type) \
  319. DECLARE_PEM_read_attr(attr, name, type) \
  320. DECLARE_PEM_write_cb_attr(attr, name, type)
  321. # define DECLARE_PEM_rw_cb_ex_attr(attr, name, type) \
  322. DECLARE_PEM_read_ex_attr(attr, name, type) \
  323. DECLARE_PEM_write_cb_ex_attr(attr, name, type)
  324. # define DECLARE_PEM_rw_cb(name, type) \
  325. DECLARE_PEM_rw_cb_attr(extern, name, type)
  326. # define DECLARE_PEM_rw_cb_ex(name, type) \
  327. DECLARE_PEM_rw_cb_ex_attr(extern, name, type)
  328. int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
  329. int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len,
  330. pem_password_cb *callback, void *u);
  331. int PEM_read_bio(BIO *bp, char **name, char **header,
  332. unsigned char **data, long *len);
  333. # define PEM_FLAG_SECURE 0x1
  334. # define PEM_FLAG_EAY_COMPATIBLE 0x2
  335. # define PEM_FLAG_ONLY_B64 0x4
  336. int PEM_read_bio_ex(BIO *bp, char **name, char **header,
  337. unsigned char **data, long *len, unsigned int flags);
  338. int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
  339. const char *name, BIO *bp, pem_password_cb *cb,
  340. void *u);
  341. int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
  342. const unsigned char *data, long len);
  343. int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
  344. const char *name, BIO *bp, pem_password_cb *cb,
  345. void *u);
  346. void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
  347. pem_password_cb *cb, void *u);
  348. int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
  349. const void *x, const EVP_CIPHER *enc,
  350. const unsigned char *kstr, int klen,
  351. pem_password_cb *cb, void *u);
  352. STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
  353. pem_password_cb *cb, void *u);
  354. STACK_OF(X509_INFO)
  355. *PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk,
  356. pem_password_cb *cb, void *u, OSSL_LIB_CTX *libctx,
  357. const char *propq);
  358. int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc,
  359. const unsigned char *kstr, int klen,
  360. pem_password_cb *cd, void *u);
  361. #ifndef OPENSSL_NO_STDIO
  362. int PEM_read(FILE *fp, char **name, char **header,
  363. unsigned char **data, long *len);
  364. int PEM_write(FILE *fp, const char *name, const char *hdr,
  365. const unsigned char *data, long len);
  366. void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
  367. pem_password_cb *cb, void *u);
  368. int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
  369. const void *x, const EVP_CIPHER *enc,
  370. const unsigned char *kstr, int klen,
  371. pem_password_cb *callback, void *u);
  372. STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
  373. pem_password_cb *cb, void *u);
  374. STACK_OF(X509_INFO)
  375. *PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
  376. void *u, OSSL_LIB_CTX *libctx, const char *propq);
  377. #endif
  378. int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
  379. int PEM_SignUpdate(EVP_MD_CTX *ctx, const unsigned char *d, unsigned int cnt);
  380. int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
  381. unsigned int *siglen, EVP_PKEY *pkey);
  382. /* The default pem_password_cb that's used internally */
  383. int PEM_def_callback(char *buf, int num, int rwflag, void *userdata);
  384. void PEM_proc_type(char *buf, int type);
  385. void PEM_dek_info(char *buf, const char *type, int len, const char *str);
  386. # include <openssl/symhacks.h>
  387. DECLARE_PEM_rw(X509, X509)
  388. DECLARE_PEM_rw(X509_AUX, X509)
  389. DECLARE_PEM_rw(X509_REQ, X509_REQ)
  390. DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
  391. DECLARE_PEM_rw(X509_CRL, X509_CRL)
  392. DECLARE_PEM_rw(X509_PUBKEY, X509_PUBKEY)
  393. DECLARE_PEM_rw(PKCS7, PKCS7)
  394. DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
  395. DECLARE_PEM_rw(PKCS8, X509_SIG)
  396. DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  397. # ifndef OPENSSL_NO_DEPRECATED_3_0
  398. DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, RSAPrivateKey, RSA)
  399. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSAPublicKey, RSA)
  400. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSA_PUBKEY, RSA)
  401. # endif
  402. # ifndef OPENSSL_NO_DEPRECATED_3_0
  403. # ifndef OPENSSL_NO_DSA
  404. DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, DSAPrivateKey, DSA)
  405. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSA_PUBKEY, DSA)
  406. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSAparams, DSA)
  407. # endif
  408. # endif
  409. # ifndef OPENSSL_NO_DEPRECATED_3_0
  410. # ifndef OPENSSL_NO_EC
  411. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, ECPKParameters, EC_GROUP)
  412. DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, ECPrivateKey, EC_KEY)
  413. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, EC_PUBKEY, EC_KEY)
  414. # endif
  415. # endif
  416. # ifndef OPENSSL_NO_DH
  417. # ifndef OPENSSL_NO_DEPRECATED_3_0
  418. DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DHparams, DH)
  419. DECLARE_PEM_write_attr(OSSL_DEPRECATEDIN_3_0, DHxparams, DH)
  420. # endif
  421. # endif
  422. DECLARE_PEM_rw_cb_ex(PrivateKey, EVP_PKEY)
  423. DECLARE_PEM_rw_ex(PUBKEY, EVP_PKEY)
  424. int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
  425. const EVP_CIPHER *enc,
  426. const unsigned char *kstr, int klen,
  427. pem_password_cb *cb, void *u);
  428. /* Why do these take a signed char *kstr? */
  429. int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid,
  430. const char *kstr, int klen,
  431. pem_password_cb *cb, void *u);
  432. int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, const EVP_CIPHER *,
  433. const char *kstr, int klen,
  434. pem_password_cb *cb, void *u);
  435. int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
  436. const char *kstr, int klen,
  437. pem_password_cb *cb, void *u);
  438. int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
  439. const char *kstr, int klen,
  440. pem_password_cb *cb, void *u);
  441. EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
  442. void *u);
  443. # ifndef OPENSSL_NO_STDIO
  444. int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
  445. const char *kstr, int klen,
  446. pem_password_cb *cb, void *u);
  447. int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
  448. const char *kstr, int klen,
  449. pem_password_cb *cb, void *u);
  450. int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
  451. const char *kstr, int klen,
  452. pem_password_cb *cb, void *u);
  453. EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
  454. void *u);
  455. int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
  456. const char *kstr, int klen,
  457. pem_password_cb *cd, void *u);
  458. # endif
  459. EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x,
  460. OSSL_LIB_CTX *libctx, const char *propq);
  461. EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
  462. int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x);
  463. EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
  464. EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
  465. EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
  466. EVP_PKEY *b2i_PublicKey_bio(BIO *in);
  467. int i2b_PrivateKey_bio(BIO *out, const EVP_PKEY *pk);
  468. int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk);
  469. EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
  470. EVP_PKEY *b2i_PVK_bio_ex(BIO *in, pem_password_cb *cb, void *u,
  471. OSSL_LIB_CTX *libctx, const char *propq);
  472. int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel,
  473. pem_password_cb *cb, void *u);
  474. int i2b_PVK_bio_ex(BIO *out, const EVP_PKEY *pk, int enclevel,
  475. pem_password_cb *cb, void *u,
  476. OSSL_LIB_CTX *libctx, const char *propq);
  477. # ifdef __cplusplus
  478. }
  479. # endif
  480. #endif