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.h"
00030
00031
#ifdef __cplusplus
00032
inline int16_t
swap16(int16_t n)
00033 {
00034
return ( ((n & 0xff) << 8) |
00035 ((n & 0xff00) >> 8) );
00036 }
00037
00038
inline uint16_t
swapu16(uint16_t n)
00039 {
00040
return ( ((n & 0xffU) << 8) |
00041 ((n & 0xff00U) >> 8) );
00042 }
00043
00044
inline int32_t
swap32(int32_t n)
00045 {
00046
return ( ((n & 0xff) << 24) |
00047 ((n & 0xff00) << 8) |
00048 ((n & 0xff0000) >> 8) |
00049 ((n & 0xff000000) >> 24) );
00050 }
00051
00052
inline uint32_t
swapu32(uint32_t n)
00053 {
00054
return ( ((n & 0xffU) << 24) |
00055 ((n & 0xff00U) << 8) |
00056 ((n & 0xff0000U) >> 8) |
00057 ((n & 0xff000000U) >> 24) );
00058 }
00059
00060
inline int64_t
swap64(int64_t n)
00061 {
00062
return ( ((n & ((int64_t) 0xff) ) << 56) |
00063 ((n & ((int64_t) 0xff) << 8) << 40) |
00064 ((n & ((int64_t) 0xff) << 16) << 24) |
00065 ((n & ((int64_t) 0xff) << 24) << 8) |
00066 ((n & ((int64_t) 0xff) << 32) >> 8) |
00067 ((n & ((int64_t) 0xff) << 40) >> 24) |
00068 ((n & ((int64_t) 0xff) << 48) >> 40) |
00069 ((n & ((int64_t) 0xff) << 56) >> 56) );
00070 }
00071
#else
00072
int16_t
swap16 (int16_t);
00073 uint16_t
swapu16(uint16_t);
00074 int32_t
swap32 (int32_t);
00075 uint32_t
swapu32(uint32_t);
00076 int64_t
swap64 (int64_t);
00077
#endif
00078
00079
#ifdef __cplusplus
00080
extern "C" {
00081
#endif
00082
00083
#ifdef __cplusplus
00084
}
00085
#endif
00086
00087
#endif