]>
Commit | Line | Data |
---|---|---|
169cc7a1 | 1 | /* crypto/pem/pem.h */ |
d02b48c6 RE |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | |
4 | * | |
5 | * This package is an SSL implementation written | |
6 | * by Eric Young (eay@cryptsoft.com). | |
7 | * The implementation was written so as to conform with Netscapes SSL. | |
0f113f3e | 8 | * |
d02b48c6 RE |
9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | |
13 | * included with this distribution is covered by the same copyright terms | |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | |
0f113f3e | 15 | * |
d02b48c6 RE |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | |
18 | * If this package is used in a product, Eric Young should be given attribution | |
19 | * as the author of the parts of the library used. | |
20 | * This can be in the form of a textual message at program startup or | |
21 | * in documentation (online or textual) provided with the package. | |
0f113f3e | 22 | * |
d02b48c6 RE |
23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | |
25 | * are met: | |
26 | * 1. Redistributions of source code must retain the copyright | |
27 | * notice, this list of conditions and the following disclaimer. | |
28 | * 2. Redistributions in binary form must reproduce the above copyright | |
29 | * notice, this list of conditions and the following disclaimer in the | |
30 | * documentation and/or other materials provided with the distribution. | |
31 | * 3. All advertising materials mentioning features or use of this software | |
32 | * must display the following acknowledgement: | |
33 | * "This product includes cryptographic software written by | |
34 | * Eric Young (eay@cryptsoft.com)" | |
35 | * The word 'cryptographic' can be left out if the rouines from the library | |
36 | * being used are not cryptographic related :-). | |
0f113f3e | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
d02b48c6 RE |
38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | |
0f113f3e | 40 | * |
d02b48c6 RE |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
51 | * SUCH DAMAGE. | |
0f113f3e | 52 | * |
d02b48c6 RE |
53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | |
55 | * copied and put under another distribution licence | |
56 | * [including the GNU Public Licence.] | |
57 | */ | |
58 | ||
d02b48c6 | 59 | #ifndef HEADER_PEM_H |
0f113f3e MC |
60 | # define HEADER_PEM_H |
61 | ||
62 | # include <openssl/e_os2.h> | |
a00ae6c4 RS |
63 | # include <openssl/bio.h> |
64 | # include <openssl/stack.h> | |
0f113f3e MC |
65 | # include <openssl/evp.h> |
66 | # include <openssl/x509.h> | |
67 | # include <openssl/pem2.h> | |
d02b48c6 | 68 | |
82271cee RL |
69 | #ifdef __cplusplus |
70 | extern "C" { | |
71 | #endif | |
72 | ||
0f113f3e MC |
73 | # define PEM_BUFSIZE 1024 |
74 | ||
0f113f3e MC |
75 | # define PEM_STRING_X509_OLD "X509 CERTIFICATE" |
76 | # define PEM_STRING_X509 "CERTIFICATE" | |
0f113f3e MC |
77 | # define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" |
78 | # define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" | |
79 | # define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" | |
80 | # define PEM_STRING_X509_CRL "X509 CRL" | |
81 | # define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" | |
82 | # define PEM_STRING_PUBLIC "PUBLIC KEY" | |
83 | # define PEM_STRING_RSA "RSA PRIVATE KEY" | |
84 | # define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" | |
85 | # define PEM_STRING_DSA "DSA PRIVATE KEY" | |
86 | # define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" | |
87 | # define PEM_STRING_PKCS7 "PKCS7" | |
88 | # define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" | |
89 | # define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" | |
90 | # define PEM_STRING_PKCS8INF "PRIVATE KEY" | |
91 | # define PEM_STRING_DHPARAMS "DH PARAMETERS" | |
92 | # define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" | |
93 | # define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" | |
94 | # define PEM_STRING_DSAPARAMS "DSA PARAMETERS" | |
95 | # define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" | |
96 | # define PEM_STRING_ECPARAMETERS "EC PARAMETERS" | |
97 | # define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" | |
98 | # define PEM_STRING_PARAMETERS "PARAMETERS" | |
99 | # define PEM_STRING_CMS "CMS" | |
100 | ||
101 | /* | |
102 | * Note that this structure is initialised by PEM_SealInit and cleaned up | |
103 | * by PEM_SealFinal (at least for now) | |
104 | */ | |
105 | typedef struct PEM_Encode_Seal_st { | |
106 | EVP_ENCODE_CTX encode; | |
107 | EVP_MD_CTX md; | |
108 | EVP_CIPHER_CTX cipher; | |
109 | } PEM_ENCODE_SEAL_CTX; | |
d02b48c6 | 110 | |
0f113f3e MC |
111 | # define PEM_TYPE_ENCRYPTED 10 |
112 | # define PEM_TYPE_MIC_ONLY 20 | |
113 | # define PEM_TYPE_MIC_CLEAR 30 | |
114 | # define PEM_TYPE_CLEAR 40 | |
115 | ||
116 | typedef struct pem_recip_st { | |
117 | char *name; | |
118 | X509_NAME *dn; | |
119 | int cipher; | |
120 | int key_enc; | |
121 | /* char iv[8]; unused and wrong size */ | |
122 | } PEM_USER; | |
123 | ||
124 | typedef struct pem_ctx_st { | |
125 | int type; /* what type of object */ | |
126 | struct { | |
127 | int version; | |
128 | int mode; | |
129 | } proc_type; | |
130 | ||
131 | char *domain; | |
132 | ||
133 | struct { | |
134 | int cipher; | |
135 | /*- | |
35a1cc90 MC |
136 | unused, and wrong size |
137 | unsigned char iv[8]; */ | |
0f113f3e MC |
138 | } DEK_info; |
139 | ||
140 | PEM_USER *originator; | |
141 | ||
142 | int num_recipient; | |
143 | PEM_USER **recipient; | |
144 | ||
50e735f9 MC |
145 | /*- |
146 | XXX(ben): don#t think this is used! | |
147 | STACK *x509_chain; / * certificate chain */ | |
0f113f3e MC |
148 | EVP_MD *md; /* signature type */ |
149 | ||
150 | int md_enc; /* is the md encrypted or not? */ | |
151 | int md_len; /* length of md_data */ | |
152 | char *md_data; /* message digest, could be pkey encrypted */ | |
153 | ||
154 | EVP_CIPHER *dec; /* date encryption cipher */ | |
155 | int key_len; /* key length */ | |
156 | unsigned char *key; /* key */ | |
35a1cc90 MC |
157 | /*- |
158 | unused, and wrong size | |
159 | unsigned char iv[8]; */ | |
0f113f3e MC |
160 | |
161 | int data_enc; /* is the data encrypted */ | |
162 | int data_len; | |
163 | unsigned char *data; | |
164 | } PEM_CTX; | |
165 | ||
166 | /* | |
167 | * These macros make the PEM_read/PEM_write functions easier to maintain and | |
168 | * write. Now they are all implemented with either: IMPLEMENT_PEM_rw(...) or | |
169 | * IMPLEMENT_PEM_rw_cb(...) | |
f62676b9 DSH |
170 | */ |
171 | ||
0f113f3e | 172 | # ifdef OPENSSL_NO_STDIO |
f62676b9 | 173 | |
0f113f3e MC |
174 | # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ |
175 | # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ | |
176 | # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ | |
177 | # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ | |
178 | # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ | |
179 | # else | |
f62676b9 | 180 | |
0f113f3e | 181 | # define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ |
74678cc2 | 182 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ |
f62676b9 | 183 | { \ |
297e6f19 | 184 | return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ |
0f113f3e | 185 | } |
f62676b9 | 186 | |
0f113f3e | 187 | # define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ |
f62676b9 DSH |
188 | int PEM_write_##name(FILE *fp, type *x) \ |
189 | { \ | |
297e6f19 | 190 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ |
41a15c4f BL |
191 | } |
192 | ||
0f113f3e | 193 | # define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ |
67ffa18c | 194 | int PEM_write_##name(FILE *fp, const type *x) \ |
41a15c4f | 195 | { \ |
297e6f19 | 196 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ |
a2400fca | 197 | } |
f62676b9 | 198 | |
0f113f3e | 199 | # define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ |
f62676b9 | 200 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ |
0f113f3e MC |
201 | unsigned char *kstr, int klen, pem_password_cb *cb, \ |
202 | void *u) \ | |
203 | { \ | |
204 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ | |
205 | } | |
41a15c4f | 206 | |
0f113f3e | 207 | # define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ |
41a15c4f | 208 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ |
0f113f3e MC |
209 | unsigned char *kstr, int klen, pem_password_cb *cb, \ |
210 | void *u) \ | |
211 | { \ | |
212 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ | |
213 | } | |
f62676b9 | 214 | |
0f113f3e | 215 | # endif |
f62676b9 | 216 | |
0f113f3e | 217 | # define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ |
74678cc2 | 218 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ |
f62676b9 | 219 | { \ |
297e6f19 | 220 | return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ |
f62676b9 DSH |
221 | } |
222 | ||
0f113f3e | 223 | # define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ |
f62676b9 DSH |
224 | int PEM_write_bio_##name(BIO *bp, type *x) \ |
225 | { \ | |
297e6f19 | 226 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ |
41a15c4f BL |
227 | } |
228 | ||
0f113f3e | 229 | # define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ |
67ffa18c | 230 | int PEM_write_bio_##name(BIO *bp, const type *x) \ |
41a15c4f | 231 | { \ |
297e6f19 | 232 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ |
f62676b9 DSH |
233 | } |
234 | ||
0f113f3e | 235 | # define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ |
f62676b9 | 236 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ |
0f113f3e MC |
237 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ |
238 | { \ | |
239 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ | |
240 | } | |
41a15c4f | 241 | |
0f113f3e | 242 | # define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ |
41a15c4f | 243 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ |
0f113f3e MC |
244 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ |
245 | { \ | |
246 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ | |
247 | } | |
f62676b9 | 248 | |
0f113f3e MC |
249 | # define IMPLEMENT_PEM_write(name, type, str, asn1) \ |
250 | IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ | |
251 | IMPLEMENT_PEM_write_fp(name, type, str, asn1) | |
f62676b9 | 252 | |
0f113f3e MC |
253 | # define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ |
254 | IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ | |
255 | IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) | |
41a15c4f | 256 | |
0f113f3e MC |
257 | # define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ |
258 | IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ | |
259 | IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) | |
f62676b9 | 260 | |
0f113f3e MC |
261 | # define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ |
262 | IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ | |
263 | IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) | |
41a15c4f | 264 | |
0f113f3e MC |
265 | # define IMPLEMENT_PEM_read(name, type, str, asn1) \ |
266 | IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ | |
267 | IMPLEMENT_PEM_read_fp(name, type, str, asn1) | |
f62676b9 | 268 | |
0f113f3e MC |
269 | # define IMPLEMENT_PEM_rw(name, type, str, asn1) \ |
270 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | |
271 | IMPLEMENT_PEM_write(name, type, str, asn1) | |
f62676b9 | 272 | |
0f113f3e MC |
273 | # define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ |
274 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | |
275 | IMPLEMENT_PEM_write_const(name, type, str, asn1) | |
41a15c4f | 276 | |
0f113f3e MC |
277 | # define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ |
278 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | |
279 | IMPLEMENT_PEM_write_cb(name, type, str, asn1) | |
f62676b9 | 280 | |
dbd665c2 DSH |
281 | /* These are the same except they are for the declarations */ |
282 | ||
0f113f3e MC |
283 | # if defined(OPENSSL_NO_STDIO) |
284 | ||
285 | # define DECLARE_PEM_read_fp(name, type) /**/ | |
286 | # define DECLARE_PEM_write_fp(name, type) /**/ | |
287 | # define DECLARE_PEM_write_cb_fp(name, type) /**/ | |
288 | # else | |
289 | ||
290 | # define DECLARE_PEM_read_fp(name, type) \ | |
291 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); | |
292 | ||
293 | # define DECLARE_PEM_write_fp(name, type) \ | |
294 | int PEM_write_##name(FILE *fp, type *x); | |
295 | ||
296 | # define DECLARE_PEM_write_fp_const(name, type) \ | |
297 | int PEM_write_##name(FILE *fp, const type *x); | |
298 | ||
299 | # define DECLARE_PEM_write_cb_fp(name, type) \ | |
300 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ | |
301 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | |
302 | ||
303 | # endif | |
304 | ||
0f113f3e MC |
305 | # define DECLARE_PEM_read_bio(name, type) \ |
306 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); | |
307 | ||
308 | # define DECLARE_PEM_write_bio(name, type) \ | |
309 | int PEM_write_bio_##name(BIO *bp, type *x); | |
310 | ||
311 | # define DECLARE_PEM_write_bio_const(name, type) \ | |
312 | int PEM_write_bio_##name(BIO *bp, const type *x); | |
313 | ||
314 | # define DECLARE_PEM_write_cb_bio(name, type) \ | |
315 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ | |
316 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | |
317 | ||
0f113f3e MC |
318 | # define DECLARE_PEM_write(name, type) \ |
319 | DECLARE_PEM_write_bio(name, type) \ | |
320 | DECLARE_PEM_write_fp(name, type) | |
321 | # define DECLARE_PEM_write_const(name, type) \ | |
322 | DECLARE_PEM_write_bio_const(name, type) \ | |
323 | DECLARE_PEM_write_fp_const(name, type) | |
324 | # define DECLARE_PEM_write_cb(name, type) \ | |
325 | DECLARE_PEM_write_cb_bio(name, type) \ | |
326 | DECLARE_PEM_write_cb_fp(name, type) | |
327 | # define DECLARE_PEM_read(name, type) \ | |
328 | DECLARE_PEM_read_bio(name, type) \ | |
329 | DECLARE_PEM_read_fp(name, type) | |
330 | # define DECLARE_PEM_rw(name, type) \ | |
331 | DECLARE_PEM_read(name, type) \ | |
332 | DECLARE_PEM_write(name, type) | |
333 | # define DECLARE_PEM_rw_const(name, type) \ | |
334 | DECLARE_PEM_read(name, type) \ | |
335 | DECLARE_PEM_write_const(name, type) | |
336 | # define DECLARE_PEM_rw_cb(name, type) \ | |
337 | DECLARE_PEM_read(name, type) \ | |
338 | DECLARE_PEM_write_cb(name, type) | |
0f113f3e | 339 | typedef int pem_password_cb (char *buf, int size, int rwflag, void *userdata); |
0f113f3e MC |
340 | |
341 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); | |
342 | int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *len, | |
343 | pem_password_cb *callback, void *u); | |
344 | ||
0f113f3e MC |
345 | int PEM_read_bio(BIO *bp, char **name, char **header, |
346 | unsigned char **data, long *len); | |
347 | int PEM_write_bio(BIO *bp, const char *name, const char *hdr, | |
348 | const unsigned char *data, long len); | |
349 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, | |
350 | const char *name, BIO *bp, pem_password_cb *cb, | |
351 | void *u); | |
352 | void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, | |
353 | pem_password_cb *cb, void *u); | |
354 | int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, | |
355 | const EVP_CIPHER *enc, unsigned char *kstr, int klen, | |
356 | pem_password_cb *cb, void *u); | |
357 | ||
358 | STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, | |
359 | pem_password_cb *cb, void *u); | |
360 | int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, | |
361 | unsigned char *kstr, int klen, | |
362 | pem_password_cb *cd, void *u); | |
0f113f3e MC |
363 | |
364 | int PEM_read(FILE *fp, char **name, char **header, | |
365 | unsigned char **data, long *len); | |
366 | int PEM_write(FILE *fp, const char *name, const char *hdr, | |
367 | const unsigned char *data, long len); | |
368 | void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, | |
369 | pem_password_cb *cb, void *u); | |
370 | int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, | |
371 | void *x, const EVP_CIPHER *enc, unsigned char *kstr, | |
372 | int klen, pem_password_cb *callback, void *u); | |
373 | STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, | |
374 | pem_password_cb *cb, void *u); | |
375 | ||
376 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, | |
377 | EVP_MD *md_type, unsigned char **ek, int *ekl, | |
378 | unsigned char *iv, EVP_PKEY **pubk, int npubk); | |
379 | int PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, | |
380 | unsigned char *in, int inl); | |
381 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, | |
382 | unsigned char *out, int *outl, EVP_PKEY *priv); | |
383 | ||
384 | int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); | |
385 | int PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *d, unsigned int cnt); | |
386 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, | |
387 | unsigned int *siglen, EVP_PKEY *pkey); | |
388 | ||
389 | int PEM_def_callback(char *buf, int num, int w, void *key); | |
390 | void PEM_proc_type(char *buf, int type); | |
391 | void PEM_dek_info(char *buf, const char *type, int len, char *str); | |
392 | ||
393 | # include <openssl/symhacks.h> | |
8c197cc5 | 394 | |
dbd665c2 | 395 | DECLARE_PEM_rw(X509, X509) |
ce1b4fe1 | 396 | DECLARE_PEM_rw(X509_AUX, X509) |
a8fe430a MC |
397 | DECLARE_PEM_rw(X509_REQ, X509_REQ) |
398 | DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) | |
dbd665c2 | 399 | DECLARE_PEM_rw(X509_CRL, X509_CRL) |
dbd665c2 | 400 | DECLARE_PEM_rw(PKCS7, PKCS7) |
dbd665c2 | 401 | DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) |
dbd665c2 | 402 | DECLARE_PEM_rw(PKCS8, X509_SIG) |
dbd665c2 | 403 | DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) |
0f113f3e | 404 | # ifndef OPENSSL_NO_RSA |
dbd665c2 | 405 | DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) |
a8fe430a MC |
406 | DECLARE_PEM_rw_const(RSAPublicKey, RSA) |
407 | DECLARE_PEM_rw(RSA_PUBKEY, RSA) | |
0f113f3e MC |
408 | # endif |
409 | # ifndef OPENSSL_NO_DSA | |
dbd665c2 | 410 | DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) |
a8fe430a MC |
411 | DECLARE_PEM_rw(DSA_PUBKEY, DSA) |
412 | DECLARE_PEM_rw_const(DSAparams, DSA) | |
0f113f3e MC |
413 | # endif |
414 | # ifndef OPENSSL_NO_EC | |
67ffa18c | 415 | DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) |
a8fe430a MC |
416 | DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) |
417 | DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) | |
0f113f3e MC |
418 | # endif |
419 | # ifndef OPENSSL_NO_DH | |
a8fe430a MC |
420 | DECLARE_PEM_rw_const(DHparams, DH) |
421 | DECLARE_PEM_write_const(DHxparams, DH) | |
0f113f3e | 422 | # endif |
a8fe430a MC |
423 | DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) |
424 | DECLARE_PEM_rw(PUBKEY, EVP_PKEY) | |
52664f50 | 425 | |
525f51f6 | 426 | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, |
0f113f3e MC |
427 | char *kstr, int klen, |
428 | pem_password_cb *cb, void *u); | |
1d5edd08 RE |
429 | int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, |
430 | char *, int, pem_password_cb *, void *); | |
525f51f6 | 431 | int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, |
0f113f3e MC |
432 | char *kstr, int klen, |
433 | pem_password_cb *cb, void *u); | |
525f51f6 | 434 | int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, |
0f113f3e MC |
435 | char *kstr, int klen, |
436 | pem_password_cb *cb, void *u); | |
437 | EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, | |
438 | void *u); | |
525f51f6 DSH |
439 | |
440 | int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, | |
0f113f3e MC |
441 | char *kstr, int klen, |
442 | pem_password_cb *cb, void *u); | |
525f51f6 | 443 | int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, |
0f113f3e MC |
444 | char *kstr, int klen, |
445 | pem_password_cb *cb, void *u); | |
525f51f6 | 446 | int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, |
0f113f3e MC |
447 | char *kstr, int klen, |
448 | pem_password_cb *cb, void *u); | |
525f51f6 | 449 | |
0f113f3e MC |
450 | EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, |
451 | void *u); | |
525f51f6 | 452 | |
0f113f3e MC |
453 | int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, |
454 | char *kstr, int klen, pem_password_cb *cd, | |
455 | void *u); | |
525f51f6 | 456 | |
3e4585c8 DSH |
457 | EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); |
458 | int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); | |
459 | ||
a0156a92 DSH |
460 | EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); |
461 | EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); | |
462 | EVP_PKEY *b2i_PrivateKey_bio(BIO *in); | |
463 | EVP_PKEY *b2i_PublicKey_bio(BIO *in); | |
464 | int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); | |
465 | int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); | |
0f113f3e | 466 | # ifndef OPENSSL_NO_RC4 |
a0156a92 DSH |
467 | EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); |
468 | int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, | |
0f113f3e MC |
469 | pem_password_cb *cb, void *u); |
470 | # endif | |
a0156a92 | 471 | |
d02b48c6 | 472 | /* BEGIN ERROR CODES */ |
0f113f3e MC |
473 | /* |
474 | * The following lines are auto generated by the script mkerr.pl. Any changes | |
6d311938 DSH |
475 | * made after this point may be overwritten when the script is next run. |
476 | */ | |
b476df64 | 477 | void ERR_load_PEM_strings(void); |
6d311938 | 478 | |
d02b48c6 RE |
479 | /* Error codes for the PEM functions. */ |
480 | ||
481 | /* Function codes. */ | |
0f113f3e MC |
482 | # define PEM_F_B2I_DSS 127 |
483 | # define PEM_F_B2I_PVK_BIO 128 | |
484 | # define PEM_F_B2I_RSA 129 | |
485 | # define PEM_F_CHECK_BITLEN_DSA 130 | |
486 | # define PEM_F_CHECK_BITLEN_RSA 131 | |
487 | # define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 | |
488 | # define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 | |
489 | # define PEM_F_DO_B2I 132 | |
490 | # define PEM_F_DO_B2I_BIO 133 | |
491 | # define PEM_F_DO_BLOB_HEADER 134 | |
492 | # define PEM_F_DO_PK8PKEY 126 | |
493 | # define PEM_F_DO_PK8PKEY_FP 125 | |
494 | # define PEM_F_DO_PVK_BODY 135 | |
495 | # define PEM_F_DO_PVK_HEADER 136 | |
496 | # define PEM_F_I2B_PVK 137 | |
497 | # define PEM_F_I2B_PVK_BIO 138 | |
498 | # define PEM_F_LOAD_IV 101 | |
499 | # define PEM_F_PEM_ASN1_READ 102 | |
500 | # define PEM_F_PEM_ASN1_READ_BIO 103 | |
501 | # define PEM_F_PEM_ASN1_WRITE 104 | |
502 | # define PEM_F_PEM_ASN1_WRITE_BIO 105 | |
503 | # define PEM_F_PEM_DEF_CALLBACK 100 | |
504 | # define PEM_F_PEM_DO_HEADER 106 | |
505 | # define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 | |
506 | # define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 | |
507 | # define PEM_F_PEM_PK8PKEY 119 | |
508 | # define PEM_F_PEM_READ 108 | |
509 | # define PEM_F_PEM_READ_BIO 109 | |
510 | # define PEM_F_PEM_READ_BIO_DHPARAMS 141 | |
511 | # define PEM_F_PEM_READ_BIO_PARAMETERS 140 | |
512 | # define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 | |
513 | # define PEM_F_PEM_READ_DHPARAMS 142 | |
514 | # define PEM_F_PEM_READ_PRIVATEKEY 124 | |
515 | # define PEM_F_PEM_SEALFINAL 110 | |
516 | # define PEM_F_PEM_SEALINIT 111 | |
517 | # define PEM_F_PEM_SIGNFINAL 112 | |
518 | # define PEM_F_PEM_WRITE 113 | |
519 | # define PEM_F_PEM_WRITE_BIO 114 | |
520 | # define PEM_F_PEM_WRITE_PRIVATEKEY 139 | |
521 | # define PEM_F_PEM_X509_INFO_READ 115 | |
522 | # define PEM_F_PEM_X509_INFO_READ_BIO 116 | |
523 | # define PEM_F_PEM_X509_INFO_WRITE_BIO 117 | |
d02b48c6 RE |
524 | |
525 | /* Reason codes. */ | |
0f113f3e MC |
526 | # define PEM_R_BAD_BASE64_DECODE 100 |
527 | # define PEM_R_BAD_DECRYPT 101 | |
528 | # define PEM_R_BAD_END_LINE 102 | |
529 | # define PEM_R_BAD_IV_CHARS 103 | |
530 | # define PEM_R_BAD_MAGIC_NUMBER 116 | |
531 | # define PEM_R_BAD_PASSWORD_READ 104 | |
532 | # define PEM_R_BAD_VERSION_NUMBER 117 | |
533 | # define PEM_R_BIO_WRITE_FAILURE 118 | |
534 | # define PEM_R_CIPHER_IS_NULL 127 | |
535 | # define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 | |
536 | # define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 119 | |
537 | # define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 120 | |
538 | # define PEM_R_INCONSISTENT_HEADER 121 | |
539 | # define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 122 | |
540 | # define PEM_R_KEYBLOB_TOO_SHORT 123 | |
541 | # define PEM_R_NOT_DEK_INFO 105 | |
542 | # define PEM_R_NOT_ENCRYPTED 106 | |
543 | # define PEM_R_NOT_PROC_TYPE 107 | |
544 | # define PEM_R_NO_START_LINE 108 | |
545 | # define PEM_R_PROBLEMS_GETTING_PASSWORD 109 | |
546 | # define PEM_R_PUBLIC_KEY_NO_RSA 110 | |
547 | # define PEM_R_PVK_DATA_TOO_SHORT 124 | |
548 | # define PEM_R_PVK_TOO_SHORT 125 | |
549 | # define PEM_R_READ_KEY 111 | |
550 | # define PEM_R_SHORT_HEADER 112 | |
551 | # define PEM_R_UNSUPPORTED_CIPHER 113 | |
552 | # define PEM_R_UNSUPPORTED_ENCRYPTION 114 | |
553 | # define PEM_R_UNSUPPORTED_KEY_COMPONENTS 126 | |
6d311938 | 554 | |
d02b48c6 RE |
555 | #ifdef __cplusplus |
556 | } | |
557 | #endif | |
558 | #endif |