Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

libnet-asn1.h

Go to the documentation of this file.
00001 /*
00002  *  $Id$
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, 1999, 2000 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_long  oid;
00058 #define MAX_SUBID   0xFFFFFFFF
00059 #else
00060 typedef u_char  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_char *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_char 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_char *
00113 libnet_build_asn1_int(
00114     u_char *,           /* Pointer to the output buffer */
00115     int *,              /* Number of valid bytes left in the buffer */
00116     u_char,             /* ASN object type */
00117     long *,             /* Pointer to a long integer */
00118     int                 /* Size of a long 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 u_char *
00129 libnet_build_asn1_uint(
00130     u_char *,           /* Pointer to the output buffer */
00131     int *,              /* Number of valid bytes left in the buffer */
00132     u_char,             /* ASN object type */
00133     u_long *,           /* Pointer to an unsigned long integer */
00134     int                 /* Size of a long integer */
00135     );
00136 
00137 
00138 /*
00139  *  Builds an ASN object containing an octect string.
00140  *
00141  *  Returns NULL upon error or a pointer to the first byte past the end of
00142  *  this object (the start of the next object).
00143  */
00144 
00145 u_char *
00146 libnet_build_asn1_string(
00147     u_char *,           /* Pointer to the output buffer */
00148     int *,              /* Number of valid bytes left in the buffer */
00149     u_char,             /* ASN object type */
00150     u_char *,           /* Pointer to a string to be built into an object */
00151     int                 /* Size of the string */
00152     );
00153 
00154 
00155 /*
00156  *  Builds an ASN header for an object with the ID and length specified.  This
00157  *  only works on data types < 30, i.e. no extension octets.  The maximum
00158  *  length is 0xFFFF;
00159  *
00160  *  Returns a pointer to the first byte of the contents of this object or
00161  *  NULL upon error
00162  */
00163 
00164 u_char *
00165 libnet_build_asn1_header(
00166     u_char *,       /* Pointer to the start of the object */
00167     int *,          /* Number of valid bytes left in buffer */
00168     u_char,         /* ASN object type */
00169     int             /* ASN object length */
00170     );
00171 
00172 
00173 u_char *
00174 libnet_build_asn1_length(
00175     u_char *,       /* Pointer to start of object */
00176     int *,          /* Number of valid bytes in buffer */
00177     int             /* Length of object */
00178     );
00179 
00180 
00181 /*
00182  *  Builds an ASN header for a sequence with the ID and length specified.
00183  *
00184  *  This only works on data types < 30, i.e. no extension octets.
00185  *  The maximum length is 0xFFFF;
00186  *
00187  *  Returns a pointer to the first byte of the contents of this object.
00188  *  Returns NULL on any error.
00189  */
00190 
00191 u_char *
00192 libnet_build_asn1_sequence(
00193     u_char *,
00194     int *,
00195     u_char,
00196     int
00197     );
00198 
00199 
00200 /*
00201  *  Builds an ASN object identifier object containing the input string.
00202  *
00203  *  Returns NULL upon error or a pointer to the first byte past the end of
00204  *  this object (the start of the next object).
00205  */
00206 
00207 u_char *
00208 libnet_build_asn1_objid(
00209     u_char *,
00210     int *,
00211     u_char,
00212     oid *,
00213     int
00214     );
00215 
00216 
00217 /*
00218  *  Builds an ASN null object.
00219  *
00220  *  Returns NULL upon error or a pointer to the first byte past the end of
00221  *  this object (the start of the next object).
00222  */
00223 
00224 u_char *
00225 libnet_build_asn1_null(
00226     u_char *,
00227     int *,
00228     u_char
00229     );
00230 
00231 
00232 /*
00233  *  Builds an ASN bitstring.
00234  *
00235  *  Returns NULL upon error or a pointer to the first byte past the end of
00236  *  this object (the start of the next object).
00237  */
00238 
00239 u_char *
00240 libnet_build_asn1_bitstring(
00241     u_char *,
00242     int *,
00243     u_char,
00244     u_char *,       /* Pointer to the input buffer */
00245     int             /* Length of the input buffer */
00246     );
00247 
00248 
00249 #endif  /* __LIBNET_ASN1_H */
00250 
00251 /* EOF */

Generated on Sun May 14 14:51:19 2006 by  doxygen 1.4.2