Coverage Report

Created: 2026-05-20 07:05

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
0
#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
        return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str, fp,            \
121
0
            (void **)x, cb, u);                                             \
122
0
    }
Unexecuted instantiation: PEM_read_SSL_SESSION
Unexecuted instantiation: PEM_read_X509
Unexecuted instantiation: PEM_read_X509_AUX
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_X509_ACERT
123
124
#define IMPLEMENT_PEM_write_fp(name, type, str, asn1)              \
125
    PEM_write_fnsig(name, type, FILE, write)                       \
126
0
    {                                                              \
127
0
        return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
128
0
            x, NULL, NULL, 0, NULL, NULL);                         \
129
0
    }
130
131
#ifndef OPENSSL_NO_DEPRECATED_3_0
132
#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
133
    IMPLEMENT_PEM_write_fp(name, type, str, asn1)
134
#endif
135
136
#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)           \
137
    PEM_write_cb_fnsig(name, type, FILE, write)                    \
138
0
    {                                                              \
139
0
        return PEM_ASN1_write((i2d_of_void *)i2d_##asn1, str, out, \
140
0
            x, enc, kstr, klen, cb, u);                            \
141
0
    }
Unexecuted instantiation: PEM_write_RSAPrivateKey
Unexecuted instantiation: PEM_write_DSAPrivateKey
Unexecuted instantiation: PEM_write_ECPrivateKey
142
143
#ifndef OPENSSL_NO_DEPRECATED_3_0
144
#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
145
    IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
146
#endif
147
#endif
148
149
#define IMPLEMENT_PEM_read_bio(name, type, str, asn1)                \
150
    type *PEM_read_bio_##name(BIO *bp, type **x,                     \
151
        pem_password_cb *cb, void *u)                                \
152
0
    {                                                                \
153
0
        return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str, bp, \
154
0
            (void **)x, cb, u);                                      \
155
0
    }
Unexecuted instantiation: PEM_read_bio_SSL_SESSION
Unexecuted instantiation: PEM_read_bio_X509
Unexecuted instantiation: PEM_read_bio_X509_AUX
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_X509_ACERT
156
157
#define IMPLEMENT_PEM_write_bio(name, type, str, asn1)                 \
158
    PEM_write_fnsig(name, type, BIO, write_bio)                        \
159
0
    {                                                                  \
160
0
        return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
161
0
            x, NULL, NULL, 0, NULL, NULL);                             \
162
0
    }
163
164
#ifndef OPENSSL_NO_DEPRECATED_3_0
165
#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
166
    IMPLEMENT_PEM_write_bio(name, type, str, asn1)
167
#endif
168
169
#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)              \
170
    PEM_write_cb_fnsig(name, type, BIO, write_bio)                     \
171
0
    {                                                                  \
172
0
        return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1, str, out, \
173
0
            x, enc, kstr, klen, cb, u);                                \
174
0
    }
Unexecuted instantiation: PEM_write_bio_RSAPrivateKey
Unexecuted instantiation: PEM_write_bio_DSAPrivateKey
Unexecuted instantiation: PEM_write_bio_ECPrivateKey
175
176
#ifndef OPENSSL_NO_DEPRECATED_3_0
177
#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
178
    IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1)
179
#endif
180
181
#define IMPLEMENT_PEM_write(name, type, str, asn1) \
182
    IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
183
    IMPLEMENT_PEM_write_fp(name, type, str, asn1)
184
185
#ifndef OPENSSL_NO_DEPRECATED_3_0
186
#define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
187
    IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
188
    IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
189
#endif
190
191
#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
192
    IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
193
    IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
194
195
#ifndef OPENSSL_NO_DEPRECATED_3_0
196
#define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
197
    IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
198
    IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
199
#endif
200
201
#define IMPLEMENT_PEM_read(name, type, str, asn1) \
202
    IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
203
    IMPLEMENT_PEM_read_fp(name, type, str, asn1)
204
205
#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
206
    IMPLEMENT_PEM_read(name, type, str, asn1)   \
207
    IMPLEMENT_PEM_write(name, type, str, asn1)
208
209
#ifndef OPENSSL_NO_DEPRECATED_3_0
210
#define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
211
    IMPLEMENT_PEM_read(name, type, str, asn1)         \
212
    IMPLEMENT_PEM_write_const(name, type, str, asn1)
