2 * $Id: libnet-asn1.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
4 * libnet-asn1.h - Network routine library ASN.1 header file
6 * Definitions for Abstract Syntax Notation One, ASN.1
7 * As defined in ISO/IS 8824 and ISO/IS 8825
9 * Copyright 1988, 1989 by Carnegie Mellon University
10 * All rights reserved.
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.
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
28 * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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.
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
53 #ifndef __LIBNET_ASN1_H
54 #define __LIBNET_ASN1_H
56 #ifndef EIGHTBIT_SUBIDS
58 #define MAX_SUBID 0xFFFFFFFF
61 #define MAX_SUBID 0xFF
64 #define MAX_OID_LEN 64 /* max subid's in an oid */
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)
75 #define ASN_UNIVERSAL (0x00)
76 #define ASN_APPLICATION (0x40)
77 #define ASN_CONTEXT (0x80)
78 #define ASN_PRIVATE (0xC0)
80 #define ASN_PRIMITIVE (0x00)
81 #define ASN_CONSTRUCTOR (0x20)
83 #define ASN_LONG_LEN (0x80)
84 #define ASN_EXTENSION_ID (0x1F)
85 #define ASN_BIT8 (0x80)
87 #define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
88 #define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID)
91 * All of the build_asn1_* (build_asn1_length being an exception) functions
92 * take the same first 3 arguments:
94 * u_char *data: This is a pointer to the start of the data object to be
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.
106 * Builds an ASN object containing an integer.
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).
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 */
123 * Builds an ASN object containing an unsigned integer.
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).
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 */
139 * Builds an ASN object containing an octect string.
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).
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 */
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
160 * Returns a pointer to the first byte of the contents of this object or
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 */
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 */
182 * Builds an ASN header for a sequence with the ID and length specified.
184 * This only works on data types < 30, i.e. no extension octets.
185 * The maximum length is 0xFFFF;
187 * Returns a pointer to the first byte of the contents of this object.
188 * Returns NULL on any error.
192 libnet_build_asn1_sequence(
201 * Builds an ASN object identifier object containing the input string.
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).
208 libnet_build_asn1_objid(
218 * Builds an ASN null object.
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).
225 libnet_build_asn1_null(
233 * Builds an ASN bitstring.
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).
240 libnet_build_asn1_bitstring(
244 u_char *, /* Pointer to the input buffer */
245 int /* Length of the input buffer */
249 #endif /* __LIBNET_ASN1_H */