00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _ENDIANNESS_H
00027 #define _ENDIANNESS_H
00028
00029 #include "beecrypt/beecrypt.h"
00030
00031 #if defined(__cplusplus) || HAVE_INLINE
00032
00033 static inline int16_t _swap16(int16_t n)
00034 {
00035 return ( ((n & 0xff) << 8) |
00036 ((n & 0xff00) >> 8) );
00037 }
00038 # define swap16(n) _swap16(n)
00039
00040 static inline uint16_t _swapu16(uint16_t n)
00041 {
00042 return ( ((n & 0xffU) << 8) |
00043 ((n & 0xff00U) >> 8) );
00044 }
00045 # define swapu16(n) _swap16(n)
00046
00047 # ifdef __arch__swab32
00048 # define swap32(n) __arch__swab32(n)
00049 # define swapu32(n) __arch__swab32(n)
00050 # else
00051
00052 static inline int32_t _swap32(int32_t n)
00053 {
00054 return ( ((n & 0xff) << 24) |
00055 ((n & 0xff00) << 8) |
00056 ((n & 0xff0000) >> 8) |
00057 ((n & 0xff000000) >> 24) );
00058 }
00059 # define swap32(n) _swap32(n)
00060
00061 static inline uint32_t _swapu32(uint32_t n)
00062 {
00063 return ( ((n & 0xffU) << 24) |
00064 ((n & 0xff00U) << 8) |
00065 ((n & 0xff0000U) >> 8) |
00066 ((n & 0xff000000U) >> 24) );
00067 }
00068 # define swapu32(n) _swapu32(n)
00069
00070 # endif
00071
00072 # ifdef __arch__swab64
00073 # define swap64(n) __arch__swab64(n)
00074 # define swapu64(n) __arch__swab64(n)
00075 # else
00076
00077 static inline int64_t _swap64(int64_t n)
00078 {
00079 return ( ((n & ((int64_t) 0xff) ) << 56) |
00080 ((n & ((int64_t) 0xff) << 8) << 40) |
00081 ((n & ((int64_t) 0xff) << 16) << 24) |
00082 ((n & ((int64_t) 0xff) << 24) << 8) |
00083 ((n & ((int64_t) 0xff) << 32) >> 8) |
00084 ((n & ((int64_t) 0xff) << 40) >> 24) |
00085 ((n & ((int64_t) 0xff) << 48) >> 40) |
00086 ((n & ((int64_t) 0xff) << 56) >> 56) );
00087 }
00088 # define swap64(n) _swap64(n)
00089
00090 static inline uint64_t _swapu64(uint64_t n)
00091 {
00092 return ( ((n & ((uint64_t) 0xff) ) << 56) |
00093 ((n & ((uint64_t) 0xff) << 8) << 40) |
00094 ((n & ((uint64_t) 0xff) << 16) << 24) |
00095 ((n & ((uint64_t) 0xff) << 24) << 8) |
00096 ((n & ((uint64_t) 0xff) << 32) >> 8) |
00097 ((n & ((uint64_t) 0xff) << 40) >> 24) |
00098 ((n & ((uint64_t) 0xff) << 48) >> 40) |
00099 ((n & ((uint64_t) 0xff) << 56) >> 56) );
00100 }
00101 # define swapu64(n) _swapu64(n)
00102
00103 # endif
00104
00105 #else
00106 BEECRYPTAPI
00107 int16_t swap16 (int16_t);
00108 BEECRYPTAPI
00109 uint16_t swapu16(uint16_t);
00110 BEECRYPTAPI
00111 int32_t swap32 (int32_t);
00112 BEECRYPTAPI
00113 uint32_t swapu32(uint32_t);
00114 BEECRYPTAPI
00115 int64_t swap64 (int64_t);
00116 BEECRYPTAPI
00117 uint64_t swapu64(uint64_t);
00118 #endif
00119
00120 #ifdef __cplusplus
00121 extern "C" {
00122 #endif
00123
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127
00128 #endif