213
#endif
214
215
#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
216
    IMPLEMENT_PEM_read(name, type, str, asn1)      \
217
    IMPLEMENT_PEM_write_cb(name, type, str, asn1)
218
219
/* These are the same except they are for the declarations */
220
221
/*
222
 * The mysterious 'extern' that's passed to some macros is innocuous,
223
 * and is there to quiet pre-C99 compilers that may complain about empty
224
 * arguments in macro calls.
225
 */
226
#if defined(OPENSSL_NO_STDIO)
227
228
#define DECLARE_PEM_read_fp_attr(attr, name, type) /**/
229
#define DECLARE_PEM_read_fp_ex_attr(attr, name, type) /**/
230
#define DECLARE_PEM_write_fp_attr(attr, name, type) /**/
231
#define DECLARE_PEM_write_fp_ex_attr(attr, name, type) /**/
232
#ifndef OPENSSL_NO_DEPRECATED_3_0
233
#define DECLARE_PEM_write_fp_const_attr(attr, name, type) /**/
234
#endif
235
#define DECLARE_PEM_write_cb_fp_attr(attr, name, type) /**/
236
#define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) /**/
237
238
#else
239
240
#define DECLARE_PEM_read_fp_attr(attr, name, type) \
241
    attr PEM_read_cb_fnsig(name, type, FILE, read);
242
#define DECLARE_PEM_read_fp_ex_attr(attr, name, type) \
243
    attr PEM_read_cb_fnsig(name, type, FILE, read);   \
244
    attr PEM_read_cb_ex_fnsig(name, type, FILE, read);
245
246
#define DECLARE_PEM_write_fp_attr(attr, name, type) \
247
    attr PEM_write_fnsig(name, type, FILE, write);
248
#define DECLARE_PEM_write_fp_ex_attr(attr, name, type) \
249
    attr PEM_write_fnsig(name, type, FILE, write);     \
250
    attr PEM_write_ex_fnsig(name, type, FILE, write);
251
#ifndef OPENSSL_NO_DEPRECATED_3_0
252
#define DECLARE_PEM_write_fp_const_attr(attr, name, type) \
253
    attr PEM_write_fnsig(name, type, FILE, write);
254
#endif
255
#define DECLARE_PEM_write_cb_fp_attr(attr, name, type) \
256
    attr PEM_write_cb_fnsig(name, type, FILE, write);
257
#define DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type) \
258
    attr PEM_write_cb_fnsig(name, type, FILE, write);     \
259
    attr PEM_write_cb_ex_fnsig(name, type, FILE, write);
260
261
#endif
262
263
#define DECLARE_PEM_read_fp(name, type) \
264
    DECLARE_PEM_read_fp_attr(extern, name, type)
265
#define DECLARE_PEM_write_fp(name, type) \
266
    DECLARE_PEM_write_fp_attr(extern, name, type)
267
#ifndef OPENSSL_NO_DEPRECATED_3_0
268
#define DECLARE_PEM_write_fp_const(name, type) \
269
    DECLARE_PEM_write_fp_const_attr(extern, name, type)
270
#endif
271
#define DECLARE_PEM_write_cb_fp(name, type) \
272
    DECLARE_PEM_write_cb_fp_attr(extern, name, type)
273
274
#define DECLARE_PEM_read_bio_attr(attr, name, type) \
275
    attr PEM_read_cb_fnsig(name, type, BIO, read_bio);
276
#define DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
277
    attr PEM_read_cb_fnsig(name, type, BIO, read_bio); \
278
    attr PEM_read_cb_ex_fnsig(name, type, BIO, read_bio);
279
#define DECLARE_PEM_read_bio(name, type) \
280
    DECLARE_PEM_read_bio_attr(extern, name, type)
281
#define DECLARE_PEM_read_bio_ex(name, type) \
282
    DECLARE_PEM_read_bio_ex_attr(extern, name, type)
283
284
#define DECLARE_PEM_write_bio_attr(attr, name, type) \
285
    attr PEM_write_fnsig(name, type, BIO, write_bio);
286
#define DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
287
    attr PEM_write_fnsig(name, type, BIO, write_bio);   \
288
    attr PEM_write_ex_fnsig(name, type, BIO, write_bio);
289
#define DECLARE_PEM_write_bio(name, type) \
290
    DECLARE_PEM_write_bio_attr(extern, name, type)
