2 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
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
11 # define OPENSSL_PEM_H
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
19 # include <openssl/e_os2.h>
20 # include <openssl/bio.h>
21 # include <openssl/safestack.h>
22 # include <openssl/evp.h>
23 # include <openssl/x509.h>
24 # include <openssl/pemerr.h>
30 # define PEM_BUFSIZE 1024
32 # define PEM_STRING_X509_OLD "X509 CERTIFICATE"
33 # define PEM_STRING_X509 "CERTIFICATE"
34 # define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
35 # define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
36 # define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
37 # define PEM_STRING_X509_CRL "X509 CRL"
38 # define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
39 # define PEM_STRING_PUBLIC "PUBLIC KEY"
40 # define PEM_STRING_RSA "RSA PRIVATE KEY"
41 # define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
42 # define PEM_STRING_DSA "DSA PRIVATE KEY"
43 # define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY"
44 # define PEM_STRING_PKCS7 "PKCS7"
45 # define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA"
46 # define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
47 # define PEM_STRING_PKCS8INF "PRIVATE KEY"
48 # define PEM_STRING_DHPARAMS "DH PARAMETERS"
49 # define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS"
50 # define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
51 # define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
52 # define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
53 # define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
54 # define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
55 # define PEM_STRING_PARAMETERS "PARAMETERS"
56 # define PEM_STRING_CMS "CMS"
58 # define PEM_TYPE_ENCRYPTED 10
59 # define PEM_TYPE_MIC_ONLY 20
60 # define PEM_TYPE_MIC_CLEAR 30
61 # define PEM_TYPE_CLEAR 40
64 * These macros make the PEM_read/PEM_write functions easier to maintain and
65 * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or
66 * IMPLEMENT_PEM_rw_cb(...)
69 # define PEM_read_cb_fnsig(name, type, INTYPE, readname) \
70 type *PEM_##readname##_##name(INTYPE *out, type **x, \
71 pem_password_cb *cb, void *u)
72 # define PEM_read_cb_ex_fnsig(name, type, INTYPE, readname) \
73 type *PEM_##readname##_##name##_ex(INTYPE *out, type **x, \
74 pem_password_cb *cb, void *u, \
75 OSSL_LIB_CTX *libctx, \
78 # define PEM_write_fnsig(name, type, OUTTYPE, writename) \
79 int PEM_##writename##_##name(OUTTYPE *out, const type *x)
80 # define PEM_write_cb_fnsig(name, type, OUTTYPE, writename) \
81 int PEM_##writename##_##name(OUTTYPE *out, const type *x, \
82 const EVP_CIPHER *enc, \
83 const unsigned char *kstr, int klen, \
84 pem_password_cb *cb, void *u)
85 # define PEM_write_ex_fnsig(name, type, OUTTYPE, writename) \
86 int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \
87 OSSL_LIB_CTX *libctx, \
89 # define PEM_write_cb_ex_fnsig(name, type, OUTTYPE, writename) \
90 int PEM_##writename##_##name##_ex(OUTTYPE *out, const type *x, \
91 const EVP_CIPHER *enc, \
92 const unsigned char *kstr, int klen, \
93 pem_password_cb *cb, void *u, \
94 OSSL_LIB_CTX *libctx, \
97 # ifdef OPENSSL_NO_STDIO
99 # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
100 # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
101 # ifndef OPENSSL_NO_DEPRECATED_3_0
102 # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/
104 # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
105 # ifndef OPENSSL_NO_DEPRECATED_3_0
106 # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/
110 # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
111 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u) \
113 return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str, fp, \
114 (void **)x, cb, u); \
117 # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
118 PEM_write_fnsig(name, type, FILE, write) \
120 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
121 x, NULL, NULL, 0, NULL, NULL); \
124 # ifndef OPENSSL_NO_DEPRECATED_3_0
125 # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
126 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
129 # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
130 PEM_write_cb_fnsig(name, type, FILE, write) \
132 return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
133 x, enc, kstr, klen, cb, u); \
136 # ifndef OPENSSL_NO_DEPRECATED_3_0
137 # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
138 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
142 # define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
143 type *PEM_read_bio_##name(BIO *bp, type **x, \
144 pem_password_cb *cb, void *u) \
146 return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str, bp, \
147 (void **)x, cb, u); \
150 # define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
151 PEM_write_fnsig(name, type, BIO, write_bio) \
153 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
154 x, NULL,NULL,0,NULL,NULL); \
157 # ifndef OPENSSL_NO_DEPRECATED_3_0
158 # define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
159 IMPLEMENT_PEM_write_bio(name, type, str, asn1)
162 # define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
163 PEM_write_cb_fnsig(name, type, BIO, write_bio) \
165 return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
166 x, enc, kstr, klen, cb, u); \
169 # ifndef OPENSSL_NO_DEPRECATED_3_0
170 # define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
171 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)
174 # define IMPLEMENT_PEM_write(name, type, str, asn1) \
175 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
176 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
178 # ifndef OPENSSL_NO_DEPRECATED_3_0
179 # define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
180 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
181 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
184 # define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
185 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
186 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
188 # ifndef OPENSSL_NO_DEPRECATED_3_0
189 # define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
190 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
191 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
194 # define IMPLEMENT_PEM_read(name, type, str, asn1) \
195 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
196 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
198 # define IMPLEMENT_PEM_rw(name, type, str, asn1) \
199 IMPLEMENT_PEM_read(name, type, str, asn1) \
200 IMPLEMENT_PEM_write(name, type, str, asn1)
202 # ifndef OPENSSL_NO_DEPRECATED_3_0
203 # define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
204 IMPLEMENT_PEM_read(name, type, str, asn1) \
205 IMPLEMENT_PEM_write_const(name, type, str, asn1)
208 # define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
209 IMPLEMENT_PEM_read(name, type, str, asn1) \
210 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
212 /* These are the same except they are for the declarations */
215 * The mysterious 'extern' that's passed to some macros is innocuous,
216 * and is there to quiet pre-C99 compilers that may complain about empty
217 * arguments in macro calls.
219 # if defined(OPENSSL_NO_STDIO)
221 # define DECLARE_PEM_read_fp_attr(attr, name, type) /**/
222 # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) /**/
223 # define DECLARE_PEM_write_fp_attr(attr, name, type) /**/
224 # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) /**/
225 # ifndef OPENSSL_NO_DEPRECATED_3_0
226 # define DECLARE_PEM_write_fp_const_attr(attr, name, type) /**/
228 # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) /**/
229 # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) /**/
233 # define DECLARE_PEM_read_fp_attr(attr, name, type) \
234 attr PEM_read_cb_fnsig(name, type, FILE, read);
235 # define DECLARE_PEM_read_fp_ex_attr(attr, name, type) \
236 attr PEM_read_cb_fnsig(name, type, FILE, read); \
237 attr PEM_read_cb_ex_fnsig(name, type, FILE, read);
239 # define DECLARE_PEM_write_fp_attr(attr, name, type) \
240 attr PEM_write_fnsig(name, type, FILE, write);
241 # define DECLARE_PEM_write_fp_ex_attr(attr, name, type) \
242 attr PEM_write_fnsig(name, type, FILE, write); \
243 attr PEM_write_ex_fnsig(name, type, FILE, write);
244 # ifndef OPENSSL_NO_DEPRECATED_3_0
245 # define DECLARE_PEM_write_fp_const_attr(attr, name, type) \
246 attr PEM_write_fnsig(name, type, FILE, write);
248 # define DECLARE_PEM_write_cb_fp_attr(attr, name, type) \
249 attr PEM_write_cb_fnsig(name, type, FILE, write);
250 # define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) \
251 attr PEM_write_cb_fnsig(name, type, FILE, write); \
252 attr PEM_write_cb_ex_fnsig(name, type, FILE, write);
256 # define DECLARE_PEM_read_fp(name, type) \
257 DECLARE_PEM_read_fp_attr(extern, name, type)
258 # define DECLARE_PEM_write_fp(name, type) \
259 DECLARE_PEM_write_fp_attr(extern, name, type)
260 # ifndef OPENSSL_NO_DEPRECATED_3_0
261 # define DECLARE_PEM_write_fp_const(name, type) \
262 DECLARE_PEM_write_fp_const_attr(extern, name, type)
264 # define DECLARE_PEM_write_cb_fp(name, type) \
265 DECLARE_PEM_write_cb_fp_attr(extern, name, type)
267 # define DECLARE_PEM_read_bio_attr(attr, name, type) \
268 attr PEM_read_cb_fnsig(name, type, BIO, read_bio);
269 # define DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
270 attr PEM_read_cb_fnsig(name, type, BIO, read_bio); \
271 attr PEM_read_cb_ex_fnsig(name, type, BIO, read_bio);
272 # define DECLARE_PEM_read_bio(name, type) \
273 DECLARE_PEM_read_bio_attr(extern, name, type)
274 # define DECLARE_PEM_read_bio_ex(name, type) \
275 DECLARE_PEM_read_bio_ex_attr(extern, name, type)
277 # define DECLARE_PEM_write_bio_attr(attr, name, type) \
278 attr PEM_write_fnsig(name, type, BIO, write_bio);
279 # define DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
280 attr PEM_write_fnsig(name, type, BIO, write_bio); \
281 attr PEM_write_ex_fnsig(name, type, BIO, write_bio);
282 # define DECLARE_PEM_write_bio(name, type) \
283 DECLARE_PEM_write_bio_attr(extern, name, type)
284 # define DECLARE_PEM_write_bio_ex(name, type) \
285 DECLARE_PEM_write_bio_ex_attr(extern, name, type)
287 # ifndef OPENSSL_NO_DEPRECATED_3_0
288 # define DECLARE_PEM_write_bio_const_attr(attr, name, type) \
289 attr PEM_write_fnsig(name, type, BIO, write_bio);
290 # define DECLARE_PEM_write_bio_const(name, type) \
291 DECLARE_PEM_write_bio_const_attr(extern, name, type)
294 # define DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
295 attr PEM_write_cb_fnsig(name, type, BIO, write_bio);
296 # define DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
297 attr PEM_write_cb_fnsig(name, type, BIO, write_bio); \
298 attr PEM_write_cb_ex_fnsig(name, type, BIO, write_bio);
299 # define DECLARE_PEM_write_cb_bio(name, type) \
300 DECLARE_PEM_write_cb_bio_attr(extern, name, type)
301 # define DECLARE_PEM_write_cb_ex_bio(name, type) \
302 DECLARE_PEM_write_cb_bio_ex_attr(extern, name, type)
304 # define DECLARE_PEM_write_attr(attr, name, type) \
305 DECLARE_PEM_write_bio_attr(attr, name, type) \
306 DECLARE_PEM_write_fp_attr(attr, name, type)
307 # define DECLARE_PEM_write_ex_attr(attr, name, type) \
308 DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
309 DECLARE_PEM_write_fp_ex_attr(attr, name, type)
310 # define DECLARE_PEM_write(name, type) \
311 DECLARE_PEM_write_attr(extern, name, type)
312 # define DECLARE_PEM_write_ex(name, type) \
313 DECLARE_PEM_write_ex_attr(extern, name, type)
314 # ifndef OPENSSL_NO_DEPRECATED_3_0
315 # define DECLARE_PEM_write_const_attr(attr, name, type) \
316 DECLARE_PEM_write_bio_const_attr(attr, name, type) \
317 DECLARE_PEM_write_fp_const_attr(attr, name, type)
318 # define DECLARE_PEM_write_const(name, type) \
319 DECLARE_PEM_write_const_attr(extern, name, type)
321 # define DECLARE_PEM_write_cb_attr(attr, name, type) \
322 DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
323 DECLARE_PEM_write_cb_fp_attr(attr, name, type)
324 # define DECLARE_PEM_write_cb_ex_attr(attr, name, type) \
325 DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
326 DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type)
327 # define DECLARE_PEM_write_cb(name, type) \
328 DECLARE_PEM_write_cb_attr(extern, name, type)
329 # define DECLARE_PEM_write_cb_ex(name, type) \
330 DECLARE_PEM_write_cb_ex_attr(extern, name, type)
331 # define DECLARE_PEM_read_attr(attr, name, type) \
332 DECLARE_PEM_read_bio_attr(attr, name, type) \
333 DECLARE_PEM_read_fp_attr(attr, name, type)
334 # define DECLARE_PEM_read_ex_attr(attr, name, type) \
335 DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
336 DECLARE_PEM_read_fp_ex_attr(attr, name, type)
337 # define DECLARE_PEM_read(name, type) \
338 DECLARE_PEM_read_attr(extern, name, type)
339 # define DECLARE_PEM_read_ex(name, type) \
340 DECLARE_PEM_read_ex_attr(extern, name, type)
341 # define DECLARE_PEM_rw_attr(attr, name, type) \
342 DECLARE_PEM_read_attr(attr, name, type) \
343 DECLARE_PEM_write_attr(attr, name, type)
344 # define DECLARE_PEM_rw_ex_attr(attr, name, type) \
345 DECLARE_PEM_read_ex_attr(attr, name, type) \
346 DECLARE_PEM_write_ex_attr(attr, name, type)
347 # define DECLARE_PEM_rw(name, type) \
348 DECLARE_PEM_rw_attr(extern, name, type)
349 # define DECLARE_PEM_rw_ex(name, type) \
350 DECLARE_PEM_rw_ex_attr(extern, name, type)
351 # ifndef OPENSSL_NO_DEPRECATED_3_0
352 # define DECLARE_PEM_rw_const_attr(attr, name, type) \
353 DECLARE_PEM_read_attr(attr, name, type) \
354 DECLARE_PEM_write_const_attr(attr, name, type)
355 # define DECLARE_PEM_rw_const(name, type) \
356 DECLARE_PEM_rw_const_attr(extern, name, type)
358 # define DECLARE_PEM_rw_cb_attr(attr, name, type) \
359 DECLARE_PEM_read_attr(attr, name, type) \
360 DECLARE_PEM_write_cb_attr(attr, name, type)
361 # define DECLARE_PEM_rw_cb_ex_attr(attr, name, type) \
362 DECLARE_PEM_read_ex_attr(attr, name, type) \
363 DECLARE_PEM_write_cb_ex_attr(attr, name, type)
364 # define DECLARE_PEM_rw_cb(name, type) \
365 DECLARE_PEM_rw_cb_attr(extern, name, type)
366 # define DECLARE_PEM_rw_cb_ex(name, type) \
367 DECLARE_PEM_rw_cb_ex_attr(extern, name, type)
369 int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
370 int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len,
371 pem_password_cb *callback, void *u);
373 int PEM_read_bio(BIO *bp, char **name, char **header,
374 unsigned char **data, long *len);
375 # define PEM_FLAG_SECURE 0x1
376 # define PEM_FLAG_EAY_COMPATIBLE 0x2
377 # define PEM_FLAG_ONLY_B64 0x4
378 int PEM_read_bio_ex(BIO *bp, char **name, char **header,
379 unsigned char **data, long *len, unsigned int flags);
380 int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
381 const char *name, BIO *bp, pem_password_cb *cb,
383 int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
384 const unsigned char *data, long len);
385 int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
386 const char *name, BIO *bp, pem_password_cb *cb,
388 void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
389 pem_password_cb *cb, void *u);
390 int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
391 const void *x, const EVP_CIPHER *enc,
392 const unsigned char *kstr, int klen,
393 pem_password_cb *cb, void *u);
395 STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
396 pem_password_cb *cb, void *u);
398 *PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk,
399 pem_password_cb *cb, void *u, OSSL_LIB_CTX *libctx,
402 int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc,
403 const unsigned char *kstr, int klen,
404 pem_password_cb *cd, void *u);
406 #ifndef OPENSSL_NO_STDIO
407 int PEM_read(FILE *fp, char **name, char **header,
408 unsigned char **data, long *len);
409 int PEM_write(FILE *fp, const char *name, const char *hdr,
410 const unsigned char *data, long len);
411 void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
412 pem_password_cb *cb, void *u);
413 int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
414 const void *x, const EVP_CIPHER *enc,
415 const unsigned char *kstr, int klen,
416 pem_password_cb *callback, void *u);
417 STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
418 pem_password_cb *cb, void *u);
420 *PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
421 void *u, OSSL_LIB_CTX *libctx, const char *propq);
424 int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
425 int PEM_SignUpdate(EVP_MD_CTX *ctx, const unsigned char *d, unsigned int cnt);
426 int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
427 unsigned int *siglen, EVP_PKEY *pkey);
429 /* The default pem_password_cb that's used internally */
430 int PEM_def_callback(char *buf, int num, int rwflag, void *userdata);
431 void PEM_proc_type(char *buf, int type);
432 void PEM_dek_info(char *buf, const char *type, int len, const char *str);
434 # include <openssl/symhacks.h>
436 DECLARE_PEM_rw(X509, X509)
437 DECLARE_PEM_rw(X509_AUX, X509)
438 DECLARE_PEM_rw(X509_REQ, X509_REQ)
439 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
440 DECLARE_PEM_rw(X509_CRL, X509_CRL)
441 DECLARE_PEM_rw(X509_PUBKEY, X509_PUBKEY)
442 DECLARE_PEM_rw(PKCS7, PKCS7)
443 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
444 DECLARE_PEM_rw(PKCS8, X509_SIG)
445 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
446 # ifndef OPENSSL_NO_DEPRECATED_3_0
447 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, RSAPrivateKey, RSA)
448 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSAPublicKey, RSA)
449 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSA_PUBKEY, RSA)
451 # ifndef OPENSSL_NO_DEPRECATED_3_0
452 # ifndef OPENSSL_NO_DSA
453 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, DSAPrivateKey, DSA)
454 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSA_PUBKEY, DSA)
455 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSAparams, DSA)
459 # ifndef OPENSSL_NO_DEPRECATED_3_0
460 # ifndef OPENSSL_NO_EC
461 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, ECPKParameters, EC_GROUP)
462 DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, ECPrivateKey, EC_KEY)
463 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, EC_PUBKEY, EC_KEY)
467 # ifndef OPENSSL_NO_DH
468 # ifndef OPENSSL_NO_DEPRECATED_3_0
469 DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DHparams, DH)
470 DECLARE_PEM_write_attr(OSSL_DEPRECATEDIN_3_0, DHxparams, DH)
473 DECLARE_PEM_rw_cb_ex(PrivateKey, EVP_PKEY)
474 DECLARE_PEM_rw_ex(PUBKEY, EVP_PKEY)
476 int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
477 const EVP_CIPHER *enc,
478 const unsigned char *kstr, int klen,
479 pem_password_cb *cb, void *u);
481 /* Why do these take a signed char *kstr? */
482 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid,
483 const char *kstr, int klen,
484 pem_password_cb *cb, void *u);
485 int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, const EVP_CIPHER *,
486 const char *kstr, int klen,
487 pem_password_cb *cb, void *u);
488 int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
489 const char *kstr, int klen,
490 pem_password_cb *cb, void *u);
491 int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
492 const char *kstr, int klen,
493 pem_password_cb *cb, void *u);
494 EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
497 # ifndef OPENSSL_NO_STDIO
498 int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
499 const char *kstr, int klen,
500 pem_password_cb *cb, void *u);
501 int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
502 const char *kstr, int klen,
503 pem_password_cb *cb, void *u);
504 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
505 const char *kstr, int klen,
506 pem_password_cb *cb, void *u);
508 EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
511 int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
512 const char *kstr, int klen,
513 pem_password_cb *cd, void *u);
515 EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x,
516 OSSL_LIB_CTX *libctx, const char *propq);
517 EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
518 int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x);
520 EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
521 EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
522 EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
523 EVP_PKEY *b2i_PublicKey_bio(BIO *in);
524 int i2b_PrivateKey_bio(BIO *out, const EVP_PKEY *pk);
525 int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk);
526 EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
527 EVP_PKEY *b2i_PVK_bio_ex(BIO *in, pem_password_cb *cb, void *u,
528 OSSL_LIB_CTX *libctx, const char *propq);
529 int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel,
530 pem_password_cb *cb, void *u);
531 int i2b_PVK_bio_ex(BIO *out, const EVP_PKEY *pk, int enclevel,
532 pem_password_cb *cb, void *u,
533 OSSL_LIB_CTX *libctx, const char *propq);