diff options
Diffstat (limited to 'Modules/sha256module.c')
-rw-r--r-- | Modules/sha256module.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/Modules/sha256module.c b/Modules/sha256module.c index 76d91af..4abd1cd 100644 --- a/Modules/sha256module.c +++ b/Modules/sha256module.c @@ -21,13 +21,6 @@ #include "hashlib.h" -/* Endianness testing and definitions */ -#define TestEndianness(variable) {int i=1; variable=PCT_BIG_ENDIAN;\ - if (*((char*)&i)==1) variable=PCT_LITTLE_ENDIAN;} - -#define PCT_LITTLE_ENDIAN 1 -#define PCT_BIG_ENDIAN 0 - /* Some useful types */ typedef unsigned char SHA_BYTE; @@ -50,7 +43,6 @@ typedef struct { SHA_INT32 digest[8]; /* Message digest */ SHA_INT32 count_lo, count_hi; /* 64-bit bit count */ SHA_BYTE data[SHA_BLOCKSIZE]; /* SHA data buffer */ - int Endianness; int local; /* unprocessed amount in data */ int digestsize; } SHAobject; @@ -58,13 +50,11 @@ typedef struct { /* When run on a little-endian CPU we need to perform byte reversal on an array of longwords. */ -static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness) +#if PY_LITTLE_ENDIAN +static void longReverse(SHA_INT32 *buffer, int byteCount) { SHA_INT32 value; - if ( Endianness == PCT_BIG_ENDIAN ) - return; - byteCount /= sizeof(*buffer); while (byteCount--) { value = *buffer; @@ -73,10 +63,10 @@ static void longReverse(SHA_INT32 *buffer, int byteCount, int Endianness) *buffer++ = ( value << 16 ) | ( value >> 16 ); } } +#endif static void SHAcopy(SHAobject *src, SHAobject *dest) { - dest->Endianness = src->Endianness; dest->local = src->local; dest->digestsize = src->digestsize; dest->count_lo = src->count_lo; @@ -131,7 +121,9 @@ sha_transform(SHAobject *sha_info) SHA_INT32 S[8], W[64], t0, t1; memcpy(W, sha_info->data, sizeof(sha_info->data)); - longReverse(W, (int)sizeof(sha_info->data), sha_info->Endianness); +#if PY_LITTLE_ENDIAN + longReverse(W, (int)sizeof(sha_info->data)); +#endif for (i = 16; i < 64; ++i) { W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16]; @@ -228,7 +220,6 @@ sha_transform(SHAobject *sha_info) static void sha_init(SHAobject *sha_info) { - TestEndianness(sha_info->Endianness) sha_info->digest[0] = 0x6A09E667L; sha_info->digest[1] = 0xBB67AE85L; sha_info->digest[2] = 0x3C6EF372L; @@ -246,7 +237,6 @@ sha_init(SHAobject *sha_info) static void sha224_init(SHAobject *sha_info) { - TestEndianness(sha_info->Endianness) sha_info->digest[0] = 0xc1059ed8L; sha_info->digest[1] = 0x367cd507L; sha_info->digest[2] = 0x3070dd17L; |