OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / include / libnet / libnet-asn1.h
1 /*
2  *  $Id: libnet-asn1.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet-asn1.h - Network routine library ASN.1 header file
5  *
6  *  Definitions for Abstract Syntax Notation One, ASN.1
7  *  As defined in ISO/IS 8824 and ISO/IS 8825
8  *
9  *  Copyright 1988, 1989 by Carnegie Mellon University
10  *  All rights reserved.
11  *
12  *  Permission to use, copy, modify, and distribute this software and its
13  *  documentation for any purpose and without fee is hereby granted,
14  *  provided that the above copyright notice appear in all copies and that
15  *  both that copyright notice and this permission notice appear in
16  *  supporting documentation, and that the name of CMU not be
17  *  used in advertising or publicity pertaining to distribution of the
18  *  software without specific, written prior permission.
19  *
20  *  CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
21  *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
22  *  CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
23  *  ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24  *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25  *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26  *  SOFTWARE.
27  *
28  *  Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
29  *  All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  * 1. Redistributions of source code must retain the above copyright
35  *    notice, this list of conditions and the following disclaimer.
36  * 2. Redistributions in binary form must reproduce the above copyright
37  *    notice, this list of conditions and the following disclaimer in the
38  *    documentation and/or other materials provided with the distribution.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  */
52
53 #ifndef __LIBNET_ASN1_H
54 #define __LIBNET_ASN1_H
55
56 #ifndef EIGHTBIT_SUBIDS
57 typedef u_long  oid;
58 #define MAX_SUBID   0xFFFFFFFF
59 #else
60 typedef u_char  oid;
61 #define MAX_SUBID   0xFF
62 #endif
63
64 #define MAX_OID_LEN         64  /* max subid's in an oid */
65
66 #define ASN_BOOLEAN         (0x01)
67 #define ASN_INTEGER         (0x02)
68 #define ASN_BIT_STR         (0x03)
69 #define ASN_OCTET_STR       (0x04)
70 #define ASN_NULL            (0x05)
71 #define ASN_OBJECT_ID       (0x06)
72 #define ASN_SEQUENCE        (0x10)
73 #define ASN_SET             (0x11)
74
75 #define ASN_UNIVERSAL       (0x00)
76 #define ASN_APPLICATION     (0x40)
77 #define ASN_CONTEXT         (0x80)
78 #define ASN_PRIVATE         (0xC0)
79
80 #define ASN_PRIMITIVE       (0x00)
81 #define ASN_CONSTRUCTOR     (0x20)
82
83 #define ASN_LONG_LEN        (0x80)
84 #define ASN_EXTENSION_ID    (0x1F)
85 #define ASN_BIT8            (0x80)
86
87 #define IS_CONSTRUCTOR(byte)  ((byte) & ASN_CONSTRUCTOR)
88 #define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID)
89
90 /*
91  *  All of the build_asn1_* (build_asn1_length being an exception) functions
92  *  take the same first 3 arguments:
93  *
94  *  u_char *data:   This is a pointer to the start of the data object to be
95  *                  manipulated.
96  *  int *datalen:   This is a pointer to the number of valid bytes following
97  *                  "data".  This should be not be exceeded in any function.
98  *                  Upon exiting a function, this value will reflect the
99  *                  changed "data" and then refer to the new number of valid
100  *                  bytes until the end of "data".
101  *  u_char type:    The ASN.1 object type.
102  */
103
104
105 /*
106  *  Builds an ASN object containing an integer.
107  *
108  *  Returns NULL upon error or a pointer to the first byte past the end of
109  *  this object (the start of the next object).
110  */
111
112 u_char *
113 libnet_build_asn1_int(
114     u_char *,           /* Pointer to the output buffer */
115     int *,              /* Number of valid bytes left in the buffer */
116     u_char,             /* ASN object type */
117     long *,             /* Pointer to a long integer */
118     int                 /* Size of a long integer */
119     );
120
121
122 /*
123  *  Builds an ASN object containing an unsigned integer.
124  *
125  *  Returns NULL upon error or a pointer to the first byte past the end of
126  *  this object (the start of the next object).
127  */
128 u_char *
129 libnet_build_asn1_uint(
130     u_char *,           /* Pointer to the output buffer */
131     int *,              /* Number of valid bytes left in the buffer */
132     u_char,             /* ASN object type */
133     u_long *,           /* Pointer to an unsigned long integer */
134     int                 /* Size of a long integer */
135     );
136
137
138 /*
139  *  Builds an ASN object containing an octect string.
140  *
141  *  Returns NULL upon error or a pointer to the first byte past the end of
142  *  this object (the start of the next object).
143  */
144
145 u_char *
146 libnet_build_asn1_string(
147     u_char *,           /* Pointer to the output buffer */
148     int *,              /* Number of valid bytes left in the buffer */
149     u_char,             /* ASN object type */
150     u_char *,           /* Pointer to a string to be built into an object */
151     int                 /* Size of the string */
152     );
153
154
155 /*
156  *  Builds an ASN header for an object with the ID and length specified.  This
157  *  only works on data types < 30, i.e. no extension octets.  The maximum
158  *  length is 0xFFFF;
159  *
160  *  Returns a pointer to the first byte of the contents of this object or
161  *  NULL upon error
162  */
163
164 u_char *
165 libnet_build_asn1_header(
166     u_char *,       /* Pointer to the start of the object */
167     int *,          /* Number of valid bytes left in buffer */
168     u_char,         /* ASN object type */
169     int             /* ASN object length */
170     );
171
172
173 u_char *
174 libnet_build_asn1_length(
175     u_char *,       /* Pointer to start of object */
176     int *,          /* Number of valid bytes in buffer */
177     int             /* Length of object */
178     );
179
180
181 /*
182  *  Builds an ASN header for a sequence with the ID and length specified.
183  *
184  *  This only works on data types < 30, i.e. no extension octets.
185  *  The maximum length is 0xFFFF;
186  *
187  *  Returns a pointer to the first byte of the contents of this object.
188  *  Returns NULL on any error.
189  */
190
191 u_char *
192 libnet_build_asn1_sequence(
193     u_char *,
194     int *,
195     u_char,
196     int
197     );
198
199
200 /*
201  *  Builds an ASN object identifier object containing the input string.
202  *
203  *  Returns NULL upon error or a pointer to the first byte past the end of
204  *  this object (the start of the next object).
205  */
206
207 u_char *
208 libnet_build_asn1_objid(
209     u_char *,
210     int *,
211     u_char,
212     oid *,
213     int
214     );
215
216
217 /*
218  *  Builds an ASN null object.
219  *
220  *  Returns NULL upon error or a pointer to the first byte past the end of
221  *  this object (the start of the next object).
222  */
223
224 u_char *
225 libnet_build_asn1_null(
226     u_char *,
227     int *,
228     u_char
229     );
230
231
232 /*
233  *  Builds an ASN bitstring.
234  *
235  *  Returns NULL upon error or a pointer to the first byte past the end of
236  *  this object (the start of the next object).
237  */
238
239 u_char *
240 libnet_build_asn1_bitstring(
241     u_char *,
242     int *,
243     u_char,
244     u_char *,       /* Pointer to the input buffer */
245     int             /* Length of the input buffer */
246     );
247
248
249 #endif  /* __LIBNET_ASN1_H */
250
251 /* EOF */