diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 11f7173a9c..c792468c50 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,13 @@ The license applies to all entries newer than 2009-04-28. */ +2010-06-22 17:59 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * src/rtl/hbsha2.c + * src/rtl/hbsha2hm.c + + Added Win64 support for SHA1 functions. + ; NOTE: HMAC keys longer than 2^32 bytes are not support + (unlike with SHA1), probably not huge limitation. + 2010-06-22 17:37 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/hbsha2hm.c * src/rtl/hbsha2.c diff --git a/harbour/src/rtl/hbsha2.c b/harbour/src/rtl/hbsha2.c index a77305b792..34aa99c57d 100644 --- a/harbour/src/rtl/hbsha2.c +++ b/harbour/src/rtl/hbsha2.c @@ -60,7 +60,35 @@ HB_FUNC( HB_SHA224 ) sha224_ctx ctx; sha224_init( &ctx ); - sha224_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + sha224_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + sha224_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif sha224_final( &ctx, digest ); if( ! hb_parl( 2 ) ) @@ -79,7 +107,35 @@ HB_FUNC( HB_SHA256 ) sha256_ctx ctx; sha256_init( &ctx ); - sha256_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + sha256_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + sha256_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif sha256_final( &ctx, digest ); if( ! hb_parl( 2 ) ) @@ -98,7 +154,35 @@ HB_FUNC( HB_SHA384 ) sha384_ctx ctx; sha384_init( &ctx ); - sha384_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + sha384_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + sha384_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif sha384_final( &ctx, digest ); if( ! hb_parl( 2 ) ) @@ -117,7 +201,35 @@ HB_FUNC( HB_SHA512 ) sha512_ctx ctx; sha512_init( &ctx ); - sha512_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + sha512_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + sha512_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif sha512_final( &ctx, digest ); if( ! hb_parl( 2 ) ) diff --git a/harbour/src/rtl/hbsha2hm.c b/harbour/src/rtl/hbsha2hm.c index 05e23e0b33..9b48de1870 100644 --- a/harbour/src/rtl/hbsha2hm.c +++ b/harbour/src/rtl/hbsha2hm.c @@ -59,8 +59,36 @@ HB_FUNC( HB_HMAC_SHA224 ) unsigned char mac[ SHA224_DIGEST_SIZE ]; hmac_sha224_ctx ctx; - hmac_sha224_init( &ctx, hb_parcx( 2 ), hb_parclen( 2 ) ); - hmac_sha224_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + hmac_sha224_init( &ctx, hb_parcx( 2 ), ( unsigned int ) hb_parclen( 2 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + hmac_sha224_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + hmac_sha224_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif hmac_sha224_final( &ctx, mac, HB_SIZEOFARRAY( mac ) ); if( ! hb_parl( 3 ) ) @@ -78,8 +106,36 @@ HB_FUNC( HB_HMAC_SHA256 ) unsigned char mac[ SHA256_DIGEST_SIZE ]; hmac_sha256_ctx ctx; - hmac_sha256_init( &ctx, hb_parcx( 2 ), hb_parclen( 2 ) ); - hmac_sha256_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + hmac_sha256_init( &ctx, hb_parcx( 2 ), ( unsigned int ) hb_parclen( 2 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + hmac_sha256_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + hmac_sha256_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif hmac_sha256_final( &ctx, mac, HB_SIZEOFARRAY( mac ) ); if( ! hb_parl( 3 ) ) @@ -97,8 +153,36 @@ HB_FUNC( HB_HMAC_SHA384 ) unsigned char mac[ SHA384_DIGEST_SIZE ]; hmac_sha384_ctx ctx; - hmac_sha384_init( &ctx, hb_parcx( 2 ), hb_parclen( 2 ) ); - hmac_sha384_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + hmac_sha384_init( &ctx, hb_parcx( 2 ), ( unsigned int ) hb_parclen( 2 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + hmac_sha384_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + hmac_sha384_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif hmac_sha384_final( &ctx, mac, HB_SIZEOFARRAY( mac ) ); if( ! hb_parl( 3 ) ) @@ -116,8 +200,36 @@ HB_FUNC( HB_HMAC_SHA512 ) unsigned char mac[ SHA512_DIGEST_SIZE ]; hmac_sha512_ctx ctx; - hmac_sha512_init( &ctx, hb_parcx( 2 ), hb_parclen( 2 ) ); - hmac_sha512_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + hmac_sha512_init( &ctx, hb_parcx( 2 ), ( unsigned int ) hb_parclen( 2 ) ); + #if HB_SIZE_MAX > UINT_MAX + { + const char * buffer = hb_parcx( 1 ); + HB_SIZE nCount = hb_parclen( 1 ); + HB_SIZE nDone = 0; + + while( nCount ) + { + unsigned int uiChunk; + + if( nCount > ( HB_SIZE ) UINT_MAX ) + { + uiChunk = UINT_MAX; + nCount -= ( HB_SIZE ) uiChunk; + } + else + { + uiChunk = ( unsigned int ) nCount; + nCount = 0; + } + + hmac_sha512_update( &ctx, buffer + nDone, uiChunk ); + + nDone += ( HB_SIZE ) uiChunk; + } + } + #else + hmac_sha512_update( &ctx, hb_parcx( 1 ), hb_parclen( 1 ) ); + #endif hmac_sha512_final( &ctx, mac, HB_SIZEOFARRAY( mac ) ); if( ! hb_parl( 3 ) )