]> granicus.if.org Git - php/commitdiff
Disallow non-crypto hashes in HMAC and PBKDF2
authorAndrey Andreev <narf@devilix.net>
Mon, 16 Jan 2017 13:51:13 +0000 (15:51 +0200)
committerNikita Popov <nikic@php.net>
Wed, 18 Jan 2017 20:13:54 +0000 (21:13 +0100)
For this purpose add is_crypto flag to php_hash_ops.

21 files changed:
UPGRADING
ext/hash/hash.c
ext/hash/hash_adler32.c
ext/hash/hash_crc32.c
ext/hash/hash_fnv.c
ext/hash/hash_gost.c
ext/hash/hash_haval.c
ext/hash/hash_joaat.c
ext/hash/hash_md.c
ext/hash/hash_ripemd.c
ext/hash/hash_sha.c
ext/hash/hash_sha3.c
ext/hash/hash_snefru.c
ext/hash/hash_tiger.c
ext/hash/hash_whirlpool.c
ext/hash/php_hash.h
ext/hash/tests/hash_hmac_basic.phpt
ext/hash/tests/hash_hmac_error.phpt
ext/hash/tests/hash_hmac_file_basic.phpt
ext/hash/tests/hash_hmac_file_error.phpt
ext/hash/tests/hash_pbkdf2_error.phpt

index 7766d4e363b0590ee41e4b1dfcea771b99793423..6b429dae79f4f6d3685e986013170e9097ca7af0 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -42,6 +42,10 @@ PHP 7.2 UPGRADE NOTES
     such, its behavior now follows fmod() rather than the `%` operator. For
     example `bcmod('4', '3.5')` now returns '0.5' instead of '1'.
 
+- Hash:
+  . The hash_hmac(), hash_hmac_file() and hash_pbkdf2() functions no longer
+    accept non-cryptographic hashes.
+
 - PCRE:
   . preg_match() and other PCRE functions now distinguish between unmatched
     subpatterns and empty matches by reporting NULL and "" (empty string),
index 06c9f36705a3514b34706a84f06d0d327d49a07e..8040732d5370b992b56165bd70e8d67245b244ce 100644 (file)
@@ -248,6 +248,11 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename,
                php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
                RETURN_FALSE;
        }
+       else if (!ops->is_crypto) {
+               php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
+               RETURN_FALSE;
+       }
+
        if (isfilename) {
                if (CHECK_NULL_PATH(data, data_len)) {
                        php_error_docref(NULL, E_WARNING, "Invalid path");
@@ -597,25 +602,6 @@ PHP_FUNCTION(hash_algos)
 }
 /* }}} */
 
-static inline zend_bool php_hash_is_crypto(const char *algo, size_t algo_len) {
-
-       char *blacklist[] = { "adler32", "crc32", "crc32b", "fnv132", "fnv1a32", "fnv164", "fnv1a64", "joaat", NULL };
-       char *lower = zend_str_tolower_dup(algo, algo_len);
-       int i = 0;
-
-       while (blacklist[i]) {
-               if (strcmp(lower, blacklist[i]) == 0) {
-                       efree(lower);
-                       return 0;
-               }
-
-               i++;
-       }
-
-       efree(lower);
-       return 1;
-}
-
 /* {{{ proto string hash_hkdf(string algo, string ikm [, int length = 0, string info = '', string salt = ''])
 RFC5869 HMAC-based key derivation function */
 PHP_FUNCTION(hash_hkdf)
@@ -636,8 +622,8 @@ PHP_FUNCTION(hash_hkdf)
                php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
                RETURN_FALSE;
        }
-       
-       if (!php_hash_is_crypto(ZSTR_VAL(algo), ZSTR_LEN(algo))) {
+
+       if (!ops->is_crypto) {
                php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
                RETURN_FALSE;
        }
@@ -736,6 +722,10 @@ PHP_FUNCTION(hash_pbkdf2)
                php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
                RETURN_FALSE;
        }
