michael@0: /* michael@0: * integers.h michael@0: * michael@0: * defines integer types (or refers to their definitions) michael@0: * michael@0: * David A. McGrew michael@0: * Cisco Systems, Inc. michael@0: */ michael@0: michael@0: /* michael@0: * michael@0: * Copyright (c) 2001-2006, Cisco Systems, Inc. michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * Redistributions in binary form must reproduce the above michael@0: * copyright notice, this list of conditions and the following michael@0: * disclaimer in the documentation and/or other materials provided michael@0: * with the distribution. michael@0: * michael@0: * Neither the name of the Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS michael@0: * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE michael@0: * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, michael@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES michael@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR michael@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED michael@0: * OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: */ michael@0: michael@0: michael@0: #ifndef INTEGERS_H michael@0: #define INTEGERS_H michael@0: michael@0: #include "config.h" /* configuration file, using autoconf */ michael@0: michael@0: #ifdef SRTP_KERNEL michael@0: michael@0: #include "kernel_compat.h" michael@0: michael@0: #else /* SRTP_KERNEL */ michael@0: michael@0: /* use standard integer definitions, if they're available */ michael@0: #ifdef HAVE_STDLIB_H michael@0: # include michael@0: #endif michael@0: #ifdef INTEGER_TYPES_H michael@0: /* Let configure tell us where to get the equivalent to */ michael@0: #include INTEGER_TYPES_H michael@0: michael@0: #if !defined(HAVE_UINT64_T) michael@0: #define NO_64BIT_MATH 1 michael@0: #endif michael@0: #else michael@0: #ifdef HAVE_STDINT_H michael@0: # include michael@0: #endif michael@0: #endif /* INTEGER_TYPES_H */ michael@0: #ifdef HAVE_INTTYPES_H michael@0: # include michael@0: #endif michael@0: #ifdef HAVE_SYS_TYPES_H michael@0: # include michael@0: #endif michael@0: #ifdef HAVE_SYS_INT_TYPES_H michael@0: # include /* this exists on Sun OS */ michael@0: #endif michael@0: #ifdef HAVE_MACHINE_TYPES_H michael@0: # include michael@0: #endif michael@0: michael@0: /* Can we do 64 bit integers? */ michael@0: #if !defined(HAVE_UINT64_T) michael@0: # if SIZEOF_UNSIGNED_LONG == 8 michael@0: typedef unsigned long uint64_t; michael@0: # elif SIZEOF_UNSIGNED_LONG_LONG == 8 michael@0: typedef unsigned long long uint64_t; michael@0: # else michael@0: # define NO_64BIT_MATH 1 michael@0: # endif michael@0: #endif michael@0: michael@0: /* Reasonable defaults for 32 bit machines - you may need to michael@0: * edit these definitions for your own machine. */ michael@0: #ifndef HAVE_UINT8_T michael@0: typedef unsigned char uint8_t; michael@0: #endif michael@0: #ifndef HAVE_UINT16_T michael@0: typedef unsigned short int uint16_t; michael@0: #endif michael@0: #ifndef HAVE_UINT32_T michael@0: typedef unsigned int uint32_t; michael@0: #endif michael@0: michael@0: #ifdef NO_64BIT_MATH michael@0: typedef double uint64_t; michael@0: /* assert that sizeof(double) == 8 */ michael@0: extern uint64_t make64(uint32_t high, uint32_t low); michael@0: extern uint32_t high32(uint64_t value); michael@0: extern uint32_t low32(uint64_t value); michael@0: #endif michael@0: michael@0: #endif /* SRTP_KERNEL */ michael@0: michael@0: /* These macros are to load and store 32-bit values from un-aligned michael@0: addresses. This is required for processors that do not allow unaligned michael@0: loads. */ michael@0: #ifdef ALIGNMENT_32BIT_REQUIRED michael@0: /* Note that if it's in a variable, you can memcpy it */ michael@0: #ifdef WORDS_BIGENDIAN michael@0: #define PUT_32(addr,value) \ michael@0: { \ michael@0: ((unsigned char *) (addr))[0] = (value >> 24); \ michael@0: ((unsigned char *) (addr))[1] = (value >> 16) & 0xff; \ michael@0: ((unsigned char *) (addr))[2] = (value >> 8) & 0xff; \ michael@0: ((unsigned char *) (addr))[3] = (value) & 0xff; \ michael@0: } michael@0: #define GET_32(addr) ((((unsigned char *) (addr))[0] << 24) | \ michael@0: (((unsigned char *) (addr))[1] << 16) | \ michael@0: (((unsigned char *) (addr))[2] << 8) | \ michael@0: (((unsigned char *) (addr))[3])) michael@0: #else michael@0: #define PUT_32(addr,value) \ michael@0: { \ michael@0: ((unsigned char *) (addr))[3] = (value >> 24); \ michael@0: ((unsigned char *) (addr))[2] = (value >> 16) & 0xff; \ michael@0: ((unsigned char *) (addr))[1] = (value >> 8) & 0xff; \ michael@0: ((unsigned char *) (addr))[0] = (value) & 0xff; \ michael@0: } michael@0: #define GET_32(addr) ((((unsigned char *) (addr))[3] << 24) | \ michael@0: (((unsigned char *) (addr))[2] << 16) | \ michael@0: (((unsigned char *) (addr))[1] << 8) | \ michael@0: (((unsigned char *) (addr))[0])) michael@0: #endif // WORDS_BIGENDIAN michael@0: #else michael@0: #define PUT_32(addr,value) *(((uint32_t *) (addr)) = (value) michael@0: #define GET_32(addr) (*(((uint32_t *) (addr))) michael@0: #endif michael@0: michael@0: #endif /* INTEGERS_H */