]> granicus.if.org Git - php/commitdiff
- fix tiger algo
authorMichael Wallner <mike@php.net>
Thu, 24 Nov 2005 14:28:34 +0000 (14:28 +0000)
committerMichael Wallner <mike@php.net>
Thu, 24 Nov 2005 14:28:34 +0000 (14:28 +0000)
ext/hash/hash_tiger.c
ext/hash/php_hash_tiger.h
ext/hash/tests/tiger.phpt

index c0fc57ee10067de5ac0ff45e9fc0edf6b6803963..57edac3cc5fe8de5a4b9e859c89a1785ac263d62 100644 (file)
 }
 /* }}} */
 
-static inline void TigerTransform(PHP_TIGER_CTX *context, const unsigned char *input, size_t length)
-{
-       php_hash_uint64 i = (php_hash_uint64) length << 3;
-       const php_hash_uint64 *ptr = (const php_hash_uint64 *) input;
-       
-       context->passed += i;
-
-       for (; i >= 64; i -= 64) {
-               tiger_compress(context->passes, ptr, context->state);
-               ptr += 8;
-       }
-}
-
 static inline void TigerFinalize(PHP_TIGER_CTX *context)
 {
        context->passed += (php_hash_uint64) context->length << 3;
@@ -161,7 +148,7 @@ PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context)
        context->state[2] = L64(0xF096A5B4C3B2E187);
 }
 
-PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, unsigned char *input, size_t len)
+PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len)
 {
        if (context->length + len < 64) {
                memcpy(&context->buffer[context->length], input, len);
@@ -172,12 +159,14 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, unsigned char *input,
                if (context->length) {
                        i = 64 - context->length;
                        memcpy(&context->buffer[context->length], input, i);
-                       TigerTransform(context, context->buffer, 64);
+                       tiger_compress(context->passes, ((const php_hash_uint64 *) context->buffer), context->state);
                        memset(context->buffer, 0, 64);
+                       context->passed += 512;
                }
                
                for (; i + 64 <= len; i += 64) {
-                       TigerTransform(context, input + i, 64);
+                       tiger_compress(context->passes, ((const php_hash_uint64 *) (input + i)), context->state);
+                       context->passed += 512;
                }
                
                memcpy(context->buffer, input + i, r);
index 75046d41ca9f72c55f1b88c0fc6875637dd1c91d..e3291c3ce1f9f259da889e4c50f5d4cbf781ba6d 100644 (file)
@@ -47,7 +47,7 @@ typedef struct {
 
 PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context);
 PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context);
-PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, unsigned char *input, size_t len);
+PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len);
 PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context);
 PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context);
 PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *context);
index 712750aec03c981d052f4a186e41e58bee7556e3..ee3f249bf12c8e86095a8fe7e5ebeeba981cfc1c 100644 (file)
@@ -6,12 +6,13 @@ tiger
 <?php
 echo hash('tiger192,3', ''),"\n";
 echo hash('tiger192,3', 'abc'),"\n";
+echo hash('tiger192,3', str_repeat('a', 63)),"\n";
 echo hash('tiger192,3', str_repeat('abc', 61)),"\n";
 echo hash('tiger192,3', str_repeat('abc', 64)),"\n";
 ?>
 --EXPECT--
 24f0130c63ac933216166e76b1bb925ff373de2d49584e7a
 f258c1e88414ab2a527ab541ffc5b8bf935f7b951c132951
+8ee409a14e6066933b63d5b2abca63d71a78f55e29eb4649
 2586156d16bf9ab1e6e48bdf5e038f8053c30e071db3bcb0
 3ee8a9405396ddba1bc038508af4164ac1fe59ef58916a85
-