You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pem.h 23 kB

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