"make update" + stripping the type-specific stack functions out of
[openssl.git] / crypto / x509 / x509.h
1 /* crypto/x509/x509.h */
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 #ifndef HEADER_X509_H
60 #define HEADER_X509_H
61
62 #ifdef VMS
63 #undef X509_REVOKED_get_ext_by_critical
64 #define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
65 #endif
66
67 #include <openssl/stack.h>
68 #include <openssl/asn1.h>
69 #include <openssl/safestack.h>
70
71 #ifndef NO_RSA
72 #include <openssl/rsa.h>
73 #endif
74
75 #ifndef NO_DSA
76 #include <openssl/dsa.h>
77 #endif
78
79 #ifndef NO_DH
80 #include <openssl/dh.h>
81 #endif
82
83 #include <openssl/evp.h>
84
85
86 #ifdef  __cplusplus
87 extern "C" {
88 #endif
89
90 #ifdef WIN32
91 /* Under Win32 this is defined in wincrypt.h */
92 #undef X509_NAME
93 #endif
94
95   /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
96 #define DECLARE_PKCS12_STACK_OF(type) \
97 STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \
98                                           type *(*d2i)(type **, \
99                                                        unsigned char **, \
100                                                        long), \
101                                           void (*free_func)(type *), \
102                                           const char *pass, int passlen, \
103                                           ASN1_STRING *oct, int seq);
104
105 #define IMPLEMENT_PKCS12_STACK_OF(type) \
106 STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \
107                                           type *(*d2i)(type **, \
108                                                        unsigned char **, \
109                                                        long), \
110                                           void (*free_func)(type *), \
111                                           const char *pass, int passlen, \
112                                           ASN1_STRING *oct, int seq) \
113     { return (STACK_OF(type) *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i, \
114                                                   (void(*)(void *))free_func, \
115                                                   pass,passlen,oct,seq); }
116
117 #define X509_FILETYPE_PEM       1
118 #define X509_FILETYPE_ASN1      2
119 #define X509_FILETYPE_DEFAULT   3
120
121 #define X509v3_KU_DIGITAL_SIGNATURE     0x0080
122 #define X509v3_KU_NON_REPUDIATION       0x0040
123 #define X509v3_KU_KEY_ENCIPHERMENT      0x0020
124 #define X509v3_KU_DATA_ENCIPHERMENT     0x0010
125 #define X509v3_KU_KEY_AGREEMENT         0x0008
126 #define X509v3_KU_KEY_CERT_SIGN         0x0004
127 #define X509v3_KU_CRL_SIGN              0x0002
128 #define X509v3_KU_ENCIPHER_ONLY         0x0001
129 #define X509v3_KU_DECIPHER_ONLY         0x8000
130 #define X509v3_KU_UNDEF                 0xffff
131
132 typedef struct X509_objects_st
133         {
134         int nid;
135         int (*a2i)();
136         int (*i2a)();
137         } X509_OBJECTS;
138
139 typedef struct X509_algor_st
140         {
141         ASN1_OBJECT *algorithm;
142         ASN1_TYPE *parameter;
143         } X509_ALGOR;
144
145 DECLARE_STACK_OF(X509_ALGOR)
146 /* This block of defines is updated by a perl script, please do not touch! */
147 #ifndef DEBUG_SAFESTACK
148         #define sk_X509_ALGOR_new(a) sk_new((int (*) \
149                 (const char * const *, const char * const *))(a))
150         #define sk_X509_ALGOR_new_null() sk_new_null()
151         #define sk_X509_ALGOR_free(a) sk_free(a)
152         #define sk_X509_ALGOR_num(a) sk_num(a)
153         #define sk_X509_ALGOR_value(a,b) ((X509_ALGOR *) \
154                 sk_value((a),(b)))
155         #define sk_X509_ALGOR_set(a,b,c) ((X509_ALGOR *) \
156                 sk_set((a),(b),(char *)(c)))
157         #define sk_X509_ALGOR_zero(a) sk_zero(a)
158         #define sk_X509_ALGOR_push(a,b) sk_push((a),(char *)(b))
159         #define sk_X509_ALGOR_unshift(a,b) sk_unshift((a),(b))
160         #define sk_X509_ALGOR_find(a,b) sk_find((a), (char *)(b))
161         #define sk_X509_ALGOR_delete(a,b) ((X509_ALGOR *) \
162                 sk_delete((a),(b)))
163         #define sk_X509_ALGOR_delete_ptr(a,b) ((X509_ALGOR *) \
164                 sk_delete_ptr((a),(char *)(b)))
165         #define sk_X509_ALGOR_insert(a,b,c) sk_insert((a),(char *)(b),(c))
166         #define sk_X509_ALGOR_set_cmp_func(a,b) ((int (*) \
167                 (const X509_ALGOR * const *,const X509_ALGOR * const *)) \
168                 sk_set_cmp_func((a),(int (*) \
169                 (const char * const *, const char * const *))(b)))
170         #define sk_X509_ALGOR_dup(a) sk_dup(a)
171         #define sk_X509_ALGOR_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
172         #define sk_X509_ALGOR_shift(a) ((X509_ALGOR *)sk_shift(a))
173         #define sk_X509_ALGOR_pop(a) ((X509_ALGOR *)sk_pop(a))
174         #define sk_X509_ALGOR_sort(a) sk_sort(a)
175 #endif /* !DEBUG_SAFESTACK */
176 /* End of perl script block, you may now edit :-) */
177 DECLARE_ASN1_SET_OF(X509_ALGOR)
178
179 typedef struct X509_val_st
180         {
181         ASN1_UTCTIME *notBefore;
182         ASN1_UTCTIME *notAfter;
183         } X509_VAL;
184
185 typedef struct X509_pubkey_st
186         {
187         X509_ALGOR *algor;
188         ASN1_BIT_STRING *public_key;
189         EVP_PKEY *pkey;
190         } X509_PUBKEY;
191
192 typedef struct X509_sig_st
193         {
194         X509_ALGOR *algor;
195         ASN1_OCTET_STRING *digest;
196         } X509_SIG;
197
198 typedef struct X509_name_entry_st
199         {
200         ASN1_OBJECT *object;
201         ASN1_STRING *value;
202         int set;
203         int size;       /* temp variable */
204         } X509_NAME_ENTRY;
205
206 DECLARE_STACK_OF(X509_NAME_ENTRY)
207 /* This block of defines is updated by a perl script, please do not touch! */
208 #ifndef DEBUG_SAFESTACK
209         #define sk_X509_NAME_ENTRY_new(a) sk_new((int (*) \
210                 (const char * const *, const char * const *))(a))
211         #define sk_X509_NAME_ENTRY_new_null() sk_new_null()
212         #define sk_X509_NAME_ENTRY_free(a) sk_free(a)
213         #define sk_X509_NAME_ENTRY_num(a) sk_num(a)
214         #define sk_X509_NAME_ENTRY_value(a,b) ((X509_NAME_ENTRY *) \
215                 sk_value((a),(b)))
216         #define sk_X509_NAME_ENTRY_set(a,b,c) ((X509_NAME_ENTRY *) \
217                 sk_set((a),(b),(char *)(c)))
218         #define sk_X509_NAME_ENTRY_zero(a) sk_zero(a)
219         #define sk_X509_NAME_ENTRY_push(a,b) sk_push((a),(char *)(b))
220         #define sk_X509_NAME_ENTRY_unshift(a,b) sk_unshift((a),(b))
221         #define sk_X509_NAME_ENTRY_find(a,b) sk_find((a), (char *)(b))
222         #define sk_X509_NAME_ENTRY_delete(a,b) ((X509_NAME_ENTRY *) \
223                 sk_delete((a),(b)))
224         #define sk_X509_NAME_ENTRY_delete_ptr(a,b) ((X509_NAME_ENTRY *) \
225                 sk_delete_ptr((a),(char *)(b)))
226         #define sk_X509_NAME_ENTRY_insert(a,b,c) sk_insert((a),(char *)(b),(c))
227         #define sk_X509_NAME_ENTRY_set_cmp_func(a,b) ((int (*) \
228                 (const X509_NAME_ENTRY * const *,const X509_NAME_ENTRY * const *)) \
229                 sk_set_cmp_func((a),(int (*) \
230                 (const char * const *, const char * const *))(b)))
231         #define sk_X509_NAME_ENTRY_dup(a) sk_dup(a)
232         #define sk_X509_NAME_ENTRY_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
233         #define sk_X509_NAME_ENTRY_shift(a) ((X509_NAME_ENTRY *)sk_shift(a))
234         #define sk_X509_NAME_ENTRY_pop(a) ((X509_NAME_ENTRY *)sk_pop(a))
235         #define sk_X509_NAME_ENTRY_sort(a) sk_sort(a)
236 #endif /* !DEBUG_SAFESTACK */
237 /* End of perl script block, you may now edit :-) */
238 DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
239
240 /* we always keep X509_NAMEs in 2 forms. */
241 typedef struct X509_name_st
242         {
243         STACK_OF(X509_NAME_ENTRY) *entries;
244         int modified;   /* true if 'bytes' needs to be built */
245 #ifdef HEADER_BUFFER_H
246         BUF_MEM *bytes;
247 #else
248         char *bytes;
249 #endif
250         unsigned long hash; /* Keep the hash around for lookups */
251         } X509_NAME;
252
253 DECLARE_STACK_OF(X509_NAME)
254 /* This block of defines is updated by a perl script, please do not touch! */
255 #ifndef DEBUG_SAFESTACK
256         #define sk_X509_NAME_new(a) sk_new((int (*) \
257                 (const char * const *, const char * const *))(a))
258         #define sk_X509_NAME_new_null() sk_new_null()
259         #define sk_X509_NAME_free(a) sk_free(a)
260         #define sk_X509_NAME_num(a) sk_num(a)
261         #define sk_X509_NAME_value(a,b) ((X509_NAME *) \
262                 sk_value((a),(b)))
263         #define sk_X509_NAME_set(a,b,c) ((X509_NAME *) \
264                 sk_set((a),(b),(char *)(c)))
265         #define sk_X509_NAME_zero(a) sk_zero(a)
266         #define sk_X509_NAME_push(a,b) sk_push((a),(char *)(b))
267         #define sk_X509_NAME_unshift(a,b) sk_unshift((a),(b))
268         #define sk_X509_NAME_find(a,b) sk_find((a), (char *)(b))
269         #define sk_X509_NAME_delete(a,b) ((X509_NAME *) \
270                 sk_delete((a),(b)))
271         #define sk_X509_NAME_delete_ptr(a,b) ((X509_NAME *) \
272                 sk_delete_ptr((a),(char *)(b)))
273         #define sk_X509_NAME_insert(a,b,c) sk_insert((a),(char *)(b),(c))
274         #define sk_X509_NAME_set_cmp_func(a,b) ((int (*) \
275                 (const X509_NAME * const *,const X509_NAME * const *)) \
276                 sk_set_cmp_func((a),(int (*) \
277                 (const char * const *, const char * const *))(b)))
278         #define sk_X509_NAME_dup(a) sk_dup(a)
279         #define sk_X509_NAME_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
280         #define sk_X509_NAME_shift(a) ((X509_NAME *)sk_shift(a))
281         #define sk_X509_NAME_pop(a) ((X509_NAME *)sk_pop(a))
282         #define sk_X509_NAME_sort(a) sk_sort(a)
283 #endif /* !DEBUG_SAFESTACK */
284 /* End of perl script block, you may now edit :-) */
285
286 #define X509_EX_V_NETSCAPE_HACK         0x8000
287 #define X509_EX_V_INIT                  0x0001
288 typedef struct X509_extension_st
289         {
290         ASN1_OBJECT *object;
291         short critical;
292         short netscape_hack;
293         ASN1_OCTET_STRING *value;
294         struct v3_ext_method *method;   /* V3 method to use */
295         void *ext_val;                  /* extension value */
296         } X509_EXTENSION;
297
298 DECLARE_STACK_OF(X509_EXTENSION)
299 /* This block of defines is updated by a perl script, please do not touch! */
300 #ifndef DEBUG_SAFESTACK
301         #define sk_X509_EXTENSION_new(a) sk_new((int (*) \
302                 (const char * const *, const char * const *))(a))
303         #define sk_X509_EXTENSION_new_null() sk_new_null()
304         #define sk_X509_EXTENSION_free(a) sk_free(a)
305         #define sk_X509_EXTENSION_num(a) sk_num(a)
306         #define sk_X509_EXTENSION_value(a,b) ((X509_EXTENSION *) \
307                 sk_value((a),(b)))
308         #define sk_X509_EXTENSION_set(a,b,c) ((X509_EXTENSION *) \
309                 sk_set((a),(b),(char *)(c)))
310         #define sk_X509_EXTENSION_zero(a) sk_zero(a)
311         #define sk_X509_EXTENSION_push(a,b) sk_push((a),(char *)(b))
312         #define sk_X509_EXTENSION_unshift(a,b) sk_unshift((a),(b))
313         #define sk_X509_EXTENSION_find(a,b) sk_find((a), (char *)(b))
314         #define sk_X509_EXTENSION_delete(a,b) ((X509_EXTENSION *) \
315                 sk_delete((a),(b)))
316         #define sk_X509_EXTENSION_delete_ptr(a,b) ((X509_EXTENSION *) \
317                 sk_delete_ptr((a),(char *)(b)))
318         #define sk_X509_EXTENSION_insert(a,b,c) sk_insert((a),(char *)(b),(c))
319         #define sk_X509_EXTENSION_set_cmp_func(a,b) ((int (*) \
320                 (const X509_EXTENSION * const *,const X509_EXTENSION * const *)) \
321                 sk_set_cmp_func((a),(int (*) \
322                 (const char * const *, const char * const *))(b)))
323         #define sk_X509_EXTENSION_dup(a) sk_dup(a)
324         #define sk_X509_EXTENSION_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
325         #define sk_X509_EXTENSION_shift(a) ((X509_EXTENSION *)sk_shift(a))
326         #define sk_X509_EXTENSION_pop(a) ((X509_EXTENSION *)sk_pop(a))
327         #define sk_X509_EXTENSION_sort(a) sk_sort(a)
328 #endif /* !DEBUG_SAFESTACK */
329 /* End of perl script block, you may now edit :-) */
330 DECLARE_ASN1_SET_OF(X509_EXTENSION)
331
332 /* a sequence of these are used */
333 typedef struct x509_attributes_st
334         {
335         ASN1_OBJECT *object;
336         int set; /* 1 for a set, 0 for a single item (which is wrong) */
337         union   {
338                 char            *ptr;
339 /* 1 */         STACK_OF(ASN1_TYPE) *set;
340 /* 0 */         ASN1_TYPE       *single;
341                 } value;
342         } X509_ATTRIBUTE;
343
344 DECLARE_STACK_OF(X509_ATTRIBUTE)
345 /* This block of defines is updated by a perl script, please do not touch! */
346 #ifndef DEBUG_SAFESTACK
347         #define sk_X509_ATTRIBUTE_new(a) sk_new((int (*) \
348                 (const char * const *, const char * const *))(a))
349         #define sk_X509_ATTRIBUTE_new_null() sk_new_null()
350         #define sk_X509_ATTRIBUTE_free(a) sk_free(a)
351         #define sk_X509_ATTRIBUTE_num(a) sk_num(a)
352         #define sk_X509_ATTRIBUTE_value(a,b) ((X509_ATTRIBUTE *) \
353                 sk_value((a),(b)))
354         #define sk_X509_ATTRIBUTE_set(a,b,c) ((X509_ATTRIBUTE *) \
355                 sk_set((a),(b),(char *)(c)))
356         #define sk_X509_ATTRIBUTE_zero(a) sk_zero(a)
357         #define sk_X509_ATTRIBUTE_push(a,b) sk_push((a),(char *)(b))
358         #define sk_X509_ATTRIBUTE_unshift(a,b) sk_unshift((a),(b))
359         #define sk_X509_ATTRIBUTE_find(a,b) sk_find((a), (char *)(b))
360         #define sk_X509_ATTRIBUTE_delete(a,b) ((X509_ATTRIBUTE *) \
361                 sk_delete((a),(b)))
362         #define sk_X509_ATTRIBUTE_delete_ptr(a,b) ((X509_ATTRIBUTE *) \
363                 sk_delete_ptr((a),(char *)(b)))
364         #define sk_X509_ATTRIBUTE_insert(a,b,c) sk_insert((a),(char *)(b),(c))
365         #define sk_X509_ATTRIBUTE_set_cmp_func(a,b) ((int (*) \
366                 (const X509_ATTRIBUTE * const *,const X509_ATTRIBUTE * const *)) \
367                 sk_set_cmp_func((a),(int (*) \
368                 (const char * const *, const char * const *))(b)))
369         #define sk_X509_ATTRIBUTE_dup(a) sk_dup(a)
370         #define sk_X509_ATTRIBUTE_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
371         #define sk_X509_ATTRIBUTE_shift(a) ((X509_ATTRIBUTE *)sk_shift(a))
372         #define sk_X509_ATTRIBUTE_pop(a) ((X509_ATTRIBUTE *)sk_pop(a))
373         #define sk_X509_ATTRIBUTE_sort(a) sk_sort(a)
374 #endif /* !DEBUG_SAFESTACK */
375 /* End of perl script block, you may now edit :-) */
376 DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
377
378 typedef struct X509_req_info_st
379         {
380         ASN1_INTEGER *version;
381         X509_NAME *subject;
382         X509_PUBKEY *pubkey;
383         /*  d=2 hl=2 l=  0 cons: cont: 00 */
384         STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
385         int req_kludge;
386         } X509_REQ_INFO;
387
388 typedef struct X509_req_st
389         {
390         X509_REQ_INFO *req_info;
391         X509_ALGOR *sig_alg;
392         ASN1_BIT_STRING *signature;
393         int references;
394         } X509_REQ;
395
396 typedef struct x509_cinf_st
397         {
398         ASN1_INTEGER *version;          /* [ 0 ] default of v1 */
399         ASN1_INTEGER *serialNumber;
400         X509_ALGOR *signature;
401         X509_NAME *issuer;
402         X509_VAL *validity;
403         X509_NAME *subject;
404         X509_PUBKEY *key;
405         ASN1_BIT_STRING *issuerUID;             /* [ 1 ] optional in v2 */
406         ASN1_BIT_STRING *subjectUID;            /* [ 2 ] optional in v2 */
407         STACK_OF(X509_EXTENSION) *extensions;   /* [ 3 ] optional in v3 */
408         } X509_CINF;
409
410 /* This stuff is certificate "auxiliary info"
411  * it contains details which are useful in certificate
412  * stores and databases. When used this is tagged onto
413  * the end of the certificate itself
414  */
415
416 typedef struct x509_cert_aux_st
417         {
418         STACK_OF(ASN1_OBJECT) *trust;           /* trusted uses */
419         STACK_OF(ASN1_OBJECT) *reject;          /* rejected uses */
420         ASN1_UTF8STRING *alias;                 /* "friendly name" */
421         ASN1_OCTET_STRING *keyid;               /* key id of private key */
422         STACK_OF(X509_ALGOR) *other;            /* other unspecified info */
423         } X509_CERT_AUX;
424
425 typedef struct x509_st
426         {
427         X509_CINF *cert_info;
428         X509_ALGOR *sig_alg;
429         ASN1_BIT_STRING *signature;
430         int valid;
431         int references;
432         char *name;
433         CRYPTO_EX_DATA ex_data;
434         /* These contain copies of various extension values */
435         long ex_pathlen;
436         unsigned long ex_flags;
437         unsigned long ex_kusage;
438         unsigned long ex_xkusage;
439         unsigned long ex_nscert;
440 #ifndef NO_SHA
441         unsigned char sha1_hash[SHA_DIGEST_LENGTH];
442 #endif
443         X509_CERT_AUX *aux;
444         } X509;
445
446 DECLARE_STACK_OF(X509)
447 /* This block of defines is updated by a perl script, please do not touch! */
448 #ifndef DEBUG_SAFESTACK
449         #define sk_X509_new(a) sk_new((int (*) \
450                 (const char * const *, const char * const *))(a))
451         #define sk_X509_new_null() sk_new_null()
452         #define sk_X509_free(a) sk_free(a)
453         #define sk_X509_num(a) sk_num(a)
454         #define sk_X509_value(a,b) ((X509 *) \
455                 sk_value((a),(b)))
456         #define sk_X509_set(a,b,c) ((X509 *) \
457                 sk_set((a),(b),(char *)(c)))
458         #define sk_X509_zero(a) sk_zero(a)
459         #define sk_X509_push(a,b) sk_push((a),(char *)(b))
460         #define sk_X509_unshift(a,b) sk_unshift((a),(b))
461         #define sk_X509_find(a,b) sk_find((a), (char *)(b))
462         #define sk_X509_delete(a,b) ((X509 *) \
463                 sk_delete((a),(b)))
464         #define sk_X509_delete_ptr(a,b) ((X509 *) \
465                 sk_delete_ptr((a),(char *)(b)))
466         #define sk_X509_insert(a,b,c) sk_insert((a),(char *)(b),(c))
467         #define sk_X509_set_cmp_func(a,b) ((int (*) \
468                 (const X509 * const *,const X509 * const *)) \
469                 sk_set_cmp_func((a),(int (*) \
470                 (const char * const *, const char * const *))(b)))
471         #define sk_X509_dup(a) sk_dup(a)
472         #define sk_X509_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
473         #define sk_X509_shift(a) ((X509 *)sk_shift(a))
474         #define sk_X509_pop(a) ((X509 *)sk_pop(a))
475         #define sk_X509_sort(a) sk_sort(a)
476 #endif /* !DEBUG_SAFESTACK */
477 /* End of perl script block, you may now edit :-) */
478 DECLARE_ASN1_SET_OF(X509)
479
480 /* This is used for a table of trust checking functions */
481
482 typedef struct x509_trust_st {
483         int trust;
484         int flags;
485         int (*check_trust)(struct x509_trust_st *, X509 *, int);
486         char *name;
487         int arg1;
488         void *arg2;
489 } X509_TRUST;
490
491 DECLARE_STACK_OF(X509_TRUST)
492 /* This block of defines is updated by a perl script, please do not touch! */
493 #ifndef DEBUG_SAFESTACK
494         #define sk_X509_TRUST_new(a) sk_new((int (*) \
495                 (const char * const *, const char * const *))(a))
496         #define sk_X509_TRUST_new_null() sk_new_null()
497         #define sk_X509_TRUST_free(a) sk_free(a)
498         #define sk_X509_TRUST_num(a) sk_num(a)
499         #define sk_X509_TRUST_value(a,b) ((X509_TRUST *) \
500                 sk_value((a),(b)))
501         #define sk_X509_TRUST_set(a,b,c) ((X509_TRUST *) \
502                 sk_set((a),(b),(char *)(c)))
503         #define sk_X509_TRUST_zero(a) sk_zero(a)
504         #define sk_X509_TRUST_push(a,b) sk_push((a),(char *)(b))
505         #define sk_X509_TRUST_unshift(a,b) sk_unshift((a),(b))
506         #define sk_X509_TRUST_find(a,b) sk_find((a), (char *)(b))
507         #define sk_X509_TRUST_delete(a,b) ((X509_TRUST *) \
508                 sk_delete((a),(b)))
509         #define sk_X509_TRUST_delete_ptr(a,b) ((X509_TRUST *) \
510                 sk_delete_ptr((a),(char *)(b)))
511         #define sk_X509_TRUST_insert(a,b,c) sk_insert((a),(char *)(b),(c))
512         #define sk_X509_TRUST_set_cmp_func(a,b) ((int (*) \
513                 (const X509_TRUST * const *,const X509_TRUST * const *)) \
514                 sk_set_cmp_func((a),(int (*) \
515                 (const char * const *, const char * const *))(b)))
516         #define sk_X509_TRUST_dup(a) sk_dup(a)
517         #define sk_X509_TRUST_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
518         #define sk_X509_TRUST_shift(a) ((X509_TRUST *)sk_shift(a))
519         #define sk_X509_TRUST_pop(a) ((X509_TRUST *)sk_pop(a))
520         #define sk_X509_TRUST_sort(a) sk_sort(a)
521 #endif /* !DEBUG_SAFESTACK */
522 /* End of perl script block, you may now edit :-) */
523
524 /* standard trust ids */
525
526 #define X509_TRUST_DEFAULT      -1      /* Only valid in purpose settings */
527
528 #define X509_TRUST_COMPAT       1
529 #define X509_TRUST_SSL_CLIENT   2
530 #define X509_TRUST_SSL_SERVER   3
531 #define X509_TRUST_EMAIL        4
532 #define X509_TRUST_OBJECT_SIGN  5
533
534 /* Keep these up to date! */
535 #define X509_TRUST_MIN          1
536 #define X509_TRUST_MAX          5
537
538
539 /* trust_flags values */
540 #define X509_TRUST_DYNAMIC      1
541 #define X509_TRUST_DYNAMIC_NAME 2
542
543 /* check_trust return codes */
544
545 #define X509_TRUST_TRUSTED      1
546 #define X509_TRUST_REJECTED     2
547 #define X509_TRUST_UNTRUSTED    3
548
549 typedef struct X509_revoked_st
550         {
551         ASN1_INTEGER *serialNumber;
552         ASN1_UTCTIME *revocationDate;
553         STACK_OF(X509_EXTENSION) /* optional */ *extensions;
554         int sequence; /* load sequence */
555         } X509_REVOKED;
556
557 DECLARE_STACK_OF(X509_REVOKED)
558 /* This block of defines is updated by a perl script, please do not touch! */
559 #ifndef DEBUG_SAFESTACK
560         #define sk_X509_REVOKED_new(a) sk_new((int (*) \
561                 (const char * const *, const char * const *))(a))
562         #define sk_X509_REVOKED_new_null() sk_new_null()
563         #define sk_X509_REVOKED_free(a) sk_free(a)
564         #define sk_X509_REVOKED_num(a) sk_num(a)
565         #define sk_X509_REVOKED_value(a,b) ((X509_REVOKED *) \
566                 sk_value((a),(b)))
567         #define sk_X509_REVOKED_set(a,b,c) ((X509_REVOKED *) \
568                 sk_set((a),(b),(char *)(c)))
569         #define sk_X509_REVOKED_zero(a) sk_zero(a)
570         #define sk_X509_REVOKED_push(a,b) sk_push((a),(char *)(b))
571         #define sk_X509_REVOKED_unshift(a,b) sk_unshift((a),(b))
572         #define sk_X509_REVOKED_find(a,b) sk_find((a), (char *)(b))
573         #define sk_X509_REVOKED_delete(a,b) ((X509_REVOKED *) \
574                 sk_delete((a),(b)))
575         #define sk_X509_REVOKED_delete_ptr(a,b) ((X509_REVOKED *) \
576                 sk_delete_ptr((a),(char *)(b)))
577         #define sk_X509_REVOKED_insert(a,b,c) sk_insert((a),(char *)(b),(c))
578         #define sk_X509_REVOKED_set_cmp_func(a,b) ((int (*) \
579                 (const X509_REVOKED * const *,const X509_REVOKED * const *)) \
580                 sk_set_cmp_func((a),(int (*) \
581                 (const char * const *, const char * const *))(b)))
582         #define sk_X509_REVOKED_dup(a) sk_dup(a)
583         #define sk_X509_REVOKED_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
584         #define sk_X509_REVOKED_shift(a) ((X509_REVOKED *)sk_shift(a))
585         #define sk_X509_REVOKED_pop(a) ((X509_REVOKED *)sk_pop(a))
586         #define sk_X509_REVOKED_sort(a) sk_sort(a)
587 #endif /* !DEBUG_SAFESTACK */
588 /* End of perl script block, you may now edit :-) */
589 DECLARE_ASN1_SET_OF(X509_REVOKED)
590
591 typedef struct X509_crl_info_st
592         {
593         ASN1_INTEGER *version;
594         X509_ALGOR *sig_alg;
595         X509_NAME *issuer;
596         ASN1_UTCTIME *lastUpdate;
597         ASN1_UTCTIME *nextUpdate;
598         STACK_OF(X509_REVOKED) *revoked;
599         STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
600         } X509_CRL_INFO;
601
602 typedef struct X509_crl_st
603         {
604         /* actual signature */
605         X509_CRL_INFO *crl;
606         X509_ALGOR *sig_alg;
607         ASN1_BIT_STRING *signature;
608         int references;
609         } X509_CRL;
610
611 DECLARE_STACK_OF(X509_CRL)
612 /* This block of defines is updated by a perl script, please do not touch! */
613 #ifndef DEBUG_SAFESTACK
614         #define sk_X509_CRL_new(a) sk_new((int (*) \
615                 (const char * const *, const char * const *))(a))
616         #define sk_X509_CRL_new_null() sk_new_null()
617         #define sk_X509_CRL_free(a) sk_free(a)
618         #define sk_X509_CRL_num(a) sk_num(a)
619         #define sk_X509_CRL_value(a,b) ((X509_CRL *) \
620                 sk_value((a),(b)))
621         #define sk_X509_CRL_set(a,b,c) ((X509_CRL *) \
622                 sk_set((a),(b),(char *)(c)))
623         #define sk_X509_CRL_zero(a) sk_zero(a)
624         #define sk_X509_CRL_push(a,b) sk_push((a),(char *)(b))
625         #define sk_X509_CRL_unshift(a,b) sk_unshift((a),(b))
626         #define sk_X509_CRL_find(a,b) sk_find((a), (char *)(b))
627         #define sk_X509_CRL_delete(a,b) ((X509_CRL *) \
628                 sk_delete((a),(b)))
629         #define sk_X509_CRL_delete_ptr(a,b) ((X509_CRL *) \
630                 sk_delete_ptr((a),(char *)(b)))
631         #define sk_X509_CRL_insert(a,b,c) sk_insert((a),(char *)(b),(c))
632         #define sk_X509_CRL_set_cmp_func(a,b) ((int (*) \
633                 (const X509_CRL * const *,const X509_CRL * const *)) \
634                 sk_set_cmp_func((a),(int (*) \
635                 (const char * const *, const char * const *))(b)))
636         #define sk_X509_CRL_dup(a) sk_dup(a)
637         #define sk_X509_CRL_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
638         #define sk_X509_CRL_shift(a) ((X509_CRL *)sk_shift(a))
639         #define sk_X509_CRL_pop(a) ((X509_CRL *)sk_pop(a))
640         #define sk_X509_CRL_sort(a) sk_sort(a)
641 #endif /* !DEBUG_SAFESTACK */
642 /* End of perl script block, you may now edit :-) */
643 DECLARE_ASN1_SET_OF(X509_CRL)
644
645 typedef struct private_key_st
646         {
647         int version;
648         /* The PKCS#8 data types */
649         X509_ALGOR *enc_algor;
650         ASN1_OCTET_STRING *enc_pkey;    /* encrypted pub key */
651
652         /* When decrypted, the following will not be NULL */
653         EVP_PKEY *dec_pkey;
654
655         /* used to encrypt and decrypt */
656         int key_length;
657         char *key_data;
658         int key_free;   /* true if we should auto free key_data */
659
660         /* expanded version of 'enc_algor' */
661         EVP_CIPHER_INFO cipher;
662
663         int references;
664         } X509_PKEY;
665
666 #ifdef HEADER_ENVELOPE_H
667 typedef struct X509_info_st
668         {
669         X509 *x509;
670         X509_CRL *crl;
671         X509_PKEY *x_pkey;
672
673         EVP_CIPHER_INFO enc_cipher;
674         int enc_len;
675         char *enc_data;
676
677         int references;
678         } X509_INFO;
679
680 DECLARE_STACK_OF(X509_INFO)
681 /* This block of defines is updated by a perl script, please do not touch! */
682 #ifndef DEBUG_SAFESTACK
683         #define sk_X509_INFO_new(a) sk_new((int (*) \
684                 (const char * const *, const char * const *))(a))
685         #define sk_X509_INFO_new_null() sk_new_null()
686         #define sk_X509_INFO_free(a) sk_free(a)
687         #define sk_X509_INFO_num(a) sk_num(a)
688         #define sk_X509_INFO_value(a,b) ((X509_INFO *) \
689                 sk_value((a),(b)))
690         #define sk_X509_INFO_set(a,b,c) ((X509_INFO *) \
691                 sk_set((a),(b),(char *)(c)))
692         #define sk_X509_INFO_zero(a) sk_zero(a)
693         #define sk_X509_INFO_push(a,b) sk_push((a),(char *)(b))
694         #define sk_X509_INFO_unshift(a,b) sk_unshift((a),(b))
695         #define sk_X509_INFO_find(a,b) sk_find((a), (char *)(b))
696         #define sk_X509_INFO_delete(a,b) ((X509_INFO *) \
697                 sk_delete((a),(b)))
698         #define sk_X509_INFO_delete_ptr(a,b) ((X509_INFO *) \
699                 sk_delete_ptr((a),(char *)(b)))
700         #define sk_X509_INFO_insert(a,b,c) sk_insert((a),(char *)(b),(c))
701         #define sk_X509_INFO_set_cmp_func(a,b) ((int (*) \
702                 (const X509_INFO * const *,const X509_INFO * const *)) \
703                 sk_set_cmp_func((a),(int (*) \
704                 (const char * const *, const char * const *))(b)))
705         #define sk_X509_INFO_dup(a) sk_dup(a)
706         #define sk_X509_INFO_pop_free(a,b) sk_pop_free((a),(void (*)(void *))(b))
707         #define sk_X509_INFO_shift(a) ((X509_INFO *)sk_shift(a))
708         #define sk_X509_INFO_pop(a) ((X509_INFO *)sk_pop(a))
709         #define sk_X509_INFO_sort(a) sk_sort(a)
710 #endif /* !DEBUG_SAFESTACK */
711 /* End of perl script block, you may now edit :-) */
712 #endif
713
714 /* The next 2 structures and their 8 routines were sent to me by
715  * Pat Richard <patr@x509.com> and are used to manipulate
716  * Netscapes spki structures - useful if you are writing a CA web page
717  */
718 typedef struct Netscape_spkac_st
719         {
720         X509_PUBKEY *pubkey;
721         ASN1_IA5STRING *challenge;      /* challenge sent in atlas >= PR2 */
722         } NETSCAPE_SPKAC;
723
724 typedef struct Netscape_spki_st
725         {
726         NETSCAPE_SPKAC *spkac;  /* signed public key and challenge */
727         X509_ALGOR *sig_algor;
728         ASN1_BIT_STRING *signature;
729         } NETSCAPE_SPKI;
730
731 /* Netscape certificate sequence structure */
732 typedef struct Netscape_certificate_sequence
733         {
734         ASN1_OBJECT *type;
735         STACK_OF(X509) *certs;
736         } NETSCAPE_CERT_SEQUENCE;
737
738 typedef struct CBCParameter_st
739         {
740         unsigned char iv[8];
741         } CBC_PARAM;
742
743 /* Password based encryption structure */
744
745 typedef struct PBEPARAM_st {
746 ASN1_OCTET_STRING *salt;
747 ASN1_INTEGER *iter;
748 } PBEPARAM;
749
750 /* Password based encryption V2 structures */
751
752 typedef struct PBE2PARAM_st {
753 X509_ALGOR *keyfunc;
754 X509_ALGOR *encryption;
755 } PBE2PARAM;
756
757 typedef struct PBKDF2PARAM_st {
758 ASN1_TYPE *salt;        /* Usually OCTET STRING but could be anything */
759 ASN1_INTEGER *iter;
760 ASN1_INTEGER *keylength;
761 X509_ALGOR *prf;
762 } PBKDF2PARAM;
763
764
765 /* PKCS#8 private key info structure */
766
767 typedef struct pkcs8_priv_key_info_st
768         {
769         int broken;     /* Flag for various broken formats */
770 #define PKCS8_OK                0
771 #define PKCS8_NO_OCTET          1
772 #define PKCS8_EMBEDDED_PARAM    2
773 #define PKCS8_NS_DB             3
774         ASN1_INTEGER *version;
775         X509_ALGOR *pkeyalg;
776         ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
777         STACK_OF(X509_ATTRIBUTE) *attributes;
778         } PKCS8_PRIV_KEY_INFO;
779
780 #ifdef  __cplusplus
781 }
782 #endif
783
784 #include <openssl/x509_vfy.h>
785 #include <openssl/pkcs7.h>
786
787 #ifdef  __cplusplus
788 extern "C" {
789 #endif
790
791 #ifdef SSLEAY_MACROS
792 #define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
793         a->signature,(char *)a->cert_info,r)
794 #define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
795         a->sig_alg,a->signature,(char *)a->req_info,r)
796 #define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
797         a->sig_alg, a->signature,(char *)a->crl,r)
798
799 #define X509_sign(x,pkey,md) \
800         ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
801                 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
802 #define X509_REQ_sign(x,pkey,md) \
803         ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
804                 x->signature, (char *)x->req_info,pkey,md)
805 #define X509_CRL_sign(x,pkey,md) \
806         ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
807                 x->signature, (char *)x->crl,pkey,md)
808 #define NETSCAPE_SPKI_sign(x,pkey,md) \
809         ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
810                 x->signature, (char *)x->spkac,pkey,md)
811
812 #define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
813                 (char *(*)())d2i_X509,(char *)x509)
814 #define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
815                 (int (*)())i2d_X509_ATTRIBUTE, \
816                 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
817 #define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
818                 (int (*)())i2d_X509_EXTENSION, \
819                 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
820 #define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
821                 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
822 #define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
823 #define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
824                 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
825 #define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
826
827 #define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
828                 (char *(*)())d2i_X509_CRL,(char *)crl)
829 #define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
830                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
831                 (unsigned char **)(crl))
832 #define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
833                 (unsigned char *)crl)
834 #define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
835                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
836                 (unsigned char **)(crl))
837 #define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
838                 (unsigned char *)crl)
839
840 #define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
841                 (char *(*)())d2i_PKCS7,(char *)p7)
842 #define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
843                 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
844                 (unsigned char **)(p7))
845 #define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
846                 (unsigned char *)p7)
847 #define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
848                 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
849                 (unsigned char **)(p7))
850 #define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
851                 (unsigned char *)p7)
852
853 #define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
854                 (char *(*)())d2i_X509_REQ,(char *)req)
855 #define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
856                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
857                 (unsigned char **)(req))
858 #define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
859                 (unsigned char *)req)
860 #define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
861                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
862                 (unsigned char **)(req))
863 #define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
864                 (unsigned char *)req)
865
866 #define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
867                 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
868 #define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
869                 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
870
871 #define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
872                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
873                 (unsigned char **)(rsa))
874 #define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
875                 (unsigned char *)rsa)
876 #define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
877                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
878                 (unsigned char **)(rsa))
879 #define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
880                 (unsigned char *)rsa)
881
882 #define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
883                 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
884                 (unsigned char **)(rsa))
885 #define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
886                 (unsigned char *)rsa)
887 #define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
888                 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
889                 (unsigned char **)(rsa))
890 #define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
891                 (unsigned char *)rsa)
892
893 #define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
894                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
895                 (unsigned char **)(dsa))
896 #define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
897                 (unsigned char *)dsa)
898 #define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
899                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
900                 (unsigned char **)(dsa))
901 #define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
902                 (unsigned char *)dsa)
903
904 #define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
905                 (char *(*)())d2i_X509_ALGOR,(char *)xn)
906
907 #define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
908                 (char *(*)())d2i_X509_NAME,(char *)xn)
909 #define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
910                 (int (*)())i2d_X509_NAME_ENTRY, \
911                 (char *(*)())d2i_X509_NAME_ENTRY,\
912                 (char *)ne)
913
914 #define X509_digest(data,type,md,len) \
915         ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
916 #define X509_NAME_digest(data,type,md,len) \
917         ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
918 #ifndef PKCS7_ISSUER_AND_SERIAL_digest
919 #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
920         ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
921                 (char *)data,md,len)
922 #endif
923 #endif
924
925 #define X509_EXT_PACK_UNKNOWN   1
926 #define X509_EXT_PACK_STRING    2
927
928 #define         X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
929 /* #define      X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
930 #define         X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
931 #define         X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
932 #define         X509_extract_key(x)     X509_get_pubkey(x) /*****/
933 #define         X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
934 #define         X509_REQ_get_subject_name(x) ((x)->req_info->subject)
935 #define         X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
936 #define         X509_name_cmp(a,b)      X509_NAME_cmp((a),(b))
937 #define         X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
938
939 #define         X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
940 #define         X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
941 #define         X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
942 #define         X509_CRL_get_issuer(x) ((x)->crl->issuer)
943 #define         X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
944
945 /* This one is only used so that a binary form can output, as in
946  * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
947 #define         X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
948
949
950 const char *X509_verify_cert_error_string(long n);
951
952 #ifndef SSLEAY_MACROS
953 #ifdef HEADER_ENVELOPE_H
954 int X509_verify(X509 *a, EVP_PKEY *r);
955
956 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
957 int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
958 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
959
960 NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len);
961 char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x);
962 EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x);
963 int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey);
964
965 int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki);
966
967 int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
968 int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
969 int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
970 int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
971
972 int X509_digest(const X509 *data,const EVP_MD *type,
973                 unsigned char *md, unsigned int *len);
974 int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type,
975                 unsigned char *md, unsigned int *len);
976 int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type,
977                 unsigned char *md, unsigned int *len);
978 int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type,
979                 unsigned char *md, unsigned int *len);
980 #endif
981
982 #ifndef NO_FP_API
983 X509 *d2i_X509_fp(FILE *fp, X509 **x509);
984 int i2d_X509_fp(FILE *fp,X509 *x509);
985 X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
986 int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
987 X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
988 int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
989 #ifndef NO_RSA
990 RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
991 int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
992 RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
993 int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
994 RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa);
995 int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa);
996 #endif
997 #ifndef NO_DSA
998 DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa);
999 int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
1000 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
1001 int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
1002 #endif
1003 X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
1004 int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
1005 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
1006                                                 PKCS8_PRIV_KEY_INFO **p8inf);
1007 int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
1008 int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key);
1009 int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey);
1010 EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a);
1011 #endif
1012
1013 #ifdef HEADER_BIO_H
1014 X509 *d2i_X509_bio(BIO *bp,X509 **x509);
1015 int i2d_X509_bio(BIO *bp,X509 *x509);
1016 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
1017 int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
1018 X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
1019 int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
1020 #ifndef NO_RSA
1021 RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
1022 int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
1023 RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
1024 int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
1025 RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa);
1026 int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa);
1027 #endif
1028 #ifndef NO_DSA
1029 DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa);
1030 int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
1031 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
1032 int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
1033 #endif
1034 X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
1035 int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
1036 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
1037                                                 PKCS8_PRIV_KEY_INFO **p8inf);
1038 int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
1039 int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key);
1040 int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey);
1041 EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
1042 #endif
1043
1044 X509 *X509_dup(X509 *x509);
1045 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
1046 X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
1047 X509_CRL *X509_CRL_dup(X509_CRL *crl);
1048 X509_REQ *X509_REQ_dup(X509_REQ *req);
1049 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
1050 X509_NAME *X509_NAME_dup(X509_NAME *xn);
1051 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
1052 #ifndef NO_RSA
1053 RSA *RSAPublicKey_dup(RSA *rsa);
1054 RSA *RSAPrivateKey_dup(RSA *rsa);
1055 #endif
1056
1057 #endif /* !SSLEAY_MACROS */
1058
1059 int             X509_cmp_current_time(ASN1_UTCTIME *s);
1060 ASN1_UTCTIME *  X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
1061
1062 const char *    X509_get_default_cert_area(void );
1063 const char *    X509_get_default_cert_dir(void );
1064 const char *    X509_get_default_cert_file(void );
1065 const char *    X509_get_default_cert_dir_env(void );
1066 const char *    X509_get_default_cert_file_env(void );
1067 const char *    X509_get_default_private_dir(void );
1068
1069 X509_REQ *      X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
1070 X509 *          X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
1071 void ERR_load_X509_strings(void );
1072
1073 X509_ALGOR *    X509_ALGOR_new(void );
1074 void            X509_ALGOR_free(X509_ALGOR *a);
1075 int             i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
1076 X509_ALGOR *    d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
1077                         long length);
1078
1079 X509_VAL *      X509_VAL_new(void );
1080 void            X509_VAL_free(X509_VAL *a);
1081 int             i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
1082 X509_VAL *      d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
1083                         long length);
1084
1085 X509_PUBKEY *   X509_PUBKEY_new(void );
1086 void            X509_PUBKEY_free(X509_PUBKEY *a);
1087 int             i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
1088 X509_PUBKEY *   d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
1089                         long length);
1090 int             X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
1091 EVP_PKEY *      X509_PUBKEY_get(X509_PUBKEY *key);
1092 int             X509_get_pubkey_parameters(EVP_PKEY *pkey,
1093                                            STACK_OF(X509) *chain);
1094 int             i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
1095 EVP_PKEY *      d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
1096                         long length);
1097 #ifndef NO_RSA
1098 int             i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
1099 RSA *           d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
1100                         long length);
1101 #endif
1102 #ifndef NO_DSA
1103 int             i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
1104 DSA *           d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
1105                         long length);
1106 #endif
1107
1108 X509_SIG *      X509_SIG_new(void );
1109 void            X509_SIG_free(X509_SIG *a);
1110 int             i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
1111 X509_SIG *      d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
1112
1113 X509_REQ_INFO *X509_REQ_INFO_new(void);
1114 void            X509_REQ_INFO_free(X509_REQ_INFO *a);
1115 int             i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
1116 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
1117                         long length);
1118
1119 X509_REQ *      X509_REQ_new(void);
1120 void            X509_REQ_free(X509_REQ *a);
1121 int             i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
1122 X509_REQ *      d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
1123
1124 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
1125 void            X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
1126 int             i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
1127 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
1128                         long length);
1129 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
1130
1131
1132 X509_EXTENSION *X509_EXTENSION_new(void );
1133 void            X509_EXTENSION_free(X509_EXTENSION *a);
1134 int             i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
1135 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
1136                         long length);
1137
1138 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
1139 void            X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
1140 int             i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
1141 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
1142                         long length);
1143
1144 X509_NAME *     X509_NAME_new(void);
1145 void            X509_NAME_free(X509_NAME *a);
1146 int             i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
1147 X509_NAME *     d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
1148 int             X509_NAME_set(X509_NAME **xn, X509_NAME *name);
1149
1150
1151 X509_CINF *     X509_CINF_new(void);
1152 void            X509_CINF_free(X509_CINF *a);
1153 int             i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
1154 X509_CINF *     d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
1155
1156 X509 *          X509_new(void);
1157 void            X509_free(X509 *a);
1158 int             i2d_X509(X509 *a,unsigned char **pp);
1159 X509 *          d2i_X509(X509 **a,unsigned char **pp,long length);
1160 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1161              CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1162 int X509_set_ex_data(X509 *r, int idx, void *arg);
1163 void *X509_get_ex_data(X509 *r, int idx);
1164 int             i2d_X509_AUX(X509 *a,unsigned char **pp);
1165 X509 *          d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
1166
1167 X509_CERT_AUX * X509_CERT_AUX_new(void);
1168 void            X509_CERT_AUX_free(X509_CERT_AUX *a);
1169 int             i2d_X509_CERT_AUX(X509_CERT_AUX *a,unsigned char **pp);
1170 X509_CERT_AUX * d2i_X509_CERT_AUX(X509_CERT_AUX **a,unsigned char **pp,
1171                                                                 long length);
1172 int X509_alias_set1(X509 *x, unsigned char *name, int len);
1173 unsigned char * X509_alias_get0(X509 *x, int *len);
1174 int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
1175 int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
1176 int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj);
1177 void X509_trust_clear(X509 *x);
1178 void X509_reject_clear(X509 *x);
1179
1180 X509_REVOKED *  X509_REVOKED_new(void);
1181 void            X509_REVOKED_free(X509_REVOKED *a);
1182 int             i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
1183 X509_REVOKED *  d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
1184
1185 X509_CRL_INFO *X509_CRL_INFO_new(void);
1186 void            X509_CRL_INFO_free(X509_CRL_INFO *a);
1187 int             i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
1188 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
1189                         long length);
1190
1191 X509_CRL *      X509_CRL_new(void);
1192 void            X509_CRL_free(X509_CRL *a);
1193 int             i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
1194 X509_CRL *      d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
1195
1196 X509_PKEY *     X509_PKEY_new(void );
1197 void            X509_PKEY_free(X509_PKEY *a);
1198 int             i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
1199 X509_PKEY *     d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
1200
1201 NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
1202 void            NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
1203 int             i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
1204 NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
1205                         long length);
1206
1207 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
1208 void            NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
1209 int             i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
1210 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
1211                 long length);
1212
1213
1214 int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
1215 NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
1216 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
1217 void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
1218
1219 #ifdef HEADER_ENVELOPE_H
1220 X509_INFO *     X509_INFO_new(void);
1221 void            X509_INFO_free(X509_INFO *a);
1222 char *          X509_NAME_oneline(X509_NAME *a,char *buf,int size);
1223
1224 int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
1225         ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
1226
1227 int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
1228         unsigned char *md,unsigned int *len);
1229
1230 int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
1231         ASN1_BIT_STRING *signature,
1232         char *data,EVP_PKEY *pkey, const EVP_MD *type);
1233 #endif
1234
1235 int             X509_set_version(X509 *x,long version);
1236 int             X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
1237 ASN1_INTEGER *  X509_get_serialNumber(X509 *x);
1238 int             X509_set_issuer_name(X509 *x, X509_NAME *name);
1239 X509_NAME *     X509_get_issuer_name(X509 *a);
1240 int             X509_set_subject_name(X509 *x, X509_NAME *name);
1241 X509_NAME *     X509_get_subject_name(X509 *a);
1242 int             X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
1243 int             X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
1244 int             X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
1245 EVP_PKEY *      X509_get_pubkey(X509 *x);
1246 int             X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
1247
1248 int             X509_REQ_set_version(X509_REQ *x,long version);
1249 int             X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
1250 int             X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
1251 EVP_PKEY *      X509_REQ_get_pubkey(X509_REQ *req);
1252 int             X509_REQ_extension_nid(int nid);
1253 int *           X509_REQ_get_extension_nids(void);
1254 void            X509_REQ_set_extension_nids(int *nids);
1255 STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req);
1256 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
1257                                 int nid);
1258 int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts);
1259 int X509_REQ_get_attr_count(const X509_REQ *req);
1260 int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,
1261                           int lastpos);
1262 int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj,
1263                           int lastpos);
1264 X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc);
1265 X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc);
1266 int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr);
1267 int X509_REQ_add1_attr_by_OBJ(X509_REQ *req,
1268                         ASN1_OBJECT *obj, int type,
1269                         unsigned char *bytes, int len);
1270 int X509_REQ_add1_attr_by_NID(X509_REQ *req,
1271                         int nid, int type,
1272                         unsigned char *bytes, int len);
1273 int X509_REQ_add1_attr_by_txt(X509_REQ *req,
1274                         char *attrname, int type,
1275                         unsigned char *bytes, int len);
1276
1277 int             X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
1278
1279 int             X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
1280 unsigned long   X509_issuer_and_serial_hash(X509 *a);
1281
1282 int             X509_issuer_name_cmp(const X509 *a, const X509 *b);
1283 unsigned long   X509_issuer_name_hash(X509 *a);
1284
1285 int             X509_subject_name_cmp(const X509 *a, const X509 *b);
1286 unsigned long   X509_subject_name_hash(X509 *x);
1287
1288 int             X509_cmp(const X509 *a, const X509 *b);
1289 int             X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b);
1290 unsigned long   X509_NAME_hash(X509_NAME *x);
1291
1292 int             X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b);
1293 #ifndef NO_FP_API
1294 int             X509_print_fp(FILE *bp,X509 *x);
1295 int             X509_CRL_print_fp(FILE *bp,X509_CRL *x);
1296 int             X509_REQ_print_fp(FILE *bp,X509_REQ *req);
1297 #endif
1298
1299 #ifdef HEADER_BIO_H
1300 int             X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
1301 int             X509_print(BIO *bp,X509 *x);
1302 int             X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent);
1303 int             X509_CRL_print(BIO *bp,X509_CRL *x);
1304 int             X509_REQ_print(BIO *bp,X509_REQ *req);
1305 #endif
1306
1307 int             X509_NAME_entry_count(X509_NAME *name);
1308 int             X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
1309                         char *buf,int len);
1310 int             X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
1311                         char *buf,int len);
1312
1313 /* NOTE: you should be passsing -1, not 0 as lastpos.  The functions that use
1314  * lastpos, search after that position on. */
1315 int             X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
1316 int             X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
1317                         int lastpos);
1318 X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
1319 X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
1320 int             X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
1321                         int loc, int set);
1322 int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
1323                         unsigned char *bytes, int len, int loc, int set);
1324 int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
1325                         unsigned char *bytes, int len, int loc, int set);
1326 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
1327                 char *field, int type, unsigned char *bytes, int len);
1328 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
1329                         int type,unsigned char *bytes, int len);
1330 int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type,
1331                         unsigned char *bytes, int len, int loc, int set);
1332 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
1333                         ASN1_OBJECT *obj, int type,unsigned char *bytes,
1334                         int len);
1335 int             X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
1336                         ASN1_OBJECT *obj);
1337 int             X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
1338                         unsigned char *bytes, int len);
1339 ASN1_OBJECT *   X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
1340 ASN1_STRING *   X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
1341
1342 int             X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
1343 int             X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
1344                                       int nid, int lastpos);
1345 int             X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
1346                                       ASN1_OBJECT *obj,int lastpos);
1347 int             X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
1348                                            int crit, int lastpos);
1349 X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
1350 X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
1351 STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
1352                                          X509_EXTENSION *ex, int loc);
1353
1354 int             X509_get_ext_count(X509 *x);
1355 int             X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
1356 int             X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
1357 int             X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
1358 X509_EXTENSION *X509_get_ext(X509 *x, int loc);
1359 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
1360 int             X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
1361 void    *       X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
1362
1363 int             X509_CRL_get_ext_count(X509_CRL *x);
1364 int             X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
1365 int             X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
1366 int             X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
1367 X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
1368 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
1369 int             X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
1370 void    *       X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
1371
1372 int             X509_REVOKED_get_ext_count(X509_REVOKED *x);
1373 int             X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
1374 int             X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
1375 int             X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
1376 X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
1377 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
1378 int             X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
1379 void    *       X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
1380
1381 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
1382                         int nid, int crit, ASN1_OCTET_STRING *data);
1383 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
1384                         ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
1385 int             X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
1386 int             X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
1387 int             X509_EXTENSION_set_data(X509_EXTENSION *ex,
1388                         ASN1_OCTET_STRING *data);
1389 ASN1_OBJECT *   X509_EXTENSION_get_object(X509_EXTENSION *ex);
1390 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
1391 int             X509_EXTENSION_get_critical(X509_EXTENSION *ex);
1392
1393 int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
1394 int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
1395                           int lastpos);
1396 int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj,
1397                           int lastpos);
1398 X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
1399 X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
1400 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
1401                                          X509_ATTRIBUTE *attr);
1402 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x,
1403                         ASN1_OBJECT *obj, int type,
1404                         unsigned char *bytes, int len);
1405 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1406                         int nid, int type,
1407                         unsigned char *bytes, int len);
1408 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1409                         char *attrname, int type,
1410                         unsigned char *bytes, int len);
1411 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1412              int atrtype, void *data, int len);
1413 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
1414              ASN1_OBJECT *obj, int atrtype, void *data, int len);
1415 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
1416                 char *atrname, int type, unsigned char *bytes, int len);
1417 int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, ASN1_OBJECT *obj);
1418 int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, void *data, int len);
1419 void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx,
1420                                         int atrtype, void *data);
1421 int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1422 ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1423 ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1424
1425 int             X509_verify_cert(X509_STORE_CTX *ctx);
1426
1427 /* lookup a cert from a X509 STACK */
1428 X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
1429                                      ASN1_INTEGER *serial);
1430 X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
1431
1432 int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
1433 PBEPARAM *PBEPARAM_new(void);
1434 PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
1435 void PBEPARAM_free(PBEPARAM *a);
1436 X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
1437 X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
1438                                          unsigned char *salt, int saltlen);
1439
1440 int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
1441 PBKDF2PARAM *PBKDF2PARAM_new(void);
1442 PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
1443 void PBKDF2PARAM_free(PBKDF2PARAM *a);
1444
1445 int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
1446 PBE2PARAM *PBE2PARAM_new(void);
1447 PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
1448 void PBE2PARAM_free(PBE2PARAM *a);
1449
1450 /* PKCS#8 utilities */
1451
1452 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
1453 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
1454 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
1455                                          unsigned char **pp, long length);
1456 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
1457
1458 EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
1459 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
1460 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken);
1461 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
1462
1463 int X509_check_trust(X509 *x, int id, int flags);
1464 int X509_TRUST_get_count(void);
1465 X509_TRUST * X509_TRUST_get0(int idx);
1466 int X509_TRUST_get_by_id(int id);
1467 int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
1468                                         char *name, int arg1, void *arg2);
1469 void X509_TRUST_cleanup(void);
1470 int X509_TRUST_get_flags(X509_TRUST *xp);
1471 char *X509_TRUST_get0_name(X509_TRUST *xp);
1472 int X509_TRUST_get_trust(X509_TRUST *xp);
1473
1474 /* BEGIN ERROR CODES */
1475 /* The following lines are auto generated by the script mkerr.pl. Any changes
1476  * made after this point may be overwritten when the script is next run.
1477  */
1478
1479 /* Error codes for the X509 functions. */
1480
1481 /* Function codes. */
1482 #define X509_F_ADD_CERT_DIR                              100
1483 #define X509_F_BY_FILE_CTRL                              101
1484 #define X509_F_DIR_CTRL                                  102
1485 #define X509_F_GET_CERT_BY_SUBJECT                       103
1486 #define X509_F_NETSCAPE_SPKI_B64_DECODE                  129
1487 #define X509_F_NETSCAPE_SPKI_B64_ENCODE                  130
1488 #define X509_F_X509V3_ADD_EXT                            104
1489 #define X509_F_X509_ADD_ATTR                             135
1490 #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID              136
1491 #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ              137
1492 #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT              140
1493 #define X509_F_X509_ATTRIBUTE_GET0_DATA                  139
1494 #define X509_F_X509_ATTRIBUTE_SET1_DATA                  138
1495 #define X509_F_X509_CHECK_PRIVATE_KEY                    128
1496 #define X509_F_X509_EXTENSION_CREATE_BY_NID              108
1497 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ              109
1498 #define X509_F_X509_GET_PUBKEY_PARAMETERS                110
1499 #define X509_F_X509_LOAD_CERT_CRL_FILE                   132
1500 #define X509_F_X509_LOAD_CERT_FILE                       111
1501 #define X509_F_X509_LOAD_CRL_FILE                        112
1502 #define X509_F_X509_NAME_ADD_ENTRY                       113
1503 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID             114
1504 #define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT             131
1505 #define X509_F_X509_NAME_ENTRY_SET_OBJECT                115
1506 #define X509_F_X509_NAME_ONELINE                         116
1507 #define X509_F_X509_NAME_PRINT                           117
1508 #define X509_F_X509_PRINT_FP                             118
1509 #define X509_F_X509_PUBKEY_GET                           119
1510 #define X509_F_X509_PUBKEY_SET                           120
1511 #define X509_F_X509_REQ_PRINT                            121
1512 #define X509_F_X509_REQ_PRINT_FP                         122
1513 #define X509_F_X509_REQ_TO_X509                          123
1514 #define X509_F_X509_STORE_ADD_CERT                       124
1515 #define X509_F_X509_STORE_ADD_CRL                        125
1516 #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT            134
1517 #define X509_F_X509_TO_X509_REQ                          126
1518 #define X509_F_X509_TRUST_ADD                            133
1519 #define X509_F_X509_VERIFY_CERT                          127
1520
1521 /* Reason codes. */
1522 #define X509_R_BAD_X509_FILETYPE                         100
1523 #define X509_R_BASE64_DECODE_ERROR                       118
1524 #define X509_R_CANT_CHECK_DH_KEY                         114
1525 #define X509_R_CERT_ALREADY_IN_HASH_TABLE                101
1526 #define X509_R_ERR_ASN1_LIB                              102
1527 #define X509_R_INVALID_DIRECTORY                         113
1528 #define X509_R_INVALID_FIELD_NAME                        119
1529 #define X509_R_KEY_TYPE_MISMATCH                         115
1530 #define X509_R_KEY_VALUES_MISMATCH                       116
1531 #define X509_R_LOADING_CERT_DIR                          103
1532 #define X509_R_LOADING_DEFAULTS                          104
1533 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY              105
1534 #define X509_R_SHOULD_RETRY                              106
1535 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN        107
1536 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY            108
1537 #define X509_R_UNKNOWN_KEY_TYPE                          117
1538 #define X509_R_UNKNOWN_NID                               109
1539 #define X509_R_UNKNOWN_PURPOSE_ID                        121
1540 #define X509_R_UNKNOWN_TRUST_ID                          120
1541 #define X509_R_UNSUPPORTED_ALGORITHM                     111
1542 #define X509_R_WRONG_LOOKUP_TYPE                         112
1543 #define X509_R_WRONG_TYPE                                122
1544
1545 #ifdef  __cplusplus
1546 }
1547 #endif
1548 #endif
1549