netwerk/srtp/src/crypto/include/integers.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * integers.h
     3  *
     4  * defines integer types (or refers to their definitions)
     5  *
     6  * David A. McGrew
     7  * Cisco Systems, Inc.
     8  */
    10 /*
    11  *	
    12  * Copyright (c) 2001-2006, Cisco Systems, Inc.
    13  * All rights reserved.
    14  * 
    15  * Redistribution and use in source and binary forms, with or without
    16  * modification, are permitted provided that the following conditions
    17  * are met:
    18  * 
    19  *   Redistributions of source code must retain the above copyright
    20  *   notice, this list of conditions and the following disclaimer.
    21  * 
    22  *   Redistributions in binary form must reproduce the above
    23  *   copyright notice, this list of conditions and the following
    24  *   disclaimer in the documentation and/or other materials provided
    25  *   with the distribution.
    26  * 
    27  *   Neither the name of the Cisco Systems, Inc. nor the names of its
    28  *   contributors may be used to endorse or promote products derived
    29  *   from this software without specific prior written permission.
    30  * 
    31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    34  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    35  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    36  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    38  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    42  * OF THE POSSIBILITY OF SUCH DAMAGE.
    43  *
    44  */
    47 #ifndef INTEGERS_H
    48 #define INTEGERS_H
    50 #include "config.h"	/* configuration file, using autoconf          */
    52 #ifdef SRTP_KERNEL
    54 #include "kernel_compat.h"
    56 #else /* SRTP_KERNEL */
    58 /* use standard integer definitions, if they're available  */
    59 #ifdef HAVE_STDLIB_H
    60 # include <stdlib.h>
    61 #endif
    62 #ifdef INTEGER_TYPES_H
    63 /* Let configure tell us where to get the equivalent to <stdint.h> */
    64 #include INTEGER_TYPES_H
    66 #if !defined(HAVE_UINT64_T)
    67 #define NO_64BIT_MATH 1
    68 #endif
    69 #else
    70 #ifdef HAVE_STDINT_H
    71 # include <stdint.h>
    72 #endif
    73 #endif /* INTEGER_TYPES_H */
    74 #ifdef HAVE_INTTYPES_H
    75 # include <inttypes.h>
    76 #endif
    77 #ifdef HAVE_SYS_TYPES_H
    78 # include <sys/types.h>
    79 #endif
    80 #ifdef HAVE_SYS_INT_TYPES_H
    81 # include <sys/int_types.h>    /* this exists on Sun OS */
    82 #endif
    83 #ifdef HAVE_MACHINE_TYPES_H
    84 # include <machine/types.h>
    85 #endif
    87 /* Can we do 64 bit integers? */
    88 #if !defined(HAVE_UINT64_T)
    89 # if SIZEOF_UNSIGNED_LONG == 8
    90 typedef unsigned long		uint64_t;
    91 # elif SIZEOF_UNSIGNED_LONG_LONG == 8
    92 typedef unsigned long long	uint64_t;
    93 # else
    94 #  define NO_64BIT_MATH 1
    95 # endif
    96 #endif
    98 /* Reasonable defaults for 32 bit machines - you may need to
    99  * edit these definitions for your own machine. */
   100 #ifndef HAVE_UINT8_T
   101 typedef unsigned char		uint8_t;
   102 #endif
   103 #ifndef HAVE_UINT16_T
   104 typedef unsigned short int	uint16_t;
   105 #endif
   106 #ifndef HAVE_UINT32_T
   107 typedef unsigned int		uint32_t;
   108 #endif
   110 #ifdef NO_64BIT_MATH
   111 typedef double uint64_t;
   112 /* assert that sizeof(double) == 8 */
   113 extern uint64_t make64(uint32_t high, uint32_t low);
   114 extern uint32_t high32(uint64_t value);
   115 extern uint32_t low32(uint64_t value);
   116 #endif
   118 #endif /* SRTP_KERNEL */
   120 /* These macros are to load and store 32-bit values from un-aligned
   121    addresses.  This is required for processors that do not allow unaligned
   122    loads. */
   123 #ifdef ALIGNMENT_32BIT_REQUIRED
   124 /* Note that if it's in a variable, you can memcpy it */
   125 #ifdef WORDS_BIGENDIAN
   126 #define PUT_32(addr,value) \
   127     { \
   128         ((unsigned char *) (addr))[0] = (value >> 24); \
   129         ((unsigned char *) (addr))[1] = (value >> 16) & 0xff; \
   130         ((unsigned char *) (addr))[2] = (value >> 8) & 0xff; \
   131         ((unsigned char *) (addr))[3] = (value)      & 0xff; \
   132     }
   133 #define GET_32(addr) ((((unsigned char *) (addr))[0] << 24) |  \
   134                       (((unsigned char *) (addr))[1] << 16) |  \
   135                       (((unsigned char *) (addr))[2] << 8)  |  \
   136                       (((unsigned char *) (addr))[3])) 
   137 #else
   138 #define PUT_32(addr,value) \
   139     { \
   140         ((unsigned char *) (addr))[3] = (value >> 24); \
   141         ((unsigned char *) (addr))[2] = (value >> 16) & 0xff; \
   142         ((unsigned char *) (addr))[1] = (value >> 8) & 0xff; \
   143         ((unsigned char *) (addr))[0] = (value)      & 0xff; \
   144     }
   145 #define GET_32(addr) ((((unsigned char *) (addr))[3] << 24) |  \
   146                       (((unsigned char *) (addr))[2] << 16) |  \
   147                       (((unsigned char *) (addr))[1] << 8)  |  \
   148                       (((unsigned char *) (addr))[0])) 
   149 #endif // WORDS_BIGENDIAN
   150 #else
   151 #define PUT_32(addr,value) *(((uint32_t *) (addr)) = (value)
   152 #define GET_32(addr) (*(((uint32_t *) (addr)))
   153 #endif
   155 #endif /* INTEGERS_H */

mercurial