8cdfe0fc9d27afbaf0399ec395bf11da2331f941
[openssl.git] / crypto / x509 / x509.h
1
2 /* crypto/x509/x509.h */
3 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
4  * All rights reserved.
5  *
6  * This package is an SSL implementation written
7  * by Eric Young (eay@cryptsoft.com).
8  * The implementation was written so as to conform with Netscapes SSL.
9  * 
10  * This library is free for commercial and non-commercial use as long as
11  * the following conditions are aheared to.  The following conditions
12  * apply to all code found in this distribution, be it the RC4, RSA,
13  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
14  * included with this distribution is covered by the same copyright terms
15  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16  * 
17  * Copyright remains Eric Young's, and as such any Copyright notices in
18  * the code are not to be removed.
19  * If this package is used in a product, Eric Young should be given attribution
20  * as the author of the parts of the library used.
21  * This can be in the form of a textual message at program startup or
22  * in documentation (online or textual) provided with the package.
23  * 
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the copyright
28  *    notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in the
31  *    documentation and/or other materials provided with the distribution.
32  * 3. All advertising materials mentioning features or use of this software
33  *    must display the following acknowledgement:
34  *    "This product includes cryptographic software written by
35  *     Eric Young (eay@cryptsoft.com)"
36  *    The word 'cryptographic' can be left out if the rouines from the library
37  *    being used are not cryptographic related :-).
38  * 4. If you include any Windows specific code (or a derivative thereof) from 
39  *    the apps directory (application code) you must include an acknowledgement:
40  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41  * 
42  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
43  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  * 
54  * The licence and distribution terms for any publically available version or
55  * derivative of this code cannot be changed.  i.e. this code cannot simply be
56  * copied and put under another distribution licence
57  * [including the GNU Public Licence.]
58  */
59
60 #ifndef HEADER_X509_H
61 #define HEADER_X509_H
62
63 #ifdef  __cplusplus
64 extern "C" {
65 #endif
66
67 #include "stack.h"
68 #include "asn1.h"
69
70 #ifndef NO_RSA
71 #include "rsa.h"
72 #else
73 #define RSA     long
74 #endif
75
76 #ifndef NO_DSA
77 #include "dsa.h"
78 #else
79 #define DSA     long
80 #endif
81
82 #ifndef NO_DH
83 #include "dh.h"
84 #else
85 #define DH      long
86 #endif
87
88 #include "evp.h"
89
90 #define X509_FILETYPE_PEM       1
91 #define X509_FILETYPE_ASN1      2
92 #define X509_FILETYPE_DEFAULT   3
93
94 #define X509v3_KU_DIGITAL_SIGNATURE     0x0080
95 #define X509v3_KU_NON_REPUDIATION       0x0040
96 #define X509v3_KU_KEY_ENCIPHERMENT      0x0020
97 #define X509v3_KU_DATA_ENCIPHERMENT     0x0010
98 #define X509v3_KU_KEY_AGREEMENT         0x0008
99 #define X509v3_KU_KEY_CERT_SIGN         0x0004
100 #define X509v3_KU_CRL_SIGN              0x0002
101 #define X509v3_KU_ENCIPHER_ONLY         0x0001
102 #define X509v3_KU_DECIPHER_ONLY         0x8000
103 #define X509v3_KU_UNDEF                 0xffff
104
105 typedef struct X509_objects_st
106         {
107         int nid;
108         int (*a2i)();
109         int (*i2a)();
110         } X509_OBJECTS;
111
112 typedef struct X509_algor_st
113         {
114         ASN1_OBJECT *algorithm;
115         ASN1_TYPE *parameter;
116         } X509_ALGOR;
117
118 typedef struct X509_val_st
119         {
120         ASN1_UTCTIME *notBefore;
121         ASN1_UTCTIME *notAfter;
122         } X509_VAL;
123
124 typedef struct X509_pubkey_st
125         {
126         X509_ALGOR *algor;
127         ASN1_BIT_STRING *public_key;
128         struct evp_pkey_st /* EVP_PKEY*/ *pkey;
129         } X509_PUBKEY;
130
131 typedef struct X509_sig_st
132         {
133         X509_ALGOR *algor;
134         ASN1_OCTET_STRING *digest;
135         } X509_SIG;
136
137 typedef struct X509_name_entry_st
138         {
139         ASN1_OBJECT *object;
140         ASN1_STRING *value;
141         int set;
142         int size;       /* temp variable */
143         } X509_NAME_ENTRY;
144
145 /* we always keep X509_NAMEs in 2 forms. */
146 typedef struct X509_name_st
147         {
148         STACK *entries; /* of X509_NAME_ENTRY */
149         int modified;   /* true if 'bytes' needs to be built */
150 #ifdef HEADER_BUFFER_H
151         BUF_MEM *bytes;
152 #else
153         char *bytes;
154 #endif
155         unsigned long hash; /* Keep the hash around for lookups */
156         } X509_NAME;
157
158 #define X509_EX_V_NETSCAPE_HACK         0x8000
159 #define X509_EX_V_INIT                  0x0001
160 typedef struct X509_extension_st
161         {
162         ASN1_OBJECT *object;
163         short critical;
164         short netscape_hack;
165         ASN1_OCTET_STRING *value;
166         long argl;                      /* used when decoding */
167         char *argp;                     /* used when decoding */
168         void (*ex_free)();              /* clear argp stuff */
169         } X509_EXTENSION;
170
171 /* #if 1 */
172 typedef struct x509_extension_method_st
173         {
174         int nid;
175         int data_type;
176         int pack_type;
177         void (*ex_clear)();
178         int (*ex_get_bool)();
179         int (*ex_set_bool)();
180         int (*ex_get_str)();
181         int (*ex_set_str)();
182         char *(*ex_get_struct)();
183         int (*ex_set_struct)();
184         int (*a2i)();
185         int (*i2a)();
186         } X509_EXTENSION_METHOD;
187 /* #endif */
188
189 typedef struct X509_req_info_st
190         {
191         ASN1_INTEGER *version;
192         X509_NAME *subject;
193         X509_PUBKEY *pubkey;
194         /*  d=2 hl=2 l=  0 cons: cont: 00 */
195         STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
196         int req_kludge;
197         } X509_REQ_INFO;
198
199 typedef struct X509_req_st
200         {
201         X509_REQ_INFO *req_info;
202         X509_ALGOR *sig_alg;
203         ASN1_BIT_STRING *signature;
204         int references;
205         } X509_REQ;
206
207 typedef struct x509_cinf_st
208         {
209         ASN1_INTEGER *version;          /* [ 0 ] default of v1 */
210         ASN1_INTEGER *serialNumber;
211         X509_ALGOR *signature;
212         X509_NAME *issuer;
213         X509_VAL *validity;
214         X509_NAME *subject;
215         X509_PUBKEY *key;
216         ASN1_BIT_STRING *issuerUID;             /* [ 1 ] optional in v2 */
217         ASN1_BIT_STRING *subjectUID;            /* [ 2 ] optional in v2 */
218         STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */
219         } X509_CINF;
220
221 typedef struct x509_st
222         {
223         X509_CINF *cert_info;
224         X509_ALGOR *sig_alg;
225         ASN1_BIT_STRING *signature;
226         int valid;
227         int references;
228         char *name;
229         } X509;
230
231 typedef struct X509_revoked_st
232         {
233         ASN1_INTEGER *serialNumber;
234         ASN1_UTCTIME *revocationDate;
235         STACK /* optional X509_EXTENSION */ *extensions;
236         int sequence; /* load sequence */
237         } X509_REVOKED;
238
239 typedef struct X509_crl_info_st
240         {
241         ASN1_INTEGER *version;
242         X509_ALGOR *sig_alg;
243         X509_NAME *issuer;
244         ASN1_UTCTIME *lastUpdate;
245         ASN1_UTCTIME *nextUpdate;
246         STACK /* X509_REVOKED */ *revoked;
247         STACK /* [0] X509_EXTENSION */ *extensions;
248         } X509_CRL_INFO;
249
250 typedef struct X509_crl_st
251         {
252         /* actual signature */
253         X509_CRL_INFO *crl;
254         X509_ALGOR *sig_alg;
255         ASN1_BIT_STRING *signature;
256         int references;
257         } X509_CRL;
258
259 /* a sequence of these are used */
260 typedef struct x509_attributes_st
261         {
262         ASN1_OBJECT *object;
263         int set; /* 1 for a set, 0 for a single item (which is wrong) */
264         union   {
265                 char            *ptr;
266 /* 1 */         STACK /* ASN1_TYPE */ *set;
267 /* 0 */         ASN1_TYPE       *single;
268                 } value;
269         } X509_ATTRIBUTE;
270
271 typedef struct private_key_st
272         {
273         int version;
274         /* The PKCS#8 data types */
275         X509_ALGOR *enc_algor;
276         ASN1_OCTET_STRING *enc_pkey;    /* encrypted pub key */
277
278         /* When decrypted, the following will not be NULL */
279         EVP_PKEY *dec_pkey;
280
281         /* used to encrypt and decrypt */
282         int key_length;
283         char *key_data;
284         int key_free;   /* true if we should auto free key_data */
285
286         /* expanded version of 'enc_algor' */
287         EVP_CIPHER_INFO cipher;
288
289         int references;
290         } X509_PKEY;
291
292 #ifdef HEADER_ENVELOPE_H
293 typedef struct X509_info_st
294         {
295         X509 *x509;
296         X509_CRL *crl;
297         X509_PKEY *x_pkey;
298
299         EVP_CIPHER_INFO enc_cipher;
300         int enc_len;
301         char *enc_data;
302
303         int references;
304         } X509_INFO;
305 #endif
306
307 /* The next 2 structures and their 8 routines were sent to me by
308  * Pat Richard <patr@x509.com> and are used to manipulate
309  * Netscapes spki strucutres - usefull if you are writing a CA web page
310  */
311 typedef struct Netscape_spkac_st
312         {
313         X509_PUBKEY *pubkey;
314         ASN1_IA5STRING *challenge;      /* challenge sent in atlas >= PR2 */
315         } NETSCAPE_SPKAC;
316
317 typedef struct Netscape_spki_st
318         {
319         NETSCAPE_SPKAC *spkac;  /* signed public key and challenge */
320         X509_ALGOR *sig_algor;
321         ASN1_BIT_STRING *signature;
322         } NETSCAPE_SPKI;
323
324 /* Netscape certificate sequence structure */
325 typedef struct Netscape_certificate_sequence
326         {
327         ASN1_OBJECT *type;
328         STACK /* X509 */ *certs;
329         } NETSCAPE_CERT_SEQUENCE;
330
331 #ifndef HEADER_BN_H
332 #define BIGNUM          char
333 #endif
334
335 typedef struct CBCParameter_st
336         {
337         unsigned char iv[8];
338         } CBC_PARAM;
339
340 /* Password based encryption structure */
341
342 typedef struct PBEPARAM_st {
343 ASN1_OCTET_STRING *salt;
344 ASN1_INTEGER *iter;
345 } PBEPARAM;
346
347 /* PKCS#8 private key info structure */
348
349 typedef struct pkcs8_priv_key_info_st
350         {
351         int broken;     /* Flag for various broken formats */
352 #define PKCS8_OK        0
353 #define PKCS8_NO_OCTET  1
354         ASN1_INTEGER *version;
355         X509_ALGOR *pkeyalg;
356         ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
357         STACK *attributes;
358         } PKCS8_PRIV_KEY_INFO;
359
360 #include "x509_vfy.h"
361 #include "pkcs7.h"
362
363 #ifdef SSLEAY_MACROS
364 #define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
365         a->signature,(char *)a->cert_info,r)
366 #define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
367         a->sig_alg,a->signature,(char *)a->req_info,r)
368 #define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
369         a->sig_alg, a->signature,(char *)a->crl,r)
370
371 #define X509_sign(x,pkey,md) \
372         ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
373                 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
374 #define X509_REQ_sign(x,pkey,md) \
375         ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
376                 x->signature, (char *)x->req_info,pkey,md)
377 #define X509_CRL_sign(x,pkey,md) \
378         ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
379                 x->signature, (char *)x->crl,pkey,md)
380 #define NETSCAPE_SPKI_sign(x,pkey,md) \
381         ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
382                 x->signature, (char *)x->spkac,pkey,md)
383
384 #define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
385                 (char *(*)())d2i_X509,(char *)x509)
386 #define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
387                 (int (*)())i2d_X509_ATTRIBUTE, \
388                 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
389 #define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
390                 (int (*)())i2d_X509_EXTENSION, \
391                 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
392 #define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
393                 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
394 #define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
395 #define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
396                 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
397 #define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
398
399 #define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
400                 (char *(*)())d2i_X509_CRL,(char *)crl)
401 #define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
402                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
403                 (unsigned char **)(crl))
404 #define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
405                 (unsigned char *)crl)
406 #define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
407                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
408                 (unsigned char **)(crl))
409 #define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
410                 (unsigned char *)crl)
411
412 #define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
413                 (char *(*)())d2i_PKCS7,(char *)p7)
414 #define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
415                 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
416                 (unsigned char **)(p7))
417 #define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
418                 (unsigned char *)p7)
419 #define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
420                 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
421                 (unsigned char **)(p7))
422 #define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
423                 (unsigned char *)p7)
424
425 #define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
426                 (char *(*)())d2i_X509_REQ,(char *)req)
427 #define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
428                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
429                 (unsigned char **)(req))
430 #define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
431                 (unsigned char *)req)
432 #define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
433                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
434                 (unsigned char **)(req))
435 #define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
436                 (unsigned char *)req)
437
438 #define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
439                 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
440 #define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
441                 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
442
443 #define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
444                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
445                 (unsigned char **)(rsa))
446 #define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
447                 (unsigned char *)rsa)
448 #define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
449                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
450                 (unsigned char **)(rsa))
451 #define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
452                 (unsigned char *)rsa)
453
454 #define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
455                 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
456                 (unsigned char **)(rsa))
457 #define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
458                 (unsigned char *)rsa)
459 #define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
460                 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
461                 (unsigned char **)(rsa))
462 #define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
463                 (unsigned char *)rsa)
464
465 #define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
466                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
467                 (unsigned char **)(dsa))
468 #define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
469                 (unsigned char *)dsa)
470 #define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
471                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
472                 (unsigned char **)(dsa))
473 #define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
474                 (unsigned char *)dsa)
475
476 #define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
477                 (char *(*)())d2i_X509_ALGOR,(char *)xn)
478
479 #define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
480                 (char *(*)())d2i_X509_NAME,(char *)xn)
481 #define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
482                 (int (*)())i2d_X509_NAME_ENTRY, \
483                 (char *(*)())d2i_X509_NAME_ENTRY,\
484                 (char *)ne)
485
486 #define X509_digest(data,type,md,len) \
487         ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
488 #define X509_NAME_digest(data,type,md,len) \
489         ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
490 #ifndef PKCS7_ISSUER_AND_SERIAL_digest
491 #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
492         ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
493                 (char *)data,md,len)
494 #endif
495 #endif
496
497 #define X509_EXT_PACK_UNKNOWN   1
498 #define X509_EXT_PACK_STRING    2
499
500 #define         X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
501 /* #define      X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
502 #define         X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
503 #define         X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
504 #define         X509_extract_key(x)     X509_get_pubkey(x) /*****/
505 #define         X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
506 #define         X509_REQ_get_subject_name(x) ((x)->req_info->subject)
507 #define         X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
508 #define         X509_name_cmp(a,b)      X509_NAME_cmp((a),(b))
509 #define         X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
510
511 #define         X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
512 #define         X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
513 #define         X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
514 #define         X509_CRL_get_issuer(x) ((x)->crl->issuer)
515 #define         X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
516
517 /* This one is only used so that a binary form can output, as in
518  * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
519 #define         X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
520
521 #ifndef NOPROTO
522
523 #ifndef SSLEAY_MACROS
524 #ifdef HEADER_ENVELOPE_H
525 int X509_verify(X509 *a, EVP_PKEY *r);
526 char *X509_verify_cert_error_string(long n);
527
528 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
529 int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
530 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
531
532 int X509_sign(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
533 int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, EVP_MD *md);
534 int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, EVP_MD *md);
535 int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, EVP_MD *md);
536
537 int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len);
538 int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
539         unsigned char *md,unsigned int *len);
540 #endif
541
542 #ifndef NO_FP_API
543 X509 *d2i_X509_fp(FILE *fp, X509 *x509);
544 int i2d_X509_fp(FILE *fp,X509 *x509);
545 X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL *crl);
546 int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
547 X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ *req);
548 int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
549 RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
550 int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
551 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
552 int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
553 RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA *rsa);
554 int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
555 #endif
556
557 #ifdef HEADER_BIO_H
558 X509 *d2i_X509_bio(BIO *bp,X509 *x509);
559 int i2d_X509_bio(BIO *bp,X509 *x509);
560 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL *crl);
561 int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
562 X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ *req);
563 int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
564 RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
565 int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
566 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
567 int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
568 RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA *rsa);
569 int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
570 #endif
571
572 X509 *X509_dup(X509 *x509);
573 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
574 X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
575 X509_CRL *X509_CRL_dup(X509_CRL *crl);
576 X509_REQ *X509_REQ_dup(X509_REQ *req);
577 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
578 X509_NAME *X509_NAME_dup(X509_NAME *xn);
579 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
580 RSA *RSAPublicKey_dup(RSA *rsa);
581 RSA *RSAPrivateKey_dup(RSA *rsa);
582
583 #endif /* !SSLEAY_MACROS */
584
585 int             X509_cmp_current_time(ASN1_UTCTIME *s);
586 ASN1_UTCTIME *  X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
587
588 char *          X509_get_default_cert_area(void );
589 char *          X509_get_default_cert_dir(void );
590 char *          X509_get_default_cert_file(void );
591 char *          X509_get_default_cert_dir_env(void );
592 char *          X509_get_default_cert_file_env(void );
593 char *          X509_get_default_private_dir(void );
594
595 X509_REQ *      X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
596 X509 *          X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
597 void ERR_load_X509_strings(void );
598
599 X509_ALGOR *    X509_ALGOR_new(void );
600 void            X509_ALGOR_free(X509_ALGOR *a);
601 int             i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
602 X509_ALGOR *    d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
603                         long length);
604
605 X509_VAL *      X509_VAL_new(void );
606 void            X509_VAL_free(X509_VAL *a);
607 int             i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
608 X509_VAL *      d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
609                         long length);
610
611 X509_PUBKEY *   X509_PUBKEY_new(void );
612 void            X509_PUBKEY_free(X509_PUBKEY *a);
613 int             i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
614 X509_PUBKEY *   d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
615                         long length);
616 int             X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
617 EVP_PKEY *      X509_PUBKEY_get(X509_PUBKEY *key);
618 int             X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain);
619
620
621 X509_SIG *      X509_SIG_new(void );
622 void            X509_SIG_free(X509_SIG *a);
623 int             i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
624 X509_SIG *      d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
625
626 X509_REQ_INFO *X509_REQ_INFO_new(void);
627 void            X509_REQ_INFO_free(X509_REQ_INFO *a);
628 int             i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
629 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
630                         long length);
631
632 X509_REQ *      X509_REQ_new(void);
633 void            X509_REQ_free(X509_REQ *a);
634 int             i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
635 X509_REQ *      d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
636
637 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
638 void            X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
639 int             i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
640 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
641                         long length);
642 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, char *value);
643
644
645 X509_EXTENSION *X509_EXTENSION_new(void );
646 void            X509_EXTENSION_free(X509_EXTENSION *a);
647 int             i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
648 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
649                         long length);
650
651 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
652 void            X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
653 int             i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
654 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
655                         long length);
656
657 X509_NAME *     X509_NAME_new(void);
658 void            X509_NAME_free(X509_NAME *a);
659 int             i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
660 X509_NAME *     d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
661 int             X509_NAME_set(X509_NAME **xn, X509_NAME *name);
662
663
664 X509_CINF *     X509_CINF_new(void);
665 void            X509_CINF_free(X509_CINF *a);
666 int             i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
667 X509_CINF *     d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
668
669 X509 *          X509_new(void);
670 void            X509_free(X509 *a);
671 int             i2d_X509(X509 *a,unsigned char **pp);
672 X509 *          d2i_X509(X509 **a,unsigned char **pp,long length);
673
674 X509_REVOKED *  X509_REVOKED_new(void);
675 void            X509_REVOKED_free(X509_REVOKED *a);
676 int             i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
677 X509_REVOKED *  d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
678
679 X509_CRL_INFO *X509_CRL_INFO_new(void);
680 void            X509_CRL_INFO_free(X509_CRL_INFO *a);
681 int             i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
682 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
683                         long length);
684
685 X509_CRL *      X509_CRL_new(void);
686 void            X509_CRL_free(X509_CRL *a);
687 int             i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
688 X509_CRL *      d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
689
690 X509_PKEY *     X509_PKEY_new(void );
691 void            X509_PKEY_free(X509_PKEY *a);
692 int             i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
693 X509_PKEY *     d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
694
695 NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
696 void            NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
697 int             i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
698 NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
699                         long length);
700
701 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
702 void            NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
703 int             i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
704 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
705                 long length);
706
707
708 int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
709 NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
710 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
711 void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
712
713 #ifdef HEADER_ENVELOPE_H
714 X509_INFO *     X509_INFO_new(void);
715 void            X509_INFO_free(X509_INFO *a);
716 char *          X509_NAME_oneline(X509_NAME *a,char *buf,int size);
717
718 int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
719         ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
720
721 int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
722         unsigned char *md,unsigned int *len);
723
724 int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
725         ASN1_BIT_STRING *signature,
726         char *data,EVP_PKEY *pkey, EVP_MD *type);
727 #endif
728
729 int             X509_set_version(X509 *x,long version);
730 int             X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
731 ASN1_INTEGER *  X509_get_serialNumber(X509 *x);
732 int             X509_set_issuer_name(X509 *x, X509_NAME *name);
733 X509_NAME *     X509_get_issuer_name(X509 *a);
734 int             X509_set_subject_name(X509 *x, X509_NAME *name);
735 X509_NAME *     X509_get_subject_name(X509 *a);
736 int             X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
737 int             X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
738 int             X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
739 EVP_PKEY *      X509_get_pubkey(X509 *x);
740 int             X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
741
742 int             X509_REQ_set_version(X509_REQ *x,long version);
743 int             X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
744 int             X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
745 EVP_PKEY *      X509_REQ_get_pubkey(X509_REQ *req);
746
747 int             X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
748
749 int             X509_issuer_and_serial_cmp(X509 *a, X509 *b);
750 unsigned long   X509_issuer_and_serial_hash(X509 *a);
751
752 int             X509_issuer_name_cmp(X509 *a, X509 *b);
753 unsigned long   X509_issuer_name_hash(X509 *a);
754
755 int             X509_subject_name_cmp(X509 *a,X509 *b);
756 unsigned long   X509_subject_name_hash(X509 *x);
757
758 int             X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
759 unsigned long   X509_NAME_hash(X509_NAME *x);
760
761 int             X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
762 #ifndef NO_FP_API
763 int             X509_print_fp(FILE *bp,X509 *x);
764 int             X509_CRL_print_fp(FILE *bp,X509_CRL *x);
765 int             X509_REQ_print_fp(FILE *bp,X509_REQ *req);
766 #endif
767
768 #ifdef HEADER_BIO_H
769 int             X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
770 int             X509_print(BIO *bp,X509 *x);
771 int             X509_CRL_print(BIO *bp,X509_CRL *x);
772 int             X509_REQ_print(BIO *bp,X509_REQ *req);
773 #endif
774
775 int             X509_NAME_entry_count(X509_NAME *name);
776 int             X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
777                         char *buf,int len);
778 int             X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
779                         char *buf,int len);
780
781 /* NOTE: you should be passsing -1, not 0 as lastpos.  The functions that use
782  * lastpos, seach after that position on. */
783 int             X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
784 int             X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
785                         int lastpos);
786 X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
787 X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
788 int             X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
789                         int loc, int set);
790 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
791                         int type,unsigned char *bytes, int len);
792 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
793                         ASN1_OBJECT *obj, int type,unsigned char *bytes,
794                         int len);
795 int             X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
796                         ASN1_OBJECT *obj);
797 int             X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
798                         unsigned char *bytes, int len);
799 ASN1_OBJECT *   X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
800 ASN1_STRING *   X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
801
802 int             X509v3_get_ext_count(STACK *x);
803 int             X509v3_get_ext_by_NID(STACK *x, int nid, int lastpos);
804 int             X509v3_get_ext_by_OBJ(STACK *x,ASN1_OBJECT *obj,int lastpos);
805 int             X509v3_get_ext_by_critical(STACK *x, int crit, int lastpos);
806 X509_EXTENSION *X509v3_get_ext(STACK *x, int loc);
807 X509_EXTENSION *X509v3_delete_ext(STACK *x, int loc);
808 STACK *         X509v3_add_ext(STACK **x, X509_EXTENSION *ex, int loc);
809
810 int             X509v3_data_type_by_OBJ(ASN1_OBJECT *obj);
811 int             X509v3_data_type_by_NID(int nid);
812 int             X509v3_pack_type_by_OBJ(ASN1_OBJECT *obj);
813 int             X509v3_pack_type_by_NID(int nid);
814
815 int             X509_get_ext_count(X509 *x);
816 int             X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
817 int             X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
818 int             X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
819 X509_EXTENSION *X509_get_ext(X509 *x, int loc);
820 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
821 int             X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
822
823 int             X509_CRL_get_ext_count(X509_CRL *x);
824 int             X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
825 int             X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
826 int             X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
827 X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
828 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
829 int             X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
830
831 int             X509_REVOKED_get_ext_count(X509_REVOKED *x);
832 int             X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
833 int             X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
834 int             X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
835 X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
836 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
837 int             X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
838
839 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
840                         int nid, int crit, ASN1_OCTET_STRING *data);
841 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
842                         ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
843 int             X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
844 int             X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
845 int             X509_EXTENSION_set_data(X509_EXTENSION *ex,
846                         ASN1_OCTET_STRING *data);
847 ASN1_OBJECT *   X509_EXTENSION_get_object(X509_EXTENSION *ex);
848 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
849 int             X509_EXTENSION_get_critical(X509_EXTENSION *ex);
850 ASN1_OCTET_STRING *X509v3_pack_string(ASN1_OCTET_STRING **ex,int type,
851                         unsigned char *bytes, int len);
852 ASN1_STRING *   X509v3_unpack_string(ASN1_STRING **ex,int type,
853                         ASN1_OCTET_STRING *os);
854
855 int             X509_verify_cert(X509_STORE_CTX *ctx);
856
857 /* lookup a cert from a X509 STACK */
858 X509 *X509_find_by_issuer_and_serial(STACK *sk,X509_NAME *name,
859                 ASN1_INTEGER *serial);
860 X509 *X509_find_by_subject(STACK *sk,X509_NAME *name);
861
862 int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
863 PBEPARAM *PBEPARAM_new(void);
864 PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
865 void PBEPARAM_free(PBEPARAM *a);
866 X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
867
868 /* PKCS#8 utilities */
869
870 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
871 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
872 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
873                                          unsigned char **pp, long length);
874 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
875
876 EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
877 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
878 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
879
880 /* Password based encryption routines */
881
882 int EVP_PBE_ALGOR_CipherInit(X509_ALGOR *algor, unsigned char *pass,
883                                  int passlen, EVP_CIPHER_CTX *ctx, int en_de);
884 int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
885                                                  EVP_PBE_KEYGEN *keygen);
886
887 #else
888
889 #ifndef SSLEAY_MACROS
890 #ifdef HEADER_ENVELOPE_H
891 int X509_verify();
892 int X509_REQ_verify();
893 int X509_CRL_verify();
894 int NETSCAPE_SPKI_verify();
895
896 int X509_sign();
897 int X509_REQ_sign();
898 int X509_CRL_sign();
899 int NETSCAPE_SPKI_sign();
900
901 int X509_digest();
902 int X509_NAME_digest();
903 #endif
904
905 #ifndef NO_FP_API
906 X509 *d2i_X509_fp();
907 int i2d_X509_fp();
908 X509_CRL *d2i_X509_CRL_fp();
909 int i2d_X509_CRL_fp();
910 X509_REQ *d2i_X509_REQ_fp();
911 int i2d_X509_REQ_fp();
912 RSA *d2i_RSAPrivateKey_fp();
913 int i2d_RSAPrivateKey_fp();
914 DSA *d2i_DSAPrivateKey_fp();
915 int i2d_DSAPrivateKey_fp();
916 RSA *d2i_RSAPublicKey_fp();
917 int i2d_RSAPublicKey_fp();
918 #endif
919
920 X509 *d2i_X509_bio();
921 int i2d_X509_bio();
922 X509_CRL *d2i_X509_CRL_bio();
923 int i2d_X509_CRL_bio();
924 X509_REQ *d2i_X509_REQ_bio();
925 int i2d_X509_REQ_bio();
926 RSA *d2i_RSAPrivateKey_bio();
927 int i2d_RSAPrivateKey_bio();
928 DSA *d2i_DSAPrivateKey_bio();
929 int i2d_DSAPrivateKey_bio();
930 RSA *d2i_RSAPublicKey_bio();
931 int i2d_RSAPublicKey_bio();
932
933 X509 *X509_dup();
934 X509_ATTRIBUTE *X509_ATTRIBUTE_dup();
935 X509_EXTENSION *X509_EXTENSION_dup();
936 X509_CRL *X509_CRL_dup();
937 X509_REQ *X509_REQ_dup();
938 X509_NAME *X509_NAME_dup();
939 X509_NAME_ENTRY *X509_NAME_ENTRY_dup();
940 RSA *RSAPublicKey_dup();
941 RSA *RSAPrivateKey_dup();
942
943 #endif /* !SSLEAY_MACROS */
944
945 int             X509_cmp_current_time();
946 ASN1_UTCTIME *  X509_gmtime_adj();
947
948 char *          X509_get_default_cert_area();
949 char *          X509_get_default_cert_dir();
950 char *          X509_get_default_cert_file();
951 char *          X509_get_default_cert_dir_env();
952 char *          X509_get_default_cert_file_env();
953 char *          X509_get_default_private_dir();
954
955 X509_REQ *      X509_to_X509_REQ();
956 X509 *          X509_REQ_to_X509();
957 void ERR_load_X509_strings();
958
959 X509_ALGOR *    X509_ALGOR_new();
960 void            X509_ALGOR_free();
961 int             i2d_X509_ALGOR();
962 X509_ALGOR *    d2i_X509_ALGOR();
963
964 X509_VAL *      X509_VAL_new();
965 void            X509_VAL_free();
966 int             i2d_X509_VAL();
967 X509_VAL *      d2i_X509_VAL();
968
969 X509_PUBKEY *   X509_PUBKEY_new();
970 void            X509_PUBKEY_free();
971 int             i2d_X509_PUBKEY();
972 X509_PUBKEY *   d2i_X509_PUBKEY();
973 int             X509_PUBKEY_set();
974 EVP_PKEY *      X509_PUBKEY_get();
975 int             X509_get_pubkey_parameters();
976
977 X509_SIG *      X509_SIG_new();
978 void            X509_SIG_free();
979 int             i2d_X509_SIG();
980 X509_SIG *      d2i_X509_SIG();
981
982 X509_REQ_INFO *X509_REQ_INFO_new();
983 void            X509_REQ_INFO_free();
984 int             i2d_X509_REQ_INFO();
985 X509_REQ_INFO *d2i_X509_REQ_INFO();
986
987 X509_REQ *      X509_REQ_new();
988 void            X509_REQ_free();
989 int             i2d_X509_REQ();
990 X509_REQ *      d2i_X509_REQ();
991
992 X509_ATTRIBUTE *X509_ATTRIBUTE_new();
993 void            X509_ATTRIBUTE_free();
994 int             i2d_X509_ATTRIBUTE();
995 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE();
996 X509_ATTRIBUTE *X509_ATTRIBUTE_create();
997
998 X509_EXTENSION *X509_EXTENSION_new();
999 void            X509_EXTENSION_free();
1000 int             i2d_X509_EXTENSION();
1001 X509_EXTENSION *d2i_X509_EXTENSION();
1002
1003 X509_NAME_ENTRY *X509_NAME_ENTRY_new();
1004 void            X509_NAME_ENTRY_free();
1005 int             i2d_X509_NAME_ENTRY();
1006 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY();
1007
1008 X509_NAME *     X509_NAME_new();
1009 void            X509_NAME_free();
1010 int             i2d_X509_NAME();
1011 X509_NAME *     d2i_X509_NAME();
1012 int             X509_NAME_set();
1013
1014
1015 X509_CINF *     X509_CINF_new();
1016 void            X509_CINF_free();
1017 int             i2d_X509_CINF();
1018 X509_CINF *     d2i_X509_CINF();
1019
1020 X509 *          X509_new();
1021 void            X509_free();
1022 int             i2d_X509();
1023 X509 *          d2i_X509();
1024
1025 X509_REVOKED *  X509_REVOKED_new();
1026 void            X509_REVOKED_free();
1027 int             i2d_X509_REVOKED();
1028 X509_REVOKED *  d2i_X509_REVOKED();
1029
1030 X509_CRL_INFO *X509_CRL_INFO_new();
1031 void            X509_CRL_INFO_free();
1032 int             i2d_X509_CRL_INFO();
1033 X509_CRL_INFO *d2i_X509_CRL_INFO();
1034
1035 X509_CRL *      X509_CRL_new();
1036 void            X509_CRL_free();
1037 int             i2d_X509_CRL();
1038 X509_CRL *      d2i_X509_CRL();
1039
1040 X509_PKEY *     X509_PKEY_new();
1041 void            X509_PKEY_free();
1042 int             i2d_X509_PKEY();
1043 X509_PKEY *     d2i_X509_PKEY();
1044
1045 NETSCAPE_SPKI * NETSCAPE_SPKI_new();
1046 void            NETSCAPE_SPKI_free();
1047 int             i2d_NETSCAPE_SPKI();
1048 NETSCAPE_SPKI * d2i_NETSCAPE_SPKI();
1049
1050 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new();
1051 void            NETSCAPE_SPKAC_free();
1052 int             i2d_NETSCAPE_SPKAC();
1053 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC();
1054
1055 int i2d_NETSCAPE_CERT_SEQUENCE();
1056 NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new();
1057 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE();
1058 void NETSCAPE_CERT_SEQUENCE_free();
1059
1060 #ifdef HEADER_ENVELOPE_H
1061 X509_INFO *     X509_INFO_new();
1062 void            X509_INFO_free();
1063 #endif
1064
1065 char *          X509_NAME_oneline();
1066
1067 int ASN1_verify();
1068 int ASN1_digest();
1069 int ASN1_sign();
1070
1071 int             X509_set_version();
1072 int             X509_set_serialNumber();
1073 ASN1_INTEGER *  X509_get_serialNumber();
1074 int             X509_set_issuer_name();
1075 X509_NAME *     X509_get_issuer_name();
1076 int             X509_set_subject_name();
1077 X509_NAME *     X509_get_subject_name();
1078 int             X509_set_notBefore();
1079 int             X509_set_notAfter();
1080 int             X509_set_pubkey();
1081 EVP_PKEY *      X509_get_pubkey();
1082 int             X509_certificate_type();
1083
1084 int             X509_REQ_set_version();
1085 int             X509_REQ_set_subject_name();
1086 int             X509_REQ_set_pubkey();
1087 EVP_PKEY *      X509_REQ_get_pubkey();
1088
1089 int             X509_check_private_key();
1090
1091 int             X509_issuer_and_serial_cmp();
1092 unsigned long   X509_issuer_and_serial_hash();
1093
1094 int             X509_issuer_name_cmp();
1095 unsigned long   X509_issuer_name_hash();
1096
1097 int             X509_subject_name_cmp();
1098 unsigned long   X509_subject_name_hash();
1099
1100 int             X509_NAME_cmp ();
1101 unsigned long   X509_NAME_hash();
1102
1103 int             X509_CRL_cmp();
1104 #ifndef NO_FP_API
1105 int             X509_print_fp();
1106 int             X509_CRL_print_fp();
1107 int             X509_REQ_print_fp();
1108 #endif
1109
1110 int             X509_NAME_print();
1111 int             X509_print();
1112 int             X509_CRL_print();
1113 int             X509_REQ_print();
1114
1115 int             X509_NAME_entry_count();
1116 int             X509_NAME_get_text_by_NID();
1117 int             X509_NAME_get_text_by_OBJ();
1118
1119 int             X509_NAME_get_index_by_NID();
1120 int             X509_NAME_get_index_by_OBJ();
1121 X509_NAME_ENTRY *X509_NAME_get_entry();
1122 X509_NAME_ENTRY *X509_NAME_delete_entry();
1123 int             X509_NAME_add_entry();
1124 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID();
1125 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ();
1126 int             X509_NAME_ENTRY_set_object();
1127 int             X509_NAME_ENTRY_set_data();
1128 ASN1_OBJECT *   X509_NAME_ENTRY_get_object();
1129 ASN1_STRING *   X509_NAME_ENTRY_get_data();
1130
1131 int             X509v3_get_ext_count();
1132 int             X509v3_get_ext_by_NID();
1133 int             X509v3_get_ext_by_OBJ();
1134 int             X509v3_get_ext_by_critical();
1135 X509_EXTENSION *X509v3_get_ext();
1136 X509_EXTENSION *X509v3_delete_ext();
1137 STACK *         X509v3_add_ext();
1138
1139 int             X509v3_data_type_by_OBJ();
1140 int             X509v3_data_type_by_NID();
1141 int             X509v3_pack_type_by_OBJ();
1142 int             X509v3_pack_type_by_NID();
1143
1144 int             X509_get_ext_count();
1145 int             X509_get_ext_by_NID();
1146 int             X509_get_ext_by_OBJ();
1147 int             X509_get_ext_by_critical();
1148 X509_EXTENSION *X509_get_ext();
1149 X509_EXTENSION *X509_delete_ext();
1150 int             X509_add_ext();
1151
1152 int             X509_CRL_get_ext_count();
1153 int             X509_CRL_get_ext_by_NID();
1154 int             X509_CRL_get_ext_by_OBJ();
1155 int             X509_CRL_get_ext_by_critical();
1156 X509_EXTENSION *X509_CRL_get_ext();
1157 X509_EXTENSION *X509_CRL_delete_ext();
1158 int             X509_CRL_add_ext();
1159
1160 int             X509_REVOKED_get_ext_count();
1161 int             X509_REVOKED_get_ext_by_NID();
1162 int             X509_REVOKED_get_ext_by_OBJ();
1163 int             X509_REVOKED_get_ext_by_critical();
1164 X509_EXTENSION *X509_REVOKED_get_ext();
1165 X509_EXTENSION *X509_REVOKED_delete_ext();
1166 int             X509_REVOKED_add_ext();
1167
1168 X509_EXTENSION *X509_EXTENSION_create_by_NID();
1169 X509_EXTENSION *X509_EXTENSION_create_by_OBJ();
1170 int             X509_EXTENSION_set_object();
1171 int             X509_EXTENSION_set_critical();
1172 int             X509_EXTENSION_set_data();
1173 ASN1_OBJECT *   X509_EXTENSION_get_object();
1174 ASN1_OCTET_STRING *X509_EXTENSION_get_data();
1175 int             X509_EXTENSION_get_critical();
1176 ASN1_OCTET_STRING *X509v3_pack_string();
1177 ASN1_STRING *   X509v3_unpack_string();
1178
1179 int             X509_verify_cert();
1180 char *          X509_verify_cert_error_string();
1181
1182 /* lookup a cert from a X509 STACK */
1183 X509 *X509_find_by_issuer_and_serial();
1184 X509 *X509_find_by_subject();
1185
1186 int i2d_PBEPARAM();
1187 PBEPARAM *PBEPARAM_new();
1188 PBEPARAM *d2i_PBEPARAM();
1189 void PBEPARAM_free();
1190
1191 int i2d_PKCS8_PRIV_KEY_INFO();
1192 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new();
1193 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO();
1194 void PKCS8_PRIV_KEY_INFO_free();
1195
1196 EVP_PKEY *EVP_PKCS82PKEY();
1197 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8();
1198 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken();
1199
1200 int EVP_PBE_ALGOR_CipherInit();
1201 int EVP_PBE_alg_add();
1202 X509_ALGOR *PKCS5_pbe_set();
1203
1204 #endif
1205
1206 /* BEGIN ERROR CODES */
1207 /* Error codes for the X509 functions. */
1208
1209 /* Function codes. */
1210 #define X509_F_ADD_CERT_DIR                              100
1211 #define X509_F_BY_FILE_CTRL                              101
1212 #define X509_F_DIR_CTRL                                  102
1213 #define X509_F_GET_CERT_BY_SUBJECT                       103
1214 #define X509_F_X509V3_ADD_EXT                            104
1215 #define X509_F_X509V3_ADD_EXTENSION                      105
1216 #define X509_F_X509V3_PACK_STRING                        106
1217 #define X509_F_X509V3_UNPACK_STRING                      107
1218 #define X509_F_X509_CHECK_PRIVATE_KEY                    128
1219 #define X509_F_X509_EXTENSION_CREATE_BY_NID              108
1220 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ              109
1221 #define X509_F_X509_GET_PUBKEY_PARAMETERS                110
1222 #define X509_F_X509_LOAD_CERT_FILE                       111
1223 #define X509_F_X509_LOAD_CRL_FILE                        112
1224 #define X509_F_X509_NAME_ADD_ENTRY                       113
1225 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID             114
1226 #define X509_F_X509_NAME_ENTRY_SET_OBJECT                115
1227 #define X509_F_X509_NAME_ONELINE                         116
1228 #define X509_F_X509_NAME_PRINT                           117
1229 #define X509_F_X509_PRINT_FP                             118
1230 #define X509_F_X509_PUBKEY_GET                           119
1231 #define X509_F_X509_PUBKEY_SET                           120
1232 #define X509_F_X509_REQ_PRINT                            121
1233 #define X509_F_X509_REQ_PRINT_FP                         122
1234 #define X509_F_X509_REQ_TO_X509                          123
1235 #define X509_F_X509_STORE_ADD_CERT                       124
1236 #define X509_F_X509_STORE_ADD_CRL                        125
1237 #define X509_F_X509_TO_X509_REQ                          126
1238 #define X509_F_X509_VERIFY_CERT                          127
1239
1240 /* Reason codes. */
1241 #define X509_R_BAD_X509_FILETYPE                         100
1242 #define X509_R_CANT_CHECK_DH_KEY                         114
1243 #define X509_R_CERT_ALREADY_IN_HASH_TABLE                101
1244 #define X509_R_ERR_ASN1_LIB                              102
1245 #define X509_R_INVALID_DIRECTORY                         113
1246 #define X509_R_KEY_TYPE_MISMATCH                         115
1247 #define X509_R_KEY_VALUES_MISMATCH                       116
1248 #define X509_R_LOADING_CERT_DIR                          103
1249 #define X509_R_LOADING_DEFAULTS                          104
1250 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY              105
1251 #define X509_R_SHOULD_RETRY                              106
1252 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN        107
1253 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY            108
1254 #define X509_R_UNKNOWN_KEY_TYPE                          117
1255 #define X509_R_UNKNOWN_NID                               109
1256 #define X509_R_UNKNOWN_STRING_TYPE                       110
1257 #define X509_R_UNSUPPORTED_ALGORITHM                     111
1258 #define X509_R_WRONG_LOOKUP_TYPE                         112
1259  
1260 #ifdef  __cplusplus
1261 }
1262 #endif
1263 #endif
1264