cvs: php4 /ext/mhash mhash.c /ext/mhash/tests 001.phpt 002.phpt 003.phpt skip.inc
| From: | Ilia Alshanetsky | Date: | Wed, 20 Nov 2002 06:48:39 +0000 |
| Subject: | cvs: php4 /ext/mhash mhash.c /ext/mhash/tests 001.phpt 002.phpt 003.phpt skip.inc | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-16465@lists.php.net to get a copy of this message | ||
iliaa Wed Nov 20 01:48:39 2002 EDT
Added files:
/php4/ext/mhash/tests 001.phpt 002.phpt 003.phpt skip.inc
Modified files:
/php4/ext/mhash mhash.c
Log:
Switched to a new parameter parsing API, which simplifies the code a great deal.
Made error reporting use php_error_docref()
Fixed a bug in mhash_keygen_s2k() that caused non \0 terminated data to be returned.
Added tests of all mhash functions.
Index: php4/ext/mhash/mhash.c diff -u php4/ext/mhash/mhash.c:1.39 php4/ext/mhash/mhash.c:1.40 --- php4/ext/mhash/mhash.c:1.39 Sun Aug 4 17:37:44 2002 +++ php4/ext/mhash/mhash.c Wed Nov 20 01:48:39 2002 @@ -56,22 +56,21 @@ ZEND_GET_MODULE(mhash) #endif -#define MHASH_FAILED_MSG "mhash initialization failed" -#define MHASH_KEYGEN_FAILED_MSG "mhash key generation failed" +/* SALTED S2K uses a fixed salt */ +#define SALT_SIZE 8 static PHP_MINIT_FUNCTION(mhash) { - int i; + int i, n, l; char *name; char buf[128]; - for (i = 0; i <= mhash_count(); i++) { - name = mhash_get_hash_name(i); - if (name) { - snprintf(buf, 127, "MHASH_%s", name); - zend_register_long_constant(buf, strlen(buf) + 1, - i, CONST_PERSISTENT, - module_number TSRMLS_CC); + n = mhash_count() + 1; + + for (i=0; i<n; i++) { + if ((name = mhash_get_hash_name(i))) { + l = snprintf(buf, 127, "MHASH_%s", name); + zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC); free(name); } } @@ -108,16 +107,13 @@ Gets the block size of hash */ PHP_FUNCTION(mhash_get_block_size) { - pval **hash; + int hash; - if (ZEND_NUM_ARGS() != 1 - || zend_get_parameters_ex(1, &hash) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(hash); - - RETURN_LONG(mhash_get_block_size(Z_LVAL_PP(hash))); + RETURN_LONG(mhash_get_block_size(hash)); } /* }}} */ @@ -126,17 +122,14 @@ Gets the name of hash */ PHP_FUNCTION(mhash_get_hash_name) { - pval **hash; char *name; + int hash; - if (ZEND_NUM_ARGS() != 1 - || zend_get_parameters_ex(1, &hash) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(hash); - - name = mhash_get_hash_name(Z_LVAL_PP(hash)); + name = mhash_get_hash_name(hash); if (name) { RETVAL_STRING(name, 1); free(name); @@ -151,58 +144,42 @@ Hash data with hash */ PHP_FUNCTION(mhash) { - pval **hash, **data, **key; MHASH td; int bsize; unsigned char *hash_data; - int num_args; - - num_args = ZEND_NUM_ARGS(); - - if (num_args < 2 || num_args > 3) { + int hash; + int data_len, key_len=0; + char *data, *key=NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|s", &hash, &data, &data_len, &key, &key_len) == FAILURE) { WRONG_PARAM_COUNT; } - if (num_args == 2) { /* 2 arguments, just hash */ - if (zend_get_parameters_ex(2, &hash, &data) == FAILURE) { - WRONG_PARAM_COUNT; - } - } else { /* 3 arguments, do HMAC hash (keyed hash) */ - if (zend_get_parameters_ex(3, &hash, &data, &key) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(key); - } - - convert_to_long_ex(hash); - convert_to_string_ex(data); - - bsize = mhash_get_block_size(Z_LVAL_PP(hash)); - - if (num_args == 3) { - if (mhash_get_hash_pblock(Z_LVAL_PP(hash)) == 0) { - php_error(E_WARNING, MHASH_FAILED_MSG); + + bsize = mhash_get_block_size(hash); + + if (key_len) { + if (mhash_get_hash_pblock(hash) == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed"); RETURN_FALSE; } - td = mhash_hmac_init(Z_LVAL_PP(hash), - Z_STRVAL_PP(key), - Z_STRLEN_PP(key), - mhash_get_hash_pblock(Z_LVAL_PP(hash))); + td = mhash_hmac_init(hash, key, key_len, mhash_get_hash_pblock(hash)); } else { - td = mhash_init(Z_LVAL_PP(hash)); + td = mhash_init(hash); } + if (td == MHASH_FAILED) { - php_error(E_WARNING, MHASH_FAILED_MSG); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed"); RETURN_FALSE; } - mhash(td, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); + mhash(td, data, data_len); - if (num_args == 3) { + if (key_len) { hash_data = (unsigned char *) mhash_hmac_end(td); } else { hash_data = (unsigned char *) mhash_end(td); } + if (hash_data) { RETVAL_STRINGL(hash_data, bsize, 1); mhash_free(hash_data); @@ -215,69 +192,45 @@ /* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string salt, int bytes) Generates a key using hash functions */ -/* SALTED S2K uses a fixed salt */ -#define SALT_SIZE 8 PHP_FUNCTION(mhash_keygen_s2k) { - pval **hash, **input_password, **bytes, **input_salt; - int password_len, salt_len; - int hashid, size=0, val; KEYGEN keystruct; char salt[SALT_SIZE], *ret; - char* password, error[128]; + int hash, bytes; + char *password, *in_salt; + int password_len, salt_len; - if (ZEND_NUM_ARGS() != 4) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssl", &hash, &password, &password_len, &in_salt, &salt_len, &bytes) == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_get_parameters_ex(4, &hash, &input_password, &input_salt, &bytes) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(hash); - convert_to_string_ex(input_password); - convert_to_string_ex(input_salt); - convert_to_long_ex(bytes); - - password = Z_STRVAL_PP(input_password); - password_len = Z_STRLEN_PP(input_password); - - salt_len = MIN(Z_STRLEN_PP(input_salt), SALT_SIZE); + + salt_len = MIN(salt_len, SALT_SIZE); if (salt_len > mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)) { - sprintf( error, "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)); - - php_error(E_WARNING, error); + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", + salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)); } - memcpy(salt, Z_STRVAL_PP(input_salt), salt_len); - if (salt_len < SALT_SIZE) + memcpy(salt, in_salt, salt_len); + if (salt_len < SALT_SIZE) { memset(salt + salt_len, 0, SALT_SIZE - salt_len); - salt_len=SALT_SIZE; + } + salt_len = SALT_SIZE; -/* if (salt_len==0) { - * php_error(E_WARNING, "Not using salt is really not recommended); - * } - */ - - hashid = Z_LVAL_PP(hash); - size = Z_LVAL_PP(bytes); - - keystruct.hash_algorithm[0]=hashid; - keystruct.hash_algorithm[1]=hashid; - keystruct.count=0; + keystruct.hash_algorithm[0] = hash; + keystruct.hash_algorithm[1] = hash; + keystruct.count = 0; keystruct.salt = salt; keystruct.salt_size = salt_len; - ret = emalloc(size); - if (ret==NULL) { - php_error(E_WARNING, MHASH_KEYGEN_FAILED_MSG); - RETURN_FALSE; - } + ret = emalloc(bytes + 1); - val = mhash_keygen_ext( KEYGEN_S2K_SALTED, keystruct, ret, size, password, password_len); - if (val >= 0) { - RETVAL_STRINGL(ret, size, 0); + if (mhash_keygen_ext(KEYGEN_S2K_SALTED, keystruct, ret, bytes, password, password_len) >= 0) { + ret[bytes] = '\0'; + RETVAL_STRINGL(ret, bytes, 0); } else { - php_error(E_WARNING, MHASH_KEYGEN_FAILED_MSG); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash key generation failed"); efree(ret); RETURN_FALSE; } Index: php4/ext/mhash/tests/001.phpt +++ php4/ext/mhash/tests/001.phpt --TEST-- mhash() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $supported_hash_al = array( "MHASH_MD5", "MHASH_SHA1", "MHASH_HAVAL256", "MHASH_HAVAL192", "MHASH_HAVAL224", "MHASH_HAVAL160", "MHASH_RIPEMD160", "MHASH_GOST", "MHASH_TIGER", "MHASH_CRC32", "MHASH_CRC32B" ); $data = "This is the test of the mhash extension..."; foreach ($supported_hash_al as $hash) { echo $hash . "\n"; var_dump(mhash(constant($hash), $data)); echo "\n"; } ?> --EXPECT-- MHASH_MD5 string(16) "-ÛùNÙÄâ®S*Ìj" MHASH_SHA1 string(20) "/AåZíõI{ø;£Û*}à£" MHASH_HAVAL256 string(32) "²Uþÿd'5ÇÆ¡ü¥;Ýýúñ ²u¯" MHASH_HAVAL192 string(24) "Lè7ÞH0 *²ÆpÉß×ÛÍ" MHASH_HAVAL224 string(28) "SbÑ gR¿,²Öý×r¹ÅÈÎ^È&&K á" MHASH_HAVAL160 string(20) "ƳouWi¼´ò"q{ùË" MHASH_RIPEMD160 string(20) "lGCZ¡ÓYķƯF4>XX=" MHASH_GOST string(32) " %Rνõ|ñQGòU¶C)5»,Çâ-" MHASH_TIGER string(24) ":Ãy¹ý뮫 ~g9\»T0à" MHASH_CRC32 string(4) "¸" MHASH_CRC32B string(4) "¤·Zß" Index: php4/ext/mhash/tests/002.phpt +++ php4/ext/mhash/tests/002.phpt --TEST-- mhash_get_block_size() & mhash_get_hash_name() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $hc = mhash_count() + 1; for ($i=0; $i<$hc; $i++) { if (($hn = mhash_get_hash_name($i))) { echo $hn . "\t->\t" . mhash_get_block_size($i) . "\n"; } } ?> --EXPECT-- CRC32 -> 4 MD5 -> 16 SHA1 -> 20 HAVAL256 -> 32 RIPEMD160 -> 20 TIGER -> 24 GOST -> 32 CRC32B -> 4 HAVAL224 -> 28 HAVAL192 -> 24 HAVAL160 -> 20 Index: php4/ext/mhash/tests/003.phpt +++ php4/ext/mhash/tests/003.phpt --TEST-- mhash_keygen_s2k() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $supported_hash_al = array( "MHASH_MD5", "MHASH_SHA1", "MHASH_HAVAL256", "MHASH_HAVAL192", "MHASH_HAVAL224", "MHASH_HAVAL160", "MHASH_RIPEMD160", "MHASH_GOST", "MHASH_TIGER", "MHASH_CRC32", "MHASH_CRC32B" ); foreach ($supported_hash_al as $alg) { $passwd = str_repeat($alg, 10); $salt = str_repeat($alg, 2); var_dump(mhash_keygen_s2k(constant($alg), $passwd, $salt, 100)); } ?> --EXPECT-- string(100) "N¯2Íé4z¡P¹ÀFëæ Tyªzcg®hµààt^W þÞ-ésA7Yú§:Ìíw´Ý²xdãqëS³©Õ^Ò«&UÈ,þÛè: aÇÙ×zäS" string(100) "Ý1\pE]SÂûßaªf\±§úT#$¨2¥ä³xc º=æ"IJ®'NÎÔ½÷nËJ3É<+H0§[ §À[ñÿê¿Y»qÄØ¡¸K¯mI" string(100) "ÞG Õé¢NÏPwÖH6W¥Ù«+·õ,ÊögdZUþá)oAiÉ[Nað®îú²d TÁ°¢ü2ªZîÓÕÁUÓ46}IYb,ÚÞþC®½uùÔþ÷{ñ¾[x" string(100) ""àÂq&< .ùA»/á2°dËû2æXvp½Å±Å%(ÂC;î+p«z8®²NÁu¹©dd)qï³Ùºùv_ÙæÖMINª¯çà xLtº±Ç" string(100) "\Jÿ=ZÖöÈêçyî8haÆ ó×p³¦g|yÂÚÜ«qÝàÀ«)å˼l¼ÐǨGB@kwèºQùv52O¸P¬-0·5 L m`G-2ÃI" string(100) "ÖåðïóúÌídní¶6GXìÞmÆû ¤õη#÷¡5M"míiÁ1$ù|X<O)Y;¿=Óʰ¸y.³Ø`"Ê`ëÐÙ´B Ô¯ ¾Òµ©k>G¹¸ÊÉÁ~Ä~" string(100) "äÕÛFòxâ¹Ç5ÉÏ [¦gDXgwÔÜ¡DÔ&Åb¯ùjBëö°ê7ù¡û]é¶GíÃ[G`^«ÃKç ë3C-ABâ%ßK??öK´¡¤ù" string(100) "ÀDöi½~C=wÆýBÙß}øs¾Mäd|4hYç" °I*b@ÑÄxc@sÞ¨y¾ýN%d÷× ¶FD PàÇÕ}E©À~â:pOôpwìR{M" string(100) "Âó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Ê" string(100) "H@&_YïèoQÅÒÐ1[Fq"®ÁÌÝféVÈ8ã¥EöîE<¤M¼:Ⱥ ¥rðk*±HÚu±è/}ßÛh3iW»ñJ?vui ¥=ÕW"üó" string(100) "µl«e¦>}û*©]¶F×6bCÍË. I¯jÎ¥0ÐÛ<Æ.Qyç¾¶tiý°xbØ$}õÈ´ ×ϬÈDÅDK é1uLðÝ6§¡`÷æÉ|Ecñ°" Index: php4/ext/mhash/tests/skip.inc +++ php4/ext/mhash/tests/skip.inc <?php if (!extension_loaded("mhash")) { die("skip mhash extension is not avaliable"); } ?>
Index: php4/ext/mhash/mhash.c diff -u php4/ext/mhash/mhash.c:1.39 php4/ext/mhash/mhash.c:1.40 --- php4/ext/mhash/mhash.c:1.39 Sun Aug 4 17:37:44 2002 +++ php4/ext/mhash/mhash.c Wed Nov 20 01:48:39 2002 @@ -56,22 +56,21 @@ ZEND_GET_MODULE(mhash) #endif -#define MHASH_FAILED_MSG "mhash initialization failed" -#define MHASH_KEYGEN_FAILED_MSG "mhash key generation failed" +/* SALTED S2K uses a fixed salt */ +#define SALT_SIZE 8 static PHP_MINIT_FUNCTION(mhash) { - int i; + int i, n, l; char *name; char buf[128]; - for (i = 0; i <= mhash_count(); i++) { - name = mhash_get_hash_name(i); - if (name) { - snprintf(buf, 127, "MHASH_%s", name); - zend_register_long_constant(buf, strlen(buf) + 1, - i, CONST_PERSISTENT, - module_number TSRMLS_CC); + n = mhash_count() + 1; + + for (i=0; i<n; i++) { + if ((name = mhash_get_hash_name(i))) { + l = snprintf(buf, 127, "MHASH_%s", name); + zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC); free(name); } } @@ -108,16 +107,13 @@ Gets the block size of hash */ PHP_FUNCTION(mhash_get_block_size) { - pval **hash; + int hash; - if (ZEND_NUM_ARGS() != 1 - || zend_get_parameters_ex(1, &hash) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(hash); - - RETURN_LONG(mhash_get_block_size(Z_LVAL_PP(hash))); + RETURN_LONG(mhash_get_block_size(hash)); } /* }}} */ @@ -126,17 +122,14 @@ Gets the name of hash */ PHP_FUNCTION(mhash_get_hash_name) { - pval **hash; char *name; + int hash; - if (ZEND_NUM_ARGS() != 1 - || zend_get_parameters_ex(1, &hash) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long_ex(hash); - - name = mhash_get_hash_name(Z_LVAL_PP(hash)); + name = mhash_get_hash_name(hash); if (name) { RETVAL_STRING(name, 1); free(name); @@ -151,58 +144,42 @@ Hash data with hash */ PHP_FUNCTION(mhash) { - pval **hash, **data, **key; MHASH td; int bsize; unsigned char *hash_data; - int num_args; - - num_args = ZEND_NUM_ARGS(); - - if (num_args < 2 || num_args > 3) { + int hash; + int data_len, key_len=0; + char *data, *key=NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|s", &hash, &data, &data_len, &key, &key_len) == FAILURE) { WRONG_PARAM_COUNT; } - if (num_args == 2) { /* 2 arguments, just hash */ - if (zend_get_parameters_ex(2, &hash, &data) == FAILURE) { - WRONG_PARAM_COUNT; - } - } else { /* 3 arguments, do HMAC hash (keyed hash) */ - if (zend_get_parameters_ex(3, &hash, &data, &key) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(key); - } - - convert_to_long_ex(hash); - convert_to_string_ex(data); - - bsize = mhash_get_block_size(Z_LVAL_PP(hash)); - - if (num_args == 3) { - if (mhash_get_hash_pblock(Z_LVAL_PP(hash)) == 0) { - php_error(E_WARNING, MHASH_FAILED_MSG); + + bsize = mhash_get_block_size(hash); + + if (key_len) { + if (mhash_get_hash_pblock(hash) == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed"); RETURN_FALSE; } - td = mhash_hmac_init(Z_LVAL_PP(hash), - Z_STRVAL_PP(key), - Z_STRLEN_PP(key), - mhash_get_hash_pblock(Z_LVAL_PP(hash))); + td = mhash_hmac_init(hash, key, key_len, mhash_get_hash_pblock(hash)); } else { - td = mhash_init(Z_LVAL_PP(hash)); + td = mhash_init(hash); } + if (td == MHASH_FAILED) { - php_error(E_WARNING, MHASH_FAILED_MSG); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash initialization failed"); RETURN_FALSE; } - mhash(td, Z_STRVAL_PP(data), Z_STRLEN_PP(data)); + mhash(td, data, data_len); - if (num_args == 3) { + if (key_len) { hash_data = (unsigned char *) mhash_hmac_end(td); } else { hash_data = (unsigned char *) mhash_end(td); } + if (hash_data) { RETVAL_STRINGL(hash_data, bsize, 1); mhash_free(hash_data); @@ -215,69 +192,45 @@ /* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string salt, int bytes) Generates a key using hash functions */ -/* SALTED S2K uses a fixed salt */ -#define SALT_SIZE 8 PHP_FUNCTION(mhash_keygen_s2k) { - pval **hash, **input_password, **bytes, **input_salt; - int password_len, salt_len; - int hashid, size=0, val; KEYGEN keystruct; char salt[SALT_SIZE], *ret; - char* password, error[128]; + int hash, bytes; + char *password, *in_salt; + int password_len, salt_len; - if (ZEND_NUM_ARGS() != 4) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssl", &hash, &password, &password_len, &in_salt, &salt_len, &bytes) == FAILURE) { WRONG_PARAM_COUNT; } - if (zend_get_parameters_ex(4, &hash, &input_password, &input_salt, &bytes) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(hash); - convert_to_string_ex(input_password); - convert_to_string_ex(input_salt); - convert_to_long_ex(bytes); - - password = Z_STRVAL_PP(input_password); - password_len = Z_STRLEN_PP(input_password); - - salt_len = MIN(Z_STRLEN_PP(input_salt), SALT_SIZE); + + salt_len = MIN(salt_len, SALT_SIZE); if (salt_len > mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)) { - sprintf( error, "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)); - - php_error(E_WARNING, error); + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", + salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)); } - memcpy(salt, Z_STRVAL_PP(input_salt), salt_len); - if (salt_len < SALT_SIZE) + memcpy(salt, in_salt, salt_len); + if (salt_len < SALT_SIZE) { memset(salt + salt_len, 0, SALT_SIZE - salt_len); - salt_len=SALT_SIZE; + } + salt_len = SALT_SIZE; -/* if (salt_len==0) { - * php_error(E_WARNING, "Not using salt is really not recommended); - * } - */ - - hashid = Z_LVAL_PP(hash); - size = Z_LVAL_PP(bytes); - - keystruct.hash_algorithm[0]=hashid; - keystruct.hash_algorithm[1]=hashid; - keystruct.count=0; + keystruct.hash_algorithm[0] = hash; + keystruct.hash_algorithm[1] = hash; + keystruct.count = 0; keystruct.salt = salt; keystruct.salt_size = salt_len; - ret = emalloc(size); - if (ret==NULL) { - php_error(E_WARNING, MHASH_KEYGEN_FAILED_MSG); - RETURN_FALSE; - } + ret = emalloc(bytes + 1); - val = mhash_keygen_ext( KEYGEN_S2K_SALTED, keystruct, ret, size, password, password_len); - if (val >= 0) { - RETVAL_STRINGL(ret, size, 0); + if (mhash_keygen_ext(KEYGEN_S2K_SALTED, keystruct, ret, bytes, password, password_len) >= 0) { + ret[bytes] = '\0'; + RETVAL_STRINGL(ret, bytes, 0); } else { - php_error(E_WARNING, MHASH_KEYGEN_FAILED_MSG); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "mhash key generation failed"); efree(ret); RETURN_FALSE; } Index: php4/ext/mhash/tests/001.phpt +++ php4/ext/mhash/tests/001.phpt --TEST-- mhash() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $supported_hash_al = array( "MHASH_MD5", "MHASH_SHA1", "MHASH_HAVAL256", "MHASH_HAVAL192", "MHASH_HAVAL224", "MHASH_HAVAL160", "MHASH_RIPEMD160", "MHASH_GOST", "MHASH_TIGER", "MHASH_CRC32", "MHASH_CRC32B" ); $data = "This is the test of the mhash extension..."; foreach ($supported_hash_al as $hash) { echo $hash . "\n"; var_dump(mhash(constant($hash), $data)); echo "\n"; } ?> --EXPECT-- MHASH_MD5 string(16) "-ÛùNÙÄâ®S*Ìj" MHASH_SHA1 string(20) "/AåZíõI{ø;£Û*}à£" MHASH_HAVAL256 string(32) "²Uþÿd'5ÇÆ¡ü¥;Ýýúñ ²u¯" MHASH_HAVAL192 string(24) "Lè7ÞH0 *²ÆpÉß×ÛÍ" MHASH_HAVAL224 string(28) "SbÑ gR¿,²Öý×r¹ÅÈÎ^È&&K á" MHASH_HAVAL160 string(20) "ƳouWi¼´ò"q{ùË" MHASH_RIPEMD160 string(20) "lGCZ¡ÓYķƯF4>XX=" MHASH_GOST string(32) " %Rνõ|ñQGòU¶C)5»,Çâ-" MHASH_TIGER string(24) ":Ãy¹ý뮫 ~g9\»T0à" MHASH_CRC32 string(4) "¸" MHASH_CRC32B string(4) "¤·Zß" Index: php4/ext/mhash/tests/002.phpt +++ php4/ext/mhash/tests/002.phpt --TEST-- mhash_get_block_size() & mhash_get_hash_name() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $hc = mhash_count() + 1; for ($i=0; $i<$hc; $i++) { if (($hn = mhash_get_hash_name($i))) { echo $hn . "\t->\t" . mhash_get_block_size($i) . "\n"; } } ?> --EXPECT-- CRC32 -> 4 MD5 -> 16 SHA1 -> 20 HAVAL256 -> 32 RIPEMD160 -> 20 TIGER -> 24 GOST -> 32 CRC32B -> 4 HAVAL224 -> 28 HAVAL192 -> 24 HAVAL160 -> 20 Index: php4/ext/mhash/tests/003.phpt +++ php4/ext/mhash/tests/003.phpt --TEST-- mhash_keygen_s2k() test --SKIPIF-- <?php include "skip.inc"; ?> --FILE-- <?php $supported_hash_al = array( "MHASH_MD5", "MHASH_SHA1", "MHASH_HAVAL256", "MHASH_HAVAL192", "MHASH_HAVAL224", "MHASH_HAVAL160", "MHASH_RIPEMD160", "MHASH_GOST", "MHASH_TIGER", "MHASH_CRC32", "MHASH_CRC32B" ); foreach ($supported_hash_al as $alg) { $passwd = str_repeat($alg, 10); $salt = str_repeat($alg, 2); var_dump(mhash_keygen_s2k(constant($alg), $passwd, $salt, 100)); } ?> --EXPECT-- string(100) "N¯2Íé4z¡P¹ÀFëæ Tyªzcg®hµààt^W þÞ-ésA7Yú§:Ìíw´Ý²xdãqëS³©Õ^Ò«&UÈ,þÛè: aÇÙ×zäS" string(100) "Ý1\pE]SÂûßaªf\±§úT#$¨2¥ä³xc º=æ"IJ®'NÎÔ½÷nËJ3É<+H0§[ §À[ñÿê¿Y»qÄØ¡¸K¯mI" string(100) "ÞG Õé¢NÏPwÖH6W¥Ù«+·õ,ÊögdZUþá)oAiÉ[Nað®îú²d TÁ°¢ü2ªZîÓÕÁUÓ46}IYb,ÚÞþC®½uùÔþ÷{ñ¾[x" string(100) ""àÂq&< .ùA»/á2°dËû2æXvp½Å±Å%(ÂC;î+p«z8®²NÁu¹©dd)qï³Ùºùv_ÙæÖMINª¯çà xLtº±Ç" string(100) "\Jÿ=ZÖöÈêçyî8haÆ ó×p³¦g|yÂÚÜ«qÝàÀ«)å˼l¼ÐǨGB@kwèºQùv52O¸P¬-0·5 L m`G-2ÃI" string(100) "ÖåðïóúÌídní¶6GXìÞmÆû ¤õη#÷¡5M"míiÁ1$ù|X<O)Y;¿=Óʰ¸y.³Ø`"Ê`ëÐÙ´B Ô¯ ¾Òµ©k>G¹¸ÊÉÁ~Ä~" string(100) "äÕÛFòxâ¹Ç5ÉÏ [¦gDXgwÔÜ¡DÔ&Åb¯ùjBëö°ê7ù¡û]é¶GíÃ[G`^«ÃKç ë3C-ABâ%ßK??öK´¡¤ù" string(100) "ÀDöi½~C=wÆýBÙß}øs¾Mäd|4hYç" °I*b@ÑÄxc@sÞ¨y¾ýN%d÷× ¶FD PàÇÕ}E©À~â:pOôpwìR{M" string(100) "Âó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Êåñ¥p+#Á#ýéf6y©ÛÂó!Ê" string(100) "H@&_YïèoQÅÒÐ1[Fq"®ÁÌÝféVÈ8ã¥EöîE<¤M¼:Ⱥ ¥rðk*±HÚu±è/}ßÛh3iW»ñJ?vui ¥=ÕW"üó" string(100) "µl«e¦>}û*©]¶F×6bCÍË. I¯jÎ¥0ÐÛ<Æ.Qyç¾¶tiý°xbØ$}õÈ´ ×ϬÈDÅDK é1uLðÝ6§¡`÷æÉ|Ecñ°" Index: php4/ext/mhash/tests/skip.inc +++ php4/ext/mhash/tests/skip.inc <?php if (!extension_loaded("mhash")) { die("skip mhash extension is not avaliable"); } ?>