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