pem.h 22 KB

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