From: Danilo Almeida Date: Fri, 6 Jul 2001 00:30:32 +0000 (+0000) Subject: * shs.h, shs.c, t_shs.c: Fix sha1 on Windows by renaming LONG to X-Git-Tag: krb5-1.3-alpha1~1235 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c6161220710b21c436654894c0f0709dd83217ff;p=krb5.git * shs.h, shs.c, t_shs.c: Fix sha1 on Windows by renaming LONG to SHS_LONG to avoid problem with LONG being signed on Windows. Rename BYTE to SHS_BYTE to avoid any name colisions with Windows (where BYTE and LONG are types defined in the Platform SDK). git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13568 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/sha1/ChangeLog b/src/lib/crypto/sha1/ChangeLog index b626bad8f..40f73c801 100644 --- a/src/lib/crypto/sha1/ChangeLog +++ b/src/lib/crypto/sha1/ChangeLog @@ -1,3 +1,10 @@ +2001-07-05 Danilo Almeida + + * shs.h, shs.c, t_shs.c: Fix sha1 on Windows by renaming LONG to + SHS_LONG to avoid problem with LONG being signed on Windows. + Rename BYTE to SHS_BYTE to avoid any name colisions with Windows + (where BYTE and LONG are types defined in the Platform SDK). + 2001-06-21 Ezra Peisach * t_shs.c: Cast arguments to match printf format. Declare main as diff --git a/src/lib/crypto/sha1/shs.c b/src/lib/crypto/sha1/shs.c index 358e6ba32..819de479e 100644 --- a/src/lib/crypto/sha1/shs.c +++ b/src/lib/crypto/sha1/shs.c @@ -97,15 +97,15 @@ void shsInit(shsInfo) Note that this corrupts the shsInfo->data area */ -static void SHSTransform KRB5_PROTOTYPE((LONG *digest, LONG *data)); +static void SHSTransform KRB5_PROTOTYPE((SHS_LONG *digest, SHS_LONG *data)); static void SHSTransform(digest, data) - LONG *digest; - LONG *data; + SHS_LONG *digest; + SHS_LONG *data; { - LONG A, B, C, D, E; /* Local vars */ - LONG eData[ 16 ]; /* Expanded data */ + SHS_LONG A, B, C, D, E; /* Local vars */ + SHS_LONG eData[ 16 ]; /* Expanded data */ /* Set up first buffer and local data buffer */ A = digest[ 0 ]; @@ -217,16 +217,16 @@ void SHSTransform(digest, data) void shsUpdate(shsInfo, buffer, count) SHS_INFO *shsInfo; - BYTE *buffer; + SHS_BYTE *buffer; int count; { - LONG tmp; + SHS_LONG tmp; int dataCount, canfill; - LONG *lp; + SHS_LONG *lp; /* Update bitcount */ tmp = shsInfo->countLo; - shsInfo->countLo = tmp + (((LONG) count) << 3 ); + shsInfo->countLo = tmp + (((SHS_LONG) count) << 3 ); if ((shsInfo->countLo &= 0xffffffff) < tmp) shsInfo->countHi++; /* Carry from low to high */ shsInfo->countHi += count >> 29; @@ -245,25 +245,25 @@ void shsUpdate(shsInfo, buffer, count) is not very efficient (computed shift amount), but it shouldn't happen often. */ while (dataCount % 4 && count > 0) { - *lp |= (LONG) *buffer++ << ((3 - dataCount++ % 4) * 8); + *lp |= (SHS_LONG) *buffer++ << ((3 - dataCount++ % 4) * 8); count--; } lp++; } while (lp < shsInfo->data + 16) { - *lp = (LONG) *buffer++ << 24; - *lp |= (LONG) *buffer++ << 16; - *lp |= (LONG) *buffer++ << 8; - *lp++ |= (LONG) *buffer++; + *lp = (SHS_LONG) *buffer++ << 24; + *lp |= (SHS_LONG) *buffer++ << 16; + *lp |= (SHS_LONG) *buffer++ << 8; + *lp++ |= (SHS_LONG) *buffer++; if ((count -= 4) < 4 && lp < shsInfo->data + 16) { *lp = 0; switch (count % 4) { case 3: - *lp |= (LONG) buffer[2] << 8; + *lp |= (SHS_LONG) buffer[2] << 8; case 2: - *lp |= (LONG) buffer[1] << 16; + *lp |= (SHS_LONG) buffer[1] << 16; case 1: - *lp |= (LONG) buffer[0] << 24; + *lp |= (SHS_LONG) buffer[0] << 24; } break; count = 0; @@ -278,10 +278,10 @@ void shsUpdate(shsInfo, buffer, count) while (count >= SHS_DATASIZE) { lp = shsInfo->data; while (lp < shsInfo->data + 16) { - *lp = ((LONG) *buffer++) << 24; - *lp |= ((LONG) *buffer++) << 16; - *lp |= ((LONG) *buffer++) << 8; - *lp++ |= (LONG) *buffer++; + *lp = ((SHS_LONG) *buffer++) << 24; + *lp |= ((SHS_LONG) *buffer++) << 16; + *lp |= ((SHS_LONG) *buffer++) << 8; + *lp++ |= (SHS_LONG) *buffer++; } SHSTransform(shsInfo->digest, shsInfo->data); count -= SHS_DATASIZE; @@ -290,22 +290,22 @@ void shsUpdate(shsInfo, buffer, count) if (count > 0) { lp = shsInfo->data; while (count > 4) { - *lp = ((LONG) *buffer++) << 24; - *lp |= ((LONG) *buffer++) << 16; - *lp |= ((LONG) *buffer++) << 8; - *lp++ |= (LONG) *buffer++; + *lp = ((SHS_LONG) *buffer++) << 24; + *lp |= ((SHS_LONG) *buffer++) << 16; + *lp |= ((SHS_LONG) *buffer++) << 8; + *lp++ |= (SHS_LONG) *buffer++; count -= 4; } *lp = 0; switch (count % 4) { case 0: - *lp |= ((LONG) buffer[3]); + *lp |= ((SHS_LONG) buffer[3]); case 3: - *lp |= ((LONG) buffer[2]) << 8; + *lp |= ((SHS_LONG) buffer[2]) << 8; case 2: - *lp |= ((LONG) buffer[1]) << 16; + *lp |= ((SHS_LONG) buffer[1]) << 16; case 1: - *lp |= ((LONG) buffer[0]) << 24; + *lp |= ((SHS_LONG) buffer[0]) << 24; } } } @@ -317,7 +317,7 @@ void shsFinal(shsInfo) SHS_INFO *shsInfo; { int count; - LONG *lp; + SHS_LONG *lp; /* Compute number of bytes mod 64 */ count = (int) shsInfo->countLo; @@ -328,16 +328,16 @@ void shsFinal(shsInfo) lp = shsInfo->data + count / 4; switch (count % 4) { case 3: - *lp++ |= (LONG) 0x80; + *lp++ |= (SHS_LONG) 0x80; break; case 2: - *lp++ |= (LONG) 0x80 << 8; + *lp++ |= (SHS_LONG) 0x80 << 8; break; case 1: - *lp++ |= (LONG) 0x80 << 16; + *lp++ |= (SHS_LONG) 0x80 << 16; break; case 0: - *lp++ = (LONG) 0x80 << 24; + *lp++ = (SHS_LONG) 0x80 << 24; } /* at this point, lp can point *past* shsInfo->data. If it points diff --git a/src/lib/crypto/sha1/shs.h b/src/lib/crypto/sha1/shs.h index eb2cc46e9..6bf0c2458 100644 --- a/src/lib/crypto/sha1/shs.h +++ b/src/lib/crypto/sha1/shs.h @@ -6,13 +6,8 @@ /* Some useful types */ -typedef krb5_octet BYTE; - -/* Old DOS/Windows compilers are case-insensitive */ -#if !defined(_MSDOS) && !defined(_WIN32) -typedef krb5_ui_4 LONG; -#endif - +typedef krb5_octet SHS_BYTE; +typedef krb5_ui_4 SHS_LONG; /* Define the following to use the updated SHS implementation */ #define NEW_SHS /**/ @@ -25,14 +20,14 @@ typedef krb5_ui_4 LONG; /* The structure for storing SHS info */ typedef struct { - LONG digest[ 5 ]; /* Message digest */ - LONG countLo, countHi; /* 64-bit bit count */ - LONG data[ 16 ]; /* SHS data buffer */ + SHS_LONG digest[ 5 ]; /* Message digest */ + SHS_LONG countLo, countHi; /* 64-bit bit count */ + SHS_LONG data[ 16 ]; /* SHS data buffer */ } SHS_INFO; /* Message digest functions (shs.c) */ void shsInit(SHS_INFO *shsInfo); -void shsUpdate(SHS_INFO *shsInfo, BYTE *buffer, int count); +void shsUpdate(SHS_INFO *shsInfo, SHS_BYTE *buffer, int count); void shsFinal(SHS_INFO *shsInfo); diff --git a/src/lib/crypto/sha1/t_shs.c b/src/lib/crypto/sha1/t_shs.c index 5d7d86a4c..adcb0927a 100644 --- a/src/lib/crypto/sha1/t_shs.c +++ b/src/lib/crypto/sha1/t_shs.c @@ -13,7 +13,7 @@ #ifdef NEW_SHS -static LONG shsTestResults[][ 5 ] = { +static SHS_LONG shsTestResults[][ 5 ] = { { 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL, }, { 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L, }, { 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL, } @@ -21,7 +21,7 @@ static LONG shsTestResults[][ 5 ] = { #else -static LONG shsTestResults[][ 5 ] = { +static SHS_LONG shsTestResults[][ 5 ] = { { 0x0164B8A9L, 0x14CD2A5EL, 0x74C4F7FFL, 0x082C4D97L, 0xF1EDF880L }, { 0xD2516EE1L, 0xACFA5BAFL, 0x33DFC1C4L, 0x71E43844L, 0x9EF134C8L }, { 0x3232AFFAL, 0x48628A26L, 0x653B5AAAL, 0x44541FD9L, 0x0D690603L } @@ -60,7 +60,7 @@ main() unsigned int i; #if 0 time_t secondCount; - BYTE data[ 200 ]; + SHS_BYTE data[ 200 ]; #endif /* Make sure we've got the endianness set right. If the machine is @@ -72,7 +72,7 @@ main() /* Test SHS against values given in SHS standards document */ printf( "Running SHS test 1 ... " ); shsInit( &shsInfo ); - shsUpdate( &shsInfo, ( BYTE * ) "abc", 3 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "abc", 3 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 0 ) == -1 ) { @@ -88,7 +88,7 @@ main() printf( "Running SHS test 2 ... " ); shsInit( &shsInfo ); - shsUpdate( &shsInfo, ( BYTE * ) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 1 ) == -1 ) { @@ -105,7 +105,7 @@ main() printf( "Running SHS test 3 ... " ); shsInit( &shsInfo ); for( i = 0; i < 15625; i++ ) - shsUpdate( &shsInfo, ( BYTE * ) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 2 ) == -1 ) {