]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/pem/pem_all.c
Change functions to ANSI C.
[thirdparty/openssl.git] / crypto / pem / pem_all.c
CommitLineData
d02b48c6 1/* crypto/pem/pem_all.c */
58964a49 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
d02b48c6
RE
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.
8 *
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).
15 *
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.
22 *
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 :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
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.
52 *
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
59#include <stdio.h>
60#undef SSLEAY_MACROS
58964a49 61#include "cryptlib.h"
d02b48c6
RE
62#include "bio.h"
63#include "evp.h"
64#include "x509.h"
65#include "pkcs7.h"
66#include "pem.h"
67
58964a49 68#ifndef NO_FP_API
d02b48c6 69/* The X509 functions */
6b691a5c 70X509 *PEM_read_X509(FILE *fp, X509 **x, int (*cb)())
d02b48c6
RE
71 {
72 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
73 PEM_STRING_X509,fp,(char **)x,cb));
74 }
75#endif
76
6b691a5c 77X509 *PEM_read_bio_X509(BIO *bp, X509 **x, int (*cb)())
d02b48c6
RE
78 {
79 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
80 PEM_STRING_X509,bp,(char **)x,cb));
81 }
82
58964a49 83#ifndef NO_FP_API
6b691a5c 84int PEM_write_X509(FILE *fp, X509 *x)
d02b48c6
RE
85 {
86 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
87 (char *)x, NULL,NULL,0,NULL));
88 }
89#endif
90
6b691a5c 91int PEM_write_bio_X509(BIO *bp, X509 *x)
d02b48c6
RE
92 {
93 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
94 (char *)x, NULL,NULL,0,NULL));
95 }
96
58964a49 97#ifndef NO_FP_API
d02b48c6 98/* The X509_REQ functions */
6b691a5c 99X509_REQ *PEM_read_X509_REQ(FILE *fp, X509_REQ **x, int (*cb)())
d02b48c6
RE
100 {
101 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
102 PEM_STRING_X509_REQ,fp,(char **)x,cb));
103 }
104#endif
105
6b691a5c 106X509_REQ *PEM_read_bio_X509_REQ(BIO *bp, X509_REQ **x, int (*cb)())
d02b48c6
RE
107 {
108 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
109 PEM_STRING_X509_REQ,bp,(char **)x,cb));
110 }
111
58964a49 112#ifndef NO_FP_API
6b691a5c 113int PEM_write_X509_REQ(FILE *fp, X509_REQ *x)
d02b48c6
RE
114 {
115 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
116 (char *)x, NULL,NULL,0,NULL));
117 }
118#endif
119
6b691a5c 120int PEM_write_bio_X509_REQ(BIO *bp, X509_REQ *x)
d02b48c6
RE
121 {
122 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
123 bp,(char *)x, NULL,NULL,0,NULL));
124 }
125
58964a49 126#ifndef NO_FP_API
d02b48c6 127/* The X509_CRL functions */
6b691a5c 128X509_CRL *PEM_read_X509_CRL(FILE *fp, X509_CRL **x, int (*cb)())
d02b48c6
RE
129 {
130 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
131 PEM_STRING_X509_CRL,fp,(char **)x,cb));
132 }
133#endif
134
6b691a5c 135X509_CRL *PEM_read_bio_X509_CRL(BIO *bp, X509_CRL **x, int (*cb)())
d02b48c6
RE
136 {
137 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
138 PEM_STRING_X509_CRL,bp,(char **)x,cb));
139 }
140
58964a49 141#ifndef NO_FP_API
6b691a5c 142int PEM_write_X509_CRL(FILE *fp, X509_CRL *x)
d02b48c6
RE
143 {
144 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
145 (char *)x, NULL,NULL,0,NULL));
146 }
147#endif
148
6b691a5c 149int PEM_write_bio_X509_CRL(BIO *bp, X509_CRL *x)
d02b48c6
RE
150 {
151 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
152 bp,(char *)x, NULL,NULL,0,NULL));
153 }
154
155#ifndef NO_RSA
58964a49 156#ifndef NO_FP_API
d02b48c6 157/* The RSAPrivateKey functions */
6b691a5c 158RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **x, int (*cb)())
d02b48c6
RE
159 {
160 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
161 PEM_STRING_RSA,fp,(char **)x,cb));
162 }
163
6b691a5c 164RSA *PEM_read_RSAPublicKey(FILE *fp, RSA **x, int (*cb)())
d02b48c6
RE
165 {
166 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
167 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
168 }
169#endif
170
6b691a5c 171RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **x, int (*cb)())
d02b48c6
RE
172 {
173 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
174 PEM_STRING_RSA,bp,(char **)x,cb));
175 }
176
6b691a5c 177RSA *PEM_read_bio_RSAPublicKey(BIO *bp, RSA **x, int (*cb)())
d02b48c6
RE
178 {
179 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
180 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
181 }
182
58964a49 183#ifndef NO_FP_API
6b691a5c
UM
184int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, EVP_CIPHER *enc,
185 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
186 {
187 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
188 (char *)x,enc,kstr,klen,cb));
189 }
190
6b691a5c 191int PEM_write_RSAPublicKey(FILE *fp, RSA *x)
d02b48c6
RE
192 {
193 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
194 PEM_STRING_RSA_PUBLIC,fp,
195 (char *)x,NULL,NULL,0,NULL));
196 }
197#endif
198
6b691a5c
UM
199int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
200 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
201 {
202 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
203 bp,(char *)x,enc,kstr,klen,cb));
204 }
205
6b691a5c 206int PEM_write_bio_RSAPublicKey(BIO *bp, RSA *x)
d02b48c6
RE
207 {
208 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
209 PEM_STRING_RSA_PUBLIC,
210 bp,(char *)x,NULL,NULL,0,NULL));
211 }
212#endif /* !NO_RSA */
213
214#ifndef NO_DSA
58964a49 215#ifndef NO_FP_API
d02b48c6 216/* The DSAPrivateKey functions */
6b691a5c 217DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **x, int (*cb)())
d02b48c6
RE
218 {
219 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
220 PEM_STRING_DSA,fp,(char **)x,cb));
221 }
222#endif
223
6b691a5c 224DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **x, int (*cb)())
d02b48c6
RE
225 {
226 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
227 PEM_STRING_DSA,bp,(char **)x,cb));
228 }
229
58964a49 230#ifndef NO_FP_API
6b691a5c
UM
231int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
232 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
233 {
234 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
235 (char *)x,enc,kstr,klen,cb));
236 }
237#endif
238
6b691a5c
UM
239int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
240 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
241 {
242 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
243 bp,(char *)x,enc,kstr,klen,cb));
244 }
245#endif
246
58964a49 247#ifndef NO_FP_API
d02b48c6 248/* The PrivateKey functions */
6b691a5c 249EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, int (*cb)())
d02b48c6
RE
250 {
251 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
252 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
253 }
254#endif
255
6b691a5c 256EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, int (*cb)())
d02b48c6
RE
257 {
258 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
259 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
260 }
261
58964a49 262#ifndef NO_FP_API
6b691a5c
UM
263int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, EVP_CIPHER *enc,
264 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
265 {
266 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
267 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
268 fp,(char *)x,enc,kstr,klen,cb));
269 }
270#endif
271
6b691a5c
UM
272int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, EVP_CIPHER *enc,
273 unsigned char *kstr, int klen, int (*cb)())
d02b48c6
RE
274 {
275 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
276 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
277 bp,(char *)x,enc,kstr,klen,cb));
278 }
279
58964a49 280#ifndef NO_FP_API
d02b48c6 281/* The PKCS7 functions */
6b691a5c 282PKCS7 *PEM_read_PKCS7(FILE *fp, PKCS7 **x, int (*cb)())
d02b48c6
RE
283 {
284 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
285 PEM_STRING_PKCS7,fp,(char **)x,cb));
286 }
287#endif
288
6b691a5c 289PKCS7 *PEM_read_bio_PKCS7(BIO *bp, PKCS7 **x, int (*cb)())
d02b48c6
RE
290 {
291 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
292 PEM_STRING_PKCS7,bp,(char **)x,cb));
293 }
294
58964a49 295#ifndef NO_FP_API
6b691a5c 296int PEM_write_PKCS7(FILE *fp, PKCS7 *x)
d02b48c6
RE
297 {
298 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
299 (char *)x, NULL,NULL,0,NULL));
300 }
301#endif
302
6b691a5c 303int PEM_write_bio_PKCS7(BIO *bp, PKCS7 *x)
d02b48c6
RE
304 {
305 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
306 (char *)x, NULL,NULL,0,NULL));
307 }
308
309#ifndef NO_DH
58964a49 310#ifndef NO_FP_API
d02b48c6 311/* The DHparams functions */
6b691a5c 312DH *PEM_read_DHparams(FILE *fp, DH **x, int (*cb)())
d02b48c6
RE
313 {
314 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
315 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
316 }
317#endif
318
6b691a5c 319DH *PEM_read_bio_DHparams(BIO *bp, DH **x, int (*cb)())
d02b48c6
RE
320 {
321 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
322 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
323 }
324
58964a49 325#ifndef NO_FP_API
6b691a5c 326int PEM_write_DHparams(FILE *fp, DH *x)
d02b48c6
RE
327 {
328 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
329 (char *)x, NULL,NULL,0,NULL));
330 }
331#endif
332
6b691a5c 333int PEM_write_bio_DHparams(BIO *bp, DH *x)
d02b48c6
RE
334 {
335 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
336 bp,(char *)x, NULL,NULL,0,NULL));
337 }
338#endif
339
340#ifndef NO_DSA
58964a49 341#ifndef NO_FP_API
d02b48c6 342/* The DSAparams functions */
6b691a5c 343DSA *PEM_read_DSAparams(FILE *fp, DSA **x, int (*cb)())
d02b48c6
RE
344 {
345 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
346 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
347 }
348#endif
349
6b691a5c 350DSA *PEM_read_bio_DSAparams(BIO *bp, DSA **x, int (*cb)())
d02b48c6
RE
351 {
352 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
353 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
354 }
355
58964a49 356#ifndef NO_FP_API
6b691a5c 357int PEM_write_DSAparams(FILE *fp, DSA *x)
d02b48c6
RE
358 {
359 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
360 (char *)x, NULL,NULL,0,NULL));
361 }
362#endif
363
6b691a5c 364int PEM_write_bio_DSAparams(BIO *bp, DSA *x)
d02b48c6
RE
365 {
366 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
367 bp,(char *)x, NULL,NULL,0,NULL));
368 }
369#endif
370
92c046ca
DSH
371/* The Netscape Certificate sequence functions */
372
373#ifndef NO_FP_API
6b691a5c
UM
374NETSCAPE_CERT_SEQUENCE *PEM_read_NETSCAPE_CERT_SEQUENCE(FILE *fp,
375 NETSCAPE_CERT_SEQUENCE **x, int (*cb)())
92c046ca
DSH
376 {
377 return((NETSCAPE_CERT_SEQUENCE *)
378 PEM_ASN1_read((char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,
379 PEM_STRING_X509,fp,(char **)x,cb));
380 }
381#endif
382
6b691a5c
UM
383NETSCAPE_CERT_SEQUENCE *PEM_read_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp,
384 NETSCAPE_CERT_SEQUENCE **x, int (*cb)())
92c046ca
DSH
385 {
386 return((NETSCAPE_CERT_SEQUENCE *)
387 PEM_ASN1_read_bio((char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,
388 PEM_STRING_X509,bp,(char **)x,cb));
389 }
390
391#ifndef NO_FP_API
6b691a5c 392int PEM_write_NETSCAPE_CERT_SEQUENCE(FILE *fp, NETSCAPE_CERT_SEQUENCE *x)
92c046ca
DSH
393 {
394 return(PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE,
395 PEM_STRING_X509,fp, (char *)x, NULL,NULL,0,NULL));
396 }
397#endif
398
6b691a5c 399int PEM_write_bio_NETSCAPE_CERT_SEQUENCE(BIO *bp, NETSCAPE_CERT_SEQUENCE *x)
92c046ca
DSH
400 {
401 return(PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE,
402 PEM_STRING_X509,bp, (char *)x, NULL,NULL,0,NULL));
403 }
404