pem.h 25 KB

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