+       else if (!ops->is_crypto) {
+               php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
+               RETURN_FALSE;
+       }
 
        if (iterations <= 0) {
                php_error_docref(NULL, E_WARNING, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations);
index 3cb9ddfb7e412a6b6ada5ac04ecdb47c43ef8feb..a989df592b795751bfc325bb7298a8b04667370a 100644 (file)
@@ -69,7 +69,8 @@ const php_hash_ops php_hash_adler32_ops = {
        (php_hash_copy_func_t) PHP_ADLER32Copy,
        4, /* what to say here? */
        4,
-       sizeof(PHP_ADLER32_CTX)
+       sizeof(PHP_ADLER32_CTX),
+       0
 };
 
 /*
index ee3afa78e483ebc5ee7b7f1c10bd1decec9d7849..63f5de3c76c8df9c5de651d647be1ea1341cc243 100644 (file)
@@ -79,7 +79,8 @@ const php_hash_ops php_hash_crc32_ops = {
        (php_hash_copy_func_t) PHP_CRC32Copy,
        4, /* what to say here? */
        4,
-       sizeof(PHP_CRC32_CTX)
+       sizeof(PHP_CRC32_CTX),
+       0
 };
 
 const php_hash_ops php_hash_crc32b_ops = {
@@ -89,7 +90,8 @@ const php_hash_ops php_hash_crc32b_ops = {
        (php_hash_copy_func_t) PHP_CRC32Copy,
        4, /* what to say here? */
        4,
-       sizeof(PHP_CRC32_CTX)
+       sizeof(PHP_CRC32_CTX),
+       0
 };
 
 /*
index 4a7619de162bd29f8fab67593e9bf1cca1671839..d11b6880cd3cd814db24015b9e5b93e791ed2c76 100644 (file)
@@ -31,17 +31,19 @@ const php_hash_ops php_hash_fnv132_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        4,
        4,
-       sizeof(PHP_FNV132_CTX)
+       sizeof(PHP_FNV132_CTX),
+       0
 };
 
-       const php_hash_ops php_hash_fnv1a32_ops = {
+const php_hash_ops php_hash_fnv1a32_ops = {
        (php_hash_init_func_t) PHP_FNV132Init,
        (php_hash_update_func_t) PHP_FNV1a32Update,
        (php_hash_final_func_t) PHP_FNV132Final,
        (php_hash_copy_func_t) php_hash_copy,
        4,
        4,
-       sizeof(PHP_FNV132_CTX)
+       sizeof(PHP_FNV132_CTX),
+       0
 };
 
 const php_hash_ops php_hash_fnv164_ops = {
@@ -51,7 +53,8 @@ const php_hash_ops php_hash_fnv164_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        8,
        4,
-       sizeof(PHP_FNV164_CTX)
+       sizeof(PHP_FNV164_CTX),
+       0
 };
 
 const php_hash_ops php_hash_fnv1a64_ops = {
@@ -61,7 +64,8 @@ const php_hash_ops php_hash_fnv1a64_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        8,
        4,
-       sizeof(PHP_FNV164_CTX)
+       sizeof(PHP_FNV164_CTX),
+       0
 };
 
 /* {{{ PHP_FNV132Init
index 7961fc6c3a6043ef89204d0227cc42b64244ad44..1ce8beefd423f05a7dd0047b0d934bfc7b9dd049 100644 (file)
@@ -316,7 +316,8 @@ const php_hash_ops php_hash_gost_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        32,
-       sizeof(PHP_GOST_CTX)
+       sizeof(PHP_GOST_CTX),
+       1
 };
 
 const php_hash_ops php_hash_gost_crypto_ops = {
@@ -326,7 +327,8 @@ const php_hash_ops php_hash_gost_crypto_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        32,
-       sizeof(PHP_GOST_CTX)
+       sizeof(PHP_GOST_CTX),
+       1
 };
 
 /*
index 2b10e5f2c254764d60bae1c5d93e15d754d88012..1848e2d24080cdb4de5880d067eb7698b46abf95 100644 (file)
@@ -255,7 +255,7 @@ const php_hash_ops php_hash_##p##haval##b##_ops = { \
        (php_hash_update_func_t) PHP_HAVALUpdate, \
        (php_hash_final_func_t) PHP_HAVAL##b##Final, \
        (php_hash_copy_func_t) php_hash_copy, \
-       ((b) / 8), 128, sizeof(PHP_HAVAL_CTX) }; \
+       ((b) / 8), 128, sizeof(PHP_HAVAL_CTX), 1 }; \
 PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *context) \
 {      int i; context->count[0] =      context->count[1] =     0; \
        for(i = 0; i < 8; i++) context->state[i] = D0[i]; \
index 43199465b573e9890d451e28aa89a1e984c75fc1..530f73ea90f38600e8d7c0766193ac869b58e898 100644 (file)
@@ -32,7 +32,8 @@ const php_hash_ops php_hash_joaat_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        4,
        4,
-       sizeof(PHP_JOAAT_CTX)
+       sizeof(PHP_JOAAT_CTX),
+       0
 };
 
 PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context)
index 073715d1961e5a83f257e47c1f1f0417e786388b..06afc4a08e0cb661363938c7163d3e2308ca2dfb 100644 (file)
@@ -28,7 +28,8 @@ const php_hash_ops php_hash_md5_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        16,
        64,
-       sizeof(PHP_MD5_CTX)
+       sizeof(PHP_MD5_CTX),
+       1
 };
 
 const php_hash_ops php_hash_md4_ops = {
@@ -38,7 +39,8 @@ const php_hash_ops php_hash_md4_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        16,
        64,
-       sizeof(PHP_MD4_CTX)
+       sizeof(PHP_MD4_CTX),
+       1
 };
 
 const php_hash_ops php_hash_md2_ops = {
@@ -48,7 +50,8 @@ const php_hash_ops php_hash_md2_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        16,
        16,
-       sizeof(PHP_MD2_CTX)
+       sizeof(PHP_MD2_CTX),
+       1
 };
 
 /* MD common stuff */
index d08cfe43c207d407104aaa18bbe71ef25c658215..b7f2ef4bd80b7555e76d535419b92a9d161cd25a 100644 (file)
@@ -32,7 +32,8 @@ const php_hash_ops php_hash_ripemd128_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        16,
        64,
-       sizeof(PHP_RIPEMD128_CTX)
+       sizeof(PHP_RIPEMD128_CTX),
+       1
 };
 
 const php_hash_ops php_hash_ripemd160_ops = {
@@ -42,7 +43,8 @@ const php_hash_ops php_hash_ripemd160_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        20,
        64,
-       sizeof(PHP_RIPEMD160_CTX)
+       sizeof(PHP_RIPEMD160_CTX),
+       1
 };
 
 const php_hash_ops php_hash_ripemd256_ops = {
@@ -52,7 +54,8 @@ const php_hash_ops php_hash_ripemd256_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        64,
-       sizeof(PHP_RIPEMD256_CTX)
+       sizeof(PHP_RIPEMD256_CTX),
+       1
 };
 
 const php_hash_ops php_hash_ripemd320_ops = {
@@ -62,7 +65,8 @@ const php_hash_ops php_hash_ripemd320_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        40,
        64,
-       sizeof(PHP_RIPEMD320_CTX)
+       sizeof(PHP_RIPEMD320_CTX),
+       1
 };
 
 /* {{{ PHP_RIPEMD128Init
index 6f4ff0ef7ce4874d8c83530e3f4044cb47f7c43f..dee85fc473083e3dc271cc2c421df50860480871 100644 (file)
@@ -73,7 +73,8 @@ const php_hash_ops php_hash_sha1_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        20,
        64,
-       sizeof(PHP_SHA1_CTX)
+       sizeof(PHP_SHA1_CTX),
+       1
 };
 
 #ifdef PHP_HASH_SHA1_NOT_IN_CORE
@@ -415,7 +416,8 @@ const php_hash_ops php_hash_sha256_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        64,
-       sizeof(PHP_SHA256_CTX)
+       sizeof(PHP_SHA256_CTX),
+       1
 };
 
 const php_hash_ops php_hash_sha224_ops = {
@@ -425,7 +427,8 @@ const php_hash_ops php_hash_sha224_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        28,
        64,
-       sizeof(PHP_SHA224_CTX)
+       sizeof(PHP_SHA224_CTX),
+       1
 };
 
 #define ROTR32(b,x)            ((x >> b) | (x << (32 - b)))
@@ -917,7 +920,8 @@ const php_hash_ops php_hash_sha384_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        48,
        128,
-       sizeof(PHP_SHA384_CTX)
+       sizeof(PHP_SHA384_CTX),
+       1
 };
 
 /* {{{ PHP_SHA512Init
@@ -1089,7 +1093,8 @@ const php_hash_ops php_hash_sha512_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        64,
        128,
-       sizeof(PHP_SHA512_CTX)
+       sizeof(PHP_SHA512_CTX),
+       1
 };
 
 const php_hash_ops php_hash_sha512_256_ops = {
@@ -1099,7 +1104,8 @@ const php_hash_ops php_hash_sha512_256_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        128,
-       sizeof(PHP_SHA512_CTX)
+       sizeof(PHP_SHA512_CTX),
+       1
 };
 
 const php_hash_ops php_hash_sha512_224_ops = {
@@ -1109,7 +1115,8 @@ const php_hash_ops php_hash_sha512_224_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        28,
        128,
-       sizeof(PHP_SHA512_CTX)
+       sizeof(PHP_SHA512_CTX),
+       1
 };
 
 /*
index d6eb1a0f3992e496755afdec8db0b9a424d4e8a3..3999d4556291a9f9b935eadd9587f9299ccaf799 100644 (file)
@@ -218,7 +218,8 @@ const php_hash_ops php_hash_sha3_##bits##_ops = { \
        php_hash_copy, \
        bits >> 3, \
        (1600 - (2 * bits)) >> 3, \
-       sizeof(PHP_SHA3_##bits##_CTX) \
+       sizeof(PHP_SHA3_##bits##_CTX), \
+       1 \
 }
 
 DECLARE_SHA3_OPS(224);
index 17f70d645005c6082b1eb2abaaeff5cf7ef2b9bc..5de2a283ffab5dae66e3d3d52995ef06ac0aa35e 100644 (file)
@@ -200,7 +200,8 @@ const php_hash_ops php_hash_snefru_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        32,
        32,
-       sizeof(PHP_SNEFRU_CTX)
+       sizeof(PHP_SNEFRU_CTX),
+       1
 };
 
 /*
index c7009a1b2984c9bd8f838ebd6228a697b14a3cd1..f3ea46344c6414fd859842a40c4f3eacbcad88b4 100644 (file)
@@ -251,7 +251,8 @@ PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *con
                (php_hash_copy_func_t) php_hash_copy, \
                b/8, \
                64, \
-               sizeof(PHP_TIGER_CTX) \
+               sizeof(PHP_TIGER_CTX), \
+               1 \
        }
 
 PHP_HASH_TIGER_OPS(3, 128);
index 415c346f99ede39e134f98c3a3499e7baa911176..425a89128ac7b853b593ac617f4306312e5ea088 100644 (file)
@@ -440,7 +440,8 @@ const php_hash_ops php_hash_whirlpool_ops = {
        (php_hash_copy_func_t) php_hash_copy,
        64,
        64,
-       sizeof(PHP_WHIRLPOOL_CTX)
+       sizeof(PHP_WHIRLPOOL_CTX),
+       1
 };
 
 /*
index 45a598c4ddfd66bc2671e36b350fff8132f8e600..b67b8c59a380027b5b95aa32a10f5b3478c433ec 100644 (file)
@@ -46,6 +46,7 @@ typedef struct _php_hash_ops {
        int digest_size;
        int block_size;
        int context_size;
+       unsigned is_crypto: 1;
 } php_hash_ops;
 
 typedef struct _php_hash_data {
index a0a49533d5a8ae0ad51bf39fe98ece6bca90ea42..ad4e754e55025ddf2d5eb2b1940cb2a749cafca9 100644 (file)
@@ -16,8 +16,6 @@ echo "*** Testing hash_hmac() : basic functionality ***\n";
 $content = "This is a sample string used to test the hash_hmac function with various hashing algorithms";
 $key = 'secret';
 
-echo "adler32: " . hash_hmac('adler32', $content, $key) . "\n";
-echo "crc32: " . hash_hmac('crc32', $content, $key) . "\n";
 echo "gost: " . hash_hmac('gost', $content, $key) . "\n";
 echo "haval128,3: " . hash_hmac('haval128,3', $content, $key) . "\n";
 echo "md2: " . hash_hmac('md2', $content, $key) . "\n";
@@ -34,7 +32,6 @@ echo "sha512: " . hash_hmac('sha512', $content, $key) . "\n";
 echo "snefru: " . hash_hmac('snefru', $content, $key) . "\n";
 echo "tiger192,3: " . hash_hmac('tiger192,3', $content, $key) . "\n";
 echo "whirlpool: " . hash_hmac('whirlpool', $content, $key) . "\n";
-echo "adler32(raw): " . bin2hex(hash_hmac('adler32', $content, $key, TRUE)) . "\n";
 echo "md5(raw): " . bin2hex(hash_hmac('md5', $content, $key, TRUE)) . "\n";
 echo "sha256(raw): " . bin2hex(hash_hmac('sha256', $content, $key, TRUE)) . "\n";
 
@@ -42,8 +39,6 @@ echo "sha256(raw): " . bin2hex(hash_hmac('sha256', $content, $key, TRUE)) . "\n"
 ===Done===
 --EXPECTF--
 *** Testing hash_hmac() : basic functionality ***
-adler32: 12c803f7
-crc32: 96859101
 gost: a4a3c80bdf3f8665bf07376a34dc9c1b11af7c813f4928f62e39f0c0dc564dad
 haval128,3: 4d1318607f0406bd1b7bd50907772672
 md2: 6d111dab563025e4cb5f4425c991fa12
@@ -60,7 +55,6 @@ sha512: 7de05636b18e2b0ca3427e03f53074af3a48a7b9df226daba4f22324c570638e7d7b2643
 snefru: 67af483046f9cf16fe19f9087929ccfc6ad176ade3290b4d33f43e0ddb07e711
 tiger192,3: 00a0f884f15a9e5549ed0e40ca0190522d369027e16d5b59
 whirlpool: 4a0f1582b21b7aff59bfba7f9c29131c69741b2ce80acdc7d314040f3b768cf5a17e30b74cceb86fbc6b34b1692e0addd5bfd7cfc043d40c0621f1b97e26fa49
-adler32(raw): 12c803f7
 md5(raw): 2a632783e2812cf23de100d7d6a463ae
 sha256(raw): 49bde3496b9510a17d0edd8a4b0ac70148e32a1d51e881ec76faa96534125838
 ===Done===
index 7ced431c6a9363f3b16d9307477b0028dea0bf12..bff478a55e52c871eda2789e894a7d33333e8e29 100644 (file)
@@ -16,16 +16,19 @@ $key = 'secret';
 
 echo "\n-- Testing hash_hmac() function with less than expected no. of arguments --\n";
 var_dump(hash_hmac());
-var_dump(hash_hmac('crc32'));
-var_dump(hash_hmac('crc32', $data));
+var_dump(hash_hmac('md5'));
+var_dump(hash_hmac('md5', $data));
 
 echo "\n-- Testing hash_hmac() function with more than expected no. of arguments --\n";
 $extra_arg = 10;
-var_dump(hash_hmac('crc32', $data, $key, TRUE, $extra_arg));
+var_dump(hash_hmac('md5', $data, $key, TRUE, $extra_arg));
 
 echo "\n-- Testing hash_hmac() function with invalid hash algorithm --\n";
 var_dump(hash_hmac('foo', $data, $key));
 
+echo "\n-- Testing hash_hmac() function with non-cryptographic hash algorithm --\n";
+var_dump(hash_hmac('crc32', $data, $key));
+
 ?>
 ===Done===
 --EXPECTF--
@@ -51,4 +54,9 @@ NULL
 
 Warning: hash_hmac(): Unknown hashing algorithm: foo in %s on line %d
 bool(false)
-===Done===
\ No newline at end of file
+
+-- Testing hash_hmac() function with non-cryptographic hash algorithm --
+
+Warning: hash_hmac(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
+bool(false)
+===Done===
index 5c18fd6a2d71570c9d3a1d73e39c07bfd1da0e84..8ac248756c4d48927bd3716309e2e5814f59b159 100644 (file)
@@ -36,8 +36,6 @@ fclose($fp);
 $key = 'secret';
 
 
-echo "adler32: " . hash_hmac_file('adler32', $file, $key) . "\n";
-echo "crc32: " . hash_hmac_file('crc32', $file, $key) . "\n";
 echo "gost: " . hash_hmac_file('gost', $file, $key) . "\n";
 echo "haval128,3: " . hash_hmac_file('haval128,3', $file, $key) . "\n";
 echo "md2: " . hash_hmac_file('md2', $file, $key) . "\n";
@@ -55,7 +53,6 @@ echo "snefru: " . hash_hmac_file('snefru', $file, $key) . "\n";
 echo "tiger192,3: " . hash_hmac_file('tiger192,3', $file, $key) . "\n";
 echo "whirlpool: " . hash_hmac_file('whirlpool', $file, $key) . "\n";
 
-echo "adler32(raw): " . bin2hex(hash_hmac_file('adler32', $file, $key, TRUE)) . "\n";
 echo "md5(raw): " . bin2hex(hash_hmac_file('md5', $file, $key, TRUE)). "\n";
 echo "sha256(raw): " . bin2hex(hash_hmac_file('sha256', $file, $key, TRUE)). "\n";
 
@@ -70,8 +67,6 @@ unlink($file);
 ===Done===
 --EXPECTF--
 *** Testing hash_hmac_file() : basic functionality ***
-adler32: 0f8c02f9
-crc32: f2a60b9c
 gost: 94c39a40d5db852a8dc3d24e37eebf2d53e3d711457c59cd02b614f792a9d918
 haval128,3: f1cea637451097d790354a86de3f54a3
 md2: a685475e600314bb549ab4f33c3b27cb
@@ -88,7 +83,6 @@ sha512: d460aabdf0353655059ed0d408efa91f19c4cda46acc2a4e0adf4764b06951c899fbb2ed
 snefru: 7b79787e1c1d926b6cc98327f05c5d04ba6227ab51c1398661861196016ef34c
 tiger192,3: ca89badf843ba68e3fae5832635aa848a72a4bc11676edd4
 whirlpool: 37a0fbb90547690d5e5e11c046f6654ffdb7bab15e16d9d79c7d85765cc4bdcbfd9df8db7a3ce9558f3f244fead00ca29cf05297f75596555195a0683f15d69f
-adler32(raw): 0f8c02f9
 md5(raw): 8bddf39dd1c566c27acc7fa85ec36acf
 sha256(raw): 9135286ca4c84dec711e4b831f6cd39e672e5ff93d011321274eb76733cc1e40
 Error cases:
index 26ba8aacbeced1132d52406362fe4d670571a245..29adbddba8f63c5b31e4a7f5c51e8be8df940815 100644 (file)
@@ -28,8 +28,11 @@ hash_hmac_file('crc32', $file, $key, TRUE, $extra_arg);
 echo "\n-- Testing hash_hmac_file() function with invalid hash algorithm --\n";
 hash_hmac_file('foo', $file, $key, TRUE);
 
+echo "\n-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --\n";
+hash_hmac_file('crc32', $file, $key, TRUE);
+
 echo "\n-- Testing hash_hmac_file() function with bad path --\n";
-hash_hmac_file('crc32', $file.chr(0).$file, $key, TRUE);
+hash_hmac_file('md5', $file.chr(0).$file, $key, TRUE);
 
 ?>
 ===Done===
@@ -55,7 +58,11 @@ Warning: hash_hmac_file() expects at most 4 parameters, 5 given in %s on line %d
 
 Warning: hash_hmac_file(): Unknown hashing algorithm: foo in %s on line %d
 
+-- Testing hash_hmac_file() function with non-cryptographic hash algorithm --
+
+Warning: hash_hmac_file(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
+
 -- Testing hash_hmac_file() function with bad path --
 
 Warning: hash_hmac_file(): Invalid path in %s on line %d
-===Done===
\ No newline at end of file
+===Done===
index fd70cca581ea8a6e259110fa46d21b202b575d86..8c49d365d21f0b0c0d264437c5c5de338e70486e 100644 (file)
@@ -17,21 +17,25 @@ $salt = 'salt';
 echo "\n-- Testing hash_pbkdf2() function with less than expected no. of arguments --\n";
 var_dump(@hash_pbkdf2());
 echo $php_errormsg . "\n";
-var_dump(@hash_pbkdf2('crc32'));
+var_dump(@hash_pbkdf2('md5'));
 echo $php_errormsg . "\n";
-var_dump(@hash_pbkdf2('crc32', $password));
+var_dump(@hash_pbkdf2('md5', $password));
 echo $php_errormsg . "\n";
-var_dump(@hash_pbkdf2('crc32', $password, $salt));
+var_dump(@hash_pbkdf2('md5', $password, $salt));
 echo $php_errormsg . "\n";
 
 echo "\n-- Testing hash_pbkdf2() function with more than expected no. of arguments --\n";
-var_dump(@hash_pbkdf2('crc32', $password, $salt, 10, 10, true, 'extra arg'));
+var_dump(@hash_pbkdf2('md5', $password, $salt, 10, 10, true, 'extra arg'));
 echo $php_errormsg . "\n";
 
 echo "\n-- Testing hash_pbkdf2() function with invalid hash algorithm --\n";
 var_dump(@hash_pbkdf2('foo', $password, $salt, 1));
 echo $php_errormsg . "\n";
 
+echo "\n-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --\n";
+var_dump(@hash_pbkdf2('crc32', $password, $salt, 1));
+echo $php_errormsg . "\n";
+
 echo "\n-- Testing hash_pbkdf2() function with invalid iterations --\n";
 var_dump(@hash_pbkdf2('md5', $password, $salt, 0));
 echo $php_errormsg . "\n";
@@ -65,6 +69,10 @@ hash_pbkdf2() expects at most 6 parameters, 7 given
 bool(false)
 hash_pbkdf2(): Unknown hashing algorithm: foo
 
+-- Testing hash_pbkdf2() function with non-cryptographic hash algorithm --
+bool(false)
+hash_pbkdf2(): Non-cryptographic hashing algorithm: crc32
+
 -- Testing hash_pbkdf2() function with invalid iterations --
 bool(false)
 hash_pbkdf2(): Iterations must be a positive integer: 0