6d8f0a1941df921663dca978036fa6034f7004d4
[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  __cplusplus
63 extern "C" {
64 #endif
65
66 #ifdef VMS
67 #undef X509_REVOKED_get_ext_by_critical
68 #define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
69 #endif
70
71 #include <openssl/stack.h>
72 #include <openssl/asn1.h>
73 #include <openssl/safestack.h>
74
75 #ifndef NO_RSA
76 #include <openssl/rsa.h>
77 #endif
78
79 #ifndef NO_DSA
80 #include <openssl/dsa.h>
81 #endif
82
83 #ifndef NO_DH
84 #include <openssl/dh.h>
85 #endif
86
87 #include <openssl/evp.h>
88
89
90 #ifdef WIN32
91 /* Under Win32 this is defined in wincrypt.h */
92 #undef X509_NAME
93 #endif
94
95 #define X509_FILETYPE_PEM       1
96 #define X509_FILETYPE_ASN1      2
97 #define X509_FILETYPE_DEFAULT   3
98
99 #define X509v3_KU_DIGITAL_SIGNATURE     0x0080
100 #define X509v3_KU_NON_REPUDIATION       0x0040
101 #define X509v3_KU_KEY_ENCIPHERMENT      0x0020
102 #define X509v3_KU_DATA_ENCIPHERMENT     0x0010
103 #define X509v3_KU_KEY_AGREEMENT         0x0008
104 #define X509v3_KU_KEY_CERT_SIGN         0x0004
105 #define X509v3_KU_CRL_SIGN              0x0002
106 #define X509v3_KU_ENCIPHER_ONLY         0x0001
107 #define X509v3_KU_DECIPHER_ONLY         0x8000
108 #define X509v3_KU_UNDEF                 0xffff
109
110 typedef struct X509_objects_st
111         {
112         int nid;
113         int (*a2i)();
114         int (*i2a)();
115         } X509_OBJECTS;
116
117 typedef struct X509_algor_st
118         {
119         ASN1_OBJECT *algorithm;
120         ASN1_TYPE *parameter;
121         } X509_ALGOR;
122
123 typedef struct X509_val_st
124         {
125         ASN1_UTCTIME *notBefore;
126         ASN1_UTCTIME *notAfter;
127         } X509_VAL;
128
129 typedef struct X509_pubkey_st
130         {
131         X509_ALGOR *algor;
132         ASN1_BIT_STRING *public_key;
133         EVP_PKEY *pkey;
134         } X509_PUBKEY;
135
136 typedef struct X509_sig_st
137         {
138         X509_ALGOR *algor;
139         ASN1_OCTET_STRING *digest;
140         } X509_SIG;
141
142 typedef struct X509_name_entry_st
143         {
144         ASN1_OBJECT *object;
145         ASN1_STRING *value;
146         int set;
147         int size;       /* temp variable */
148         } X509_NAME_ENTRY;
149
150 DECLARE_STACK_OF(X509_NAME_ENTRY)
151 DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
152
153 /* we always keep X509_NAMEs in 2 forms. */
154 typedef struct X509_name_st
155         {
156         STACK_OF(X509_NAME_ENTRY) *entries;
157         int modified;   /* true if 'bytes' needs to be built */
158 #ifdef HEADER_BUFFER_H
159         BUF_MEM *bytes;
160 #else
161         char *bytes;
162 #endif
163         unsigned long hash; /* Keep the hash around for lookups */
164         } X509_NAME;
165
166 DECLARE_STACK_OF(X509_NAME)
167
168 #define X509_EX_V_NETSCAPE_HACK         0x8000
169 #define X509_EX_V_INIT                  0x0001
170 typedef struct X509_extension_st
171         {
172         ASN1_OBJECT *object;
173         short critical;
174         short netscape_hack;
175         ASN1_OCTET_STRING *value;
176         long argl;                      /* used when decoding */
177         char *argp;                     /* used when decoding */
178         void (*ex_free)();              /* clear argp stuff */
179         } X509_EXTENSION;
180
181 DECLARE_STACK_OF(X509_EXTENSION)
182 DECLARE_ASN1_SET_OF(X509_EXTENSION)
183
184 /* a sequence of these are used */
185 typedef struct x509_attributes_st
186         {
187         ASN1_OBJECT *object;
188         int set; /* 1 for a set, 0 for a single item (which is wrong) */
189         union   {
190                 char            *ptr;
191 /* 1 */         STACK_OF(ASN1_TYPE) *set;
192 /* 0 */         ASN1_TYPE       *single;
193                 } value;
194         } X509_ATTRIBUTE;
195
196 DECLARE_STACK_OF(X509_ATTRIBUTE)
197 DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
198
199 typedef struct X509_req_info_st
200         {
201         ASN1_INTEGER *version;
202         X509_NAME *subject;
203         X509_PUBKEY *pubkey;
204         /*  d=2 hl=2 l=  0 cons: cont: 00 */
205         STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
206         int req_kludge;
207         } X509_REQ_INFO;
208
209 typedef struct X509_req_st
210         {
211         X509_REQ_INFO *req_info;
212         X509_ALGOR *sig_alg;
213         ASN1_BIT_STRING *signature;
214         int references;
215         } X509_REQ;
216
217 typedef struct x509_cinf_st
218         {
219         ASN1_INTEGER *version;          /* [ 0 ] default of v1 */
220         ASN1_INTEGER *serialNumber;
221         X509_ALGOR *signature;
222         X509_NAME *issuer;
223         X509_VAL *validity;
224         X509_NAME *subject;
225         X509_PUBKEY *key;
226         ASN1_BIT_STRING *issuerUID;             /* [ 1 ] optional in v2 */
227         ASN1_BIT_STRING *subjectUID;            /* [ 2 ] optional in v2 */
228         STACK_OF(X509_EXTENSION) *extensions;   /* [ 3 ] optional in v3 */
229         } X509_CINF;
230
231 typedef struct x509_st
232         {
233         X509_CINF *cert_info;
234         X509_ALGOR *sig_alg;
235         ASN1_BIT_STRING *signature;
236         int valid;
237         int references;
238         char *name;
239         } X509;
240
241 DECLARE_STACK_OF(X509)
242 DECLARE_ASN1_SET_OF(X509)
243
244 typedef struct X509_revoked_st
245         {
246         ASN1_INTEGER *serialNumber;
247         ASN1_UTCTIME *revocationDate;
248         STACK_OF(X509_EXTENSION) /* optional */ *extensions;
249         int sequence; /* load sequence */
250         } X509_REVOKED;
251
252 DECLARE_STACK_OF(X509_REVOKED)
253 DECLARE_ASN1_SET_OF(X509_REVOKED)
254
255 typedef struct X509_crl_info_st
256         {
257         ASN1_INTEGER *version;
258         X509_ALGOR *sig_alg;
259         X509_NAME *issuer;
260         ASN1_UTCTIME *lastUpdate;
261         ASN1_UTCTIME *nextUpdate;
262         STACK_OF(X509_REVOKED) *revoked;
263         STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
264         } X509_CRL_INFO;
265
266 typedef struct X509_crl_st
267         {
268         /* actual signature */
269         X509_CRL_INFO *crl;
270         X509_ALGOR *sig_alg;
271         ASN1_BIT_STRING *signature;
272         int references;
273         } X509_CRL;
274
275 typedef struct private_key_st
276         {
277         int version;
278         /* The PKCS#8 data types */
279         X509_ALGOR *enc_algor;
280         ASN1_OCTET_STRING *enc_pkey;    /* encrypted pub key */
281
282         /* When decrypted, the following will not be NULL */
283         EVP_PKEY *dec_pkey;
284
285         /* used to encrypt and decrypt */
286         int key_length;
287         char *key_data;
288         int key_free;   /* true if we should auto free key_data */
289
290         /* expanded version of 'enc_algor' */
291         EVP_CIPHER_INFO cipher;
292
293         int references;
294         } X509_PKEY;
295
296 #ifdef HEADER_ENVELOPE_H
297 typedef struct X509_info_st
298         {
299         X509 *x509;
300         X509_CRL *crl;
301         X509_PKEY *x_pkey;
302
303         EVP_CIPHER_INFO enc_cipher;
304         int enc_len;
305         char *enc_data;
306
307         int references;
308         } X509_INFO;
309
310 DECLARE_STACK_OF(X509_INFO)
311 #endif
312
313 /* The next 2 structures and their 8 routines were sent to me by
314  * Pat Richard <patr@x509.com> and are used to manipulate
315  * Netscapes spki strucutres - usefull if you are writing a CA web page
316  */
317 typedef struct Netscape_spkac_st
318         {
319         X509_PUBKEY *pubkey;
320         ASN1_IA5STRING *challenge;      /* challenge sent in atlas >= PR2 */
321         } NETSCAPE_SPKAC;
322
323 typedef struct Netscape_spki_st
324         {
325         NETSCAPE_SPKAC *spkac;  /* signed public key and challenge */
326         X509_ALGOR *sig_algor;
327         ASN1_BIT_STRING *signature;
328         } NETSCAPE_SPKI;
329
330 /* Netscape certificate sequence structure */
331 typedef struct Netscape_certificate_sequence
332         {
333         ASN1_OBJECT *type;
334         STACK_OF(X509) *certs;
335         } NETSCAPE_CERT_SEQUENCE;
336
337 #ifndef HEADER_BN_H
338 #define BIGNUM          char
339 #endif
340
341 typedef struct CBCParameter_st
342         {
343         unsigned char iv[8];
344         } CBC_PARAM;
345
346 /* Password based encryption structure */
347
348 typedef struct PBEPARAM_st {
349 ASN1_OCTET_STRING *salt;
350 ASN1_INTEGER *iter;
351 } PBEPARAM;
352
353 /* Password based encryption V2 structures */
354
355 typedef struct PBE2PARAM_st {
356 X509_ALGOR *keyfunc;
357 X509_ALGOR *encryption;
358 } PBE2PARAM;
359
360 typedef struct PBKDF2PARAM_st {
361 ASN1_OCTET_STRING *salt;
362 ASN1_INTEGER *iter;
363 ASN1_INTEGER *keylength;
364 X509_ALGOR *prf;
365 } PBKDF2PARAM;
366
367
368 /* PKCS#8 private key info structure */
369
370 typedef struct pkcs8_priv_key_info_st
371         {
372         int broken;     /* Flag for various broken formats */
373 #define PKCS8_OK        0
374 #define PKCS8_NO_OCTET  1
375         ASN1_INTEGER *version;
376         X509_ALGOR *pkeyalg;
377         ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
378         STACK_OF(X509_ATTRIBUTE) *attributes;
379         } PKCS8_PRIV_KEY_INFO;
380
381 #include <openssl/x509_vfy.h>
382 #include <openssl/pkcs7.h>
383
384 #ifdef SSLEAY_MACROS
385 #define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
386         a->signature,(char *)a->cert_info,r)
387 #define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \
388         a->sig_alg,a->signature,(char *)a->req_info,r)
389 #define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \
390         a->sig_alg, a->signature,(char *)a->crl,r)
391
392 #define X509_sign(x,pkey,md) \
393         ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \
394                 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)
395 #define X509_REQ_sign(x,pkey,md) \
396         ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \
397                 x->signature, (char *)x->req_info,pkey,md)
398 #define X509_CRL_sign(x,pkey,md) \
399         ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \
400                 x->signature, (char *)x->crl,pkey,md)
401 #define NETSCAPE_SPKI_sign(x,pkey,md) \
402         ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \
403                 x->signature, (char *)x->spkac,pkey,md)
404
405 #define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
406                 (char *(*)())d2i_X509,(char *)x509)
407 #define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
408                 (int (*)())i2d_X509_ATTRIBUTE, \
409                 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
410 #define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
411                 (int (*)())i2d_X509_EXTENSION, \
412                 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
413 #define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \
414                 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))
415 #define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)
416 #define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \
417                 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))
418 #define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)
419
420 #define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \
421                 (char *(*)())d2i_X509_CRL,(char *)crl)
422 #define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \
423                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\
424                 (unsigned char **)(crl))
425 #define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\
426                 (unsigned char *)crl)
427 #define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \
428                 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\
429                 (unsigned char **)(crl))
430 #define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\
431                 (unsigned char *)crl)
432
433 #define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \
434                 (char *(*)())d2i_PKCS7,(char *)p7)
435 #define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \
436                 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\
437                 (unsigned char **)(p7))
438 #define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
439                 (unsigned char *)p7)
440 #define d2i_PKCS7_bio(bp,p7) (PKCS7 *)ASN1_d2i_bio((char *(*)()) \
441                 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),\
442                 (unsigned char **)(p7))
443 #define i2d_PKCS7_bio(bp,p7) ASN1_i2d_bio(i2d_PKCS7,bp,\
444                 (unsigned char *)p7)
445
446 #define X509_REQ_dup(req) (X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, \
447                 (char *(*)())d2i_X509_REQ,(char *)req)
448 #define d2i_X509_REQ_fp(fp,req) (X509_REQ *)ASN1_d2i_fp((char *(*)())\
449                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),\
450                 (unsigned char **)(req))
451 #define i2d_X509_REQ_fp(fp,req) ASN1_i2d_fp(i2d_X509_REQ,fp,\
452                 (unsigned char *)req)
453 #define d2i_X509_REQ_bio(bp,req) (X509_REQ *)ASN1_d2i_bio((char *(*)())\
454                 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),\
455                 (unsigned char **)(req))
456 #define i2d_X509_REQ_bio(bp,req) ASN1_i2d_bio(i2d_X509_REQ,bp,\
457                 (unsigned char *)req)
458
459 #define RSAPublicKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, \
460                 (char *(*)())d2i_RSAPublicKey,(char *)rsa)
461 #define RSAPrivateKey_dup(rsa) (RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, \
462                 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)
463
464 #define d2i_RSAPrivateKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
465                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), \
466                 (unsigned char **)(rsa))
467 #define i2d_RSAPrivateKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPrivateKey,fp, \
468                 (unsigned char *)rsa)
469 #define d2i_RSAPrivateKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
470                 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), \
471                 (unsigned char **)(rsa))
472 #define i2d_RSAPrivateKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPrivateKey,bp, \
473                 (unsigned char *)rsa)
474
475 #define d2i_RSAPublicKey_fp(fp,rsa) (RSA *)ASN1_d2i_fp((char *(*)())\
476                 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), \
477                 (unsigned char **)(rsa))
478 #define i2d_RSAPublicKey_fp(fp,rsa) ASN1_i2d_fp(i2d_RSAPublicKey,fp, \
479                 (unsigned char *)rsa)
480 #define d2i_RSAPublicKey_bio(bp,rsa) (RSA *)ASN1_d2i_bio((char *(*)())\
481                 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), \
482                 (unsigned char **)(rsa))
483 #define i2d_RSAPublicKey_bio(bp,rsa) ASN1_i2d_bio(i2d_RSAPublicKey,bp, \
484                 (unsigned char *)rsa)
485
486 #define d2i_DSAPrivateKey_fp(fp,dsa) (DSA *)ASN1_d2i_fp((char *(*)())\
487                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), \
488                 (unsigned char **)(dsa))
489 #define i2d_DSAPrivateKey_fp(fp,dsa) ASN1_i2d_fp(i2d_DSAPrivateKey,fp, \
490                 (unsigned char *)dsa)
491 #define d2i_DSAPrivateKey_bio(bp,dsa) (DSA *)ASN1_d2i_bio((char *(*)())\
492                 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), \
493                 (unsigned char **)(dsa))
494 #define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
495                 (unsigned char *)dsa)
496
497 #define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
498                 (char *(*)())d2i_X509_ALGOR,(char *)xn)
499
500 #define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
501                 (char *(*)())d2i_X509_NAME,(char *)xn)
502 #define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
503                 (int (*)())i2d_X509_NAME_ENTRY, \
504                 (char *(*)())d2i_X509_NAME_ENTRY,\
505                 (char *)ne)
506
507 #define X509_digest(data,type,md,len) \
508         ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
509 #define X509_NAME_digest(data,type,md,len) \
510         ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
511 #ifndef PKCS7_ISSUER_AND_SERIAL_digest
512 #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
513         ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
514                 (char *)data,md,len)
515 #endif
516 #endif
517
518 #define X509_EXT_PACK_UNKNOWN   1
519 #define X509_EXT_PACK_STRING    2
520
521 #define         X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
522 /* #define      X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */
523 #define         X509_get_notBefore(x) ((x)->cert_info->validity->notBefore)
524 #define         X509_get_notAfter(x) ((x)->cert_info->validity->notAfter)
525 #define         X509_extract_key(x)     X509_get_pubkey(x) /*****/
526 #define         X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version)
527 #define         X509_REQ_get_subject_name(x) ((x)->req_info->subject)
528 #define         X509_REQ_extract_key(a) X509_REQ_get_pubkey(a)
529 #define         X509_name_cmp(a,b)      X509_NAME_cmp((a),(b))
530 #define         X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
531
532 #define         X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
533 #define         X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
534 #define         X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
535 #define         X509_CRL_get_issuer(x) ((x)->crl->issuer)
536 #define         X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
537
538 /* This one is only used so that a binary form can output, as in
539  * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
540 #define         X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
541
542
543 #ifndef SSLEAY_MACROS
544 #ifdef HEADER_ENVELOPE_H
545 int X509_verify(X509 *a, EVP_PKEY *r);
546 const char *X509_verify_cert_error_string(long n);
547
548 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
549 int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
550 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
551
552 int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
553 int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
554 int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
555 int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
556
557 int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len);
558 int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
559         unsigned char *md,unsigned int *len);
560 #endif
561
562 #ifndef NO_FP_API
563 X509 *d2i_X509_fp(FILE *fp, X509 **x509);
564 int i2d_X509_fp(FILE *fp,X509 *x509);
565 X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
566 int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
567 X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
568 int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
569 #ifndef NO_RSA
570 RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
571 int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
572 RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
573 int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
574 #endif
575 #ifndef NO_DSA
576 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
577 int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
578 #endif
579 #endif
580
581 #ifdef HEADER_BIO_H
582 X509 *d2i_X509_bio(BIO *bp,X509 **x509);
583 int i2d_X509_bio(BIO *bp,X509 *x509);
584 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
585 int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
586 X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
587 int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
588 #ifndef NO_RSA
589 RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
590 int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
591 RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
592 int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
593 #endif
594 #ifndef NO_DSA
595 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
596 int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
597 #endif
598 #endif
599
600 X509 *X509_dup(X509 *x509);
601 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
602 X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
603 X509_CRL *X509_CRL_dup(X509_CRL *crl);
604 X509_REQ *X509_REQ_dup(X509_REQ *req);
605 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
606 X509_NAME *X509_NAME_dup(X509_NAME *xn);
607 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
608 #ifndef NO_RSA
609 RSA *RSAPublicKey_dup(RSA *rsa);
610 RSA *RSAPrivateKey_dup(RSA *rsa);
611 #endif
612
613 #endif /* !SSLEAY_MACROS */
614
615 int             X509_cmp_current_time(ASN1_UTCTIME *s);
616 ASN1_UTCTIME *  X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
617
618 const char *    X509_get_default_cert_area(void );
619 const char *    X509_get_default_cert_dir(void );
620 const char *    X509_get_default_cert_file(void );
621 const char *    X509_get_default_cert_dir_env(void );
622 const char *    X509_get_default_cert_file_env(void );
623 const char *    X509_get_default_private_dir(void );
624
625 X509_REQ *      X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
626 X509 *          X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
627 void ERR_load_X509_strings(void );
628
629 X509_ALGOR *    X509_ALGOR_new(void );
630 void            X509_ALGOR_free(X509_ALGOR *a);
631 int             i2d_X509_ALGOR(X509_ALGOR *a,unsigned char **pp);
632 X509_ALGOR *    d2i_X509_ALGOR(X509_ALGOR **a,unsigned char **pp,
633                         long length);
634
635 X509_VAL *      X509_VAL_new(void );
636 void            X509_VAL_free(X509_VAL *a);
637 int             i2d_X509_VAL(X509_VAL *a,unsigned char **pp);
638 X509_VAL *      d2i_X509_VAL(X509_VAL **a,unsigned char **pp,
639                         long length);
640
641 X509_PUBKEY *   X509_PUBKEY_new(void );
642 void            X509_PUBKEY_free(X509_PUBKEY *a);
643 int             i2d_X509_PUBKEY(X509_PUBKEY *a,unsigned char **pp);
644 X509_PUBKEY *   d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp,
645                         long length);
646 int             X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
647 EVP_PKEY *      X509_PUBKEY_get(X509_PUBKEY *key);
648 int             X509_get_pubkey_parameters(EVP_PKEY *pkey,
649                                            STACK_OF(X509) *chain);
650
651
652 X509_SIG *      X509_SIG_new(void );
653 void            X509_SIG_free(X509_SIG *a);
654 int             i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
655 X509_SIG *      d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
656
657 X509_REQ_INFO *X509_REQ_INFO_new(void);
658 void            X509_REQ_INFO_free(X509_REQ_INFO *a);
659 int             i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
660 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
661                         long length);
662
663 X509_REQ *      X509_REQ_new(void);
664 void            X509_REQ_free(X509_REQ *a);
665 int             i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
666 X509_REQ *      d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
667
668 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
669 void            X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
670 int             i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
671 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
672                         long length);
673 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
674
675
676 X509_EXTENSION *X509_EXTENSION_new(void );
677 void            X509_EXTENSION_free(X509_EXTENSION *a);
678 int             i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
679 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
680                         long length);
681
682 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
683 void            X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
684 int             i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
685 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
686                         long length);
687
688 X509_NAME *     X509_NAME_new(void);
689 void            X509_NAME_free(X509_NAME *a);
690 int             i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
691 X509_NAME *     d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
692 int             X509_NAME_set(X509_NAME **xn, X509_NAME *name);
693
694
695 X509_CINF *     X509_CINF_new(void);
696 void            X509_CINF_free(X509_CINF *a);
697 int             i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
698 X509_CINF *     d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
699
700 X509 *          X509_new(void);
701 void            X509_free(X509 *a);
702 int             i2d_X509(X509 *a,unsigned char **pp);
703 X509 *          d2i_X509(X509 **a,unsigned char **pp,long length);
704
705 X509_REVOKED *  X509_REVOKED_new(void);
706 void            X509_REVOKED_free(X509_REVOKED *a);
707 int             i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
708 X509_REVOKED *  d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
709
710 X509_CRL_INFO *X509_CRL_INFO_new(void);
711 void            X509_CRL_INFO_free(X509_CRL_INFO *a);
712 int             i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
713 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
714                         long length);
715
716 X509_CRL *      X509_CRL_new(void);
717 void            X509_CRL_free(X509_CRL *a);
718 int             i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
719 X509_CRL *      d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
720
721 X509_PKEY *     X509_PKEY_new(void );
722 void            X509_PKEY_free(X509_PKEY *a);
723 int             i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
724 X509_PKEY *     d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
725
726 NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
727 void            NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
728 int             i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
729 NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
730                         long length);
731
732 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
733 void            NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
734 int             i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
735 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
736                 long length);
737
738
739 int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
740 NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
741 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
742 void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
743
744 #ifdef HEADER_ENVELOPE_H
745 X509_INFO *     X509_INFO_new(void);
746 void            X509_INFO_free(X509_INFO *a);
747 char *          X509_NAME_oneline(X509_NAME *a,char *buf,int size);
748
749 int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
750         ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
751
752 int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
753         unsigned char *md,unsigned int *len);
754
755 int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
756         ASN1_BIT_STRING *signature,
757         char *data,EVP_PKEY *pkey, const EVP_MD *type);
758 #endif
759
760 int             X509_set_version(X509 *x,long version);
761 int             X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
762 ASN1_INTEGER *  X509_get_serialNumber(X509 *x);
763 int             X509_set_issuer_name(X509 *x, X509_NAME *name);
764 X509_NAME *     X509_get_issuer_name(X509 *a);
765 int             X509_set_subject_name(X509 *x, X509_NAME *name);
766 X509_NAME *     X509_get_subject_name(X509 *a);
767 int             X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
768 int             X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
769 int             X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
770 EVP_PKEY *      X509_get_pubkey(X509 *x);
771 int             X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
772
773 int             X509_REQ_set_version(X509_REQ *x,long version);
774 int             X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
775 int             X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
776 EVP_PKEY *      X509_REQ_get_pubkey(X509_REQ *req);
777
778 int             X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
779
780 int             X509_issuer_and_serial_cmp(X509 *a, X509 *b);
781 unsigned long   X509_issuer_and_serial_hash(X509 *a);
782
783 int             X509_issuer_name_cmp(X509 *a, X509 *b);
784 unsigned long   X509_issuer_name_hash(X509 *a);
785
786 int             X509_subject_name_cmp(X509 *a,X509 *b);
787 unsigned long   X509_subject_name_hash(X509 *x);
788
789 int             X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
790 unsigned long   X509_NAME_hash(X509_NAME *x);
791
792 int             X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
793 #ifndef NO_FP_API
794 int             X509_print_fp(FILE *bp,X509 *x);
795 int             X509_CRL_print_fp(FILE *bp,X509_CRL *x);
796 int             X509_REQ_print_fp(FILE *bp,X509_REQ *req);
797 #endif
798
799 #ifdef HEADER_BIO_H
800 int             X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
801 int             X509_print(BIO *bp,X509 *x);
802 int             X509_CRL_print(BIO *bp,X509_CRL *x);
803 int             X509_REQ_print(BIO *bp,X509_REQ *req);
804 #endif
805
806 int             X509_NAME_entry_count(X509_NAME *name);
807 int             X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
808                         char *buf,int len);
809 int             X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
810                         char *buf,int len);
811
812 /* NOTE: you should be passsing -1, not 0 as lastpos.  The functions that use
813  * lastpos, seach after that position on. */
814 int             X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
815 int             X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
816                         int lastpos);
817 X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
818 X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
819 int             X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
820                         int loc, int set);
821 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
822                         int type,unsigned char *bytes, int len);
823 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
824                         ASN1_OBJECT *obj, int type,unsigned char *bytes,
825                         int len);
826 int             X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
827                         ASN1_OBJECT *obj);
828 int             X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
829                         unsigned char *bytes, int len);
830 ASN1_OBJECT *   X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
831 ASN1_STRING *   X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
832
833 int             X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
834 int             X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
835                                       int nid, int lastpos);
836 int             X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
837                                       ASN1_OBJECT *obj,int lastpos);
838 int             X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
839                                            int crit, int lastpos);
840 X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
841 X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
842 STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
843                                          X509_EXTENSION *ex, int loc);
844
845 int             X509_get_ext_count(X509 *x);
846 int             X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
847 int             X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
848 int             X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
849 X509_EXTENSION *X509_get_ext(X509 *x, int loc);
850 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
851 int             X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
852
853 int             X509_CRL_get_ext_count(X509_CRL *x);
854 int             X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
855 int             X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
856 int             X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
857 X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
858 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
859 int             X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
860
861 int             X509_REVOKED_get_ext_count(X509_REVOKED *x);
862 int             X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
863 int             X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
864 int             X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
865 X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
866 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
867 int             X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
868
869 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
870                         int nid, int crit, ASN1_OCTET_STRING *data);
871 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
872                         ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
873 int             X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
874 int             X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
875 int             X509_EXTENSION_set_data(X509_EXTENSION *ex,
876                         ASN1_OCTET_STRING *data);
877 ASN1_OBJECT *   X509_EXTENSION_get_object(X509_EXTENSION *ex);
878 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
879 int             X509_EXTENSION_get_critical(X509_EXTENSION *ex);
880
881 int             X509_verify_cert(X509_STORE_CTX *ctx);
882
883 /* lookup a cert from a X509 STACK */
884 X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
885                                      ASN1_INTEGER *serial);
886 X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
887
888 int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
889 PBEPARAM *PBEPARAM_new(void);
890 PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
891 void PBEPARAM_free(PBEPARAM *a);
892 X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
893
894 int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
895 PBKDF2PARAM *PBKDF2PARAM_new(void);
896 PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
897 void PBKDF2PARAM_free(PBKDF2PARAM *a);
898
899 int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
900 PBE2PARAM *PBE2PARAM_new(void);
901 PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
902 void PBE2PARAM_free(PBE2PARAM *a);
903
904 /* PKCS#8 utilities */
905
906 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
907 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
908 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
909                                          unsigned char **pp, long length);
910 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
911
912 EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
913 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
914 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
915
916 /* Password based encryption routines */
917
918 int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
919              unsigned char *salt, int saltlen, int iter, EVP_CIPHER_CTX *ctx,
920              int en_de);
921 int EVP_PBE_ALGOR_CipherInit(X509_ALGOR *algor, const char *pass,
922                              int passlen, EVP_CIPHER_CTX *ctx, int en_de);
923 int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
924                     EVP_PBE_KEYGEN *keygen);
925 void EVP_PBE_cleanup(void);
926
927 /* BEGIN ERROR CODES */
928 /* The following lines are auto generated by the script mkerr.pl. Any changes
929  * made after this point may be overwritten when the script is next run.
930  */
931
932 /* Error codes for the X509 functions. */
933
934 /* Function codes. */
935 #define X509_F_ADD_CERT_DIR                              100
936 #define X509_F_BY_FILE_CTRL                              101
937 #define X509_F_DIR_CTRL                                  102
938 #define X509_F_GET_CERT_BY_SUBJECT                       103
939 #define X509_F_X509V3_ADD_EXT                            104
940 #define X509_F_X509_CHECK_PRIVATE_KEY                    128
941 #define X509_F_X509_EXTENSION_CREATE_BY_NID              108
942 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ              109
943 #define X509_F_X509_GET_PUBKEY_PARAMETERS                110
944 #define X509_F_X509_LOAD_CERT_FILE                       111
945 #define X509_F_X509_LOAD_CRL_FILE                        112
946 #define X509_F_X509_NAME_ADD_ENTRY                       113
947 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID             114
948 #define X509_F_X509_NAME_ENTRY_SET_OBJECT                115
949 #define X509_F_X509_NAME_ONELINE                         116
950 #define X509_F_X509_NAME_PRINT                           117
951 #define X509_F_X509_PRINT_FP                             118
952 #define X509_F_X509_PUBKEY_GET                           119
953 #define X509_F_X509_PUBKEY_SET                           120
954 #define X509_F_X509_REQ_PRINT                            121
955 #define X509_F_X509_REQ_PRINT_FP                         122
956 #define X509_F_X509_REQ_TO_X509                          123
957 #define X509_F_X509_STORE_ADD_CERT                       124
958 #define X509_F_X509_STORE_ADD_CRL                        125
959 #define X509_F_X509_TO_X509_REQ                          126
960 #define X509_F_X509_VERIFY_CERT                          127
961
962 /* Reason codes. */
963 #define X509_R_BAD_X509_FILETYPE                         100
964 #define X509_R_CANT_CHECK_DH_KEY                         114
965 #define X509_R_CERT_ALREADY_IN_HASH_TABLE                101
966 #define X509_R_ERR_ASN1_LIB                              102
967 #define X509_R_INVALID_DIRECTORY                         113
968 #define X509_R_KEY_TYPE_MISMATCH                         115
969 #define X509_R_KEY_VALUES_MISMATCH                       116
970 #define X509_R_LOADING_CERT_DIR                          103
971 #define X509_R_LOADING_DEFAULTS                          104
972 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY              105
973 #define X509_R_SHOULD_RETRY                              106
974 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN        107
975 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY            108
976 #define X509_R_UNKNOWN_KEY_TYPE                          117
977 #define X509_R_UNKNOWN_NID                               109
978 #define X509_R_UNSUPPORTED_ALGORITHM                     111
979 #define X509_R_WRONG_LOOKUP_TYPE                         112
980
981 #ifdef  __cplusplus
982 }
983 #endif
984 #endif
985