1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/integers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +/* 1.5 + * integers.h 1.6 + * 1.7 + * defines integer types (or refers to their definitions) 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + */ 1.12 + 1.13 +/* 1.14 + * 1.15 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.16 + * All rights reserved. 1.17 + * 1.18 + * Redistribution and use in source and binary forms, with or without 1.19 + * modification, are permitted provided that the following conditions 1.20 + * are met: 1.21 + * 1.22 + * Redistributions of source code must retain the above copyright 1.23 + * notice, this list of conditions and the following disclaimer. 1.24 + * 1.25 + * Redistributions in binary form must reproduce the above 1.26 + * copyright notice, this list of conditions and the following 1.27 + * disclaimer in the documentation and/or other materials provided 1.28 + * with the distribution. 1.29 + * 1.30 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.31 + * contributors may be used to endorse or promote products derived 1.32 + * from this software without specific prior written permission. 1.33 + * 1.34 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.35 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.36 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.37 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.38 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.39 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.40 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.41 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.42 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.43 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.44 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.45 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.46 + * 1.47 + */ 1.48 + 1.49 + 1.50 +#ifndef INTEGERS_H 1.51 +#define INTEGERS_H 1.52 + 1.53 +#include "config.h" /* configuration file, using autoconf */ 1.54 + 1.55 +#ifdef SRTP_KERNEL 1.56 + 1.57 +#include "kernel_compat.h" 1.58 + 1.59 +#else /* SRTP_KERNEL */ 1.60 + 1.61 +/* use standard integer definitions, if they're available */ 1.62 +#ifdef HAVE_STDLIB_H 1.63 +# include <stdlib.h> 1.64 +#endif 1.65 +#ifdef INTEGER_TYPES_H 1.66 +/* Let configure tell us where to get the equivalent to <stdint.h> */ 1.67 +#include INTEGER_TYPES_H 1.68 + 1.69 +#if !defined(HAVE_UINT64_T) 1.70 +#define NO_64BIT_MATH 1 1.71 +#endif 1.72 +#else 1.73 +#ifdef HAVE_STDINT_H 1.74 +# include <stdint.h> 1.75 +#endif 1.76 +#endif /* INTEGER_TYPES_H */ 1.77 +#ifdef HAVE_INTTYPES_H 1.78 +# include <inttypes.h> 1.79 +#endif 1.80 +#ifdef HAVE_SYS_TYPES_H 1.81 +# include <sys/types.h> 1.82 +#endif 1.83 +#ifdef HAVE_SYS_INT_TYPES_H 1.84 +# include <sys/int_types.h> /* this exists on Sun OS */ 1.85 +#endif 1.86 +#ifdef HAVE_MACHINE_TYPES_H 1.87 +# include <machine/types.h> 1.88 +#endif 1.89 + 1.90 +/* Can we do 64 bit integers? */ 1.91 +#if !defined(HAVE_UINT64_T) 1.92 +# if SIZEOF_UNSIGNED_LONG == 8 1.93 +typedef unsigned long uint64_t; 1.94 +# elif SIZEOF_UNSIGNED_LONG_LONG == 8 1.95 +typedef unsigned long long uint64_t; 1.96 +# else 1.97 +# define NO_64BIT_MATH 1 1.98 +# endif 1.99 +#endif 1.100 + 1.101 +/* Reasonable defaults for 32 bit machines - you may need to 1.102 + * edit these definitions for your own machine. */ 1.103 +#ifndef HAVE_UINT8_T 1.104 +typedef unsigned char uint8_t; 1.105 +#endif 1.106 +#ifndef HAVE_UINT16_T 1.107 +typedef unsigned short int uint16_t; 1.108 +#endif 1.109 +#ifndef HAVE_UINT32_T 1.110 +typedef unsigned int uint32_t; 1.111 +#endif 1.112 + 1.113 +#ifdef NO_64BIT_MATH 1.114 +typedef double uint64_t; 1.115 +/* assert that sizeof(double) == 8 */ 1.116 +extern uint64_t make64(uint32_t high, uint32_t low); 1.117 +extern uint32_t high32(uint64_t value); 1.118 +extern uint32_t low32(uint64_t value); 1.119 +#endif 1.120 + 1.121 +#endif /* SRTP_KERNEL */ 1.122 + 1.123 +/* These macros are to load and store 32-bit values from un-aligned 1.124 + addresses. This is required for processors that do not allow unaligned 1.125 + loads. */ 1.126 +#ifdef ALIGNMENT_32BIT_REQUIRED 1.127 +/* Note that if it's in a variable, you can memcpy it */ 1.128 +#ifdef WORDS_BIGENDIAN 1.129 +#define PUT_32(addr,value) \ 1.130 + { \ 1.131 + ((unsigned char *) (addr))[0] = (value >> 24); \ 1.132 + ((unsigned char *) (addr))[1] = (value >> 16) & 0xff; \ 1.133 + ((unsigned char *) (addr))[2] = (value >> 8) & 0xff; \ 1.134 + ((unsigned char *) (addr))[3] = (value) & 0xff; \ 1.135 + } 1.136 +#define GET_32(addr) ((((unsigned char *) (addr))[0] << 24) | \ 1.137 + (((unsigned char *) (addr))[1] << 16) | \ 1.138 + (((unsigned char *) (addr))[2] << 8) | \ 1.139 + (((unsigned char *) (addr))[3])) 1.140 +#else 1.141 +#define PUT_32(addr,value) \ 1.142 + { \ 1.143 + ((unsigned char *) (addr))[3] = (value >> 24); \ 1.144 + ((unsigned char *) (addr))[2] = (value >> 16) & 0xff; \ 1.145 + ((unsigned char *) (addr))[1] = (value >> 8) & 0xff; \ 1.146 + ((unsigned char *) (addr))[0] = (value) & 0xff; \ 1.147 + } 1.148 +#define GET_32(addr) ((((unsigned char *) (addr))[3] << 24) | \ 1.149 + (((unsigned char *) (addr))[2] << 16) | \ 1.150 + (((unsigned char *) (addr))[1] << 8) | \ 1.151 + (((unsigned char *) (addr))[0])) 1.152 +#endif // WORDS_BIGENDIAN 1.153 +#else 1.154 +#define PUT_32(addr,value) *(((uint32_t *) (addr)) = (value) 1.155 +#define GET_32(addr) (*(((uint32_t *) (addr))) 1.156 +#endif 1.157 + 1.158 +#endif /* INTEGERS_H */