2003-03-03 00:59:24 +00:00
|
|
|
/* fix for MSVC ...evil! */
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define CONST64(n) n ## ui64
|
|
|
|
typedef unsigned __int64 ulong64;
|
|
|
|
#else
|
|
|
|
#define CONST64(n) n ## ULL
|
|
|
|
typedef unsigned long long ulong64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern char *crypt_error;
|
|
|
|
|
|
|
|
/* ---- HELPER MACROS ---- */
|
|
|
|
#ifdef ENDIAN_NEUTRAL
|
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
|
|
|
{ (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); }
|
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
|
|
|
{ x = ((unsigned long)((y)[3] & 255)<<24) | \
|
|
|
|
((unsigned long)((y)[2] & 255)<<16) | \
|
|
|
|
((unsigned long)((y)[1] & 255)<<8) | \
|
|
|
|
((unsigned long)((y)[0] & 255)); }
|
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
|
|
|
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
|
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
|
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
|
|
|
{ (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); }
|
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
|
|
|
{ x = ((unsigned long)((y)[0] & 255)<<24) | \
|
|
|
|
((unsigned long)((y)[1] & 255)<<16) | \
|
|
|
|
((unsigned long)((y)[2] & 255)<<8) | \
|
|
|
|
((unsigned long)((y)[3] & 255)); }
|
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
|
|
|
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
|
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
|
|
|
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
|
|
|
|
|
|
|
|
#endif /* ENDIAN_NEUTRAL */
|
|
|
|
|
|
|
|
#ifdef ENDIAN_LITTLE
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
|
|
|
{ (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); }
|
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
|
|
|
{ x = ((unsigned long)((y)[0] & 255)<<24) | \
|
|
|
|
((unsigned long)((y)[1] & 255)<<16) | \
|
|
|
|
((unsigned long)((y)[2] & 255)<<8) | \
|
|
|
|
((unsigned long)((y)[3] & 255)); }
|
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
|
|
|
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
|
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
|
|
|
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
|
|
|
|
|
|
|
|
#ifdef ENDIAN_32BITWORD
|
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ unsigned long __t = (x); memcpy(y, &__t, 4); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
|
|
|
memcpy(&(x), y, 4);
|
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
|
|
|
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
|
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
|
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
|
|
|
|
|
|
|
|
#else /* 64-bit words then */
|
|
|
|
|
|
|
|
#define STORE32L(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ unsigned long __t = (x); memcpy(y, &__t, 4); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
|
|
|
{ memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
|
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ ulong64 __t = (x); memcpy(y, &__t, 8); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
|
|
|
{ memcpy(&(x), y, 8); }
|
|
|
|
|
|
|
|
#endif /* ENDIAN_64BITWORD */
|
|
|
|
|
|
|
|
#endif /* ENDIAN_LITTLE */
|
|
|
|
|
|
|
|
#ifdef ENDIAN_BIG
|
|
|
|
#define STORE32L(x, y) \
|
|
|
|
{ (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); }
|
|
|
|
|
|
|
|
#define LOAD32L(x, y) \
|
|
|
|
{ x = ((unsigned long)((y)[0] & 255)<<24) | \
|
|
|
|
((unsigned long)((y)[1] & 255)<<16) | \
|
|
|
|
((unsigned long)((y)[2] & 255)<<8) | \
|
|
|
|
((unsigned long)((y)[3] & 255)); }
|
|
|
|
|
|
|
|
#define STORE64L(x, y) \
|
|
|
|
{ (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64L(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[0] & 255))<<56)|(((ulong64)((y)[1] & 255))<<48) | \
|
|
|
|
(((ulong64)((y)[2] & 255))<<40)|(((ulong64)((y)[3] & 255))<<32) | \
|
|
|
|
(((ulong64)((y)[4] & 255))<<24)|(((ulong64)((y)[5] & 255))<<16) | \
|
|
|
|
(((ulong64)((y)[6] & 255))<<8)|(((ulong64)((y)[7] & 255))); }
|
|
|
|
|
|
|
|
#ifdef ENDIAN_32BITWORD
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ unsigned long __t = (x); memcpy(y, &__t, 4); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
|
|
|
memcpy(&(x), y, 4);
|
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
|
|
|
{ (y)[7] = (unsigned char)(((x)>>56)&255); (y)[6] = (unsigned char)(((x)>>48)&255); \
|
|
|
|
(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); \
|
|
|
|
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
|
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
|
|
|
{ x = (((ulong64)((y)[7] & 255))<<56)|(((ulong64)((y)[6] & 255))<<48)| \
|
|
|
|
(((ulong64)((y)[5] & 255))<<40)|(((ulong64)((y)[4] & 255))<<32)| \
|
|
|
|
(((ulong64)((y)[3] & 255))<<24)|(((ulong64)((y)[2] & 255))<<16)| \
|
|
|
|
(((ulong64)((y)[1] & 255))<<8)|(((ulong64)((y)[0] & 255))); }
|
|
|
|
|
|
|
|
#else /* 64-bit words then */
|
|
|
|
|
|
|
|
#define STORE32H(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ unsigned long __t = (x); memcpy(y, &__t, 4); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD32H(x, y) \
|
|
|
|
{ memcpy(&(x), y, 4); x &= 0xFFFFFFFF; }
|
|
|
|
|
|
|
|
#define STORE64H(x, y) \
|
2003-03-29 18:19:07 +00:00
|
|
|
{ ulong64 __t = (x); memcpy(y, &__t, 8); }
|
2003-03-03 00:59:24 +00:00
|
|
|
|
|
|
|
#define LOAD64H(x, y) \
|
|
|
|
{ memcpy(&(x), y, 8); }
|
|
|
|
|
|
|
|
#endif /* ENDIAN_64BITWORD */
|
|
|
|
#endif /* ENDIAN_BIG */
|
|
|
|
|
|
|
|
#define BSWAP(x) ( ((x>>24)&0x000000FFUL) | ((x<<24)&0xFF000000UL) | \
|
|
|
|
((x>>8)&0x0000FF00UL) | ((x<<8)&0x00FF0000UL) )
|
|
|
|
|
2003-03-03 01:02:42 +00:00
|
|
|
#define ROL(x, y) ( (((unsigned long)(x)<<(unsigned long)((y)&31)) | (((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
|
|
|
#define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
|
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))
|
|
|
|
|
|
|
|
#undef MAX
|
|
|
|
#undef MIN
|
|
|
|
#define MAX(x, y) ( ((x)>(y))?(x):(y) )
|
|
|
|
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
|