pem.h 25 KB

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