Go to the documentation of this file.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
00027
00028
00029
00030
00031
00032 #ifndef SecurityDefinesHPP
00033 #define SecurityDefinesHPP
00034
00035
00038
00039 enum ECryptType
00040 {
00041 etSimpleDES = 0,
00042 etXTEA = 1
00043 };
00044
00045
00046 #define SHFR(x, n) (x >> n)
00047 #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
00048 #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
00049 #define CH(x, y, z) ((x & y) ^ (~x & z))
00050 #define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
00051
00052
00053
00054 #define PACK32(str, x)\
00055 { \
00056 *(x) = ((Uint32) *((str) + 3)) | \
00057 ((Uint32) *((str) + 2) << 8) | \
00058 ((Uint32) *((str) + 1) << 16) | \
00059 ((Uint32) *((str) + 0) << 24); \
00060 }
00061
00062
00063
00064 #define UNPACK32(x, str) \
00065 { \
00066 *((str) + 3) = (Uint8) ((x)); \
00067 *((str) + 2) = (Uint8) ((x) >> 8); \
00068 *((str) + 1) = (Uint8) ((x) >> 16); \
00069 *((str) + 0) = (Uint8) ((x) >> 24); \
00070 }
00071
00072
00073
00074 #define PACK64(str, x) \
00075 { \
00076 *(x) = ((Uint64) *((str) + 7) ) | \
00077 ((Uint64) *((str) + 6) << 8) | \
00078 ((Uint64) *((str) + 5) << 16) | \
00079 ((Uint64) *((str) + 4) << 24) | \
00080 ((Uint64) *((str) + 3) << 32) | \
00081 ((Uint64) *((str) + 2) << 40) | \
00082 ((Uint64) *((str) + 1) << 48) | \
00083 ((Uint64) *((str) + 0) << 56); \
00084 }
00085
00086
00087
00088 #define UNPACK64(x, str) \
00089 { \
00090 *((str) + 7) = (Uint8) ((x)); \
00091 *((str) + 6) = (Uint8) ((x) >> 8); \
00092 *((str) + 5) = (Uint8) ((x) >> 16); \
00093 *((str) + 4) = (Uint8) ((x) >> 24); \
00094 *((str) + 3) = (Uint8) ((x) >> 32); \
00095 *((str) + 2) = (Uint8) ((x) >> 40); \
00096 *((str) + 1) = (Uint8) ((x) >> 48); \
00097 *((str) + 0) = (Uint8) ((x) >> 56); \
00098 }
00099
00100
00101
00102 #if defined(ZEUS_LITTLE_ENDIAN)
00103
00104 #ifndef HOST_c2l
00105 #define HOST_c2l(c,l) (\
00106 l =(((unsigned long)(*((c)++))) ), \
00107 l|=(((unsigned long)(*((c)++)))<< 8), \
00108 l|=(((unsigned long)(*((c)++)))<<16), \
00109 l|=(((unsigned long)(*((c)++)))<<24), \
00110 l)
00111 #endif
00112 #ifndef HOST_l2c
00113 #define HOST_l2c(l,c) (\
00114 *((c)++)=(unsigned char)(((l) )&0xff), \
00115 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
00116 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
00117 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
00118 l)
00119 #endif
00120
00121 #else //defined(ZEUS_BIG_ENDIAN)
00122 #ifndef HOST_c2l
00123 #define HOST_c2l(c,l) (\
00124 l =(((unsigned long)(*((c)++)))<<24), \
00125 l|=(((unsigned long)(*((c)++)))<<16), \
00126 l|=(((unsigned long)(*((c)++)))<< 8), \
00127 l|=(((unsigned long)(*((c)++))) ), \
00128 l)
00129 #endif
00130
00131 #ifndef HOST_l2c
00132 #define HOST_l2c(l,c) (\
00133 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
00134 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
00135 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
00136 *((c)++)=(unsigned char)(((l) )&0xff), \
00137 l)
00138 #endif
00139 #endif //defined(ZEUS_BIG_ENDIAN)
00140
00141
00142
00143 #ifdef ZEUS_BIG_ENDIAN
00144 #define SWAP(n) (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
00145 #else
00146 #define SWAP(n) (n)
00147 #endif
00148
00149 #endif