Coverage Report

Created: 2025-12-31 06:58

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