291
#define DECLARE_PEM_write_bio_ex(name, type) \
292
    DECLARE_PEM_write_bio_ex_attr(extern, name, type)
293
294
#ifndef OPENSSL_NO_DEPRECATED_3_0
295
#define DECLARE_PEM_write_bio_const_attr(attr, name, type) \
296
    attr PEM_write_fnsig(name, type, BIO, write_bio);
297
#define DECLARE_PEM_write_bio_const(name, type) \
298
    DECLARE_PEM_write_bio_const_attr(extern, name, type)
299
#endif
300
301
#define DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
302
    attr PEM_write_cb_fnsig(name, type, BIO, write_bio);
303
#define DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
304
    attr PEM_write_cb_fnsig(name, type, BIO, write_bio);   \
305
    attr PEM_write_cb_ex_fnsig(name, type, BIO, write_bio);
306
#define DECLARE_PEM_write_cb_bio(name, type) \
307
    DECLARE_PEM_write_cb_bio_attr(extern, name, type)
308
#define DECLARE_PEM_write_cb_ex_bio(name, type) \
309
    DECLARE_PEM_write_cb_bio_ex_attr(extern, name, type)
310
311
#define DECLARE_PEM_write_attr(attr, name, type) \
312
    DECLARE_PEM_write_bio_attr(attr, name, type) \
313
    DECLARE_PEM_write_fp_attr(attr, name, type)
314
#define DECLARE_PEM_write_ex_attr(attr, name, type) \
315
    DECLARE_PEM_write_bio_ex_attr(attr, name, type) \
316
    DECLARE_PEM_write_fp_ex_attr(attr, name, type)
317
#define DECLARE_PEM_write(name, type) \
318
    DECLARE_PEM_write_attr(extern, name, type)
319
#define DECLARE_PEM_write_ex(name, type) \
320
    DECLARE_PEM_write_ex_attr(extern, name, type)
321
#ifndef OPENSSL_NO_DEPRECATED_3_0
322
#define DECLARE_PEM_write_const_attr(attr, name, type) \
323
    DECLARE_PEM_write_bio_const_attr(attr, name, type) \
324
    DECLARE_PEM_write_fp_const_attr(attr, name, type)
325
#define DECLARE_PEM_write_const(name, type) \
326
    DECLARE_PEM_write_const_attr(extern, name, type)
327
#endif
328
#define DECLARE_PEM_write_cb_attr(attr, name, type) \
329
    DECLARE_PEM_write_cb_bio_attr(attr, name, type) \
330
    DECLARE_PEM_write_cb_fp_attr(attr, name, type)
331
#define DECLARE_PEM_write_cb_ex_attr(attr, name, type) \
332
    DECLARE_PEM_write_cb_bio_ex_attr(attr, name, type) \
333
    DECLARE_PEM_write_cb_fp_ex_attr(attr, name, type)
334
#define DECLARE_PEM_write_cb(name, type) \
335
    DECLARE_PEM_write_cb_attr(extern, name, type)
336
#define DECLARE_PEM_write_cb_ex(name, type) \
337
    DECLARE_PEM_write_cb_ex_attr(extern, name, type)
338
#define DECLARE_PEM_read_attr(attr, name, type) \
339
    DECLARE_PEM_read_bio_attr(attr, name, type) \
340
    DECLARE_PEM_read_fp_attr(attr, name, type)
341
#define DECLARE_PEM_read_ex_attr(attr, name, type) \
342
    DECLARE_PEM_read_bio_ex_attr(attr, name, type) \
343
    DECLARE_PEM_read_fp_ex_attr(attr, name, type)
344
#define DECLARE_PEM_read(name, type) \
345
    DECLARE_PEM_read_attr(extern, name, type)
346
#define DECLARE_PEM_read_ex(name, type) \
347
    DECLARE_PEM_read_ex_attr(extern, name, type)
348
#define DECLARE_PEM_rw_attr(attr, name, type) \
349
    DECLARE_PEM_read_attr(attr, name, type)   \
350
    DECLARE_PEM_write_attr(attr, name, type)
351
#define DECLARE_PEM_rw_ex_attr(attr, name, type) \
352
    DECLARE_PEM_read_ex_attr(attr, name, type)   \
353
    DECLARE_PEM_write_ex_attr(attr, name, type)
354
#define DECLARE_PEM_rw(name, type) \
355
    DECLARE_PEM_rw_attr(extern, name, type)
