2003-07-11 02:09:41 +00:00
|
|
|
|
2003-03-03 00:59:24 +00:00
|
|
|
/* ---- HELPER MACROS ---- */
|
|
|
|
#ifdef ENDIAN_NEUTRAL
|
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
|
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = ((ulong32)((y)[3] & 255)<<24) | \
|
2014-04-03 15:06:56 +02:00
|
|
|
((ulong32)((y)[2] & 255)<<16) | \
|
|
|
|
((ulong32)((y)[1] & 255)<<8) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
((ulong32)((y)[0] & 255)); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
2003-03-03 00:59:24 +00:00
|
|
|
(y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
|
2003-03-03 00:59:24 +00:00
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
|
|
|
|
(y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = ((ulong32)((y)[0] & 255)<<24) | \
|
2014-04-03 15:06:56 +02:00
|
|
|
((ulong32)((y)[1] & 255)<<16) | \
|
|
|
|
((ulong32)((y)[2] & 255)<<8) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
((ulong32)((y)[3] & 255)); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
2003-03-03 00:59:24 +00:00
|
|
|
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
|
2003-03-03 00:59:24 +00:00
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#endif /* ENDIAN_NEUTRAL */
|
|
|
|
|
|
|
|
#ifdef ENDIAN_LITTLE
|
|
|
|
|
Some fixes necessary to support the Clang compiler
First of all, it had a failure in SEED:
LTC_KSEED failed for x=0, I got:
expected actual (ciphertext)
5e == 5e
ba == ba
c6 == c6
e0 == e0
05 != 00
4e != 00
16 != 00
68 != 00
19 == 19
af == af
f1 == f1
cc == cc
6d != 00
34 != 00
6c != 00
db != 00
Since SEED uses the 32H macros, this is really analogous to the
problem I saw with the 64H macros in Camellia with gcc. Not sure why
gcc only had a problem with 64H and not 32H, but since this is an
interaction with the optimizer, it's not going to happen every time
the macro is used (hence why the store tests pass; only when you get
into the complexity of a real cipher do you start having problems) and
it makes sense it will vary from compiler to compiler.
Anyway, I went ahead and added the ability to use __builtin_bswap32,
in addition to __builtin_bswap64, which I already did in a previous
commit. This solves the problem for clang, although I had to add new
logic to detect the bswap builtins in clang, since it has a different
way to detect them than gcc (see the comments in the code). The
detection logic was complicated enough, and applied to both the 32H
and 64H macros, so I factored out the detection logic into
tomcrypt_cfg.h.
2011-09-26 00:39:19 -07:00
|
|
|
#ifdef LTC_HAVE_BSWAP_BUILTIN
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong32 __t = __builtin_bswap32 ((x)); \
|
|
|
|
XMEMCPY ((y), &__t, 4); } while(0)
|
Some fixes necessary to support the Clang compiler
First of all, it had a failure in SEED:
LTC_KSEED failed for x=0, I got:
expected actual (ciphertext)
5e == 5e
ba == ba
c6 == c6
e0 == e0
05 != 00
4e != 00
16 != 00
68 != 00
19 == 19
af == af
f1 == f1
cc == cc
6d != 00
34 != 00
6c != 00
db != 00
Since SEED uses the 32H macros, this is really analogous to the
problem I saw with the 64H macros in Camellia with gcc. Not sure why
gcc only had a problem with 64H and not 32H, but since this is an
interaction with the optimizer, it's not going to happen every time
the macro is used (hence why the store tests pass; only when you get
into the complexity of a real cipher do you start having problems) and
it makes sense it will vary from compiler to compiler.
Anyway, I went ahead and added the ability to use __builtin_bswap32,
in addition to __builtin_bswap64, which I already did in a previous
commit. This solves the problem for clang, although I had to add new
logic to detect the bswap builtins in clang, since it has a different
way to detect them than gcc (see the comments in the code). The
detection logic was complicated enough, and applied to both the 32H
and 64H macros, so I factored out the detection logic into
tomcrypt_cfg.h.
2011-09-26 00:39:19 -07:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY (&(x), (y), 4); \
|
|
|
|
(x) = __builtin_bswap32 ((x)); } while(0)
|
Some fixes necessary to support the Clang compiler
First of all, it had a failure in SEED:
LTC_KSEED failed for x=0, I got:
expected actual (ciphertext)
5e == 5e
ba == ba
c6 == c6
e0 == e0
05 != 00
4e != 00
16 != 00
68 != 00
19 == 19
af == af
f1 == f1
cc == cc
6d != 00
34 != 00
6c != 00
db != 00
Since SEED uses the 32H macros, this is really analogous to the
problem I saw with the 64H macros in Camellia with gcc. Not sure why
gcc only had a problem with 64H and not 32H, but since this is an
interaction with the optimizer, it's not going to happen every time
the macro is used (hence why the store tests pass; only when you get
into the complexity of a real cipher do you start having problems) and
it makes sense it will vary from compiler to compiler.
Anyway, I went ahead and added the ability to use __builtin_bswap32,
in addition to __builtin_bswap64, which I already did in a previous
commit. This solves the problem for clang, although I had to add new
logic to detect the bswap builtins in clang, since it has a different
way to detect them than gcc (see the comments in the code). The
detection logic was complicated enough, and applied to both the 32H
and 64H macros, so I factored out the detection logic into
tomcrypt_cfg.h.
2011-09-26 00:39:19 -07:00
|
|
|
|
|
|
|
#elif !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__))))
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
|
|
|
asm __volatile__ ( \
|
|
|
|
"bswapl %0 \n\t" \
|
2006-12-16 18:10:04 +00:00
|
|
|
"movl %0,(%1)\n\t" \
|
2005-04-17 11:37:13 +00:00
|
|
|
"bswapl %0 \n\t" \
|
2006-12-16 18:10:04 +00:00
|
|
|
::"r"(x), "r"(y));
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
|
|
|
asm __volatile__ ( \
|
2006-11-17 14:21:24 +00:00
|
|
|
"movl (%1),%0\n\t" \
|
2005-04-17 11:37:13 +00:00
|
|
|
"bswapl %0\n\t" \
|
2006-11-17 14:21:24 +00:00
|
|
|
:"=r"(x): "r"(y));
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2003-03-03 00:59:24 +00:00
|
|
|
#define STORE32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255); \
|
|
|
|
(y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = ((ulong32)((y)[0] & 255)<<24) | \
|
2014-04-03 15:06:56 +02:00
|
|
|
((ulong32)((y)[1] & 255)<<16) | \
|
|
|
|
((ulong32)((y)[2] & 255)<<8) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
((ulong32)((y)[3] & 255)); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
|
|
|
|
Some fixes necessary to support the Clang compiler
First of all, it had a failure in SEED:
LTC_KSEED failed for x=0, I got:
expected actual (ciphertext)
5e == 5e
ba == ba
c6 == c6
e0 == e0
05 != 00
4e != 00
16 != 00
68 != 00
19 == 19
af == af
f1 == f1
cc == cc
6d != 00
34 != 00
6c != 00
db != 00
Since SEED uses the 32H macros, this is really analogous to the
problem I saw with the 64H macros in Camellia with gcc. Not sure why
gcc only had a problem with 64H and not 32H, but since this is an
interaction with the optimizer, it's not going to happen every time
the macro is used (hence why the store tests pass; only when you get
into the complexity of a real cipher do you start having problems) and
it makes sense it will vary from compiler to compiler.
Anyway, I went ahead and added the ability to use __builtin_bswap32,
in addition to __builtin_bswap64, which I already did in a previous
commit. This solves the problem for clang, although I had to add new
logic to detect the bswap builtins in clang, since it has a different
way to detect them than gcc (see the comments in the code). The
detection logic was complicated enough, and applied to both the 32H
and 64H macros, so I factored out the detection logic into
tomcrypt_cfg.h.
2011-09-26 00:39:19 -07:00
|
|
|
#ifdef LTC_HAVE_BSWAP_BUILTIN
|
2011-09-25 20:18:26 -07:00
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong64 __t = __builtin_bswap64 ((x)); \
|
|
|
|
XMEMCPY ((y), &__t, 8); } while(0)
|
2011-09-25 20:18:26 -07:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY (&(x), (y), 8); \
|
|
|
|
(x) = __builtin_bswap64 ((x)); } while(0)
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
/* x86_64 processor */
|
2011-09-25 20:18:26 -07:00
|
|
|
#elif !defined(LTC_NO_BSWAP) && (defined(__GNUC__) && defined(__x86_64__))
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
|
|
|
asm __volatile__ ( \
|
|
|
|
"bswapq %0 \n\t" \
|
2006-12-16 18:10:04 +00:00
|
|
|
"movq %0,(%1)\n\t" \
|
2005-04-17 11:37:13 +00:00
|
|
|
"bswapq %0 \n\t" \
|
2011-09-25 17:11:25 -07:00
|
|
|
::"r"(x), "r"(y): "memory");
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
|
|
|
asm __volatile__ ( \
|
2006-11-17 14:21:24 +00:00
|
|
|
"movq (%1),%0\n\t" \
|
2005-04-17 11:37:13 +00:00
|
|
|
"bswapq %0\n\t" \
|
2011-09-25 17:11:25 -07:00
|
|
|
:"=r"(x): "r"(y): "memory");
|
2005-04-17 11:37:13 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2003-03-03 00:59:24 +00:00
|
|
|
#define STORE64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
2003-03-03 00:59:24 +00:00
|
|
|
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
|
2003-03-03 00:59:24 +00:00
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
2005-04-17 11:37:13 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-26 14:43:15 +02:00
|
|
|
#ifdef ENDIAN_32BITWORD
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
2003-03-03 00:59:24 +00:00
|
|
|
(y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
|
2003-03-03 00:59:24 +00:00
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#else /* 64-bit words then */
|
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong64 __t = (x); XMEMCPY(y, &__t, 8); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 8); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#endif /* ENDIAN_64BITWORD */
|
|
|
|
|
|
|
|
#endif /* ENDIAN_LITTLE */
|
|
|
|
|
|
|
|
#ifdef ENDIAN_BIG
|
|
|
|
#define STORE32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
|
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = ((ulong32)((y)[3] & 255)<<24) | \
|
2014-04-03 15:06:56 +02:00
|
|
|
((ulong32)((y)[2] & 255)<<16) | \
|
|
|
|
((ulong32)((y)[1] & 255)<<8) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
((ulong32)((y)[0] & 255)); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
2004-06-23 19:55:24 +00:00
|
|
|
(y)[5] = (unsigned char)(((x)>>40)&255); (y)[4] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48) | \
|
2004-06-23 19:55:24 +00:00
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16) | \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
2012-07-26 14:43:15 +02:00
|
|
|
#ifdef ENDIAN_32BITWORD
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
2004-06-23 19:55:24 +00:00
|
|
|
(y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned char)(((x)>>32)&255); \
|
|
|
|
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
|
2014-04-04 01:02:46 +02:00
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48)| \
|
2004-06-23 19:55:24 +00:00
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16)| \
|
2014-04-04 01:02:46 +02:00
|
|
|
(((ulong64)((y)[6] & 255))<<8)| (((ulong64)((y)[7] & 255))); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#else /* 64-bit words then */
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong32 __t = (x); XMEMCPY(y, &__t, 4); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 4); x &= 0xFFFFFFFF; } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { ulong64 __t = (x); XMEMCPY(y, &__t, 8); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
2014-04-04 01:02:46 +02:00
|
|
|
do { XMEMCPY(&(x), y, 8); } while(0)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#endif /* ENDIAN_64BITWORD */
|
|
|
|
#endif /* ENDIAN_BIG */
|
|
|
|
|
|
|
|
#define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \
|
|
|
|
((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) )
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
|
|
|
|
/* 32-bit Rotates */
|
|
|
|
#if defined(_MSC_VER)
|
2003-06-19 15:23:20 +00:00
|
|
|
|
2003-07-16 17:43:06 +00:00
|
|
|
/* instrinsic rotate */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#pragma intrinsic(_lrotr,_lrotl)
|
|
|
|
#define ROR(x,n) _lrotr(x,n)
|
|
|
|
#define ROL(x,n) _lrotl(x,n)
|
2004-12-30 23:55:53 +00:00
|
|
|
#define RORc(x,n) _lrotr(x,n)
|
|
|
|
#define ROLc(x,n) _lrotl(x,n)
|
2003-06-19 15:23:20 +00:00
|
|
|
|
2006-04-06 19:48:32 +00:00
|
|
|
#elif !defined(__STRICT_ANSI__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC) && !defined(LTC_NO_ASM)
|
2003-09-08 01:06:11 +00:00
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROL(ulong32 word, int i)
|
2003-09-08 01:06:11 +00:00
|
|
|
{
|
2004-12-30 23:55:53 +00:00
|
|
|
asm ("roll %%cl,%0"
|
2004-02-20 20:03:32 +00:00
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"c" (i));
|
|
|
|
return word;
|
2003-09-08 01:06:11 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROR(ulong32 word, int i)
|
2003-09-08 01:06:11 +00:00
|
|
|
{
|
2004-12-30 23:55:53 +00:00
|
|
|
asm ("rorl %%cl,%0"
|
2004-02-20 20:03:32 +00:00
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"c" (i));
|
|
|
|
return word;
|
2003-09-08 01:06:11 +00:00
|
|
|
}
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
#ifndef LTC_NO_ROLC
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROLc(ulong32 word, const int i)
|
2004-12-30 23:55:53 +00:00
|
|
|
{
|
|
|
|
asm ("roll %2,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"I" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 RORc(ulong32 word, const int i)
|
2004-12-30 23:55:53 +00:00
|
|
|
{
|
|
|
|
asm ("rorl %2,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"I" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define ROLc ROL
|
|
|
|
#define RORc ROR
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-04-06 19:48:32 +00:00
|
|
|
#elif !defined(__STRICT_ANSI__) && defined(LTC_PPC32)
|
2005-11-18 05:15:37 +00:00
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROL(ulong32 word, int i)
|
2005-11-18 05:15:37 +00:00
|
|
|
{
|
|
|
|
asm ("rotlw %0,%0,%2"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"r" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROR(ulong32 word, int i)
|
2005-11-18 05:15:37 +00:00
|
|
|
{
|
|
|
|
asm ("rotlw %0,%0,%2"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"r" (32-i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef LTC_NO_ROLC
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 ROLc(ulong32 word, const int i)
|
2005-11-18 05:15:37 +00:00
|
|
|
{
|
|
|
|
asm ("rotlwi %0,%0,%2"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"I" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong32 RORc(ulong32 word, const int i)
|
2005-11-18 05:15:37 +00:00
|
|
|
{
|
|
|
|
asm ("rotrwi %0,%0,%2"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"I" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define ROLc ROL
|
|
|
|
#define RORc ROR
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-06-19 15:23:20 +00:00
|
|
|
#else
|
|
|
|
|
2003-07-16 17:43:06 +00:00
|
|
|
/* rotates the hard way */
|
2014-04-03 15:06:56 +02:00
|
|
|
#define ROL(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
|
|
|
#define ROR(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
|
|
|
#define ROLc(x, y) ( (((ulong32)(x)<<(ulong32)((y)&31)) | (((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
|
|
|
#define RORc(x, y) ( ((((ulong32)(x)&0xFFFFFFFFUL)>>(ulong32)((y)&31)) | ((ulong32)(x)<<(ulong32)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
2003-03-03 00:59:24 +00:00
|
|
|
|
2003-06-19 15:23:20 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
|
|
|
|
/* 64-bit Rotates */
|
2006-04-06 19:48:32 +00:00
|
|
|
#if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__x86_64__) && !defined(LTC_NO_ASM)
|
2004-10-30 03:00:26 +00:00
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong64 ROL64(ulong64 word, int i)
|
2004-10-30 03:00:26 +00:00
|
|
|
{
|
2004-12-30 23:55:53 +00:00
|
|
|
asm("rolq %%cl,%0"
|
2004-10-30 03:00:26 +00:00
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"c" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong64 ROR64(ulong64 word, int i)
|
2004-10-30 03:00:26 +00:00
|
|
|
{
|
2004-12-30 23:55:53 +00:00
|
|
|
asm("rorq %%cl,%0"
|
2004-10-30 03:00:26 +00:00
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"c" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
#ifndef LTC_NO_ROLC
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong64 ROL64c(ulong64 word, const int i)
|
2004-12-30 23:55:53 +00:00
|
|
|
{
|
|
|
|
asm("rolq %2,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"J" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:06:56 +02:00
|
|
|
static inline ulong64 ROR64c(ulong64 word, const int i)
|
2004-12-30 23:55:53 +00:00
|
|
|
{
|
|
|
|
asm("rorq %2,%0"
|
|
|
|
:"=r" (word)
|
|
|
|
:"0" (word),"J" (i));
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* LTC_NO_ROLC */
|
|
|
|
|
2005-04-17 11:37:13 +00:00
|
|
|
#define ROL64c ROL64
|
|
|
|
#define ROR64c ROR64
|
2004-12-30 23:55:53 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* Not x86_64 */
|
2004-10-30 03:00:26 +00:00
|
|
|
|
2003-03-03 00:59:24 +00:00
|
|
|
#define ROL64(x, y) \
|
|
|
|
( (((x)<<((ulong64)(y)&63)) | \
|
|
|
|
(((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
|
|
|
|
|
|
|
|
#define ROR64(x, y) \
|
|
|
|
( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
|
|
|
|
((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
|
|
|
|
|
2004-12-30 23:55:53 +00:00
|
|
|
#define ROL64c(x, y) \
|
|
|
|
( (((x)<<((ulong64)(y)&63)) | \
|
|
|
|
(((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)64-((y)&63)))) & CONST64(0xFFFFFFFFFFFFFFFF))
|
|
|
|
|
|
|
|
#define ROR64c(x, y) \
|
|
|
|
( ((((x)&CONST64(0xFFFFFFFFFFFFFFFF))>>((ulong64)(y)&CONST64(63))) | \
|
|
|
|
((x)<<((ulong64)(64-((y)&CONST64(63)))))) & CONST64(0xFFFFFFFFFFFFFFFF))
|
|
|
|
|
2004-10-30 03:00:26 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-01 16:36:47 +00:00
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(x, y) ( ((x)>(y))?(x):(y) )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
|
|
|
|
#endif
|
2003-06-19 15:23:20 +00:00
|
|
|
|
|
|
|
/* extract a byte portably */
|
2003-07-16 17:43:06 +00:00
|
|
|
#ifdef _MSC_VER
|
2003-06-19 15:23:20 +00:00
|
|
|
#define byte(x, n) ((unsigned char)((x) >> (8 * (n))))
|
|
|
|
#else
|
|
|
|
#define byte(x, n) (((x) >> (8 * (n))) & 255)
|
2012-07-26 14:43:15 +02:00
|
|
|
#endif
|
2005-06-09 00:08:13 +00:00
|
|
|
|
|
|
|
/* $Source$ */
|
|
|
|
/* $Revision$ */
|
|
|
|
/* $Date$ */
|