Rid the world of yet more evil casts.
[openssl.git] / crypto / x509 / x_all.c
1 /* crypto/x509/x_all.c */
2 /* Copyright (C) 1995-1998 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 "stack.h"
62 #include "cryptlib.h"
63 #include "buffer.h"
64 #include "asn1.h"
65 #include "evp.h"
66 #include "x509.h"
67
68 int X509_verify(a,r)
69 X509 *a;
70 EVP_PKEY *r;
71         {
72         return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,
73                 a->signature,(char *)a->cert_info,r));
74         }
75
76 int X509_REQ_verify(a,r)
77 X509_REQ *a;
78 EVP_PKEY *r;
79         {
80         return( ASN1_verify((int (*)())i2d_X509_REQ_INFO,
81                 a->sig_alg,a->signature,(char *)a->req_info,r));
82         }
83
84 int X509_CRL_verify(a,r)
85 X509_CRL *a;
86 EVP_PKEY *r;
87         {
88         return(ASN1_verify((int (*)())i2d_X509_CRL_INFO,
89                 a->sig_alg, a->signature,(char *)a->crl,r));
90         }
91
92 int NETSCAPE_SPKI_verify(a,r)
93 NETSCAPE_SPKI *a;
94 EVP_PKEY *r;
95         {
96         return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC,
97                 a->sig_algor,a->signature, (char *)a->spkac,r));
98         }
99
100 int X509_sign(x,pkey,md)
101 X509 *x;
102 EVP_PKEY *pkey;
103 EVP_MD *md;
104         {
105         return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature,
106                 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md));
107         }
108
109 int X509_REQ_sign(x,pkey,md)
110 X509_REQ *x;
111 EVP_PKEY *pkey;
112 EVP_MD *md;
113         {
114         return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL,
115                 x->signature, (char *)x->req_info,pkey,md));
116         }
117
118 int X509_CRL_sign(x,pkey,md)
119 X509_CRL *x;
120 EVP_PKEY *pkey;
121 EVP_MD *md;
122         {
123         return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,
124                 x->sig_alg, x->signature, (char *)x->crl,pkey,md));
125         }
126
127 int NETSCAPE_SPKI_sign(x,pkey,md)
128 NETSCAPE_SPKI *x;
129 EVP_PKEY *pkey;
130 EVP_MD *md;
131         {
132         return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL,
133                 x->signature, (char *)x->spkac,pkey,md));
134         }
135
136 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(xa)
137 X509_ATTRIBUTE *xa;
138         {
139         return((X509_ATTRIBUTE *)ASN1_dup((int (*)())i2d_X509_ATTRIBUTE,
140                 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa));
141         }
142
143 X509 *X509_dup(x509)
144 X509 *x509;
145         {
146         return((X509 *)ASN1_dup((int (*)())i2d_X509,
147                 (char *(*)())d2i_X509,(char *)x509));
148         }
149
150 X509_EXTENSION *X509_EXTENSION_dup(ex)
151 X509_EXTENSION *ex;
152         {
153         return((X509_EXTENSION *)ASN1_dup(
154                 (int (*)())i2d_X509_EXTENSION,
155                 (char *(*)())d2i_X509_EXTENSION,(char *)ex));
156         }
157
158 #ifndef NO_FP_API
159 X509 *d2i_X509_fp(fp,x509)
160 FILE *fp;
161 X509 *x509;
162         {
163         return((X509 *)ASN1_d2i_fp((char *(*)())X509_new,
164                 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)));
165         }
166
167 int i2d_X509_fp(fp,x509)
168 FILE *fp;
169 X509 *x509;
170         {
171         return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509));
172         }
173 #endif
174
175 X509 *d2i_X509_bio(bp,x509)
176 BIO *bp;
177 X509 *x509;
178         {
179         return((X509 *)ASN1_d2i_bio((char *(*)())X509_new,
180                 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)));
181         }
182
183 int i2d_X509_bio(bp,x509)
184 BIO *bp;
185 X509 *x509;
186         {
187         return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509));
188         }
189
190 X509_CRL *X509_CRL_dup(crl)
191 X509_CRL *crl;
192         {
193         return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL,
194                 (char *(*)())d2i_X509_CRL,(char *)crl));
195         }
196
197 #ifndef NO_FP_API
198 X509_CRL *d2i_X509_CRL_fp(fp,crl)
199 FILE *fp;
200 X509_CRL *crl;
201         {
202         return((X509_CRL *)ASN1_d2i_fp((char *(*)())
203                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),
204                 (unsigned char **)(crl)));
205         }
206
207 int i2d_X509_CRL_fp(fp,crl)
208 FILE *fp;
209 X509_CRL *crl;
210         {
211         return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl));
212         }
213 #endif
214
215 X509_CRL *d2i_X509_CRL_bio(bp,crl)
216 BIO *bp;
217 X509_CRL *crl;
218         {
219         return((X509_CRL *)ASN1_d2i_bio((char *(*)())
220                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),
221                 (unsigned char **)(crl)));
222         }
223
224 int i2d_X509_CRL_bio(bp,crl)
225 BIO *bp;
226 X509_CRL *crl;
227         {
228         return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl));
229         }
230
231 PKCS7 *PKCS7_dup(p7)
232 PKCS7 *p7;
233         {
234         return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7,
235                 (char *(*)())d2i_PKCS7,(char *)p7));
236         }
237
238 #ifndef NO_FP_API
239 PKCS7 *d2i_PKCS7_fp(fp,p7)
240 FILE *fp;
241 PKCS7 *p7;
242         {
243         return((PKCS7 *)ASN1_d2i_fp((char *(*)())
244                 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),
245                 (unsigned char **)(p7)));
246         }
247
248 int i2d_PKCS7_fp(fp,p7)
249 FILE *fp;
250 PKCS7 *p7;
251         {
252         return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7));
253         }
254 #endif
255
256 PKCS7 *d2i_PKCS7_bio(bp,p7)
257 BIO *bp;
258 PKCS7 *p7;
259         {
260         return((PKCS7 *)ASN1_d2i_bio((char *(*)())
261                 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),
262                 (unsigned char **)(p7)));
263         }
264
265 int i2d_PKCS7_bio(bp,p7)
266 BIO *bp;
267 PKCS7 *p7;
268         {
269         return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7));
270         }
271
272 X509_REQ *X509_REQ_dup(req)
273 X509_REQ *req;
274         {
275         return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ,
276                 (char *(*)())d2i_X509_REQ,(char *)req));
277         }
278
279 #ifndef NO_FP_API
280 X509_REQ *d2i_X509_REQ_fp(fp,req)
281 FILE *fp;
282 X509_REQ *req;
283         {
284         return((X509_REQ *)ASN1_d2i_fp((char *(*)())
285                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),
286                 (unsigned char **)(req)));
287         }
288
289 int i2d_X509_REQ_fp(fp,req)
290 FILE *fp;
291 X509_REQ *req;
292         {
293         return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req));
294         }
295 #endif
296
297 X509_REQ *d2i_X509_REQ_bio(bp,req)
298 BIO *bp;
299 X509_REQ *req;
300         {
301         return((X509_REQ *)ASN1_d2i_bio((char *(*)())
302                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),
303                 (unsigned char **)(req)));
304         }
305
306 int i2d_X509_REQ_bio(bp,req)
307 BIO *bp;
308 X509_REQ *req;
309         {
310         return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req));
311         }
312
313 #ifndef NO_RSA
314 RSA *RSAPublicKey_dup(rsa)
315 RSA *rsa;
316         {
317         return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey,
318                 (char *(*)())d2i_RSAPublicKey,(char *)rsa));
319         }
320
321 RSA *RSAPrivateKey_dup(rsa)
322 RSA *rsa;
323         {
324         return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey,
325                 (char *(*)())d2i_RSAPrivateKey,(char *)rsa));
326         }
327
328 #ifndef NO_FP_API
329 RSA *d2i_RSAPrivateKey_fp(fp,rsa)
330 FILE *fp;
331 RSA *rsa;
332         {
333         return((RSA *)ASN1_d2i_fp((char *(*)())
334                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp),
335                 (unsigned char **)(rsa)));
336         }
337
338 int i2d_RSAPrivateKey_fp(fp,rsa)
339 FILE *fp;
340 RSA *rsa;
341         {
342         return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa));
343         }
344
345 RSA *d2i_RSAPublicKey_fp(fp,rsa)
346 FILE *fp;
347 RSA *rsa;
348         {
349         return((RSA *)ASN1_d2i_fp((char *(*)())
350                 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp),
351                 (unsigned char **)(rsa)));
352         }
353
354 int i2d_RSAPublicKey_fp(fp,rsa)
355 FILE *fp;
356 RSA *rsa;
357         {
358         return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
359         }
360 #endif
361
362 RSA *d2i_RSAPrivateKey_bio(bp,rsa)
363 BIO *bp;
364 RSA *rsa;
365         {
366         return((RSA *)ASN1_d2i_bio((char *(*)())
367                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp),
368                 (unsigned char **)(rsa)));
369         }
370
371 int i2d_RSAPrivateKey_bio(bp,rsa)
372 BIO *bp;
373 RSA *rsa;
374         {
375         return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa));
376         }
377
378 RSA *d2i_RSAPublicKey_bio(bp,rsa)
379 BIO *bp;
380 RSA *rsa;
381         {
382         return((RSA *)ASN1_d2i_bio((char *(*)())
383                 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp),
384                 (unsigned char **)(rsa)));
385         }
386
387 int i2d_RSAPublicKey_bio(bp,rsa)
388 BIO *bp;
389 RSA *rsa;
390         {
391         return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
392         }
393 #endif
394
395 #ifndef NO_DSA
396 #ifndef NO_FP_API
397 DSA *d2i_DSAPrivateKey_fp(fp,dsa)
398 FILE *fp;
399 DSA *dsa;
400         {
401         return((DSA *)ASN1_d2i_fp((char *(*)())
402                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
403                 (unsigned char **)(dsa)));
404         }
405
406 int i2d_DSAPrivateKey_fp(fp,dsa)
407 FILE *fp;
408 DSA *dsa;
409         {
410         return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
411         }
412 #endif
413
414 DSA *d2i_DSAPrivateKey_bio(bp,dsa)
415 BIO *bp;
416 DSA *dsa;
417         {
418         return((DSA *)ASN1_d2i_bio((char *(*)())
419                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
420                 (unsigned char **)(dsa)));
421         }
422
423 int i2d_DSAPrivateKey_bio(bp,dsa)
424 BIO *bp;
425 DSA *dsa;
426         {
427         return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
428         }
429 #endif
430
431 X509_ALGOR *X509_ALGOR_dup(xn)
432 X509_ALGOR *xn;
433         {
434         return((X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,
435         (char *(*)())d2i_X509_ALGOR,(char *)xn));
436         }
437
438 X509_NAME *X509_NAME_dup(xn)
439 X509_NAME *xn;
440         {
441         return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME,
442                 (char *(*)())d2i_X509_NAME,(char *)xn));
443         }
444
445 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(ne)
446 X509_NAME_ENTRY *ne;
447         {
448         return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY,
449                 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
450         }
451
452 int X509_digest(data,type,md,len)
453 X509 *data;
454 EVP_MD *type;
455 unsigned char *md;
456 unsigned int *len;
457         {
458         return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
459         }
460
461 int X509_NAME_digest(data,type,md,len)
462 X509_NAME *data;
463 EVP_MD *type;
464 unsigned char *md;
465 unsigned int *len;
466         {
467         return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
468         }
469
470 int PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len)
471 PKCS7_ISSUER_AND_SERIAL *data;
472 EVP_MD *type;
473 unsigned char *md;
474 unsigned int *len;
475         {
476         return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
477                 (char *)data,md,len));
478         }
479