Main Page | File List | Globals

libnet-asn1.h

00001 /*
00002  *  $Id: libnet-asn1.h,v 1.2 2003/09/23 22:36:54 mike Exp $
00003  *
00004  *  libnet-asn1.h - Network routine library ASN.1 header file
00005  *
00006  *  Definitions for Abstract Syntax Notation One, ASN.1
00007  *  As defined in ISO/IS 8824 and ISO/IS 8825
00008  *
00009  *  Copyright 1988, 1989 by Carnegie Mellon University
00010  *  All rights reserved.
00011  *
00012  *  Permission to use, copy, modify, and distribute this software and its
00013  *  documentation for any purpose and without fee is hereby granted,
00014  *  provided that the above copyright notice appear in all copies and that
00015  *  both that copyright notice and this permission notice appear in
00016  *  supporting documentation, and that the name of CMU not be
00017  *  used in advertising or publicity pertaining to distribution of the
00018  *  software without specific, written prior permission.
00019  *
00020  *  CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00021  *  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00022  *  CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00023  *  ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00024  *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00025  *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00026  *  SOFTWARE.
00027  *
00028  *  Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
00029  *  All rights reserved.
00030  *
00031  * Redistribution and use in source and binary forms, with or without
00032  * modification, are permitted provided that the following conditions
00033  * are met:
00034  * 1. Redistributions of source code must retain the above copyright
00035  *    notice, this list of conditions and the following disclaimer.
00036  * 2. Redistributions in binary form must reproduce the above copyright
00037  *    notice, this list of conditions and the following disclaimer in the
00038  *    documentation and/or other materials provided with the distribution.
00039  *
00040  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00041  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00042  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00043  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00044  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00045  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00046  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00047  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00048  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00049  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00050  * SUCH DAMAGE.
00051  */
00052 
00053 #ifndef __LIBNET_ASN1_H
00054 #define __LIBNET_ASN1_H
00055 
00056 #ifndef EIGHTBIT_SUBIDS
00057 typedef u_int32_t  oid;
00058 #define MAX_SUBID   0xFFFFFFFF
00059 #else
00060 typedef u_int8_t  oid;
00061 #define MAX_SUBID   0xFF
00062 #endif
00063 
00064 #define MAX_OID_LEN         64  /* max subid's in an oid */
00065 
00066 #define ASN_BOOLEAN         (0x01)
00067 #define ASN_INTEGER         (0x02)
00068 #define ASN_BIT_STR         (0x03)
00069 #define ASN_OCTET_STR       (0x04)
00070 #define ASN_NULL            (0x05)
00071 #define ASN_OBJECT_ID       (0x06)
00072 #define ASN_SEQUENCE        (0x10)
00073 #define ASN_SET             (0x11)
00074 
00075 #define ASN_UNIVERSAL       (0x00)
00076 #define ASN_APPLICATION     (0x40)
00077 #define ASN_CONTEXT         (0x80)
00078 #define ASN_PRIVATE         (0xC0)
00079 
00080 #define ASN_PRIMITIVE       (0x00)
00081 #define ASN_CONSTRUCTOR     (0x20)
00082 
00083 #define ASN_LONG_LEN        (0x80)
00084 #define ASN_EXTENSION_ID    (0x1F)
00085 #define ASN_BIT8            (0x80)
00086 
00087 #define IS_CONSTRUCTOR(byte)  ((byte) & ASN_CONSTRUCTOR)
00088 #define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID)
00089 
00090 /*
00091  *  All of the build_asn1_* (build_asn1_length being an exception) functions
00092  *  take the same first 3 arguments:
00093  *
00094  *  u_int8_t *data:   This is a pointer to the start of the data object to be
00095  *                  manipulated.
00096  *  int *datalen:   This is a pointer to the number of valid bytes following
00097  *                  "data".  This should be not be exceeded in any function.
00098  *                  Upon exiting a function, this value will reflect the
00099  *                  changed "data" and then refer to the new number of valid
00100  *                  bytes until the end of "data".
00101  *  u_int8_t type:    The ASN.1 object type.
00102  */
00103 
00104 
00105 /*
00106  *  Builds an ASN object containing an integer.
00107  *
00108  *  Returns NULL upon error or a pointer to the first byte past the end of
00109  *  this object (the start of the next object).
00110  */
00111 
00112 u_int8_t *
00113 libnet_build_asn1_int(
00114     u_int8_t *,           /* Pointer to the output buffer */
00115     int *,              /* Number of valid bytes left in the buffer */
00116     u_int8_t,             /* ASN object type */
00117     int32_t *,             /* Pointer to a int32_t integer */
00118     int                 /* Size of a int32_t integer */
00119     );
00120 
00121 
00122 /*
00123  *  Builds an ASN object containing an unsigned integer.
00124  *
00125  *  Returns NULL upon error or a pointer to the first byte past the end of
00126  *  this object (the start of the next object).
00127  */
00128 
00129 u_int8_t *
00130 libnet_build_asn1_uint(
00131     u_int8_t *,           /* Pointer to the output buffer */
00132     int *,              /* Number of valid bytes left in the buffer */
00133     u_int8_t,             /* ASN object type */
00134     u_int32_t *,           /* Pointer to an unsigned int32_t integer */
00135     int                 /* Size of a int32_t integer */
00136     );
00137 
00138 
00139 /*
00140  *  Builds an ASN object containing an octect string.
00141  *
00142  *  Returns NULL upon error or a pointer to the first byte past the end of
00143  *  this object (the start of the next object).
00144  */
00145 
00146 u_int8_t *
00147 libnet_build_asn1_string(
00148     u_int8_t *,           /* Pointer to the output buffer */
00149     int *,              /* Number of valid bytes left in the buffer */
00150     u_int8_t,             /* ASN object type */
00151     u_int8_t *,           /* Pointer to a string to be built into an object */
00152     int                 /* Size of the string */
00153     );
00154 
00155 
00156 /*
00157  *  Builds an ASN header for an object with the ID and length specified.  This
00158  *  only works on data types < 30, i.e. no extension octets.  The maximum
00159  *  length is 0xFFFF;
00160  *
00161  *  Returns a pointer to the first byte of the contents of this object or
00162  *  NULL upon error
00163  */
00164 
00165 u_int8_t *
00166 libnet_build_asn1_header(
00167     u_int8_t *,       /* Pointer to the start of the object */
00168     int *,          /* Number of valid bytes left in buffer */
00169     u_int8_t,         /* ASN object type */
00170     int             /* ASN object length */
00171     );
00172 
00173 
00174 u_int8_t *
00175 libnet_build_asn1_length(
00176     u_int8_t *,       /* Pointer to start of object */
00177     int *,          /* Number of valid bytes in buffer */
00178     int             /* Length of object */
00179     );
00180 
00181 
00182 /*
00183  *  Builds an ASN header for a sequence with the ID and length specified.
00184  *
00185  *  This only works on data types < 30, i.e. no extension octets.
00186  *  The maximum length is 0xFFFF;
00187  *
00188  *  Returns a pointer to the first byte of the contents of this object.
00189  *  Returns NULL on any error.
00190  */
00191 
00192 u_int8_t *
00193 libnet_build_asn1_sequence(
00194     u_int8_t *,
00195     int *,
00196     u_int8_t,
00197     int
00198     );
00199 
00200 
00201 /*
00202  *  Builds an ASN object identifier object containing the input string.
00203  *
00204  *  Returns NULL upon error or a pointer to the first byte past the end of
00205  *  this object (the start of the next object).
00206  */
00207 
00208 u_int8_t *
00209 libnet_build_asn1_objid(
00210     u_int8_t *,
00211     int *,
00212     u_int8_t,
00213     oid *,
00214     int
00215     );
00216 
00217 
00218 /*
00219  *  Builds an ASN null object.
00220  *
00221  *  Returns NULL upon error or a pointer to the first byte past the end of
00222  *  this object (the start of the next object).
00223  */
00224 
00225 u_int8_t *
00226 libnet_build_asn1_null(
00227     u_int8_t *,
00228     int *,
00229     u_int8_t
00230     );
00231 
00232 
00233 /*
00234  *  Builds an ASN bitstring.
00235  *
00236  *  Returns NULL upon error or a pointer to the first byte past the end of
00237  *  this object (the start of the next object).
00238  */
00239 
00240 u_int8_t *
00241 libnet_build_asn1_bitstring(
00242     u_int8_t *,
00243     int *,
00244     u_int8_t,
00245     u_int8_t *,       /* Pointer to the input buffer */
00246     int             /* Length of the input buffer */
00247     );
00248 
00249 
00250 #endif  /* __LIBNET_ASN1_H */
00251 
00252 /* EOF */

Generated on Wed Nov 12 09:57:54 2003 for libnet by doxygen 1.3.2