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