BeeCrypt
4.2.1
|
00001 /* 00002 * Copyright (c) 1998, 1999, 2000, 2001, 2004 X-Way Rights BV 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 */ 00019 00020 #ifndef _ENDIANNESS_H 00021 #define _ENDIANNESS_H 00022 00023 #include "beecrypt/beecrypt.h" 00024 00025 #if defined(__cplusplus) || HAVE_INLINE 00026 00027 static inline int16_t _swap16(int16_t n) 00028 { 00029 return ( ((n & 0xff) << 8) | 00030 ((n & 0xff00) >> 8) ); 00031 } 00032 # define swap16(n) _swap16(n) 00033 00034 static inline uint16_t _swapu16(uint16_t n) 00035 { 00036 return ( ((n & 0xffU) << 8) | 00037 ((n & 0xff00U) >> 8) ); 00038 } 00039 # define swapu16(n) _swap16(n) 00040 00041 # ifdef __arch__swab32 00042 # define swap32(n) __arch__swab32(n) 00043 # define swapu32(n) __arch__swab32(n) 00044 # else 00045 00046 static inline int32_t _swap32(int32_t n) 00047 { 00048 return ( ((n & 0xff) << 24) | 00049 ((n & 0xff00) << 8) | 00050 ((n & 0xff0000) >> 8) | 00051 ((n & 0xff000000) >> 24) ); 00052 } 00053 # define swap32(n) _swap32(n) 00054 00055 static inline uint32_t _swapu32(uint32_t n) 00056 { 00057 return ( ((n & 0xffU) << 24) | 00058 ((n & 0xff00U) << 8) | 00059 ((n & 0xff0000U) >> 8) | 00060 ((n & 0xff000000U) >> 24) ); 00061 } 00062 # define swapu32(n) _swapu32(n) 00063 00064 # endif 00065 00066 # ifdef __arch__swab64 00067 # define swap64(n) __arch__swab64(n) 00068 # define swapu64(n) __arch__swab64(n) 00069 # else 00070 00071 static inline int64_t _swap64(int64_t n) 00072 { 00073 return ( ((n & ((int64_t) 0xff) ) << 56) | 00074 ((n & ((int64_t) 0xff) << 8) << 40) | 00075 ((n & ((int64_t) 0xff) << 16) << 24) | 00076 ((n & ((int64_t) 0xff) << 24) << 8) | 00077 ((n & ((int64_t) 0xff) << 32) >> 8) | 00078 ((n & ((int64_t) 0xff) << 40) >> 24) | 00079 ((n & ((int64_t) 0xff) << 48) >> 40) | 00080 ((n & ((int64_t) 0xff) << 56) >> 56) ); 00081 } 00082 # define swap64(n) _swap64(n) 00083 00084 static inline uint64_t _swapu64(uint64_t n) 00085 { 00086 return ( ((n & ((uint64_t) 0xff) ) << 56) | 00087 ((n & ((uint64_t) 0xff) << 8) << 40) | 00088 ((n & ((uint64_t) 0xff) << 16) << 24) | 00089 ((n & ((uint64_t) 0xff) << 24) << 8) | 00090 ((n & ((uint64_t) 0xff) << 32) >> 8) | 00091 ((n & ((uint64_t) 0xff) << 40) >> 24) | 00092 ((n & ((uint64_t) 0xff) << 48) >> 40) | 00093 ((n & ((uint64_t) 0xff) << 56) >> 56) ); 00094 } 00095 # define swapu64(n) _swapu64(n) 00096 00097 # endif 00098 00099 #else 00100 BEECRYPTAPI 00101 int16_t swap16 (int16_t); 00102 BEECRYPTAPI 00103 uint16_t swapu16(uint16_t); 00104 BEECRYPTAPI 00105 int32_t swap32 (int32_t); 00106 BEECRYPTAPI 00107 uint32_t swapu32(uint32_t); 00108 BEECRYPTAPI 00109 int64_t swap64 (int64_t); 00110 BEECRYPTAPI 00111 uint64_t swapu64(uint64_t); 00112 #endif 00113 00114 #ifdef __cplusplus 00115 extern "C" { 00116 #endif 00117 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 00122 #endif