3 #define CONST64(n) n ## ui64
4 typedef unsigned __int64
ulong64;
6 #define CONST64(n) n ## ULL
13 #if defined(__x86_64__) || (defined(__sparc__) && defined(__arch64__))
22 #define STORE32L(x, y) \
23 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
24 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
26 #define LOAD32L(x, y) \
27 { x = ((unsigned long)((y)[3] & 255)<<24) | \
28 ((unsigned long)((y)[2] & 255)<<16) | \
29 ((unsigned long)((y)[1] & 255)<<8) | \
30 ((unsigned long)((y)[0] & 255)); }
32 #define STORE64L(x, y) \
33 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
34 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
35 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
36 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
38 #define LOAD64L(x, y) \
39 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
40 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
41 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
42 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
44 #define STORE32H(x, y) \
45 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
46 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
48 #define LOAD32H(x, y) \
49 { x = ((unsigned long)((y)[0] & 255)<<24) | \
50 ((unsigned long)((y)[1] & 255)<<16) | \
51 ((unsigned long)((y)[2] & 255)<<8) | \
52 ((unsigned long)((y)[3] & 255)); }
54 #define STORE64H(x, y) \
55 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
56 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
57 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
58 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
60 #define LOAD64H(x, y) \
61 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
62 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
63 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
64 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
70 #if !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
72 #define STORE32H(x, y) \
79 #define LOAD32H(x, y) \
87 #define STORE32H(x, y) \
88 { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
89 (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
91 #define LOAD32H(x, y) \
92 { x = ((unsigned long)((y)[0] & 255)<<24) | \
93 ((unsigned long)((y)[1] & 255)<<16) | \
94 ((unsigned long)((y)[2] & 255)<<8) | \
95 ((unsigned long)((y)[3] & 255)); }
101 #if !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__))
103 #define STORE64H(x, y) \
110 #define LOAD64H(x, y) \
118 #define STORE64H(x, y) \
119 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
120 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
121 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
122 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
124 #define LOAD64H(x, y) \
125 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
126 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
127 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
128 (((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
132 #ifdef ENDIAN_32BITWORD
134 #define STORE32L(x, y) \
135 { ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
137 #define LOAD32L(x, y) \
140 #define STORE64L(x, y) \
141 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
142 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
143 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
144 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
146 #define LOAD64L(x, y) \
147 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
148 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
149 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
150 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
154 #define STORE32L(x, y) \
155 { ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
157 #define LOAD32L(x, y) \
158 { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; }
160 #define STORE64L(x, y) \
161 { ulong64 __t = (x); XMEMCPY(y, &__t, 8); }
163 #define LOAD64L(x, y) \
164 { XMEMCPY(&(x), y, 8); }
171 #define STORE32L(x, y) \
172 { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
173 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
175 #define LOAD32L(x, y) \
176 { x = ((unsigned long)((y)[3] & 255)<<24) | \
177 ((unsigned long)((y)[2] & 255)<<16) | \
178 ((unsigned long)((y)[1] & 255)<<8) | \
179 ((unsigned long)((y)[0] & 255)); }
181 #define STORE64L(x, y) \
182 { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
183 (y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
184 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
185 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
187 #define LOAD64L(x, y) \
188 { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
189 (((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
190 (((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
191 (((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
193 #ifdef ENDIAN_32BITWORD
195 #define STORE32H(x, y) \
196 { ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
198 #define LOAD32H(x, y) \
201 #define STORE64H(x, y) \
202 { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
203 (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
204 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
205 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
207 #define LOAD64H(x, y) \
208 { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
209 (((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
210 (((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
211 (((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); }
215 #define STORE32H(x, y) \
216 { ulong32 __t = (x); XMEMCPY(y, &__t, 4); }
218 #define LOAD32H(x, y) \
219 { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; }
221 #define STORE64H(x, y) \
222 { ulong64 __t = (x); XMEMCPY(y, &__t, 8); }
224 #define LOAD64H(x, y) \
225 { XMEMCPY(&(x), y, 8); }
230 #define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \
231 ((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) )
235 #if defined(_MSC_VER)
239 #pragma intrinsic(_lrotr,_lrotl)
240 #define ROR(x,n) _lrotr(x,n)
241 #define ROL(x,n) _lrotl(x,n)
242 #define RORc(x,n) _lrotr(x,n)
243 #define ROLc(x,n) _lrotl(x,n)
245 #elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
247 static inline unsigned ROL(
unsigned word,
int i)
251 :
"0" (word),
"c" (i));
255 static inline unsigned ROR(
unsigned word,
int i)
259 :
"0" (word),
"c" (i));
265 static inline unsigned ROLc(
unsigned word,
const int i)
269 :
"0" (word),
"I" (i));
273 static inline unsigned RORc(
unsigned word,
const int i)
277 :
"0" (word),
"I" (i));
288 #elif !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
290 static inline unsigned ROL(
unsigned word,
int i)
292 asm (
"rotlw %0,%0,%2"
294 :
"0" (word),
"r" (i));
298 static inline unsigned ROR(
unsigned word,
int i)
300 asm (
"rotlw %0,%0,%2"
302 :
"0" (word),
"r" (32-i));
308 static inline unsigned ROLc(
unsigned word,
const int i)
310 asm (
"rotlwi %0,%0,%2"
312 :
"0" (word),
"I" (i));
316 static inline unsigned RORc(
unsigned word,
const int i)
318 asm (
"rotrwi %0,%0,%2"
320 :
"0" (word),
"I" (i));
335 #define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
336 #define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
337 #define ROLc(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
338 #define RORc(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
344 #if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM)
346 static inline unsigned long ROL64(
unsigned long word,
int i)
350 :
"0" (word),
"c" (i));
354 static inline unsigned long ROR64(
unsigned long word,
int i)
358 :
"0" (word),
"c" (i));
364 static inline unsigned long ROL64c(
unsigned long word,
const int i)
368 :
"0" (word),
"J" (i));
372 static inline unsigned long ROR64c(
unsigned long word,
const int i)
376 :
"0" (word),
"J" (i));
389 #define ROL64(x, y) \
390 ( (((x)<<((ulong64)(y)&63)) | \
391 (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
393 #define ROR64(x, y) \
394 ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
395 ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
397 #define ROL64c(x, y) \
398 ( (((x)<<((ulong64)(y)&63)) | \
399 (((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
401 #define ROR64c(x, y) \
402 ( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
403 ((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
408 #define MAX(x, y) ( ((x)>(y))?(x):(y) )
412 #define MIN(x, y) ( ((x)<(y))?(x):(y) )
417 #define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
419 #define byte(x, n) (((x) >> (8 * (n))) & 255)
#define ROLc(x, y)
Definition: tomcrypt_macros.h:337
#define ROL64(x, y)
Definition: tomcrypt_macros.h:389
#define ROL64c(x, y)
Definition: tomcrypt_macros.h:397
#define ROR(x, y)
Definition: tomcrypt_macros.h:336
unsigned long ulong32
Definition: tomcrypt_macros.h:16
unsigned long long ulong64
Definition: tomcrypt_macros.h:7
#define ROL(x, y)
Definition: tomcrypt_macros.h:335
#define ROR64(x, y)
Definition: tomcrypt_macros.h:393
#define ROR64c(x, y)
Definition: tomcrypt_macros.h:401
#define RORc(x, y)
Definition: tomcrypt_macros.h:338