scottmac Sat Jun 28 15:20:49 2008 UTC Removed files: /php-src/ext/mhash mhash.dsp /php-src/ext/mhash/tests 001.phpt 002.phpt 003.phpt skip.inc
Modified files: /php-src/ext/hash CREDITS config.m4 hash.c /php-src/ext/hash/tests mhash_001.phpt mhash_002.phpt mhash_003.phpt skip_mhash.inc /php-src/ext/mhash config.m4 mhash.c php_mhash.h Log: MFB: Make the old mhash API a wrapper around hash, this removes a dependency.
http://cvs.php.net/viewvc.cgi/php-src/ext/hash/CREDITS?r1=1.2&r2=1.3&diff_format=u Index: php-src/ext/hash/CREDITS diff -u php-src/ext/hash/CREDITS:1.2 php-src/ext/hash/CREDITS:1.3 --- php-src/ext/hash/CREDITS:1.2 Fri Nov 25 18:24:32 2005 +++ php-src/ext/hash/CREDITS Sat Jun 28 15:20:49 2008 @@ -1,2 +1,2 @@ PHP hash -Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner +Sara Golemon, Rasmus Lerdorf, Stefan Esser, Michael Wallner, Scott MacVicar http://cvs.php.net/viewvc.cgi/php-src/ext/hash/config.m4?r1=1.12&r2=1.13&diff_format=u Index: php-src/ext/hash/config.m4 diff -u php-src/ext/hash/config.m4:1.12 php-src/ext/hash/config.m4:1.13 --- php-src/ext/hash/config.m4:1.12 Tue Jul 3 17:24:36 2007 +++ php-src/ext/hash/config.m4 Sat Jun 28 15:20:49 2008 @@ -1,9 +1,17 @@ -dnl $Id: config.m4,v 1.12 2007/07/03 17:24:36 sniper Exp $ +dnl $Id: config.m4,v 1.13 2008/06/28 15:20:49 scottmac Exp $ dnl config.m4 for extension hash PHP_ARG_ENABLE(hash, whether to enable hash support, [ --disable-hash Disable hash support], yes) +if test "$PHP_MHASH" != "no"; then + if test "$PHP_HASH" == "no"; then + PHP_HASH="yes" + fi + + AC_DEFINE(PHP_MHASH_BC, 1, [ ]) +fi + if test "$PHP_HASH" != "no"; then AC_DEFINE(HAVE_HASH_EXT,1,[Have HASH Extension]) http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.43&r2=1.44&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.43 php-src/ext/hash/hash.c:1.44 --- php-src/ext/hash/hash.c:1.43 Tue Jun 3 17:27:10 2008 +++ php-src/ext/hash/hash.c Sat Jun 28 15:20:49 2008 @@ -13,10 +13,11 @@ | [EMAIL PROTECTED] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[EMAIL PROTECTED]> | + | Scott MacVicar <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: hash.c,v 1.43 2008/06/03 17:27:10 scottmac Exp $ */ +/* $Id: hash.c,v 1.44 2008/06/28 15:20:49 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -35,6 +36,48 @@ # define DEFAULT_CONTEXT NULL #endif +#ifdef PHP_MHASH_BC +struct mhash_bc_entry { + char *mhash_name; + char *hash_name; + int value; +}; + +#define MHASH_NUM_ALGOS 29 + +static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = { + {"CRC32", "crc32", 0}, + {"MD5", "md5", 1}, + {"SHA1", "sha1", 2}, + {"HAVAL256", "haval256,3", 3}, + {NULL, NULL, 4}, + {"RIPEMD160", "ripemd160", 5}, + {NULL, NULL, 6}, + {"TIGER", "tiger192,3", 7}, + {"GOST", "gost", 8}, + {"CRC32B", "crc32b", 9}, + {"HAVAL224", "haval224,3", 10}, + {"HAVAL192", "haval192,3", 11}, + {"HAVAL160", "haval160,3", 12}, + {"HAVAL128", "haval128,3", 13}, + {"TIGER128", "tiger128,3", 14}, + {"TIGER160", "tiger160,3", 15}, + {"MD4", "md4", 16}, + {"SHA256", "sha256", 17}, + {"ADLER32", "adler32", 18}, + {"SHA224", "sha224", 19}, + {"SHA512", "sha512", 20}, + {"SHA384", "sha384", 21}, + {"WHIRLPOOL", "whirlpool", 22}, + {"RIPEMD128", "ripemd128", 23}, + {"RIPEMD256", "ripemd256", 24}, + {"RIPEMD320", "ripemd320", 25}, + {NULL, NULL, 26}, /* support needs to be added for snefru 128 */ + {"SNEFRU256", "snefru256", 27}, + {"MD2", "md2", 28} +}; +#endif + /* Hash Registry Access */ PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) /* {{{ */ @@ -74,12 +117,12 @@ /* Userspace */ -static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* {{{ */ +static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */ { char *algo, *data, *digest; int algo_len, data_len; zend_uchar data_type = IS_STRING; - zend_bool raw_output = 0; + zend_bool raw_output = raw_output_default; const php_hash_ops *ops; void *context; php_stream *stream = NULL; @@ -175,7 +218,7 @@ Returns lowercase hexits by default */ PHP_FUNCTION(hash) { - php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0); } /* }}} */ @@ -184,16 +227,16 @@ Returns lowercase hexits by default */ PHP_FUNCTION(hash_file) { - php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0); } /* }}} */ -static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* {{{ */ +static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */ { char *algo, *data, *digest, *key, *K; int algo_len, data_len, key_len, i; zend_uchar data_type = IS_STRING, key_type = IS_STRING; - zend_bool raw_output = 0; + zend_bool raw_output = raw_output_default; const php_hash_ops *ops; void *context; php_stream *stream = NULL; @@ -338,7 +381,7 @@ Returns lowercase hexits by default */ PHP_FUNCTION(hash_hmac) { - php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0); } /* }}} */ @@ -347,7 +390,7 @@ Returns lowercase hexits by default */ PHP_FUNCTION(hash_hmac_file) { - php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0); } /* }}} */ @@ -731,6 +774,186 @@ } /* }}} */ +#ifdef PHP_MHASH_BC + +static void mhash_init(INIT_FUNC_ARGS) +{ + char buf[128]; + int len; + int algo_number = 0; + + for (algo_number = 0; algo_number < MHASH_NUM_ALGOS; algo_number++) { + struct mhash_bc_entry algorithm = mhash_to_hash[algo_number]; + if (algorithm.mhash_name == NULL) { + continue; + } + + len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name)); + { + char name[len+1]; + memcpy(name, buf, len+1); + REGISTER_LONG_CONSTANT(name, algorithm.value, CONST_CS | CONST_PERSISTENT); + } + } +} + +/* {{{ proto binary mhash(int hash, binary data [, binary key]) U + Hash data with hash */ +PHP_FUNCTION(mhash) +{ + zval **z_algorithm; + int algorithm; + + if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_ex(1, &z_algorithm) == FAILURE) { + WRONG_PARAM_COUNT; + } + + algorithm = Z_LVAL_PP(z_algorithm); + + /* need to conver the first parameter from int to string */ + if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) { + struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm]; + if (algorithm_lookup.hash_name) { + ZVAL_STRING(*z_algorithm, algorithm_lookup.hash_name, 1); + } + } + + if (ZEND_NUM_ARGS() == 3) { + php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1); + } else if (ZEND_NUM_ARGS() == 2) { + php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1); + } else { + WRONG_PARAM_COUNT; + } +} +/* }}} */ + +/* {{{ proto string mhash_get_hash_name(int hash) U + Gets the name of hash */ +PHP_FUNCTION(mhash_get_hash_name) +{ + int algorithm; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) { + return; + } + + if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) { + struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm]; + if (algorithm_lookup.mhash_name) { + RETURN_STRING(algorithm_lookup.mhash_name, 1); + } + } + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto int mhash_count(void) U + Gets the number of available hashes */ +PHP_FUNCTION(mhash_count) +{ + if (zend_parse_parameters_none() == FAILURE) { + return; + } + RETURN_LONG(MHASH_NUM_ALGOS - 1); +} +/* }}} */ + +/* {{{ proto int mhash_get_block_size(int hash) U + Gets the block size of hash */ +PHP_FUNCTION(mhash_get_block_size) +{ + int algorithm; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) { + return; + } + RETVAL_FALSE; + + if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) { + struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm]; + if (algorithm_lookup.mhash_name) { + const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name)); + if (ops) { + RETVAL_LONG(ops->digest_size); + } + } + } +} +/* }}} */ + +#define SALT_SIZE 8 + +/* {{{ proto binary mhash_keygen_s2k(int hash, binary input_password, binary salt, int bytes) + Generates a key using hash functions */ +PHP_FUNCTION(mhash_keygen_s2k) +{ + int algorithm, bytes; + char *password, *salt; + int password_len, salt_len; + char padded_salt[SALT_SIZE]; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lSSl", &algorithm, &password, &password_len, &salt, &salt_len, &bytes) == FAILURE) { + return; + } + + if (bytes <= 0){ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "the byte parameter must be greater than 0"); + RETURN_FALSE; + } + + salt_len = MIN(salt_len, SALT_SIZE); + + memcpy(padded_salt, salt, salt_len); + if (salt_len < SALT_SIZE) { + memset(padded_salt + salt_len, 0, SALT_SIZE - salt_len); + } + salt_len = SALT_SIZE; + + RETVAL_FALSE; + if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) { + struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm]; + if (algorithm_lookup.mhash_name) { + const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name)); + if (ops) { + unsigned char null = '\0'; + void *context; + char *key, *digest; + int i = 0, j = 0; + int block_size = ops->digest_size; + int times = bytes / block_size; + if (bytes % block_size != 0) times++; + + context = emalloc(ops->context_size); + ops->hash_init(context); + + key = ecalloc(1, times * block_size); + digest = emalloc(ops->digest_size + 1); + + for (i = 0; i < times; i++) { + ops->hash_init(context); + + for (j=0;j<i;j++) { + ops->hash_update(context, &null, 1); + } + ops->hash_update(context, (unsigned char *)padded_salt, salt_len); + ops->hash_update(context, password, password_len); + ops->hash_final(digest, context); + memcpy( &key[i*block_size], digest, block_size); + } + + RETVAL_STRINGL(key, bytes, 1); + memset(key, 0, bytes); + efree(digest); + efree(context); + efree(key); + } + } + } +} +/* }}} */ +#endif + #define PHP_HASH_HAVAL_REGISTER(p,b) php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops); /* {{{ PHP_MINIT_FUNCTION @@ -787,6 +1010,10 @@ REGISTER_LONG_CONSTANT("HASH_HMAC", PHP_HASH_HMAC, CONST_CS | CONST_PERSISTENT); +#ifdef PHP_MHASH_BC + mhash_init(INIT_FUNC_ARGS_PASSTHRU); +#endif + return SUCCESS; } /* }}} */ @@ -908,6 +1135,38 @@ ZEND_BEGIN_ARG_INFO(arginfo_hash_algos, 0) ZEND_END_ARG_INFO() +/* BC Land */ +#ifdef PHP_MHASH_BC +static +ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_block_size, 0) + ZEND_ARG_INFO(0, hash) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_hash_name, 0) + ZEND_ARG_INFO(0, hash) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_mhash_keygen_s2k, 0) + ZEND_ARG_INFO(0, hash) + ZEND_ARG_INFO(0, input_password) + ZEND_ARG_INFO(0, salt) + ZEND_ARG_INFO(0, bytes) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO(arginfo_mhash_count, 0) +ZEND_END_ARG_INFO() + +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_mhash, 0, 0, 2) + ZEND_ARG_INFO(0, hash) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, key) +ZEND_END_ARG_INFO() +#endif + # define PHP_HASH_FE(n) PHP_FE(n,arginfo_##n) #else # define PHP_HASH_FE(n) PHP_FE(n,NULL) @@ -932,6 +1191,14 @@ PHP_HASH_FE(hash_algos) +#ifdef PHP_MHASH_BC + PHP_FE(mhash_keygen_s2k, arginfo_mhash_keygen_s2k) + PHP_FE(mhash_get_block_size, arginfo_mhash_get_block_size) + PHP_FE(mhash_get_hash_name, arginfo_mhash_get_hash_name) + PHP_FE(mhash_count, arginfo_mhash_count) + PHP_FE(mhash, arginfo_mhash) +#endif + {NULL, NULL, NULL} }; /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_001.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/hash/tests/mhash_001.phpt diff -u /dev/null php-src/ext/hash/tests/mhash_001.phpt:1.2 --- /dev/null Sat Jun 28 15:20:49 2008 +++ php-src/ext/hash/tests/mhash_001.phpt Sat Jun 28 15:20:49 2008 @@ -0,0 +1,73 @@ +--TEST-- +mhash() test +--INI-- +magic_quotes_runtime=0 +--SKIPIF-- +<?php + include "skip_mhash.inc"; +?> +--FILE-- +<?php + +$supported_hash_al = array( +"MHASH_MD5" => "2d9bdb91f94e96d9c4e2ae532acc936a", +"MHASH_SHA1" => "2f9341e55a9083edf5497bf83ba3db812a7de0a3", +"MHASH_HAVAL256" => "b255feff01ad641b27358dc7909bc695a1fca53bddfdfaf19020b275928793af", +"MHASH_HAVAL192" => "4ce837de481e1e30092ab2c610057094c988dfd7db1e01cd", +"MHASH_HAVAL224" => "5362d1856752bf2c139bb2d6fdd772b9c515c8ce5ec82695264b85e1", +"MHASH_HAVAL160" => "c6b36f87750b18576981bc17b4f22271947bf9cb", +"MHASH_RIPEMD160" => "6c47435aa1d359c4b7c6af46349f0c3e1258583d", +"MHASH_GOST" => "101b0a2552cebdf5137cadf15147f21e55b6432935bb9c2c03c7e28d188b2d9e", +"MHASH_TIGER" => "fdb9019a79c33a95677e2097abae91eb0de00b3054bb5c39", +"MHASH_CRC32" => "83041db8", +"MHASH_CRC32B" => "a4b75adf" +); + +$data = "This is the test of the mhash extension..."; + +foreach ($supported_hash_al as $hash=>$wanted) { + $result = mhash(constant($hash), $data); + if (bin2hex($result)==$wanted) { + echo "$hash\nok\n"; + } else { + echo "$hash: "; + var_dump($wanted); + echo "$hash: "; + var_dump($result); + } + echo "\n"; +} +?> +--EXPECT-- +MHASH_MD5 +ok + +MHASH_SHA1 +ok + +MHASH_HAVAL256 +ok + +MHASH_HAVAL192 +ok + +MHASH_HAVAL224 +ok + +MHASH_HAVAL160 +ok + +MHASH_RIPEMD160 +ok + +MHASH_GOST +ok + +MHASH_TIGER +ok + +MHASH_CRC32 +ok + +MHASH_CRC32B +ok http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_002.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/hash/tests/mhash_002.phpt diff -u /dev/null php-src/ext/hash/tests/mhash_002.phpt:1.2 --- /dev/null Sat Jun 28 15:20:49 2008 +++ php-src/ext/hash/tests/mhash_002.phpt Sat Jun 28 15:20:49 2008 @@ -0,0 +1,64 @@ +--TEST-- +mhash_get_block_size() & mhash_get_hash_name() test +--SKIPIF-- +<?php + include "skip_mhash.inc"; +?> +--FILE-- +<?php +$supported_hash_al = array( +"MD5" => 16, +"MD4" => 16, +"SHA1" => 20, +"SHA256" => 32, +"HAVAL256" => 32, +"HAVAL192" => 24, +"HAVAL224" => 28, +"HAVAL160" => 20, +"HAVAL128" => 16, +"RIPEMD160" => 20, +"GOST" => 32, +"TIGER" => 24, +"TIGER160" => 20, +"TIGER128" => 16, +"CRC32" => 4, +"CRC32B" => 4, +"ADLER32" => 4, +"NA_XYZ" => 0 /* verify that the algorythm works */ +); + +$hc = mhash_count() + 1; + +$known_hash_al = array(); +for ($i=0; $i < $hc; $i++) { + $known_hash_al[mhash_get_hash_name($i)] = $i; +} + +foreach ($supported_hash_al as $name => $len) { + if (array_key_exists($name, $known_hash_al)) { + $len = mhash_get_block_size($known_hash_al[$name]); + echo "$name = $len\n"; + } else { + echo "$name ? $len\n"; + } +} +?> +--EXPECTREGEX-- +MD5 . 16 +MD4 . 16 +SHA1 . 20 +SHA256 . 32 +HAVAL256 . 32 +HAVAL192 . 24 +HAVAL224 . 28 +HAVAL160 . 20 +HAVAL128 . 16 +RIPEMD160 . 20 +GOST . 32 +TIGER . 24 +TIGER160 . 20 +TIGER128 . 16 +CRC32 . 4 +CRC32B . 4 +ADLER32 . 4 +NA_XYZ . 0 http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/mhash_003.phpt?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/hash/tests/mhash_003.phpt diff -u /dev/null php-src/ext/hash/tests/mhash_003.phpt:1.2 --- /dev/null Sat Jun 28 15:20:49 2008 +++ php-src/ext/hash/tests/mhash_003.phpt Sat Jun 28 15:20:49 2008 @@ -0,0 +1,71 @@ +--TEST-- +mhash_keygen_s2k() test +--SKIPIF-- +<?php + include "skip_mhash.inc"; +?> +--FILE-- +<?php + +$supported_hash_al = array( +"MHASH_MD5" => b"8690154eaf9432cde9347aa15094b9c046eb06e6a0940c5479aa7a6367ae68b5e0e0745e5709fede2d9fe9739d9aad413759faa73acced821077b4ddb2788064e371eb53b3a9d55ed2839aab2655c82cfedbe83a208461c799d9d77ae481061c81539b01", +"MHASH_SHA1" => b"dd315c70061d07455d53c2fb0b08df0c61aa665c1ab1a701fa10955423248ba832a5ade406b39b78630aba3d1688e622494a0eae279d4ece9ad4bdf76e878fcb084a33c9153c2b48131d30a75b00a7c05b91f1ffeabf59bb1271c4d8a11990b84baf6d49", +"MHASH_HAVAL256" => b"0ede47009f87d5e9a24ecf5077d60c483657a5d98404ab2bb780f5872c90caf61c0d67645a848e55fee107296f4169c95b4e61f0aeeefab2648554c1171fb0a2fc32aa5aeed3d5c155d334367d4959622cdadefe43ae17bd1a75f9d4fef77bf192be5b78", +"MHASH_HAVAL224" => b"5c4aff3d825ad608f608c8eae779ee3868610bc60a98f3d770b311a6677c797fc2dadcab71dde0c0191e068397ab297f0de5cbbc6cbcd0c78ca8470c42401f6b77e81dc2ba8d51930ff982760335324fb850ac2d30b73514004c096d60472d320e0ec349", +"MHASH_HAVAL192" => b"22e0c27126023c852ef94107bb2f1ee132b064178b9dcbfb1c32e658760b8f70bdc5b1c52599031628c2433bee2b0870ab7a38aeb21215134ec1088975b9a96487642971ef9eb3d987baf9765fd9e6d64d494e1719aa84afe7e0a0784c74979ebab1c787", +"MHASH_HAVAL160" => b"d6e5f0ef07f3facced646eedb6364758ecde6dc6fb061e00a496f5ceb723f78ea135884d9682226ded69c11d8431240ef97cad583c4f29593bbf3dd3cab0b8792eb3d86022ca6002ebd0d9b4429909d4af85bed2b5a96b3e47b9b8cac919c1177ec40d7e", +"MHASH_RIPEMD160" => b"e4d5db469af29f78e2b90dc735c9cf020a1d5b19a6674458677794d4dca144d426c562aff98d8e866a8a924299ebf6b0ea9a1637f987a1fb5de9b647edc35b1447605e1babc3084be7a003931117eb33432d4142e225df044b033f3ff64bb4a18682a4f9", +"MHASH_GOST" => b"c044f669bd7e8643953d77c682fd179242d9df157dadf873be4d9601e4647c018234689359e7220ab0492a6240d184c478634073dea87f79be7f86fd4e2564f7d709b68a46440a121250e00fc7d57d45a9c07ee23a704ff4148c0dad7077ec527b194d87", +"MHASH_TIGER" => b"67eac97b9dca0a47b1f6262f330264e4ce1c233760fe3255f642512fd3127929baccf1e758236b2768a4c2c0c06e118b19e40e2f04a5f745820fb8a99bdbc00698702a4d3120171856c4c94bda79ba1b4f60d509d7f8954da818a29797368dd47c1122aa", +"MHASH_CRC32" => b"481c40148c26185f9a59ef18e86f51c5d2d0315b46711d22ae08c1ccdd669fe956c817380815e3a545f6ee453c9da48d1d994dbc3ac8ba85a572108412f06b2a16b1489cda75b118e82f7d9bdfdb68336957bbf19e4a3f76750d6985a53dd557229dfcf3", +"MHASH_CRC32B" => b"b56cab65a63e7dfb2aa95d7fb646d79b36138a6243cdcb8f2e0949af0f966a9ccea530d0db0d1f3c98c62e5179e796beb68d7469fdb07862d8247d830bf598c8b49309d7cfacc88c44c5444b8513e931754cf0dd36a7a160f7e6c98f907c4563f1047fb0" +); + +foreach ($supported_hash_al as $hash=>$wanted) { + $passwd = str_repeat($hash, 10); + $salt = str_repeat($hash, 2); + $result = mhash_keygen_s2k(constant($hash), (binary)$passwd, (binary)$salt, 100); + if (!strcmp(bin2hex($result), $wanted)) { + echo "$hash\nok\n"; + } else { + echo "$hash: "; + var_dump($wanted); + echo "$hash: "; + var_dump(bin2hex($result)); + } + echo "\n"; +} +?> +--EXPECT-- +MHASH_MD5 +ok + +MHASH_SHA1 +ok + +MHASH_HAVAL256 +ok + +MHASH_HAVAL224 +ok + +MHASH_HAVAL192 +ok + +MHASH_HAVAL160 +ok + +MHASH_RIPEMD160 +ok + +MHASH_GOST +ok + +MHASH_TIGER +ok + +MHASH_CRC32 +ok + +MHASH_CRC32B +ok http://cvs.php.net/viewvc.cgi/php-src/ext/hash/tests/skip_mhash.inc?r1=1.1&r2=1.2&diff_format=u Index: php-src/ext/hash/tests/skip_mhash.inc diff -u /dev/null php-src/ext/hash/tests/skip_mhash.inc:1.2 --- /dev/null Sat Jun 28 15:20:49 2008 +++ php-src/ext/hash/tests/skip_mhash.inc Sat Jun 28 15:20:49 2008 @@ -0,0 +1,5 @@ +<?php +if (!extension_loaded("mhash")) { + die("skip mhash extension is not available"); +} +?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/config.m4?r1=1.17&r2=1.18&diff_format=u Index: php-src/ext/mhash/config.m4 diff -u php-src/ext/mhash/config.m4:1.17 php-src/ext/mhash/config.m4:1.18 --- php-src/ext/mhash/config.m4:1.17 Tue May 29 12:28:57 2007 +++ php-src/ext/mhash/config.m4 Sat Jun 28 15:20:49 2008 @@ -1,37 +1,12 @@ dnl -dnl $Id: config.m4,v 1.17 2007/05/29 12:28:57 mike Exp $ +dnl $Id: config.m4,v 1.18 2008/06/28 15:20:49 scottmac Exp $ dnl PHP_ARG_WITH(mhash, for mhash support, [ --with-mhash[=DIR] Include mhash support]) if test "$PHP_MHASH" != "no"; then - for i in $PHP_MHASH /usr/local /usr /opt/mhash; do - test -f $i/include/mhash.h && MHASH_DIR=$i && break - done - - if test -z "$MHASH_DIR"; then - AC_MSG_ERROR(Please reinstall libmhash - I cannot find mhash.h) - fi - - PHP_MHASH_MISSING_PROTOS= - AC_MSG_CHECKING(for missing protos) - AC_EGREP_HEADER(mhash_get_hash_name_static, [$MHASH_DIR/include/mhash.h], [ - AC_DEFINE([HAVE_MHASH_GET_HASH_NAME_STATIC_PROTO], 1, [ ]) - ], [ - PHP_MHASH_MISSING_PROTOS="mhash_get_hash_name_static" - ]) - AC_EGREP_HEADER(mhash_get_keygen_name_static, [$MHASH_DIR/include/mhash.h], [ - AC_DEFINE([HAVE_MHASH_GET_KEYGEN_NAME_STATIC_PROTO], 1, [ ]) - ], [ - PHP_MHASH_MISSING_PROTOS="mhash_get_keygen_name_static $PHP_MHASH_MISSING_PROTOS" - ]) - AC_MSG_RESULT([$PHP_MHASH_MISSING_PROTOS]) - - PHP_ADD_INCLUDE($MHASH_DIR/include) - PHP_ADD_LIBRARY_WITH_PATH(mhash, $MHASH_DIR/$PHP_LIBDIR, MHASH_SHARED_LIBADD) - - PHP_NEW_EXTENSION(mhash, mhash.c, $ext_shared) - PHP_SUBST(MHASH_SHARED_LIBADD) - AC_DEFINE(HAVE_LIBMHASH,1,[ ]) + PHP_NEW_EXTENSION(mhash, mhash.c, $ext_shared) + PHP_SUBST(MHASH_SHARED_LIBADD) + PHP_ADD_EXTENSION_DEP(mhash, hash, true) fi http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/mhash.c?r1=1.61&r2=1.62&diff_format=u Index: php-src/ext/mhash/mhash.c diff -u php-src/ext/mhash/mhash.c:1.61 php-src/ext/mhash/mhash.c:1.62 --- php-src/ext/mhash/mhash.c:1.61 Thu Feb 28 14:16:12 2008 +++ php-src/ext/mhash/mhash.c Sat Jun 28 15:20:49 2008 @@ -16,7 +16,7 @@ | Nikos Mavroyanopoulos <[EMAIL PROTECTED]> (HMAC, KEYGEN) | +----------------------------------------------------------------------+ */ -/* $Id: mhash.c,v 1.61 2008/02/28 14:16:12 felipe Exp $ */ +/* $Id: mhash.c,v 1.62 2008/06/28 15:20:49 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -24,27 +24,12 @@ #include "php.h" -#if HAVE_LIBMHASH - -#include "fcntl.h" #include "php_mhash.h" #include "php_ini.h" #include "php_globals.h" #include "ext/standard/info.h" const zend_function_entry mhash_functions[] = { - PHP_FE(mhash_count, NULL) - PHP_FE(mhash_get_block_size, NULL) - PHP_FE(mhash_get_hash_name, NULL) - PHP_FE(mhash_keygen_count, NULL) - PHP_FE(mhash_get_keygen_name, NULL) - PHP_FE(mhash_keygen_uses_hash, NULL) - PHP_FE(mhash_keygen_uses_salt, NULL) - PHP_FE(mhash_get_keygen_salt_size, NULL) - PHP_FE(mhash_keygen_uses_count, NULL) - PHP_FE(mhash, NULL) - PHP_FE(mhash_keygen, NULL) - PHP_FE(mhash_keygen_s2k, NULL) {NULL, NULL, NULL} }; @@ -63,131 +48,9 @@ ZEND_GET_MODULE(mhash) #endif -#define NO_ARGS() (SUCCESS == zend_parse_parameters_none()) - -#ifndef HAVE_MHASH_GET_HASH_NAME_STATIC_PROTO -extern const char *mhash_get_hash_name_static(hashid hash); -#endif -#ifndef HAVE_MHASH_GET_KEYGEN_NAME_STATIC_PROTO -extern const char *mhash_get_keygen_name_static(hashid type); -#endif - -/* {{{ int php_mhash */ -int php_mhash(hashid hash, const char *input_str, int input_len, const char *key_str, int key_len, char **enc, int *len TSRMLS_DC) -{ - size_t pbsize; - char *result; - MHASH mh; - - if (key_len) { - if (!(pbsize = mhash_get_hash_pblock(hash))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "HMAC incompatible hash algorithm"); - return FAILURE; - } - mh = mhash_hmac_init(hash, (char *) key_str, key_len, pbsize); - } else { - mh = mhash_init(hash); - } - - if (mh == MHASH_FAILED) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed"); - return FAILURE; - } - - mhash(mh, input_str, input_len); - - if (key_len) { - result = mhash_hmac_end(mh); - } else { - result = mhash_end(mh); - } - - if (!result) { - return FAILURE; - } - - *len = mhash_get_block_size(hash); - *enc = estrndup(result, *len); - - mhash_free(result); - - return SUCCESS; -} -/* }}} */ - -/* {{{ int php_mhash_keygen */ -int php_mhash_keygen(keygenid type, hashid hash1, hashid hash2, const char *pass_str, int pass_len, const char *salt_str, size_t salt_len, char **key, int *len, int max_len, int max_count TSRMLS_DC) -{ - KEYGEN keygen; - - if (type < 0 || type > mhash_keygen_count()) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unknown keygen type %d", type); - return FAILURE; - } - - memset(&keygen, 0, sizeof(keygen)); - - if (mhash_keygen_uses_hash_algorithm(type)) { - if (hash1 == -1) { - hash1 = hash2; - } - if (hash2 == -1) { - hash2 = hash1; - } - keygen.hash_algorithm[0] = hash1; - keygen.hash_algorithm[1] = hash2; - } - - if (mhash_keygen_uses_salt(type)) { - if (salt_len <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s requires a salt", mhash_get_keygen_name_static(type)); - return FAILURE; - } - keygen.salt = (void *) salt_str; - keygen.salt_size = salt_len; - } - - keygen.count = max_count; - - if (max_len > 0) { - *len = max_len; - } else { - *len = 128; - } - - *key = safe_emalloc(1, *len, 1); - - if (mhash_keygen_ext(type, keygen, *key, *len, (void *) pass_str, pass_len) < 0) { - efree(*key); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "key generation failed"); - return FAILURE; - } - - (*key)[*len] = '\0'; - return SUCCESS; -} -/* }}} */ - /* {{{ PHP_MINIT */ PHP_MINIT_FUNCTION(mhash) { - int i, n, l; - const char *name; - char buf[128]; - - for (i = 0, n = mhash_count() + 1; i < n; ++i) { - if ((name = (const char *) mhash_get_hash_name_static(i))) { - l = snprintf(buf, sizeof(buf), "MHASH_%s", name); - zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC); - } - } - for (i = 0, n = mhash_keygen_count() + 1; i < n; ++i) { - if ((name = (const char *) mhash_get_keygen_name_static(i))) { - l = snprintf(buf, sizeof(buf), "MHASH_KEYGEN_%s", name); - zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC); - } - } - return SUCCESS; } /* }}} */ @@ -195,208 +58,13 @@ /* {{{ PHP_MINFO */ PHP_MINFO_FUNCTION(mhash) { - char version[32]; - - snprintf(version, sizeof(version), "%d", MHASH_API_VERSION); - php_info_print_table_start(); php_info_print_table_row(2, "MHASH support", "Enabled"); - php_info_print_table_row(2, "MHASH API Version", version); + php_info_print_table_row(2, "MHASH API Version", "Emulated"); php_info_print_table_end(); } /* }}} */ -/* {{{ proto int mhash_count(void) U - Gets the number of available hashes */ -PHP_FUNCTION(mhash_count) -{ - if (!NO_ARGS()) { - return; - } - - RETURN_LONG(mhash_count()); -} - -/* }}} */ - -/* {{{ proto int mhash_get_block_size(int hash) U - Gets the block size of hash */ -PHP_FUNCTION(mhash_get_block_size) -{ - long hash; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash)) { - return; - } - - RETURN_LONG(mhash_get_block_size(hash)); -} - -/* }}} */ - -/* {{{ proto string mhash_get_hash_name(int hash) U - Gets the name of hash */ -PHP_FUNCTION(mhash_get_hash_name) -{ - const char *name; - long hash; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash)) { - return; - } - - if ((name = (const char *) mhash_get_hash_name_static(hash))) { - RETVAL_ASCII_STRING((char *) name, 1); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto int mhash_keygen_count() U - Get the number of available keygen algorithms */ -PHP_FUNCTION(mhash_keygen_count) -{ - if (!NO_ARGS()) { - return; - } - - RETURN_LONG(mhash_keygen_count()); -} -/* }}} */ - -/* {{{ proto string mhash_get_keygen_name(int keygen) U - Get the name of the keygen algorithm */ -PHP_FUNCTION(mhash_get_keygen_name) -{ - const char *name; - long keygen; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) { - return; - } - - if ((name = (const char *) mhash_get_keygen_name_static(keygen))) { - RETVAL_ASCII_STRING((char *) name, 1); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool mhash_keygen_uses_hash(int keygen) U - Whether the keygen algorithm uses a hash algorithm */ -PHP_FUNCTION(mhash_keygen_uses_hash) -{ - long keygen; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) { - return; - } - - RETURN_BOOL(mhash_keygen_uses_hash_algorithm(keygen)); -} -/* }}} */ - -/* {{{ proto bool mhash_keygen_uses_count(int keygen) U - Whether the keygen algorithm uses the bytes_count parameter */ -PHP_FUNCTION(mhash_keygen_uses_count) -{ - long keygen; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) { - return; - } - - RETURN_BOOL(mhash_keygen_uses_count(keygen)); -} -/* }}} */ - -/* {{{ proto bool mhash_keygen_uses_salt(int keygen) U - Whether the keygen algorithm requires a salt */ -PHP_FUNCTION(mhash_keygen_uses_salt) -{ - long keygen; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) { - return; - } - - RETURN_BOOL(mhash_keygen_uses_salt(keygen)); -} -/* }}} */ - -/* {{{ proto bool mhash_get_keygen_salt_size(int keygen) U - Get the required size of the salt for the keygen algorithm */ -PHP_FUNCTION(mhash_get_keygen_salt_size) -{ - long keygen; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &keygen)) { - return; - } - - RETURN_LONG(mhash_get_keygen_salt_size(keygen)); -} -/* }}} */ - -/* {{{ proto binary mhash(int hash, binary data [, binary key]) U - Hash data with hash */ -PHP_FUNCTION(mhash) -{ - long hash; - char *result, *data, *key = NULL; - int result_len, data_len, key_len = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lS|S", &hash, &data, &data_len, &key, &key_len)) { - return; - } - if (SUCCESS != php_mhash(hash, data, data_len, key, key_len, &result, &result_len TSRMLS_CC)) { - RETURN_FALSE; - } - RETURN_STRINGL(result, result_len, 0); -} - -/* }}} */ - -/* {{{ proto binary mhash_keygen(int type, int hash1, int hash2, binary password[, binary salt[, int max_key_size = 128[, int bytes_count = 0]]) U - Generate a key */ -PHP_FUNCTION(mhash_keygen) -{ - long hash1, hash2, type, max_len = 0, bytes_count = 0; - char *result_str, *pass_str, *salt_str = NULL; - int result_len, pass_len, salt_len = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllS|Sll", &type, &hash1, &hash2, &pass_str, &pass_len, &salt_str, &salt_len, &max_len, &bytes_count)) { - return; - } - if (SUCCESS != php_mhash_keygen(type, hash1, hash2, pass_str, pass_len, salt_str, salt_len, &result_str, &result_len, max_len, bytes_count TSRMLS_CC)) { - RETURN_FALSE; - } - RETURN_STRINGL(result_str, result_len, 0); -} -/* }}} */ - -/* {{{ proto binary mhash_keygen_s2k(int hash, binary input_password, binary salt, int bytes) - Generates a key using hash functions */ -PHP_FUNCTION(mhash_keygen_s2k) -{ - long hash, max_len = 0; - char *result_str, *pass_str, *salt_str = NULL; - int result_len, pass_len, salt_len = 0; - - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lSSl", &hash, &pass_str, &pass_len, &salt_str, &salt_len, &max_len)) { - return; - } - if (SUCCESS != php_mhash_keygen(KEYGEN_S2K_SALTED, hash, hash, pass_str, pass_len, salt_str, salt_len, &result_str, &result_len, max_len, 0 TSRMLS_CC)) { - RETURN_FALSE; - } - RETURN_STRINGL(result_str, result_len, 0); -} -/* }}} */ - -#endif - /* * Local variables: * tab-width: 4 http://cvs.php.net/viewvc.cgi/php-src/ext/mhash/php_mhash.h?r1=1.16&r2=1.17&diff_format=u Index: php-src/ext/mhash/php_mhash.h diff -u php-src/ext/mhash/php_mhash.h:1.16 php-src/ext/mhash/php_mhash.h:1.17 --- php-src/ext/mhash/php_mhash.h:1.16 Mon Dec 31 07:12:11 2007 +++ php-src/ext/mhash/php_mhash.h Sat Jun 28 15:20:49 2008 @@ -16,45 +16,16 @@ | Nikos Mavroyanopoulos <[EMAIL PROTECTED]> (HMAC, KEYGEN) | +----------------------------------------------------------------------+ */ -/* $Id: php_mhash.h,v 1.16 2007/12/31 07:12:11 sebastian Exp $ */ +/* $Id: php_mhash.h,v 1.17 2008/06/28 15:20:49 scottmac Exp $ */ #ifndef PHP_MHASH_H #define PHP_MHASH_H -#if HAVE_LIBMHASH - -#if PHP_API_VERSION < 19990421 -#define zend_module_entry zend_module_entry -#include "zend_modules.h" -#include "internal_functions.h" -#endif - -#include "mhash.h" - extern zend_module_entry mhash_module_entry; #define mhash_module_ptr &mhash_module_entry -int php_mhash(hashid hash, const char *input_str, int input_len, const char *key_str, int key_len, char **enc, int *len TSRMLS_DC); -int php_mhash_keygen(keygenid type, hashid hash1, hashid hash2, const char *pass_str, int pass_len, const char *salt_str, size_t salt_len, char **key, int *len, int max_len, int max_count TSRMLS_DC); - PHP_MINIT_FUNCTION(mhash); PHP_MINFO_FUNCTION(mhash); -PHP_FUNCTION(mhash_count); -PHP_FUNCTION(mhash_get_block_size); -PHP_FUNCTION(mhash_get_hash_name); -PHP_FUNCTION(mhash_keygen_count); -PHP_FUNCTION(mhash_get_keygen_name); -PHP_FUNCTION(mhash_keygen_uses_hash); -PHP_FUNCTION(mhash_keygen_uses_salt); -PHP_FUNCTION(mhash_get_keygen_salt_size); -PHP_FUNCTION(mhash_keygen_uses_count); -PHP_FUNCTION(mhash); -PHP_FUNCTION(mhash_keygen); -PHP_FUNCTION(mhash_keygen_s2k); - -#else -#define mhash_module_ptr NULL -#endif #define phpext_mhash_ptr mhash_module_ptr
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php