home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / include / libnet / libnet-asn1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  7.7 KB  |  253 lines

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