Import of old SSLeay release: SSLeay 0.9.0b
[openssl.git] / crypto / asn1 / asn1.h
1 /* crypto/asn1/asn1.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_ASN1_H
60 #define HEADER_ASN1_H
61
62 #ifdef  __cplusplus
63 extern "C" {
64 #endif
65
66 #include <time.h>
67 #include "bn.h"
68 #include "stack.h"
69
70 #define V_ASN1_UNIVERSAL                0x00
71 #define V_ASN1_APPLICATION              0x40
72 #define V_ASN1_CONTEXT_SPECIFIC         0x80
73 #define V_ASN1_PRIVATE                  0xc0
74
75 #define V_ASN1_CONSTRUCTED              0x20
76 #define V_ASN1_PRIMATIVE_TAG            0x1f
77
78 #define V_ASN1_APP_CHOOSE               -2      /* let the recipent choose */
79
80 #define V_ASN1_UNDEF                    -1
81 #define V_ASN1_EOC                      0
82 #define V_ASN1_BOOLEAN                  1       /**/
83 #define V_ASN1_INTEGER                  2
84 #define V_ASN1_NEG_INTEGER              (2+0x100)
85 #define V_ASN1_BIT_STRING               3
86 #define V_ASN1_OCTET_STRING             4
87 #define V_ASN1_NULL                     5
88 #define V_ASN1_OBJECT                   6
89 #define V_ASN1_OBJECT_DESCRIPTOR        7
90 #define V_ASN1_EXTERNAL                 8
91 #define V_ASN1_REAL                     9
92 #define V_ASN1_ENUMERATED               10      /* microsoft weirdness */
93 #define V_ASN1_SEQUENCE                 16
94 #define V_ASN1_SET                      17
95 #define V_ASN1_NUMERICSTRING            18      /**/
96 #define V_ASN1_PRINTABLESTRING          19
97 #define V_ASN1_T61STRING                20
98 #define V_ASN1_TELETEXSTRING            20      /* alias */
99 #define V_ASN1_VIDEOTEXSTRING           21      /**/
100 #define V_ASN1_IA5STRING                22
101 #define V_ASN1_UTCTIME                  23
102 #define V_ASN1_GENERALIZEDTIME          24      /**/
103 #define V_ASN1_GRAPHICSTRING            25      /**/
104 #define V_ASN1_ISO64STRING              26      /**/
105 #define V_ASN1_VISIBLESTRING            26      /* alias */
106 #define V_ASN1_GENERALSTRING            27      /**/
107 #define V_ASN1_UNIVERSALSTRING          28      /**/
108 #define V_ASN1_BMPSTRING                30
109
110 /* For use with d2i_ASN1_type_bytes() */
111 #define B_ASN1_NUMERICSTRING    0x0001
112 #define B_ASN1_PRINTABLESTRING  0x0002
113 #define B_ASN1_T61STRING        0x0004
114 #define B_ASN1_VIDEOTEXSTRING   0x0008
115 #define B_ASN1_IA5STRING        0x0010
116 #define B_ASN1_GRAPHICSTRING    0x0020
117 #define B_ASN1_ISO64STRING      0x0040
118 #define B_ASN1_GENERALSTRING    0x0080
119 #define B_ASN1_UNIVERSALSTRING  0x0100
120 #define B_ASN1_OCTET_STRING     0x0200
121 #define B_ASN1_BIT_STRING       0x0400
122 #define B_ASN1_BMPSTRING        0x0800
123 #define B_ASN1_UNKNOWN          0x1000
124
125 #ifndef DEBUG
126
127 #define ASN1_INTEGER            ASN1_STRING
128 #define ASN1_BIT_STRING         ASN1_STRING
129 #define ASN1_OCTET_STRING       ASN1_STRING
130 #define ASN1_PRINTABLESTRING    ASN1_STRING
131 #define ASN1_T61STRING          ASN1_STRING
132 #define ASN1_IA5STRING          ASN1_STRING
133 #define ASN1_UTCTIME            ASN1_STRING
134 #define ASN1_GENERALIZEDTIME    ASN1_STRING
135 #define ASN1_GENERALSTRING      ASN1_STRING
136 #define ASN1_UNIVERSALSTRING    ASN1_STRING
137 #define ASN1_BMPSTRING          ASN1_STRING
138
139 #else
140
141 typedef struct asn1_integer_st
142         {
143         int length;
144         int type;
145         unsigned char *data;
146         } ASN1_INTEGER;
147
148 typedef struct asn1_bit_string_st
149         {
150         int length;
151         int type;
152         unsigned char *data;
153         } ASN1_BIT_STRING;
154
155 typedef struct asn1_octet_string_st
156         {
157         int length;
158         int type;
159         unsigned char *data;
160         } ASN1_OCTET_STRING;
161
162 typedef struct asn1_printablestring_st
163         {
164         int length;
165         int type;
166         unsigned char *data;
167         } ASN1_PRINTABLESTRING;
168
169 typedef struct asn1_t61string_st
170         {
171         int length;
172         int type;
173         unsigned char *data;
174         } ASN1_T61STRING;
175
176 typedef struct asn1_ia5string_st
177         {
178         int length;
179         int type;
180         unsigned char *data;
181         } ASN1_IA5STRING;
182
183 typedef struct asn1_generalstring_st
184         {
185         int length;
186         int type;
187         unsigned char *data;
188         } ASN1_GENERALSTRING;
189
190 typedef struct asn1_universalstring_st
191         {
192         int length;
193         int type;
194         unsigned char *data;
195         } ASN1_UNIVERSALSTRING;
196
197 typedef struct asn1_bmpstring_st
198         {
199         int length;
200         int type;
201         unsigned char *data;
202         } ASN1_BMPSTRING;
203
204 typedef struct asn1_utctime_st
205         {
206         int length;
207         int type;
208         unsigned char *data;
209         } ASN1_UTCTIME;
210
211 typedef struct asn1_generalizedtime_st
212         {
213         int length;
214         int type;
215         unsigned char *data;
216         } ASN1_GENERALIZEDTIME;
217
218 #endif
219
220 typedef struct asn1_ctx_st
221         {
222         unsigned char *p;/* work char pointer */
223         int eos;        /* end of sequence read for indefinite encoding */
224         int error;      /* error code to use when returning an error */
225         int inf;        /* constructed if 0x20, indefinite is 0x21 */
226         int tag;        /* tag from last 'get object' */
227         int xclass;     /* class from last 'get object' */
228         long slen;      /* length of last 'get object' */
229         unsigned char *max; /* largest value of p alowed */
230         unsigned char *q;/* temporary variable */
231         unsigned char **pp;/* variable */
232         } ASN1_CTX;
233
234 /* These are used internally in the ASN1_OBJECT to keep track of
235  * whether the names and data need to be free()ed */
236 #define ASN1_OBJECT_FLAG_DYNAMIC         0x01   /* internal use */
237 #define ASN1_OBJECT_FLAG_CRITICAL        0x02   /* critical x509v3 object id */
238 #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04   /* internal use */
239 #define ASN1_OBJECT_FLAG_DYNAMIC_DATA    0x08   /* internal use */
240 typedef struct asn1_object_st
241         {
242         char *sn,*ln;
243         int nid;
244         int length;
245         unsigned char *data;
246         int flags;      /* Should we free this one */
247         } ASN1_OBJECT;
248
249 /* This is the base type that holds just about everything :-) */
250 typedef struct asn1_string_st
251         {
252         int length;
253         int type;
254         unsigned char *data;
255         } ASN1_STRING;
256
257 typedef struct asn1_type_st
258         {
259         int type;
260         union   {
261                 char *ptr;
262                 ASN1_STRING *           asn1_string;
263                 ASN1_OBJECT *           object;
264                 ASN1_INTEGER *          integer;
265                 ASN1_BIT_STRING *       bit_string;
266                 ASN1_OCTET_STRING *     octet_string;
267                 ASN1_PRINTABLESTRING *  printablestring;
268                 ASN1_T61STRING *        t61string;
269                 ASN1_IA5STRING *        ia5string;
270                 ASN1_GENERALSTRING *    generalstring;
271                 ASN1_BMPSTRING *        bmpstring;
272                 ASN1_UNIVERSALSTRING *  universalstring;
273                 ASN1_UTCTIME *          utctime;
274                 ASN1_GENERALIZEDTIME *  generalizedtime;
275                 /* set and sequence are left complete and still
276                  * contain the set or sequence bytes */
277                 ASN1_STRING *           set;
278                 ASN1_STRING *           sequence;
279                 } value;
280         } ASN1_TYPE;
281
282 typedef struct asn1_method_st
283         {
284         int (*i2d)();
285         char *(*d2i)();
286         char *(*create)();
287         void (*destroy)();
288         } ASN1_METHOD;
289
290 /* This is used when parsing some Netscape objects */
291 typedef struct asn1_header_st
292         {
293         ASN1_OCTET_STRING *header;
294         char *data;
295         ASN1_METHOD *meth;
296         } ASN1_HEADER;
297
298 #define ASN1_STRING_length(x)   ((x)->length)
299 #define ASN1_STRING_type(x)     ((x)->type)
300 #define ASN1_STRING_data(x)     ((x)->data)
301
302 /* Macros for string operations */
303 #define ASN1_BIT_STRING_new()   (ASN1_BIT_STRING *)\
304                 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
305 #define ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
306 #define ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
307                 ASN1_STRING_dup((ASN1_STRING *)a)
308 #define ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
309                 (ASN1_STRING *)a,(ASN1_STRING *)b)
310 #define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
311 /* i2d_ASN1_BIT_STRING() is a function */
312 /* d2i_ASN1_BIT_STRING() is a function */
313
314 #define ASN1_INTEGER_new()      (ASN1_INTEGER *)\
315                 ASN1_STRING_type_new(V_ASN1_INTEGER)
316 #define ASN1_INTEGER_free(a)            ASN1_STRING_free((ASN1_STRING *)a)
317 #define ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a)
318 #define ASN1_INTEGER_cmp(a,b)   ASN1_STRING_cmp(\
319                 (ASN1_STRING *)a,(ASN1_STRING *)b)
320 /* ASN1_INTEGER_set() is a function, also see BN_to_ASN1_INTEGER() */
321 /* ASN1_INTEGER_get() is a function, also see ASN1_INTEGER_to_BN() */
322 /* i2d_ASN1_INTEGER() is a function */
323 /* d2i_ASN1_INTEGER() is a function */
324
325 #define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
326                 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
327 #define ASN1_OCTET_STRING_free(a)       ASN1_STRING_free((ASN1_STRING *)a)
328 #define ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
329                 ASN1_STRING_dup((ASN1_STRING *)a)
330 #define ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
331                 (ASN1_STRING *)a,(ASN1_STRING *)b)
332 #define ASN1_OCTET_STRING_set(a,b,c)    ASN1_STRING_set((ASN1_STRING *)a,b,c)
333 #define ASN1_OCTET_STRING_print(a,b)    ASN1_STRING_print(a,(ASN1_STRING *)b)
334 #define M_i2d_ASN1_OCTET_STRING(a,pp) \
335                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\
336                 V_ASN1_OCTET_STRING)
337 /* d2i_ASN1_OCTET_STRING() is a function */
338
339 #define ASN1_PRINTABLE_new()    ASN1_STRING_type_new(V_ASN1_T61STRING)
340 #define ASN1_PRINTABLE_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
341 #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
342                 pp,a->type,V_ASN1_UNIVERSAL)
343 #define M_d2i_ASN1_PRINTABLE(a,pp,l) \
344                 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
345                         B_ASN1_PRINTABLESTRING| \
346                         B_ASN1_T61STRING| \
347                         B_ASN1_IA5STRING| \
348                         B_ASN1_BIT_STRING| \
349                         B_ASN1_UNIVERSALSTRING|\
350                         B_ASN1_BMPSTRING|\
351                         B_ASN1_UNKNOWN)
352
353 #define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\
354                 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
355 #define ASN1_PRINTABLESTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
356 #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
357                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\
358                 V_ASN1_UNIVERSAL)
359 #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \
360                 (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\
361                 ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING)
362
363 #define ASN1_T61STRING_new()    (ASN1_T61STRING_STRING *)\
364                 ASN1_STRING_type_new(V_ASN1_T61STRING)
365 #define ASN1_T61STRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
366 #define M_i2d_ASN1_T61STRING(a,pp) \
367                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\
368                 V_ASN1_UNIVERSAL)
369 #define M_d2i_ASN1_T61STRING(a,pp,l) \
370                 (ASN1_T61STRING *)d2i_ASN1_type_bytes\
371                 ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING)
372
373 #define ASN1_IA5STRING_new()    (ASN1_IA5STRING *)\
374                 ASN1_STRING_type_new(V_ASN1_IA5STRING)
375 #define ASN1_IA5STRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
376 #define M_i2d_ASN1_IA5STRING(a,pp) \
377                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
378                         V_ASN1_UNIVERSAL)
379 #define M_d2i_ASN1_IA5STRING(a,pp,l) \
380                 (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\
381                         B_ASN1_IA5STRING)
382
383 #define ASN1_UTCTIME_new()      (ASN1_UTCTIME *)\
384                 ASN1_STRING_type_new(V_ASN1_UTCTIME)
385 #define ASN1_UTCTIME_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
386 #define ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a)
387 /* i2d_ASN1_UTCTIME() is a function */
388 /* d2i_ASN1_UTCTIME() is a function */
389 /* ASN1_UTCTIME_set() is a function */
390 /* ASN1_UTCTIME_check() is a function */
391
392 #define ASN1_GENERALIZEDTIME_new()      (ASN1_GENERALIZEDTIME *)\
393                 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
394 #define ASN1_GENERALIZEDTIME_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
395 #define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\
396         (ASN1_STRING *)a)
397 /* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */
398 /* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */
399 /* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */
400 /* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */
401
402 #define ASN1_GENERALSTRING_new()        (ASN1_GENERALSTRING *)\
403                 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
404 #define ASN1_GENERALSTRING_free(a)      ASN1_STRING_free((ASN1_STRING *)a)
405 #define M_i2d_ASN1_GENERALSTRING(a,pp) \
406                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\
407                         V_ASN1_UNIVERSAL)
408 #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \
409                 (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\
410                 ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING)
411
412 #define ASN1_UNIVERSALSTRING_new()      (ASN1_UNIVERSALSTRING *)\
413                 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
414 #define ASN1_UNIVERSALSTRING_free(a)    ASN1_STRING_free((ASN1_STRING *)a)
415 #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \
416                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\
417                         V_ASN1_UNIVERSAL)
418 #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \
419                 (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\
420                 ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING)
421
422 #define ASN1_BMPSTRING_new()    (ASN1_BMPSTRING *)\
423                 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
424 #define ASN1_BMPSTRING_free(a)  ASN1_STRING_free((ASN1_STRING *)a)
425 #define M_i2d_ASN1_BMPSTRING(a,pp) \
426                 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\
427                         V_ASN1_UNIVERSAL)
428 #define M_d2i_ASN1_BMPSTRING(a,pp,l) \
429                 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
430                 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
431
432 #ifndef NOPROTO
433 ASN1_TYPE *     ASN1_TYPE_new(void );
434 void            ASN1_TYPE_free(ASN1_TYPE *a);
435 int             i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
436 ASN1_TYPE *     d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
437 int ASN1_TYPE_get(ASN1_TYPE *a);
438 void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value);
439
440 ASN1_OBJECT *   ASN1_OBJECT_new(void );
441 void            ASN1_OBJECT_free(ASN1_OBJECT *a);
442 int             i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
443 ASN1_OBJECT *   d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
444                         long length);
445
446 ASN1_STRING *   ASN1_STRING_new(void );
447 void            ASN1_STRING_free(ASN1_STRING *a);
448 ASN1_STRING *   ASN1_STRING_dup(ASN1_STRING *a);
449 ASN1_STRING *   ASN1_STRING_type_new(int type );
450 int             ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
451 int             ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len);
452
453 int             i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
454 ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
455                         long length);
456 int             ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
457 int             ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
458
459
460 int             i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
461 int             d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
462
463 int             i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
464 ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
465                         long length);
466
467 int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
468 ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
469 int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); 
470
471 int             i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
472 ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
473                         unsigned char **pp,long length);
474
475 int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
476 ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
477         unsigned char **pp, long l);
478 ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
479         unsigned char **pp, long l);
480
481 ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
482         unsigned char **pp, long l);
483 int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
484 ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a,
485         unsigned char **pp, long l);
486
487 int             i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
488 ASN1_UTCTIME *  d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
489                         long length);
490
491 int             i2d_ASN1_SET(STACK *a, unsigned char **pp,
492                         int (*func)(), int ex_tag, int ex_class);
493 STACK *         d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
494                         char *(*func)(), int ex_tag, int ex_class);
495
496 #ifdef HEADER_BIO_H
497 int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
498 int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
499 int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
500 int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
501 int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
502 #endif
503 int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
504
505 int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num);
506 ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
507         char *sn, char *ln);
508
509 int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
510 long ASN1_INTEGER_get(ASN1_INTEGER *a);
511 ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
512 BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
513
514 /* General */
515 /* given a string, return the correct type, max is the maximum length */
516 int ASN1_PRINTABLE_type(unsigned char *s, int max);
517
518 int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
519 ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
520         long length, int Ptag, int Pclass);
521 /* type is one or more of the B_ASN1_ values. */
522 ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
523                 long length,int type);
524
525 /* PARSING */
526 int asn1_Finish(ASN1_CTX *c);
527
528 /* SPECIALS */
529 int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
530         int *pclass, long omax);
531 int ASN1_check_infinite_end(unsigned char **p,long len);
532 void ASN1_put_object(unsigned char **pp, int constructed, int length,
533         int tag, int xclass);
534 int ASN1_object_size(int constructed, int length, int tag);
535
536 /* Used to implement other functions */
537 char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
538
539 #ifndef NO_FP_API
540 char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
541 int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
542 #endif
543
544 #ifdef HEADER_BIO_H
545 char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
546 int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
547 int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
548 int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
549 int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
550 #endif
551
552 /* Used to load and write netscape format cert/key */
553 int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
554 ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
555 ASN1_HEADER *ASN1_HEADER_new(void );
556 void ASN1_HEADER_free(ASN1_HEADER *a);
557
558 int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
559
560 void ERR_load_ASN1_strings(void);
561
562 /* Not used that much at this point, except for the first two */
563 ASN1_METHOD *X509_asn1_meth(void);
564 ASN1_METHOD *RSAPrivateKey_asn1_meth(void);
565 ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void);
566 ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void);
567
568 int ASN1_TYPE_set_octetstring(ASN1_TYPE *a,
569         unsigned char *data, int len);
570 int ASN1_TYPE_get_octetstring(ASN1_TYPE *a,
571         unsigned char *data, int max_len);
572 int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
573         unsigned char *data, int len);
574 int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
575         unsigned char *data, int max_len);
576
577 #else
578
579 ASN1_TYPE *     ASN1_TYPE_new();
580 void            ASN1_TYPE_free();
581 int             i2d_ASN1_TYPE();
582 ASN1_TYPE *     d2i_ASN1_TYPE();
583 int ASN1_TYPE_get();
584 void ASN1_TYPE_set();
585
586 ASN1_OBJECT *   ASN1_OBJECT_new();
587 void            ASN1_OBJECT_free();
588 int             i2d_ASN1_OBJECT();
589 ASN1_OBJECT *   d2i_ASN1_OBJECT();
590 ASN1_STRING *   ASN1_STRING_new();
591 void            ASN1_STRING_free();
592 ASN1_STRING *   ASN1_STRING_dup();
593 ASN1_STRING *   ASN1_STRING_type_new();
594 int             ASN1_STRING_cmp();
595 int             ASN1_STRING_set();
596 int             i2d_ASN1_BIT_STRING();
597 ASN1_BIT_STRING *d2i_ASN1_BIT_STRING();
598 int             ASN1_BIT_STRING_set_bit();
599 int             ASN1_BIT_STRING_get_bit();
600 int             i2d_ASN1_BOOLEAN();
601 int             d2i_ASN1_BOOLEAN();
602 int             i2d_ASN1_INTEGER();
603 ASN1_INTEGER *d2i_ASN1_INTEGER();
604 int ASN1_UTCTIME_check();
605 ASN1_UTCTIME *ASN1_UTCTIME_set();
606 int ASN1_UTCTIME_set_string();
607 int             i2d_ASN1_OCTET_STRING();
608 ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING();
609 int i2d_ASN1_PRINTABLE();
610 ASN1_STRING *d2i_ASN1_PRINTABLE();
611 ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING();
612 ASN1_T61STRING *d2i_ASN1_T61STRING();
613 int i2d_ASN1_IA5STRING();
614 ASN1_IA5STRING *d2i_ASN1_IA5STRING();
615 int             i2d_ASN1_UTCTIME();
616 ASN1_UTCTIME *  d2i_ASN1_UTCTIME();
617 int             i2d_ASN1_SET();
618 STACK *         d2i_ASN1_SET();
619 int a2d_ASN1_OBJECT();
620 ASN1_OBJECT *ASN1_OBJECT_create();
621 int ASN1_INTEGER_set();
622 long ASN1_INTEGER_get();
623 ASN1_INTEGER *BN_to_ASN1_INTEGER();
624 BIGNUM *ASN1_INTEGER_to_BN();
625 int ASN1_PRINTABLE_type();
626 int i2d_ASN1_bytes();
627 ASN1_STRING *d2i_ASN1_bytes();
628 ASN1_STRING *d2i_ASN1_type_bytes();
629 int asn1_Finish();
630 int ASN1_get_object();
631 int ASN1_check_infinite_end();
632 void ASN1_put_object();
633 int ASN1_object_size();
634 char *ASN1_dup();
635 #ifndef NO_FP_API
636 char *ASN1_d2i_fp();
637 int ASN1_i2d_fp();
638 #endif
639
640 char *ASN1_d2i_bio();
641 int ASN1_i2d_bio();
642 int ASN1_UTCTIME_print();
643 int ASN1_STRING_print();
644 int ASN1_parse();
645 int i2a_ASN1_INTEGER();
646 int a2i_ASN1_INTEGER();
647 int i2a_ASN1_OBJECT();
648 int i2t_ASN1_OBJECT();
649 int a2i_ASN1_STRING();
650 int i2a_ASN1_STRING();
651
652 int i2d_ASN1_HEADER();
653 ASN1_HEADER *d2i_ASN1_HEADER();
654 ASN1_HEADER *ASN1_HEADER_new();
655 void ASN1_HEADER_free();
656 void ERR_load_ASN1_strings();
657 ASN1_METHOD *X509_asn1_meth();
658 ASN1_METHOD *RSAPrivateKey_asn1_meth();
659 ASN1_METHOD *ASN1_IA5STRING_asn1_meth();
660 ASN1_METHOD *ASN1_BIT_STRING_asn1_meth();
661
662 int ASN1_UNIVERSALSTRING_to_string();
663
664 int ASN1_TYPE_set_octetstring();
665 int ASN1_TYPE_get_octetstring();
666 int ASN1_TYPE_set_int_octetstring();
667 int ASN1_TYPE_get_int_octetstring();
668
669 #endif
670
671 /* BEGIN ERROR CODES */
672 /* Error codes for the ASN1 functions. */
673
674 /* Function codes. */
675 #define ASN1_F_A2D_ASN1_OBJECT                           100
676 #define ASN1_F_A2I_ASN1_INTEGER                          101
677 #define ASN1_F_A2I_ASN1_STRING                           102
678 #define ASN1_F_ASN1_COLLATE_PRIMATIVE                    103
679 #define ASN1_F_ASN1_D2I_BIO                              104
680 #define ASN1_F_ASN1_D2I_FP                               105
681 #define ASN1_F_ASN1_DUP                                  106
682 #define ASN1_F_ASN1_GET_OBJECT                           107
683 #define ASN1_F_ASN1_HEADER_NEW                           108
684 #define ASN1_F_ASN1_I2D_BIO                              109
685 #define ASN1_F_ASN1_I2D_FP                               110
686 #define ASN1_F_ASN1_INTEGER_SET                          111
687 #define ASN1_F_ASN1_INTEGER_TO_BN                        112
688 #define ASN1_F_ASN1_OBJECT_NEW                           113
689 #define ASN1_F_ASN1_SIGN                                 114
690 #define ASN1_F_ASN1_STRING_NEW                           115
691 #define ASN1_F_ASN1_STRING_TYPE_NEW                      116
692 #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING             117
693 #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING                 118
694 #define ASN1_F_ASN1_TYPE_NEW                             119
695 #define ASN1_F_ASN1_UTCTIME_NEW                          120
696 #define ASN1_F_ASN1_VERIFY                               121
697 #define ASN1_F_BN_TO_ASN1_INTEGER                        122
698 #define ASN1_F_D2I_ASN1_BIT_STRING                       123
699 #define ASN1_F_D2I_ASN1_BMPSTRING                        124
700 #define ASN1_F_D2I_ASN1_BOOLEAN                          125
701 #define ASN1_F_D2I_ASN1_BYTES                            126
702 #define ASN1_F_D2I_ASN1_HEADER                           127
703 #define ASN1_F_D2I_ASN1_INTEGER                          128
704 #define ASN1_F_D2I_ASN1_OBJECT                           129
705 #define ASN1_F_D2I_ASN1_OCTET_STRING                     130
706 #define ASN1_F_D2I_ASN1_PRINT_TYPE                       131
707 #define ASN1_F_D2I_ASN1_SET                              132
708 #define ASN1_F_D2I_ASN1_TYPE                             133
709 #define ASN1_F_D2I_ASN1_TYPE_BYTES                       134
710 #define ASN1_F_D2I_ASN1_UTCTIME                          135
711 #define ASN1_F_D2I_DHPARAMS                              136
712 #define ASN1_F_D2I_DSAPARAMS                             137
713 #define ASN1_F_D2I_DSAPRIVATEKEY                         138
714 #define ASN1_F_D2I_DSAPUBLICKEY                          139
715 #define ASN1_F_D2I_NETSCAPE_PKEY                         140
716 #define ASN1_F_D2I_NETSCAPE_RSA                          141
717 #define ASN1_F_D2I_NETSCAPE_RSA_2                        142
718 #define ASN1_F_D2I_NETSCAPE_SPKAC                        143
719 #define ASN1_F_D2I_NETSCAPE_SPKI                         144
720 #define ASN1_F_D2I_PKCS7                                 145
721 #define ASN1_F_D2I_PKCS7_DIGEST                          146
722 #define ASN1_F_D2I_PKCS7_ENCRYPT                         147
723 #define ASN1_F_D2I_PKCS7_ENC_CONTENT                     148
724 #define ASN1_F_D2I_PKCS7_ENVELOPE                        149
725 #define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL               150
726 #define ASN1_F_D2I_PKCS7_RECIP_INFO                      151
727 #define ASN1_F_D2I_PKCS7_SIGNED                          152
728 #define ASN1_F_D2I_PKCS7_SIGNER_INFO                     153
729 #define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE                   154
730 #define ASN1_F_D2I_PRIVATEKEY                            155
731 #define ASN1_F_D2I_PUBLICKEY                             156
732 #define ASN1_F_D2I_RSAPRIVATEKEY                         157
733 #define ASN1_F_D2I_RSAPUBLICKEY                          158
734 #define ASN1_F_D2I_X509                                  159
735 #define ASN1_F_D2I_X509_ALGOR                            160
736 #define ASN1_F_D2I_X509_ATTRIBUTE                        161
737 #define ASN1_F_D2I_X509_CINF                             162
738 #define ASN1_F_D2I_X509_CRL                              163
739 #define ASN1_F_D2I_X509_CRL_INFO                         164
740 #define ASN1_F_D2I_X509_EXTENSION                        165
741 #define ASN1_F_D2I_X509_KEY                              166
742 #define ASN1_F_D2I_X509_NAME                             167
743 #define ASN1_F_D2I_X509_NAME_ENTRY                       168
744 #define ASN1_F_D2I_X509_PKEY                             169
745 #define ASN1_F_D2I_X509_PUBKEY                           170
746 #define ASN1_F_D2I_X509_REQ                              171
747 #define ASN1_F_D2I_X509_REQ_INFO                         172
748 #define ASN1_F_D2I_X509_REVOKED                          173
749 #define ASN1_F_D2I_X509_SIG                              174
750 #define ASN1_F_D2I_X509_VAL                              175
751 #define ASN1_F_I2D_ASN1_HEADER                           176
752 #define ASN1_F_I2D_DHPARAMS                              177
753 #define ASN1_F_I2D_DSAPARAMS                             178
754 #define ASN1_F_I2D_DSAPRIVATEKEY                         179
755 #define ASN1_F_I2D_DSAPUBLICKEY                          180
756 #define ASN1_F_I2D_NETSCAPE_RSA                          181
757 #define ASN1_F_I2D_PKCS7                                 182
758 #define ASN1_F_I2D_PRIVATEKEY                            183
759 #define ASN1_F_I2D_PUBLICKEY                             184
760 #define ASN1_F_I2D_RSAPRIVATEKEY                         185
761 #define ASN1_F_I2D_RSAPUBLICKEY                          186
762 #define ASN1_F_I2D_X509_ATTRIBUTE                        187
763 #define ASN1_F_I2T_ASN1_OBJECT                           188
764 #define ASN1_F_NETSCAPE_PKEY_NEW                         189
765 #define ASN1_F_NETSCAPE_SPKAC_NEW                        190
766 #define ASN1_F_NETSCAPE_SPKI_NEW                         191
767 #define ASN1_F_PKCS7_DIGEST_NEW                          192
768 #define ASN1_F_PKCS7_ENCRYPT_NEW                         193
769 #define ASN1_F_PKCS7_ENC_CONTENT_NEW                     194
770 #define ASN1_F_PKCS7_ENVELOPE_NEW                        195
771 #define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW               196
772 #define ASN1_F_PKCS7_NEW                                 197
773 #define ASN1_F_PKCS7_RECIP_INFO_NEW                      198
774 #define ASN1_F_PKCS7_SIGNED_NEW                          199
775 #define ASN1_F_PKCS7_SIGNER_INFO_NEW                     200
776 #define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW                   201
777 #define ASN1_F_X509_ALGOR_NEW                            202
778 #define ASN1_F_X509_ATTRIBUTE_NEW                        203
779 #define ASN1_F_X509_CINF_NEW                             204
780 #define ASN1_F_X509_CRL_INFO_NEW                         205
781 #define ASN1_F_X509_CRL_NEW                              206
782 #define ASN1_F_X509_DHPARAMS_NEW                         207
783 #define ASN1_F_X509_EXTENSION_NEW                        208
784 #define ASN1_F_X509_INFO_NEW                             209
785 #define ASN1_F_X509_KEY_NEW                              210
786 #define ASN1_F_X509_NAME_ENTRY_NEW                       211
787 #define ASN1_F_X509_NAME_NEW                             212
788 #define ASN1_F_X509_NEW                                  213
789 #define ASN1_F_X509_PKEY_NEW                             214
790 #define ASN1_F_X509_PUBKEY_NEW                           215
791 #define ASN1_F_X509_REQ_INFO_NEW                         216
792 #define ASN1_F_X509_REQ_NEW                              217
793 #define ASN1_F_X509_REVOKED_NEW                          218
794 #define ASN1_F_X509_SIG_NEW                              219
795 #define ASN1_F_X509_VAL_FREE                             220
796 #define ASN1_F_X509_VAL_NEW                              221
797
798 /* Reason codes. */
799 #define ASN1_R_BAD_CLASS                                 100
800 #define ASN1_R_BAD_GET_OBJECT                            101
801 #define ASN1_R_BAD_OBJECT_HEADER                         102
802 #define ASN1_R_BAD_PASSWORD_READ                         103
803 #define ASN1_R_BAD_PKCS7_CONTENT                         104
804 #define ASN1_R_BAD_PKCS7_TYPE                            105
805 #define ASN1_R_BAD_TAG                                   106
806 #define ASN1_R_BAD_TYPE                                  107
807 #define ASN1_R_BN_LIB                                    108
808 #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH                   109
809 #define ASN1_R_BUFFER_TOO_SMALL                          110
810 #define ASN1_R_DATA_IS_WRONG                             111
811 #define ASN1_R_DECODING_ERROR                            112
812 #define ASN1_R_ERROR_STACK                               113
813 #define ASN1_R_EXPECTING_AN_INTEGER                      114
814 #define ASN1_R_EXPECTING_AN_OBJECT                       115
815 #define ASN1_R_EXPECTING_AN_OCTET_STRING                 116
816 #define ASN1_R_EXPECTING_A_BIT_STRING                    117
817 #define ASN1_R_EXPECTING_A_BOOLEAN                       118
818 #define ASN1_R_EXPECTING_A_SEQUENCE                      119
819 #define ASN1_R_EXPECTING_A_UTCTIME                       120
820 #define ASN1_R_FIRST_NUM_TOO_LARGE                       121
821 #define ASN1_R_HEADER_TOO_LONG                           122
822 #define ASN1_R_INVALID_DIGIT                             123
823 #define ASN1_R_INVALID_SEPARATOR                         124
824 #define ASN1_R_INVALID_TIME_FORMAT                       125
825 #define ASN1_R_IV_TOO_LARGE                              126
826 #define ASN1_R_LENGTH_ERROR                              127
827 #define ASN1_R_LENGTH_MISMATCH                           128
828 #define ASN1_R_MISSING_EOS                               129
829 #define ASN1_R_MISSING_SECOND_NUMBER                     130
830 #define ASN1_R_NON_HEX_CHARACTERS                        131
831 #define ASN1_R_NOT_ENOUGH_DATA                           132
832 #define ASN1_R_ODD_NUMBER_OF_CHARS                       133
833 #define ASN1_R_PARSING                                   134
834 #define ASN1_R_PRIVATE_KEY_HEADER_MISSING                135
835 #define ASN1_R_SECOND_NUMBER_TOO_LARGE                   136
836 #define ASN1_R_SHORT_LINE                                137
837 #define ASN1_R_STRING_TOO_SHORT                          138
838 #define ASN1_R_TAG_VALUE_TOO_HIGH                        139
839 #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140
840 #define ASN1_R_TOO_LONG                                  141
841 #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY                  142
842 #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY          143
843 #define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE                    144
844 #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM          145
845 #define ASN1_R_UNKNOWN_OBJECT_TYPE                       146
846 #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE                   147
847 #define ASN1_R_UNSUPPORTED_CIPHER                        148
848 #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM          149
849 #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE               150
850 #define ASN1_R_UTCTIME_TOO_LONG                          151
851 #define ASN1_R_WRONG_PRINTABLE_TYPE                      152
852 #define ASN1_R_WRONG_TAG                                 153
853 #define ASN1_R_WRONG_TYPE                                154
854  
855 #ifdef  __cplusplus
856 }
857 #endif
858 #endif
859