356
#define DECLARE_PEM_rw_ex(name, type) \
357
    DECLARE_PEM_rw_ex_attr(extern, name, type)
358
#ifndef OPENSSL_NO_DEPRECATED_3_0
359
#define DECLARE_PEM_rw_const_attr(attr, name, type) \
360
    DECLARE_PEM_read_attr(attr, name, type)         \
361
    DECLARE_PEM_write_const_attr(attr, name, type)
362
#define DECLARE_PEM_rw_const(name, type) \
363
    DECLARE_PEM_rw_const_attr(extern, name, type)
364
#endif
365
#define DECLARE_PEM_rw_cb_attr(attr, name, type) \
366
    DECLARE_PEM_read_attr(attr, name, type)      \
367
    DECLARE_PEM_write_cb_attr(attr, name, type)
368
#define DECLARE_PEM_rw_cb_ex_attr(attr, name, type) \
369
    DECLARE_PEM_read_ex_attr(attr, name, type)      \
370
    DECLARE_PEM_write_cb_ex_attr(attr, name, type)
371
#define DECLARE_PEM_rw_cb(name, type) \
372
    DECLARE_PEM_rw_cb_attr(extern, name, type)
373
#define DECLARE_PEM_rw_cb_ex(name, type) \
374
    DECLARE_PEM_rw_cb_ex_attr(extern, name, type)
375
376
int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
377
int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len,
378
    pem_password_cb *callback, void *u);
379
380
int PEM_read_bio(BIO *bp, char **name, char **header,
381
    unsigned char **data, long *len);
382
0
#define PEM_FLAG_SECURE 0x1
383
0
#define PEM_FLAG_EAY_COMPATIBLE 0x2
384
0
#define PEM_FLAG_ONLY_B64 0x4
385
int PEM_read_bio_ex(BIO *bp, char **name, char **header,
386
    unsigned char **data, long *len, unsigned int flags);
387
int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
388
    const char *name, BIO *bp, pem_password_cb *cb,
389
    void *u);
390
int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
391
    const unsigned char *data, long len);
392
int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm,
393
    const char *name, BIO *bp, pem_password_cb *cb,
394
    void *u);
395
void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
396
    pem_password_cb *cb, void *u);
397
int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
398
    const void *x, const EVP_CIPHER *enc,
399
    const unsigned char *kstr, int klen,
400
    pem_password_cb *cb, void *u);
401
int PEM_ASN1_write_bio_ctx(OSSL_i2d_of_void_ctx *i2d, void *vctx,
402
    const char *name, BIO *bp, const void *x,
403
    const EVP_CIPHER *enc, const unsigned char *kstr,
404
    int klen, pem_password_cb *cb, void *u);
405
406
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
407
    pem_password_cb *cb, void *u);
408
STACK_OF(X509_INFO)
409
*PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk,
410
    pem_password_cb *cb, void *u, OSSL_LIB_CTX *libctx,
411
    const char *propq);
412
413
int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc,
414
    const unsigned char *kstr, int klen,
415
    pem_password_cb *cd, void *u);
416
417
#ifndef OPENSSL_NO_STDIO
418
int PEM_read(FILE *fp, char **name, char **header,
419
    unsigned char **data, long *len);
420
int PEM_write(FILE *fp, const char *name, const char *hdr,
421
    const unsigned char *data, long len);
422
void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
423
    pem_password_cb *cb, void *u);
424
int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
425
    const void *x, const EVP_CIPHER *enc,
426
    const unsigned char *kstr, int klen,
427
    pem_password_cb *callback, void *u);
428
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
429
    pem_password_cb *cb, void *u);
430
STACK_OF(X509_INFO)
431
*PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
432
    void *u, OSSL_LIB_CTX *libctx, const char *propq);
433
#endif
434
435
int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
436
int PEM_SignUpdate(EVP_MD_CTX *ctx, const unsigned char *d, unsigned int cnt);
437
int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
438
    unsigned int *siglen, EVP_PKEY *pkey);
