- Main Page
- Files

# libnet-asn1.h

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