[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
scottmacMon May 4 16:37:32 2009 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: Add missing prototypes for mhash, no code changes. http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.17&r2=1.18.2.5.2.7.2.18&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.17 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.18 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.17 Wed Dec 31 11:15:37 2008 +++ php-src/ext/hash/hash.c Mon May 4 16:37:31 2009 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.17 2008/12/31 11:15:37 sebastian Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.18 2009/05/04 16:37:31 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -527,7 +527,7 @@ } /* }}} */ -/* {{{ proto resource hash_copy(resource context) U +/* {{{ proto resource hash_copy(resource context) Copy hash resource */ PHP_FUNCTION(hash_copy) { @@ -647,6 +647,8 @@ zend_register_module_ex(&mhash_module_entry TSRMLS_CC); } +/* {{{ proto string mhash(int hash, string data [, string key]) + Hash data with hash */ PHP_FUNCTION(mhash) { zval **z_algorithm; @@ -660,7 +662,7 @@ convert_to_long_ex(z_algorithm); algorithm = Z_LVAL_PP(z_algorithm); - /* need to conver the first parameter from int to string */ + /* need to convert the first parameter from int constant to string algorithm name */ if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) { struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm]; if (algorithm_lookup.hash_name) { @@ -676,7 +678,10 @@ WRONG_PARAM_COUNT; } } +/* }}} */ +/* {{{ proto string mhash_get_hash_name(int hash) + Gets the name of hash */ PHP_FUNCTION(mhash_get_hash_name) { long algorithm; @@ -693,7 +698,10 @@ } RETURN_FALSE; } +/* }}} */ +/* {{{ proto int mhash_count(void) + Gets the number of available hashes */ PHP_FUNCTION(mhash_count) { if (zend_parse_parameters_none() == FAILURE) { @@ -701,7 +709,10 @@ } RETURN_LONG(MHASH_NUM_ALGOS - 1); } +/* }}} */ +/* {{{ proto int mhash_get_block_size(int hash) + Gets the block size of hash */ PHP_FUNCTION(mhash_get_block_size) { long algorithm; @@ -721,9 +732,12 @@ } } } +/* }}} */ #define SALT_SIZE 8 +/* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string salt, int bytes) + Generates a key using hash functions */ PHP_FUNCTION(mhash_keygen_s2k) { long algorithm, bytes; @@ -789,6 +803,7 @@ } } } +/* }}} */ #endif -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c /ext/mhash CREDITS config.m4 config.w32 mhash.c php_mhash.h
scottmacThu Nov 27 21:11:55 2008 UTC Removed files: (Branch: PHP_5_3) /php-src/ext/mhash CREDITS config.m4 config.w32 mhash.c php_mhash.h Modified files: /php-src/ext/hash hash.c Log: MFH Move mhash extension registration code into the hash module startup. This allows extension_loaded('mhash'); to work. http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.14&r2=1.18.2.5.2.7.2.15&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.14 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.15 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.14 Mon Nov 17 11:27:55 2008 +++ php-src/ext/hash/hash.c Thu Nov 27 21:11:55 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.14 2008/11/17 11:27:55 felipe Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.15 2008/11/27 21:11:55 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -607,6 +607,27 @@ #ifdef PHP_MHASH_BC +PHP_MINFO_FUNCTION(mhash) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "MHASH support", "Enabled"); + php_info_print_table_row(2, "MHASH API Version", "Emulated Support"); + php_info_print_table_end(); +} + +zend_module_entry mhash_module_entry = { + STANDARD_MODULE_HEADER, + "mhash", + NULL, + NULL, + NULL, + NULL, + NULL, + PHP_MINFO(mhash), + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES, +}; + static void mhash_init(INIT_FUNC_ARGS) { char buf[128]; @@ -622,6 +643,8 @@ len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name)); zend_register_long_constant(buf, len + 1, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); } + + zend_register_module_ex(&mhash_module_entry TSRMLS_CC); } PHP_FUNCTION(mhash) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
scottmacSat Jul 5 00:28:16 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: Fix break caused by previous commit, warning and remove zend_get_parameters() http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.9&r2=1.18.2.5.2.7.2.10&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.9 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.10 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.9Fri Jul 4 21:00:16 2008 +++ php-src/ext/hash/hash.c Sat Jul 5 00:28:16 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.9 2008/07/04 21:00:16 pajoye Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.10 2008/07/05 00:28:16 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -620,30 +620,26 @@ } len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name)); - { - char name[128]; - memcpy(name, buf, len+1); - REGISTER_LONG_CONSTANT(name, algorithm.value, CONST_CS | CONST_PERSISTENT); - } + zend_register_long_constant(buf, len + 1, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); } } PHP_FUNCTION(mhash) { - zval **z_algorithm; + zval *z_algorithm; int algorithm; - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_ex(1, &z_algorithm) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(1 TSRMLS_CC, "z", &z_algorithm) == FAILURE) { + return; } - algorithm = Z_LVAL_PP(z_algorithm); + algorithm = Z_LVAL_P(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); + ZVAL_STRING(z_algorithm, algorithm_lookup.hash_name, 1); } } @@ -754,8 +750,8 @@ 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); + ops->hash_update(context, (unsigned char *)password, password_len); + ops->hash_final((unsigned char *)digest, context); memcpy( &key[i*block_size], digest, block_size); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
pajoye Fri Jul 4 21:00:17 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: - fix compile error with vc6 (snaps) http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.8&r2=1.18.2.5.2.7.2.9&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.8 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.9 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.8Tue Jul 1 07:41:38 2008 +++ php-src/ext/hash/hash.c Fri Jul 4 21:00:16 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.8 2008/07/01 07:41:38 tony2001 Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.9 2008/07/04 21:00:16 pajoye Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -621,7 +621,7 @@ len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name)); { - char name[len+1]; + char name[128]; memcpy(name, buf, len+1); REGISTER_LONG_CONSTANT(name, algorithm.value, CONST_CS | CONST_PERSISTENT); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
tony2001Tue Jul 1 07:41:38 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: more int -> long fixes http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.7&r2=1.18.2.5.2.7.2.8&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.7 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.8 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.7Thu Jun 26 22:33:16 2008 +++ php-src/ext/hash/hash.c Tue Jul 1 07:41:38 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.7 2008/06/26 22:33:16 scottmac Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.8 2008/07/01 07:41:38 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -658,7 +658,7 @@ PHP_FUNCTION(mhash_get_hash_name) { - int algorithm; + long algorithm; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) { return; @@ -683,7 +683,7 @@ PHP_FUNCTION(mhash_get_block_size) { - int algorithm; + long algorithm; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) { return; @@ -705,7 +705,7 @@ PHP_FUNCTION(mhash_keygen_s2k) { - int algorithm, bytes; + long algorithm, bytes; char *password, *salt; int password_len, salt_len; char padded_salt[SALT_SIZE]; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
scottmacTue Jun 3 17:25:42 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: Add snefru256 as an alias for snefru, since in reality that is the implementation. http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.5&r2=1.18.2.5.2.7.2.6&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.5 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.6 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.5Mon Jun 2 12:24:22 2008 +++ php-src/ext/hash/hash.c Tue Jun 3 17:25:42 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.5 2008/06/02 12:24:22 scottmac Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.6 2008/06/03 17:25:42 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -590,6 +590,7 @@ php_hash_register_algo("tiger160,4",&php_hash_4tiger160_ops); php_hash_register_algo("tiger192,4",&php_hash_4tiger192_ops); php_hash_register_algo("snefru",&php_hash_snefru_ops); + php_hash_register_algo("snefru256", &php_hash_snefru_ops); php_hash_register_algo("gost", &php_hash_gost_ops); php_hash_register_algo("adler32", &php_hash_adler32_ops); php_hash_register_algo("crc32", &php_hash_crc32_ops); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c hash_sha.c php_hash.h php_hash_sha.h /ext/hash/tests sha224.phpt
scottmacMon Jun 2 12:24:23 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/hash/tests sha224.phpt Modified files: /php-src/ext/hash hash.c hash_sha.c php_hash.h php_hash_sha.h Log: Add sha224 support. http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.4&r2=1.18.2.5.2.7.2.5&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.4 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.5 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.4Mon Apr 21 15:37:45 2008 +++ php-src/ext/hash/hash.c Mon Jun 2 12:24:22 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.4 2008/04/21 15:37:45 tony2001 Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.5 2008/06/02 12:24:22 scottmac Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -574,6 +574,7 @@ php_hash_register_algo("md4", &php_hash_md4_ops); php_hash_register_algo("md5", &php_hash_md5_ops); php_hash_register_algo("sha1", &php_hash_sha1_ops); + php_hash_register_algo("sha224",&php_hash_sha224_ops); php_hash_register_algo("sha256",&php_hash_sha256_ops); php_hash_register_algo("sha384",&php_hash_sha384_ops); php_hash_register_algo("sha512",&php_hash_sha512_ops); http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash_sha.c?r1=1.10.2.3.2.2.2.2&r2=1.10.2.3.2.2.2.3&diff_format=u Index: php-src/ext/hash/hash_sha.c diff -u php-src/ext/hash/hash_sha.c:1.10.2.3.2.2.2.2 php-src/ext/hash/hash_sha.c:1.10.2.3.2.2.2.3 --- php-src/ext/hash/hash_sha.c:1.10.2.3.2.2.2.2Mon Apr 21 15:37:46 2008 +++ php-src/ext/hash/hash_sha.c Mon Jun 2 12:24:22 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash_sha.c,v 1.10.2.3.2.2.2.2 2008/04/21 15:37:46 tony2001 Exp $ */ +/* $Id: hash_sha.c,v 1.10.2.3.2.2.2.3 2008/06/02 12:24:22 scottmac Exp $ */ #include "php_hash.h" #include "php_hash_sha.h" @@ -406,7 +406,7 @@ #endif /* PHP_HASH_SHA1_NOT_IN_CORE */ -/* sha256 */ +/* sha224/sha256 */ const php_hash_ops php_hash_sha256_ops = { (php_hash_init_func_t) PHP_SHA256Init, @@ -418,6 +418,16 @@ sizeof(PHP_SHA256_CTX) }; +const php_hash_ops php_hash_sha224_ops = { + (php_hash_init_func_t) PHP_SHA224Init, + (php_hash_update_func_t) PHP_SHA224Update, + (php_hash_final_func_t) PHP_SHA224Final, + (php_hash_copy_func_t) php_hash_copy, + 28, + 64, + sizeof(PHP_SHA224_CTX) +}; + #define ROTR32(b,x)((x >> b) | (x << (32 - b))) #define ROTR64(b,x)((x >> b) | (x << (64 - b))) #define SHR(b, x) (x >> b) @@ -505,6 +515,102 @@ } /* }}} */ +/* {{{ PHP_SHA224Init + * SHA224 initialization. Begins an SHA224 operation, writing a new context. + */ +PHP_HASH_API void PHP_SHA224Init(PHP_SHA224_CTX * context) +{ + context->count[0] = context->count[1] = 0; + /* Load magic initialization constants. +*/ + context->state[0] = 0xc1059ed8; + context->state[1] = 0x367cd507; + context->state[2] = 0x3070dd17; + context->state[3] = 0xf70e5939; + context->state[4] = 0xffc00b31; + context->state[5] = 0x68581511; + context->state[6] = 0x64f98fa7; + context->state[7] = 0xbefa4fa4; +} +/* }}} */ + +/* {{{ PHP_SHA224Update + SHA224 block update operation. Continues an SHA224 message-digest + operation, processing another message block, and updating the + context. + */ +PHP_HASH_API void PHP_SHA224Update(PHP_SHA224_CTX * context, const unsigned char *input, unsigned int inputLen) +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int) ((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) { + context->count[1]++; + } + context->count[1] += ((php_hash_uint32) inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible. +*/ + if (inputLen >= partLen) { + memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); + SHA256Transform(context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) { + SHA256Transform(context->state, &input[i]); + } + + index = 0; + } else { + i = 0; + } + + /* Buffer remaining input */ + memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); +} +/* }}} */ + +/* {{{ PHP_SHA224Final + SHA224 finalization. Ends
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c hash_adler32.c hash_crc32.c hash_gost.c hash_haval.c hash_md.c hash_ripemd.c hash_salsa.c hash_sha.c hash_snefru.c hash_tiger.c hash_whirlpool.c php_ha
tony2001Mon Apr 21 15:37:46 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/hash/tests hash_copy_001.phpt hash_copy_002.phpt Modified files: /php-src/ext/hash hash_adler32.c hash.c hash_crc32.c hash_gost.c hash_haval.c hash_md.c hash_ripemd.c hash_salsa.c hash_sha.c hash_snefru.c hash_tiger.c hash_whirlpool.c php_hash_adler32.h php_hash_crc32.h php_hash.h Log: [DOC] add hash_copy() to be able to copy hash resource http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash_adler32.c?r1=1.3.2.4.2.2.2.1&r2=1.3.2.4.2.2.2.2&diff_format=u Index: php-src/ext/hash/hash_adler32.c diff -u php-src/ext/hash/hash_adler32.c:1.3.2.4.2.2.2.1 php-src/ext/hash/hash_adler32.c:1.3.2.4.2.2.2.2 --- php-src/ext/hash/hash_adler32.c:1.3.2.4.2.2.2.1 Mon Dec 31 07:17:08 2007 +++ php-src/ext/hash/hash_adler32.c Mon Apr 21 15:37:45 2008 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: hash_adler32.c,v 1.3.2.4.2.2.2.1 2007/12/31 07:17:08 sebastian Exp $ */ +/* $Id: hash_adler32.c,v 1.3.2.4.2.2.2.2 2008/04/21 15:37:45 tony2001 Exp $ */ #include "php_hash.h" #include "php_hash_adler32.h" @@ -49,10 +49,17 @@ context->state = 0; } +PHP_HASH_API int PHP_ADLER32Copy(const php_hash_ops *ops, PHP_ADLER32_CTX *orig_context, PHP_ADLER32_CTX *copy_context) +{ + copy_context->state = orig_context->state; + return SUCCESS; +} + const php_hash_ops php_hash_adler32_ops = { (php_hash_init_func_t) PHP_ADLER32Init, (php_hash_update_func_t) PHP_ADLER32Update, (php_hash_final_func_t) PHP_ADLER32Final, + (php_hash_copy_func_t) PHP_ADLER32Copy, 4, /* what to say here? */ 4, sizeof(PHP_ADLER32_CTX) http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.3&r2=1.18.2.5.2.7.2.4&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.3 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.4 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.3Fri Apr 4 07:47:58 2008 +++ php-src/ext/hash/hash.c Mon Apr 21 15:37:45 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.3 2008/04/04 07:47:58 tony2001 Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.4 2008/04/21 15:37:45 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -63,6 +63,15 @@ } /* }}} */ +PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */ +{ + php_hash_ops *hash_ops = (php_hash_ops *)ops; + + memcpy(dest_context, orig_context, hash_ops->context_size); + return SUCCESS; +} +/* }}} */ + /* Userspace */ static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* {{{ */ @@ -475,6 +484,41 @@ } /* }}} */ +/* {{{ proto resource hash_copy(resource context) U +Copy hash resource */ +PHP_FUNCTION(hash_copy) +{ + zval *zhash; + php_hash_data *hash, *copy_hash; + void *context; + int res; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zhash) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash); + + + context = emalloc(hash->ops->context_size); + hash->ops->hash_init(context); + + res = hash->ops->hash_copy(hash->ops, hash->context, context); + if (res != SUCCESS) { + efree(context); + RETURN_FALSE; + } + + copy_hash = emalloc(sizeof(php_hash_data)); + copy_hash->ops = hash->ops; + copy_hash->context = context; + copy_hash->options = hash->options; + copy_hash->key = hash->key; + + ZEND_REGISTER_RESOURCE(return_value, copy_hash, php_hash_le_hash); +} +/* }}} */ + /* {{{ proto array hash_algos(void) Return a list of registered hashing algorithms */ PHP_FUNCTION(hash_algos) @@ -701,6 +745,11 @@ ZEND_END_ARG_INFO() static +ZEND_BEGIN_ARG_INFO(arginfo_hash_copy, 0) + ZEND_ARG_INFO(0, context) +ZEND_END_ARG_INFO() + +static ZEND_BEGIN_ARG_INFO(arginfo_hash_algos, 0) ZEND_END_ARG_INFO() @@ -720,6 +769,7 @@ PHP_FE(hash_update_stream, arginfo_hash_update_stream) PHP_FE(hash_update_file, arginfo_hash_update_file) PHP_FE(hash_final, arginfo_hash_final) + PHP_FE(hash_copy, arginfo_hash_copy) PHP_FE(hash_algos, arginfo_hash_algos) http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash_crc32.c?r1=1.2.2.3.2.2.2.1&r2=1.2.2.3.2.
[PHP-CVS] cvs: php-src(PHP_5_3) /ext/hash hash.c
tony2001Fri Apr 4 07:47:58 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/hash hash.c Log: MFH: fix folding http://cvs.php.net/viewvc.cgi/php-src/ext/hash/hash.c?r1=1.18.2.5.2.7.2.2&r2=1.18.2.5.2.7.2.3&diff_format=u Index: php-src/ext/hash/hash.c diff -u php-src/ext/hash/hash.c:1.18.2.5.2.7.2.2 php-src/ext/hash/hash.c:1.18.2.5.2.7.2.3 --- php-src/ext/hash/hash.c:1.18.2.5.2.7.2.2Mon Dec 31 07:17:08 2007 +++ php-src/ext/hash/hash.c Fri Apr 4 07:47:58 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: hash.c,v 1.18.2.5.2.7.2.2 2007/12/31 07:17:08 sebastian Exp $ */ +/* $Id: hash.c,v 1.18.2.5.2.7.2.3 2008/04/04 07:47:58 tony2001 Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -37,7 +37,7 @@ /* Hash Registry Access */ -PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) +PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) /* {{{ */ { php_hash_ops *ops; char *lower = estrndup(algo, algo_len); @@ -50,8 +50,9 @@ return ops; } +/* }}} */ -PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) +PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */ { int algo_len = strlen(algo); char *lower = estrndup(algo, algo_len); @@ -60,10 +61,11 @@ zend_hash_add(&php_hash_hashtable, lower, algo_len + 1, (void*)ops, sizeof(php_hash_ops), NULL); efree(lower); } +/* }}} */ /* Userspace */ -static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) +static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* {{{ */ { char *algo, *data, *digest; int algo_len, data_len; @@ -120,11 +122,13 @@ RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0); } } +/* }}} */ /* {{{ proto string hash(string algo, string data[, bool raw_output = false]) Generate a hash of a given input string Returns lowercase hexits by default */ -PHP_FUNCTION(hash) { +PHP_FUNCTION(hash) +{ php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -132,12 +136,13 @@ /* {{{ proto string hash_file(string algo, string filename[, bool raw_output = false]) Generate a hash of a given file Returns lowercase hexits by default */ -PHP_FUNCTION(hash_file) { +PHP_FUNCTION(hash_file) +{ php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ -static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename) +static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename) /* {{{ */ { char *algo, *data, *digest, *key, *K; int algo_len, data_len, key_len, i; @@ -229,11 +234,13 @@ RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0); } } +/* }}} */ /* {{{ proto string hash_hmac(string algo, string data, string key[, bool raw_output = false]) Generate a hash of a given input string with a key using HMAC Returns lowercase hexits by default */ -PHP_FUNCTION(hash_hmac) { +PHP_FUNCTION(hash_hmac) +{ php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -241,7 +248,8 @@ /* {{{ proto string hash_hmac_file(string algo, string filename, string key[, bool raw_output = false]) Generate a hash of a given file with a key using HMAC Returns lowercase hexits by default */ -PHP_FUNCTION(hash_hmac_file) { +PHP_FUNCTION(hash_hmac_file) +{ php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ @@ -488,7 +496,7 @@ /* Module Housekeeping */ -static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ { php_hash_data *hash = (php_hash_data*)rsrc->ptr; @@ -506,6 +514,7 @@ } efree(hash); } +/* }}} */ #define PHP_HASH_HAVAL_REGISTER(p,b) php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php