From e4bef616f8c462bb6c5df6e7b2c2c5a5fcf34e90 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 24 Nov 2005 14:07:24 +0000 Subject: [PATCH] - fix segvs # there's still somthing wrong though --- ext/hash/hash_tiger.c | 23 +++++++++++++---------- ext/hash/tests/tiger.phpt | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 ext/hash/tests/tiger.phpt diff --git a/ext/hash/hash_tiger.c b/ext/hash/hash_tiger.c index 98c1f5933f..c0fc57ee10 100644 --- a/ext/hash/hash_tiger.c +++ b/ext/hash/hash_tiger.c @@ -23,6 +23,7 @@ #include "php_hash_tiger.h" #include "php_hash_tiger_tables.h" +/* {{{ */ #define save_abc \ aa = a; \ bb = b; \ @@ -80,7 +81,7 @@ pass(c,a,b,7) \ key_schedule \ pass(b,c,a,9) \ - for(pass_no=3; pass_nopassed += i; - + for (; i >= 64; i -= 64) { tiger_compress(context->passes, ptr, context->state); ptr += 8; @@ -125,9 +127,11 @@ static inline void TigerFinalize(PHP_TIGER_CTX *context) context->passed += (php_hash_uint64) context->length << 3; context->buffer[context->length++] = 0x1; - memset(&context->buffer[context->length], 0, context->length%8); - context->length += context->length%8; - + if (context->length % 8) { + memset(&context->buffer[context->length], 0, 8-context->length%8); + context->length += 8-context->length%8; + } + if (context->length > 56) { memset(&context->buffer[context->length], 0, 64 - context->length); tiger_compress(context->passes, ((php_hash_uint64 *) context->buffer), context->state); @@ -142,27 +146,26 @@ static inline void TigerFinalize(PHP_TIGER_CTX *context) PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context) { - context->passes = 3; + memset(context, 0, sizeof(*context)); context->state[0] = L64(0x0123456789ABCDEF); context->state[1] = L64(0xFEDCBA9876543210); context->state[2] = L64(0xF096A5B4C3B2E187); - memset(context->buffer, 0, sizeof(context->buffer)); } PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context) { - context->passes = 4; + memset(context, 0, sizeof(*context)); + context->passes = 1; context->state[0] = L64(0x0123456789ABCDEF); context->state[1] = L64(0xFEDCBA9876543210); context->state[2] = L64(0xF096A5B4C3B2E187); - memset(context->buffer, 0, sizeof(context->buffer)); } PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, unsigned char *input, size_t len) { if (context->length + len < 64) { memcpy(&context->buffer[context->length], input, len); - context->length = len; + context->length += len; } else { size_t i = 0, r = (context->length + len) % 64; diff --git a/ext/hash/tests/tiger.phpt b/ext/hash/tests/tiger.phpt new file mode 100644 index 0000000000..712750aec0 --- /dev/null +++ b/ext/hash/tests/tiger.phpt @@ -0,0 +1,17 @@ +--TEST-- +tiger +--SKIPIF-- + +--FILE-- + +--EXPECT-- +24f0130c63ac933216166e76b1bb925ff373de2d49584e7a +f258c1e88414ab2a527ab541ffc5b8bf935f7b951c132951 +2586156d16bf9ab1e6e48bdf5e038f8053c30e071db3bcb0 +3ee8a9405396ddba1bc038508af4164ac1fe59ef58916a85 + -- 2.40.0