693d42113cf72a8f31a11e3b5a4270f8bcf3b3ee
[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 *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, STACK *chain);
649
650
651 X509_SIG *      X509_SIG_new(void );
652 void            X509_SIG_free(X509_SIG *a);
653 int             i2d_X509_SIG(X509_SIG *a,unsigned char **pp);
654 X509_SIG *      d2i_X509_SIG(X509_SIG **a,unsigned char **pp,long length);
655
656 X509_REQ_INFO *X509_REQ_INFO_new(void);
657 void            X509_REQ_INFO_free(X509_REQ_INFO *a);
658 int             i2d_X509_REQ_INFO(X509_REQ_INFO *a,unsigned char **pp);
659 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a,unsigned char **pp,
660                         long length);
661
662 X509_REQ *      X509_REQ_new(void);
663 void            X509_REQ_free(X509_REQ *a);
664 int             i2d_X509_REQ(X509_REQ *a,unsigned char **pp);
665 X509_REQ *      d2i_X509_REQ(X509_REQ **a,unsigned char **pp,long length);
666
667 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
668 void            X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
669 int             i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
670 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
671                         long length);
672 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
673
674
675 X509_EXTENSION *X509_EXTENSION_new(void );
676 void            X509_EXTENSION_free(X509_EXTENSION *a);
677 int             i2d_X509_EXTENSION(X509_EXTENSION *a,unsigned char **pp);
678 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a,unsigned char **pp,
679                         long length);
680
681 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void);
682 void            X509_NAME_ENTRY_free(X509_NAME_ENTRY *a);
683 int             i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a,unsigned char **pp);
684 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a,unsigned char **pp,
685                         long length);
686
687 X509_NAME *     X509_NAME_new(void);
688 void            X509_NAME_free(X509_NAME *a);
689 int             i2d_X509_NAME(X509_NAME *a,unsigned char **pp);
690 X509_NAME *     d2i_X509_NAME(X509_NAME **a,unsigned char **pp,long length);
691 int             X509_NAME_set(X509_NAME **xn, X509_NAME *name);
692
693
694 X509_CINF *     X509_CINF_new(void);
695 void            X509_CINF_free(X509_CINF *a);
696 int             i2d_X509_CINF(X509_CINF *a,unsigned char **pp);
697 X509_CINF *     d2i_X509_CINF(X509_CINF **a,unsigned char **pp,long length);
698
699 X509 *          X509_new(void);
700 void            X509_free(X509 *a);
701 int             i2d_X509(X509 *a,unsigned char **pp);
702 X509 *          d2i_X509(X509 **a,unsigned char **pp,long length);
703
704 X509_REVOKED *  X509_REVOKED_new(void);
705 void            X509_REVOKED_free(X509_REVOKED *a);
706 int             i2d_X509_REVOKED(X509_REVOKED *a,unsigned char **pp);
707 X509_REVOKED *  d2i_X509_REVOKED(X509_REVOKED **a,unsigned char **pp,long length);
708
709 X509_CRL_INFO *X509_CRL_INFO_new(void);
710 void            X509_CRL_INFO_free(X509_CRL_INFO *a);
711 int             i2d_X509_CRL_INFO(X509_CRL_INFO *a,unsigned char **pp);
712 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a,unsigned char **pp,
713                         long length);
714
715 X509_CRL *      X509_CRL_new(void);
716 void            X509_CRL_free(X509_CRL *a);
717 int             i2d_X509_CRL(X509_CRL *a,unsigned char **pp);
718 X509_CRL *      d2i_X509_CRL(X509_CRL **a,unsigned char **pp,long length);
719
720 X509_PKEY *     X509_PKEY_new(void );
721 void            X509_PKEY_free(X509_PKEY *a);
722 int             i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
723 X509_PKEY *     d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
724
725 NETSCAPE_SPKI * NETSCAPE_SPKI_new(void );
726 void            NETSCAPE_SPKI_free(NETSCAPE_SPKI *a);
727 int             i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a,unsigned char **pp);
728 NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a,unsigned char **pp,
729                         long length);
730
731 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void );
732 void            NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a);
733 int             i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
734 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
735                 long length);
736
737
738 int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
739 NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
740 NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
741 void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
742
743 #ifdef HEADER_ENVELOPE_H
744 X509_INFO *     X509_INFO_new(void);
745 void            X509_INFO_free(X509_INFO *a);
746 char *          X509_NAME_oneline(X509_NAME *a,char *buf,int size);
747
748 int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
749         ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
750
751 int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
752         unsigned char *md,unsigned int *len);
753
754 int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
755         ASN1_BIT_STRING *signature,
756         char *data,EVP_PKEY *pkey, const EVP_MD *type);
757 #endif
758
759 int             X509_set_version(X509 *x,long version);
760 int             X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
761 ASN1_INTEGER *  X509_get_serialNumber(X509 *x);
762 int             X509_set_issuer_name(X509 *x, X509_NAME *name);
763 X509_NAME *     X509_get_issuer_name(X509 *a);
764 int             X509_set_subject_name(X509 *x, X509_NAME *name);
765 X509_NAME *     X509_get_subject_name(X509 *a);
766 int             X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm);
767 int             X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm);
768 int             X509_set_pubkey(X509 *x, EVP_PKEY *pkey);
769 EVP_PKEY *      X509_get_pubkey(X509 *x);
770 int             X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */);
771
772 int             X509_REQ_set_version(X509_REQ *x,long version);
773 int             X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name);
774 int             X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
775 EVP_PKEY *      X509_REQ_get_pubkey(X509_REQ *req);
776
777 int             X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
778
779 int             X509_issuer_and_serial_cmp(X509 *a, X509 *b);
780 unsigned long   X509_issuer_and_serial_hash(X509 *a);
781
782 int             X509_issuer_name_cmp(X509 *a, X509 *b);
783 unsigned long   X509_issuer_name_hash(X509 *a);
784
785 int             X509_subject_name_cmp(X509 *a,X509 *b);
786 unsigned long   X509_subject_name_hash(X509 *x);
787
788 int             X509_NAME_cmp (X509_NAME *a, X509_NAME *b);
789 unsigned long   X509_NAME_hash(X509_NAME *x);
790
791 int             X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
792 #ifndef NO_FP_API
793 int             X509_print_fp(FILE *bp,X509 *x);
794 int             X509_CRL_print_fp(FILE *bp,X509_CRL *x);
795 int             X509_REQ_print_fp(FILE *bp,X509_REQ *req);
796 #endif
797
798 #ifdef HEADER_BIO_H
799 int             X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
800 int             X509_print(BIO *bp,X509 *x);
801 int             X509_CRL_print(BIO *bp,X509_CRL *x);
802 int             X509_REQ_print(BIO *bp,X509_REQ *req);
803 #endif
804
805 int             X509_NAME_entry_count(X509_NAME *name);
806 int             X509_NAME_get_text_by_NID(X509_NAME *name, int nid,
807                         char *buf,int len);
808 int             X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
809                         char *buf,int len);
810
811 /* NOTE: you should be passsing -1, not 0 as lastpos.  The functions that use
812  * lastpos, seach after that position on. */
813 int             X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos);
814 int             X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj,
815                         int lastpos);
816 X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc);
817 X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
818 int             X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne,
819                         int loc, int set);
820 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
821                         int type,unsigned char *bytes, int len);
822 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
823                         ASN1_OBJECT *obj, int type,unsigned char *bytes,
824                         int len);
825 int             X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne,
826                         ASN1_OBJECT *obj);
827 int             X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
828                         unsigned char *bytes, int len);
829 ASN1_OBJECT *   X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
830 ASN1_STRING *   X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
831
832 int             X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
833 int             X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
834                                       int nid, int lastpos);
835 int             X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
836                                       ASN1_OBJECT *obj,int lastpos);
837 int             X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
838                                            int crit, int lastpos);
839 X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
840 X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
841 STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
842                                          X509_EXTENSION *ex, int loc);
843
844 int             X509_get_ext_count(X509 *x);
845 int             X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
846 int             X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
847 int             X509_get_ext_by_critical(X509 *x, int crit, int lastpos);
848 X509_EXTENSION *X509_get_ext(X509 *x, int loc);
849 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
850 int             X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
851
852 int             X509_CRL_get_ext_count(X509_CRL *x);
853 int             X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos);
854 int             X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos);
855 int             X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos);
856 X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc);
857 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc);
858 int             X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc);
859
860 int             X509_REVOKED_get_ext_count(X509_REVOKED *x);
861 int             X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos);
862 int             X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos);
863 int             X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos);
864 X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc);
865 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc);
866 int             X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc);
867
868 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex,
869                         int nid, int crit, ASN1_OCTET_STRING *data);
870 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
871                         ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data);
872 int             X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj);
873 int             X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit);
874 int             X509_EXTENSION_set_data(X509_EXTENSION *ex,
875                         ASN1_OCTET_STRING *data);
876 ASN1_OBJECT *   X509_EXTENSION_get_object(X509_EXTENSION *ex);
877 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
878 int             X509_EXTENSION_get_critical(X509_EXTENSION *ex);
879
880 int             X509_verify_cert(X509_STORE_CTX *ctx);
881
882 /* lookup a cert from a X509 STACK */
883 X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
884                                      ASN1_INTEGER *serial);
885 X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
886
887 int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
888 PBEPARAM *PBEPARAM_new(void);
889 PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
890 void PBEPARAM_free(PBEPARAM *a);
891 X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
892
893 int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
894 PBKDF2PARAM *PBKDF2PARAM_new(void);
895 PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
896 void PBKDF2PARAM_free(PBKDF2PARAM *a);
897
898 int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
899 PBE2PARAM *PBE2PARAM_new(void);
900 PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
901 void PBE2PARAM_free(PBE2PARAM *a);
902
903 /* PKCS#8 utilities */
904
905 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
906 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
907 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
908                                          unsigned char **pp, long length);
909 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
910
911 EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
912 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
913 PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
914
915 /* Password based encryption routines */
916
917 int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
918              unsigned char *salt, int saltlen, int iter, EVP_CIPHER_CTX *ctx,
919              int en_de);
920 int EVP_PBE_ALGOR_CipherInit(X509_ALGOR *algor, const char *pass,
921                              int passlen, EVP_CIPHER_CTX *ctx, int en_de);
922 int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
923                     EVP_PBE_KEYGEN *keygen);
924 void EVP_PBE_cleanup(void);
925
926 /* BEGIN ERROR CODES */
927 /* The following lines are auto generated by the script mkerr.pl. Any changes
928  * made after this point may be overwritten when the script is next run.
929  */
930
931 /* Error codes for the X509 functions. */
932
933 /* Function codes. */
934 #define X509_F_ADD_CERT_DIR                              100
935 #define X509_F_BY_FILE_CTRL                              101
936 #define X509_F_DIR_CTRL                                  102
937 #define X509_F_GET_CERT_BY_SUBJECT                       103
938 #define X509_F_X509V3_ADD_EXT                            104
939 #define X509_F_X509_CHECK_PRIVATE_KEY                    128
940 #define X509_F_X509_EXTENSION_CREATE_BY_NID              108
941 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ              109
942 #define X509_F_X509_GET_PUBKEY_PARAMETERS                110
943 #define X509_F_X509_LOAD_CERT_FILE                       111
944 #define X509_F_X509_LOAD_CRL_FILE                        112
945 #define X509_F_X509_NAME_ADD_ENTRY                       113
946 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID             114
947 #define X509_F_X509_NAME_ENTRY_SET_OBJECT                115
948 #define X509_F_X509_NAME_ONELINE                         116
949 #define X509_F_X509_NAME_PRINT                           117
950 #define X509_F_X509_PRINT_FP                             118
951 #define X509_F_X509_PUBKEY_GET                           119
952 #define X509_F_X509_PUBKEY_SET                           120
953 #define X509_F_X509_REQ_PRINT                            121
954 #define X509_F_X509_REQ_PRINT_FP                         122
955 #define X509_F_X509_REQ_TO_X509                          123
956 #define X509_F_X509_STORE_ADD_CERT                       124
957 #define X509_F_X509_STORE_ADD_CRL                        125
958 #define X509_F_X509_TO_X509_REQ                          126
959 #define X509_F_X509_VERIFY_CERT                          127
960
961 /* Reason codes. */
962 #define X509_R_BAD_X509_FILETYPE                         100
963 #define X509_R_CANT_CHECK_DH_KEY                         114
964 #define X509_R_CERT_ALREADY_IN_HASH_TABLE                101
965 #define X509_R_ERR_ASN1_LIB                              102
966 #define X509_R_INVALID_DIRECTORY                         113
967 #define X509_R_KEY_TYPE_MISMATCH                         115
968 #define X509_R_KEY_VALUES_MISMATCH                       116
969 #define X509_R_LOADING_CERT_DIR                          103
970 #define X509_R_LOADING_DEFAULTS                          104
971 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY              105
972 #define X509_R_SHOULD_RETRY                              106
973 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN        107
974 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY            108
975 #define X509_R_UNKNOWN_KEY_TYPE                          117
976 #define X509_R_UNKNOWN_NID                               109
977 #define X509_R_UNSUPPORTED_ALGORITHM                     111
978 #define X509_R_WRONG_LOOKUP_TYPE                         112
979
980 #ifdef  __cplusplus
981 }
982 #endif
983 #endif
984