439
440
/* The default pem_password_cb that's used internally */
441
int PEM_def_callback(char *buf, int num, int rwflag, void *userdata);
442
void PEM_proc_type(char *buf, int type);
443
void PEM_dek_info(char *buf, const char *type, int len, const char *str);
444
445
#include <openssl/symhacks.h>
446
447
DECLARE_PEM_rw(X509, X509)
448
DECLARE_PEM_rw(X509_AUX, X509)
449
DECLARE_PEM_rw(X509_REQ, X509_REQ)
450
DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
451
DECLARE_PEM_rw(X509_CRL, X509_CRL)
452
DECLARE_PEM_rw(X509_PUBKEY, X509_PUBKEY)
453
DECLARE_PEM_rw(PKCS7, PKCS7)
454
DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
455
DECLARE_PEM_rw(PKCS8, X509_SIG)
456
DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
457
#ifndef OPENSSL_NO_DEPRECATED_3_0
458
DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, RSAPrivateKey, RSA)
459
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSAPublicKey, RSA)
460
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, RSA_PUBKEY, RSA)
461
#endif
462
#ifndef OPENSSL_NO_DEPRECATED_3_0
463
#ifndef OPENSSL_NO_DSA
464
DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, DSAPrivateKey, DSA)
465
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSA_PUBKEY, DSA)
466
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DSAparams, DSA)
467
#endif
468
#endif
469
470
#ifndef OPENSSL_NO_DEPRECATED_3_0
471
#ifndef OPENSSL_NO_EC
472
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, ECPKParameters, EC_GROUP)
473
DECLARE_PEM_rw_cb_attr(OSSL_DEPRECATEDIN_3_0, ECPrivateKey, EC_KEY)
474
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, EC_PUBKEY, EC_KEY)
475
#endif
476
#endif
477
478
#ifndef OPENSSL_NO_DH
479
#ifndef OPENSSL_NO_DEPRECATED_3_0
480
DECLARE_PEM_rw_attr(OSSL_DEPRECATEDIN_3_0, DHparams, DH)
481
DECLARE_PEM_write_attr(OSSL_DEPRECATEDIN_3_0, DHxparams, DH)
482
#endif
483
#endif
484
DECLARE_PEM_rw_cb_ex(PrivateKey, EVP_PKEY)
485
DECLARE_PEM_rw_ex(PUBKEY, EVP_PKEY)
486
487
int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
488
    const EVP_CIPHER *enc,
489
    const unsigned char *kstr, int klen,
490
    pem_password_cb *cb, void *u);
491
492
/* Why do these take a signed char *kstr? */
493
int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid,
494
    const char *kstr, int klen,
495
    pem_password_cb *cb, void *u);
496
int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, const EVP_CIPHER *,
497
    const char *kstr, int klen,
498
    pem_password_cb *cb, void *u);
499
int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
500
    const char *kstr, int klen,
501
    pem_password_cb *cb, void *u);
502
int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
503
    const char *kstr, int klen,
504
    pem_password_cb *cb, void *u);
505
EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
506
    void *u);
507
508
#ifndef OPENSSL_NO_STDIO
509
int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
510
    const char *kstr, int klen,
511
    pem_password_cb *cb, void *u);
512
int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
513
    const char *kstr, int klen,
514
    pem_password_cb *cb, void *u);
515
int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
516
    const char *kstr, int klen,
517
    pem_password_cb *cb, void *u);
518
519
EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
520
    void *u);
521
522
int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
523
    const char *kstr, int klen,
524
    pem_password_cb *cd, void *u);
525
#endif
526
EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x,
527
    OSSL_LIB_CTX *libctx, const char *propq);
528
EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x);
529
int PEM_write_bio_Parameters(BIO *bp, const EVP_PKEY *x);
530
531
EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length);
532
EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length);
533
EVP_PKEY *b2i_PrivateKey_bio(BIO *in);
534
EVP_PKEY *b2i_PublicKey_bio(BIO *in);
535
int i2b_PrivateKey_bio(BIO *out, const EVP_PKEY *pk);
536
int i2b_PublicKey_bio(BIO *out, const EVP_PKEY *pk);
537
EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u);
538
EVP_PKEY *b2i_PVK_bio_ex(BIO *in, pem_password_cb *cb, void *u,
539
    OSSL_LIB_CTX *libctx, const char *propq);
540
int i2b_PVK_bio(BIO *out, const EVP_PKEY *pk, int enclevel,
541
    pem_password_cb *cb, void *u);
542
int i2b_PVK_bio_ex(BIO *out, const EVP_PKEY *pk, int enclevel,
543
    pem_password_cb *cb, void *u,
544
    OSSL_LIB_CTX *libctx, const char *propq);
545
546
#ifdef __cplusplus
547
}
548
#endif
549
#endif