]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/pem/pem_all.c
Import of old SSLeay release: SSLeay 0.8.1b
[thirdparty/openssl.git] / crypto / pem / pem_all.c
CommitLineData
d02b48c6
RE
1/* crypto/pem/pem_all.c */
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.
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
61#include "bio.h"
62#include "evp.h"
63#include "x509.h"
64#include "pkcs7.h"
65#include "pem.h"
66
67#ifndef WIN16
68/* The X509 functions */
69X509 *PEM_read_X509(fp,x,cb)
70FILE *fp;
71X509 **x;
72int (*cb)();
73 {
74 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
75 PEM_STRING_X509,fp,(char **)x,cb));
76 }
77#endif
78
79X509 *PEM_read_bio_X509(bp,x,cb)
80BIO *bp;
81X509 **x;
82int (*cb)();
83 {
84 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
85 PEM_STRING_X509,bp,(char **)x,cb));
86 }
87
88#ifndef WIN16
89int PEM_write_X509(fp,x)
90FILE *fp;
91X509 *x;
92 {
93 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
94 (char *)x, NULL,NULL,0,NULL));
95 }
96#endif
97
98int PEM_write_bio_X509(bp,x)
99BIO *bp;
100X509 *x;
101 {
102 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
103 (char *)x, NULL,NULL,0,NULL));
104 }
105
106#ifndef WIN16
107/* The X509_REQ functions */
108X509_REQ *PEM_read_X509_REQ(fp,x,cb)
109FILE *fp;
110X509_REQ **x;
111int (*cb)();
112 {
113 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
114 PEM_STRING_X509_REQ,fp,(char **)x,cb));
115 }
116#endif
117
118X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb)
119BIO *bp;
120X509_REQ **x;
121int (*cb)();
122 {
123 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
124 PEM_STRING_X509_REQ,bp,(char **)x,cb));
125 }
126
127#ifndef WIN16
128int PEM_write_X509_REQ(fp,x)
129FILE *fp;
130X509_REQ *x;
131 {
132 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
133 (char *)x, NULL,NULL,0,NULL));
134 }
135#endif
136
137int PEM_write_bio_X509_REQ(bp,x)
138BIO *bp;
139X509_REQ *x;
140 {
141 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
142 bp,(char *)x, NULL,NULL,0,NULL));
143 }
144
145#ifndef WIN16
146/* The X509_CRL functions */
147X509_CRL *PEM_read_X509_CRL(fp,x,cb)
148FILE *fp;
149X509_CRL **x;
150int (*cb)();
151 {
152 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
153 PEM_STRING_X509_CRL,fp,(char **)x,cb));
154 }
155#endif
156
157X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
158BIO *bp;
159X509_CRL **x;
160int (*cb)();
161 {
162 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
163 PEM_STRING_X509_CRL,bp,(char **)x,cb));
164 }
165
166#ifndef WIN16
167int PEM_write_X509_CRL(fp,x)
168FILE *fp;
169X509_CRL *x;
170 {
171 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
172 (char *)x, NULL,NULL,0,NULL));
173 }
174#endif
175
176int PEM_write_bio_X509_CRL(bp,x)
177BIO *bp;
178X509_CRL *x;
179 {
180 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
181 bp,(char *)x, NULL,NULL,0,NULL));
182 }
183
184#ifndef NO_RSA
185#ifndef WIN16
186/* The RSAPrivateKey functions */
187RSA *PEM_read_RSAPrivateKey(fp,x,cb)
188FILE *fp;
189RSA **x;
190int (*cb)();
191 {
192 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
193 PEM_STRING_RSA,fp,(char **)x,cb));
194 }
195
196RSA *PEM_read_RSAPublicKey(fp,x,cb)
197FILE *fp;
198RSA **x;
199int (*cb)();
200 {
201 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
202 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
203 }
204#endif
205
206RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb)
207BIO *bp;
208RSA **x;
209int (*cb)();
210 {
211 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
212 PEM_STRING_RSA,bp,(char **)x,cb));
213 }
214
215RSA *PEM_read_bio_RSAPublicKey(bp,x,cb)
216BIO *bp;
217RSA **x;
218int (*cb)();
219 {
220 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
221 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
222 }
223
224#ifndef WIN16
225int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
226FILE *fp;
227RSA *x;
228EVP_CIPHER *enc;
229unsigned char *kstr;
230int klen;
231int (*cb)();
232 {
233 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
234 (char *)x,enc,kstr,klen,cb));
235 }
236
237int PEM_write_RSAPublicKey(fp,x)
238FILE *fp;
239RSA *x;
240 {
241 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
242 PEM_STRING_RSA_PUBLIC,fp,
243 (char *)x,NULL,NULL,0,NULL));
244 }
245#endif
246
247int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
248BIO *bp;
249RSA *x;
250EVP_CIPHER *enc;
251unsigned char *kstr;
252int klen;
253int (*cb)();
254 {
255 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
256 bp,(char *)x,enc,kstr,klen,cb));
257 }
258
259int PEM_write_bio_RSAPublicKey(bp,x)
260BIO *bp;
261RSA *x;
262 {
263 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
264 PEM_STRING_RSA_PUBLIC,
265 bp,(char *)x,NULL,NULL,0,NULL));
266 }
267#endif /* !NO_RSA */
268
269#ifndef NO_DSA
270#ifndef WIN16
271/* The DSAPrivateKey functions */
272DSA *PEM_read_DSAPrivateKey(fp,x,cb)
273FILE *fp;
274DSA **x;
275int (*cb)();
276 {
277 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
278 PEM_STRING_DSA,fp,(char **)x,cb));
279 }
280#endif
281
282DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
283BIO *bp;
284DSA **x;
285int (*cb)();
286 {
287 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
288 PEM_STRING_DSA,bp,(char **)x,cb));
289 }
290
291#ifndef WIN16
292int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
293FILE *fp;
294DSA *x;
295EVP_CIPHER *enc;
296unsigned char *kstr;
297int klen;
298int (*cb)();
299 {
300 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
301 (char *)x,enc,kstr,klen,cb));
302 }
303#endif
304
305int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb)
306BIO *bp;
307DSA *x;
308EVP_CIPHER *enc;
309unsigned char *kstr;
310int klen;
311int (*cb)();
312 {
313 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
314 bp,(char *)x,enc,kstr,klen,cb));
315 }
316#endif
317
318#ifndef WIN16
319/* The PrivateKey functions */
320EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
321FILE *fp;
322EVP_PKEY **x;
323int (*cb)();
324 {
325 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
326 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
327 }
328#endif
329
330EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
331BIO *bp;
332EVP_PKEY **x;
333int (*cb)();
334 {
335 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
336 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
337 }
338
339#ifndef WIN16
340int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
341FILE *fp;
342EVP_PKEY *x;
343EVP_CIPHER *enc;
344unsigned char *kstr;
345int klen;
346int (*cb)();
347 {
348 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
349 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
350 fp,(char *)x,enc,kstr,klen,cb));
351 }
352#endif
353
354int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb)
355BIO *bp;
356EVP_PKEY *x;
357EVP_CIPHER *enc;
358unsigned char *kstr;
359int klen;
360int (*cb)();
361 {
362 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
363 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
364 bp,(char *)x,enc,kstr,klen,cb));
365 }
366
367#ifndef WIN16
368/* The PKCS7 functions */
369PKCS7 *PEM_read_PKCS7(fp,x,cb)
370FILE *fp;
371PKCS7 **x;
372int (*cb)();
373 {
374 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
375 PEM_STRING_PKCS7,fp,(char **)x,cb));
376 }
377#endif
378
379PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
380BIO *bp;
381PKCS7 **x;
382int (*cb)();
383 {
384 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
385 PEM_STRING_PKCS7,bp,(char **)x,cb));
386 }
387
388#ifndef WIN16
389int PEM_write_PKCS7(fp,x)
390FILE *fp;
391PKCS7 *x;
392 {
393 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
394 (char *)x, NULL,NULL,0,NULL));
395 }
396#endif
397
398int PEM_write_bio_PKCS7(bp,x)
399BIO *bp;
400PKCS7 *x;
401 {
402 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
403 (char *)x, NULL,NULL,0,NULL));
404 }
405
406#ifndef NO_DH
407#ifndef WIN16
408/* The DHparams functions */
409DH *PEM_read_DHparams(fp,x,cb)
410FILE *fp;
411DH **x;
412int (*cb)();
413 {
414 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
415 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
416 }
417#endif
418
419DH *PEM_read_bio_DHparams(bp,x,cb)
420BIO *bp;
421DH **x;
422int (*cb)();
423 {
424 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
425 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
426 }
427
428#ifndef WIN16
429int PEM_write_DHparams(fp,x)
430FILE *fp;
431DH *x;
432 {
433 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
434 (char *)x, NULL,NULL,0,NULL));
435 }
436#endif
437
438int PEM_write_bio_DHparams(bp,x)
439BIO *bp;
440DH *x;
441 {
442 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
443 bp,(char *)x, NULL,NULL,0,NULL));
444 }
445#endif
446
447#ifndef NO_DSA
448#ifndef WIN16
449/* The DSAparams functions */
450DSA *PEM_read_DSAparams(fp,x,cb)
451FILE *fp;
452DSA **x;
453int (*cb)();
454 {
455 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
456 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
457 }
458#endif
459
460DSA *PEM_read_bio_DSAparams(bp,x,cb)
461BIO *bp;
462DSA **x;
463int (*cb)();
464 {
465 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
466 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
467 }
468
469#ifndef WIN16
470int PEM_write_DSAparams(fp,x)
471FILE *fp;
472DSA *x;
473 {
474 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
475 (char *)x, NULL,NULL,0,NULL));
476 }
477#endif
478
479int PEM_write_bio_DSAparams(bp,x)
480BIO *bp;
481DSA *x;
482 {
483 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
484 bp,(char *)x, NULL,NULL,0,NULL));
485 }
486#endif
487