Coverage Report

Created: 2026-08-12 06:14

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