summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--ext/hash/hash_tiger.c78
-rw-r--r--ext/hash/tests/tiger.phpt11
3 files changed, 21 insertions, 71 deletions
diff --git a/NEWS b/NEWS
index 0cf44aa..6139581 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,9 @@ PHP NEWS
still exists for backward compatibility but is doing nothing). (Pierrick)
. Fixed bug #54995 (Missing CURLINFO_RESPONSE_CODE support). (Pierrick)
+- hash
+ . Fixed bug #60221 (Tiger hash output byte order) (Mike)
+
- pgsql
. Added pg_escape_literal() and pg_escape_identifier() (Yasuo)
diff --git a/ext/hash/hash_tiger.c b/ext/hash/hash_tiger.c
index cb8f94b..bd1d79b 100644
--- a/ext/hash/hash_tiger.c
+++ b/ext/hash/hash_tiger.c
@@ -169,6 +169,15 @@ static inline void TigerFinalize(PHP_TIGER_CTX *context)
tiger_compress(context->passes, ((php_hash_uint64 *) context->buffer), context->state);
}
+static inline void TigerDigest(unsigned char *digest_str, unsigned int digest_len, PHP_TIGER_CTX *context)
+{
+ unsigned int i;
+
+ for (i = 0; i < digest_len; ++i) {
+ digest_str[i] = (unsigned char) ((context->state[i/8] >> (8 * (i%8))) & 0xff);
+ }
+}
+
PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context)
{
memset(context, 0, sizeof(*context));
@@ -216,84 +225,21 @@ PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *i
PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context)
{
TigerFinalize(context);
-
- digest[0] = (unsigned char) ((context->state[0] >> 56) & 0xff);
- digest[1] = (unsigned char) ((context->state[0] >> 48) & 0xff);
- digest[2] = (unsigned char) ((context->state[0] >> 40) & 0xff);
- digest[3] = (unsigned char) ((context->state[0] >> 32) & 0xff);
- digest[4] = (unsigned char) ((context->state[0] >> 24) & 0xff);
- digest[5] = (unsigned char) ((context->state[0] >> 16) & 0xff);
- digest[6] = (unsigned char) ((context->state[0] >> 8) & 0xff);
- digest[7] = (unsigned char) (context->state[0] & 0xff);
- digest[8] = (unsigned char) ((context->state[1] >> 56) & 0xff);
- digest[9] = (unsigned char) ((context->state[1] >> 48) & 0xff);
- digest[10] = (unsigned char) ((context->state[1] >> 40) & 0xff);
- digest[11] = (unsigned char) ((context->state[1] >> 32) & 0xff);
- digest[12] = (unsigned char) ((context->state[1] >> 24) & 0xff);
- digest[13] = (unsigned char) ((context->state[1] >> 16) & 0xff);
- digest[14] = (unsigned char) ((context->state[1] >> 8) & 0xff);
- digest[15] = (unsigned char) (context->state[1] & 0xff);
-
+ TigerDigest(digest, 16, context);
memset(context, 0, sizeof(*context));
}
PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context)
{
TigerFinalize(context);
-
- digest[0] = (unsigned char) ((context->state[0] >> 56) & 0xff);
- digest[1] = (unsigned char) ((context->state[0] >> 48) & 0xff);
- digest[2] = (unsigned char) ((context->state[0] >> 40) & 0xff);
- digest[3] = (unsigned char) ((context->state[0] >> 32) & 0xff);
- digest[4] = (unsigned char) ((context->state[0] >> 24) & 0xff);
- digest[5] = (unsigned char) ((context->state[0] >> 16) & 0xff);
- digest[6] = (unsigned char) ((context->state[0] >> 8) & 0xff);
- digest[7] = (unsigned char) (context->state[0] & 0xff);
- digest[8] = (unsigned char) ((context->state[1] >> 56) & 0xff);
- digest[9] = (unsigned char) ((context->state[1] >> 48) & 0xff);
- digest[10] = (unsigned char) ((context->state[1] >> 40) & 0xff);
- digest[11] = (unsigned char) ((context->state[1] >> 32) & 0xff);
- digest[12] = (unsigned char) ((context->state[1] >> 24) & 0xff);
- digest[13] = (unsigned char) ((context->state[1] >> 16) & 0xff);
- digest[14] = (unsigned char) ((context->state[1] >> 8) & 0xff);
- digest[15] = (unsigned char) (context->state[1] & 0xff);
- digest[16] = (unsigned char) ((context->state[2] >> 56) & 0xff);
- digest[17] = (unsigned char) ((context->state[2] >> 48) & 0xff);
- digest[18] = (unsigned char) ((context->state[2] >> 40) & 0xff);
- digest[19] = (unsigned char) ((context->state[2] >> 32) & 0xff);
-
+ TigerDigest(digest, 20, context);
memset(context, 0, sizeof(*context));
}
PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *context)
{
TigerFinalize(context);
-
- digest[0] = (unsigned char) ((context->state[0] >> 56) & 0xff);
- digest[1] = (unsigned char) ((context->state[0] >> 48) & 0xff);
- digest[2] = (unsigned char) ((context->state[0] >> 40) & 0xff);
- digest[3] = (unsigned char) ((context->state[0] >> 32) & 0xff);
- digest[4] = (unsigned char) ((context->state[0] >> 24) & 0xff);
- digest[5] = (unsigned char) ((context->state[0] >> 16) & 0xff);
- digest[6] = (unsigned char) ((context->state[0] >> 8) & 0xff);
- digest[7] = (unsigned char) (context->state[0] & 0xff);
- digest[8] = (unsigned char) ((context->state[1] >> 56) & 0xff);
- digest[9] = (unsigned char) ((context->state[1] >> 48) & 0xff);
- digest[10] = (unsigned char) ((context->state[1] >> 40) & 0xff);
- digest[11] = (unsigned char) ((context->state[1] >> 32) & 0xff);
- digest[12] = (unsigned char) ((context->state[1] >> 24) & 0xff);
- digest[13] = (unsigned char) ((context->state[1] >> 16) & 0xff);
- digest[14] = (unsigned char) ((context->state[1] >> 8) & 0xff);
- digest[15] = (unsigned char) (context->state[1] & 0xff);
- digest[16] = (unsigned char) ((context->state[2] >> 56) & 0xff);
- digest[17] = (unsigned char) ((context->state[2] >> 48) & 0xff);
- digest[18] = (unsigned char) ((context->state[2] >> 40) & 0xff);
- digest[19] = (unsigned char) ((context->state[2] >> 32) & 0xff);
- digest[20] = (unsigned char) ((context->state[2] >> 24) & 0xff);
- digest[21] = (unsigned char) ((context->state[2] >> 16) & 0xff);
- digest[22] = (unsigned char) ((context->state[2] >> 8) & 0xff);
- digest[23] = (unsigned char) (context->state[2] & 0xff);
-
+ TigerDigest(digest, 24, context);
memset(context, 0, sizeof(*context));
}
diff --git a/ext/hash/tests/tiger.phpt b/ext/hash/tests/tiger.phpt
index ee3f249..468fc8f 100644
--- a/ext/hash/tests/tiger.phpt
+++ b/ext/hash/tests/tiger.phpt
@@ -11,8 +11,9 @@ echo hash('tiger192,3', str_repeat('abc', 61)),"\n";
echo hash('tiger192,3', str_repeat('abc', 64)),"\n";
?>
--EXPECT--
-24f0130c63ac933216166e76b1bb925ff373de2d49584e7a
-f258c1e88414ab2a527ab541ffc5b8bf935f7b951c132951
-8ee409a14e6066933b63d5b2abca63d71a78f55e29eb4649
-2586156d16bf9ab1e6e48bdf5e038f8053c30e071db3bcb0
-3ee8a9405396ddba1bc038508af4164ac1fe59ef58916a85
+3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3
+2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93
+9366604ea109e48ed763caabb2d5633b4946eb295ef5781a
+b19abf166d158625808f035edf8be4e6b0bcb31d070ec353
+badd965340a9e83e4a16f48a5038c01b856a9158ef59fec1
+