PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/hash - hash.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 353 404 87.4 %
Date: 2014-04-18 Functions: 25 27 92.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2013 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Sara Golemon <pollita@php.net>                               |
      16             :   |         Scott MacVicar <scottmac@php.net>                            |
      17             :   +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php_hash.h"
      27             : #include "ext/standard/info.h"
      28             : #include "ext/standard/file.h"
      29             : 
      30             : static int php_hash_le_hash;
      31             : HashTable php_hash_hashtable;
      32             : 
      33             : #if (PHP_MAJOR_VERSION >= 5)
      34             : # define DEFAULT_CONTEXT FG(default_context)
      35             : #else
      36             : # define DEFAULT_CONTEXT NULL
      37             : #endif
      38             : 
      39             : #ifdef PHP_MHASH_BC
      40             : struct mhash_bc_entry {
      41             :         char *mhash_name;
      42             :         char *hash_name;
      43             :         int value;
      44             : };
      45             : 
      46             : #define MHASH_NUM_ALGOS 29
      47             : 
      48             : static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
      49             :         {"CRC32", "crc32", 0},
      50             :         {"MD5", "md5", 1},
      51             :         {"SHA1", "sha1", 2},
      52             :         {"HAVAL256", "haval256,3", 3},
      53             :         {NULL, NULL, 4},
      54             :         {"RIPEMD160", "ripemd160", 5},
      55             :         {NULL, NULL, 6},
      56             :         {"TIGER", "tiger192,3", 7},
      57             :         {"GOST", "gost", 8},
      58             :         {"CRC32B", "crc32b", 9},
      59             :         {"HAVAL224", "haval224,3", 10},
      60             :         {"HAVAL192", "haval192,3", 11},
      61             :         {"HAVAL160", "haval160,3", 12},
      62             :         {"HAVAL128", "haval128,3", 13},
      63             :         {"TIGER128", "tiger128,3", 14},
      64             :         {"TIGER160", "tiger160,3", 15},
      65             :         {"MD4", "md4", 16},
      66             :         {"SHA256", "sha256", 17},
      67             :         {"ADLER32", "adler32", 18},
      68             :         {"SHA224", "sha224", 19},
      69             :         {"SHA512", "sha512", 20},
      70             :         {"SHA384", "sha384", 21},
      71             :         {"WHIRLPOOL", "whirlpool", 22},
      72             :         {"RIPEMD128", "ripemd128", 23},
      73             :         {"RIPEMD256", "ripemd256", 24},
      74             :         {"RIPEMD320", "ripemd320", 25},
      75             :         {NULL, NULL, 26}, /* support needs to be added for snefru 128 */
      76             :         {"SNEFRU256", "snefru256", 27},
      77             :         {"MD2", "md2", 28}
      78             : };
      79             : #endif
      80             : 
      81             : /* Hash Registry Access */
      82             : 
      83         375 : PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, int algo_len) /* {{{ */
      84             : {
      85             :         php_hash_ops *ops;
      86         375 :         char *lower = estrndup(algo, algo_len);
      87             : 
      88         375 :         zend_str_tolower(lower, algo_len);
      89         375 :         if (SUCCESS != zend_hash_find(&php_hash_hashtable, lower, algo_len + 1, (void*)&ops)) {
      90           4 :                 ops = NULL;
      91             :         }
      92         375 :         efree(lower);
      93             : 
      94         375 :         return ops;
      95             : }
      96             : /* }}} */
      97             : 
      98      812322 : PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */
      99             : {
     100      812322 :         int algo_len = strlen(algo);
     101      812322 :         char *lower = estrndup(algo, algo_len);
     102             :         
     103      812322 :         zend_str_tolower(lower, algo_len);
     104      812322 :         zend_hash_add(&php_hash_hashtable, lower, algo_len + 1, (void*)ops, sizeof(php_hash_ops), NULL);
     105      812322 :         efree(lower);
     106      812322 : }
     107             : /* }}} */
     108             : 
     109          79 : PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */
     110             : {
     111          79 :         php_hash_ops *hash_ops = (php_hash_ops *)ops;
     112             : 
     113          79 :         memcpy(dest_context, orig_context, hash_ops->context_size);
     114          79 :         return SUCCESS;
     115             : }
     116             : /* }}} */
     117             : 
     118             : /* Userspace */
     119             : 
     120         217 : static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
     121             : {
     122             :         char *algo, *data, *digest;
     123             :         int algo_len, data_len;
     124         217 :         zend_bool raw_output = raw_output_default;
     125             :         const php_hash_ops *ops;
     126             :         void *context;
     127         217 :         php_stream *stream = NULL;
     128             : 
     129         217 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
     130           5 :                 return;
     131             :         }
     132             : 
     133         212 :         ops = php_hash_fetch_ops(algo, algo_len);
     134         212 :         if (!ops) {
     135           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
     136           2 :                 RETURN_FALSE;
     137             :         }
     138         210 :         if (isfilename) {
     139          27 :                 stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL, DEFAULT_CONTEXT);
     140          27 :                 if (!stream) {
     141             :                         /* Stream will report errors opening file */
     142           1 :                         RETURN_FALSE;
     143             :                 }
     144             :         }
     145             : 
     146         209 :         context = emalloc(ops->context_size);
     147         209 :         ops->hash_init(context);
     148             : 
     149         209 :         if (isfilename) {
     150             :                 char buf[1024];
     151             :                 int n;
     152             : 
     153          78 :                 while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     154          26 :                         ops->hash_update(context, (unsigned char *) buf, n);
     155             :                 }
     156          26 :                 php_stream_close(stream);
     157             :         } else {
     158         183 :                 ops->hash_update(context, (unsigned char *) data, data_len);
     159             :         }
     160             : 
     161         209 :         digest = emalloc(ops->digest_size + 1);
     162         209 :         ops->hash_final((unsigned char *) digest, context);
     163         209 :         efree(context);
     164             : 
     165         209 :         if (raw_output) {
     166          18 :                 digest[ops->digest_size] = 0;
     167          18 :                 RETURN_STRINGL(digest, ops->digest_size, 0);
     168             :         } else {
     169         191 :                 char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);
     170             : 
     171         191 :                 php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
     172         191 :                 hex_digest[2 * ops->digest_size] = 0;
     173         191 :                 efree(digest);
     174         191 :                 RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
     175             :         }
     176             : }
     177             : /* }}} */
     178             : 
     179             : /* {{{ proto string hash(string algo, string data[, bool raw_output = false])
     180             : Generate a hash of a given input string
     181             : Returns lowercase hexits by default */
     182         175 : PHP_FUNCTION(hash)
     183             : {
     184         175 :         php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
     185         175 : }
     186             : /* }}} */
     187             : 
     188             : /* {{{ proto string hash_file(string algo, string filename[, bool raw_output = false])
     189             : Generate a hash of a given file
     190             : Returns lowercase hexits by default */
     191          30 : PHP_FUNCTION(hash_file)
     192             : {
     193          30 :         php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
     194          30 : }
     195             : /* }}} */
     196             : 
     197          56 : static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
     198             : {
     199             :         char *algo, *data, *digest, *key, *K;
     200             :         int algo_len, data_len, key_len, i;
     201          56 :         zend_bool raw_output = raw_output_default;
     202             :         const php_hash_ops *ops;
     203             :         void *context;
     204          56 :         php_stream *stream = NULL;
     205             : 
     206          56 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|b", &algo, &algo_len, &data, &data_len, 
     207             :                                                                                                                                   &key, &key_len, &raw_output) == FAILURE) {
     208          11 :                 return;
     209             :         }
     210             : 
     211          45 :         ops = php_hash_fetch_ops(algo, algo_len);
     212          45 :         if (!ops) {
     213           2 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
     214           2 :                 RETURN_FALSE;
     215             :         }
     216          43 :         if (isfilename) {
     217          21 :                 stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL, DEFAULT_CONTEXT);
     218          21 :                 if (!stream) {
     219             :                         /* Stream will report errors opening file */
     220           0 :                         RETURN_FALSE;
     221             :                 }
     222             :         }
     223             : 
     224          43 :         context = emalloc(ops->context_size);
     225          43 :         ops->hash_init(context);
     226             : 
     227          43 :         K = emalloc(ops->block_size);
     228          43 :         memset(K, 0, ops->block_size);
     229             : 
     230          43 :         if (key_len > ops->block_size) {
     231             :                 /* Reduce the key first */
     232           6 :                 ops->hash_update(context, (unsigned char *) key, key_len);
     233           6 :                 ops->hash_final((unsigned char *) K, context);
     234             :                 /* Make the context ready to start over */
     235           6 :                 ops->hash_init(context);
     236             :         } else {
     237          37 :                 memcpy(K, key, key_len);
     238             :         }
     239             :                         
     240             :         /* XOR ipad */
     241        2595 :         for(i=0; i < ops->block_size; i++) {
     242        2552 :                 K[i] ^= 0x36;
     243             :         }
     244          43 :         ops->hash_update(context, (unsigned char *) K, ops->block_size);
     245             : 
     246          43 :         if (isfilename) {
     247             :                 char buf[1024];
     248             :                 int n;
     249             : 
     250          63 :                 while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     251          21 :                         ops->hash_update(context, (unsigned char *) buf, n);
     252             :                 }
     253          21 :                 php_stream_close(stream);
     254             :         } else {
     255          22 :                 ops->hash_update(context, (unsigned char *) data, data_len);
     256             :         }
     257             : 
     258          43 :         digest = emalloc(ops->digest_size + 1);
     259          43 :         ops->hash_final((unsigned char *) digest, context);
     260             : 
     261             :         /* Convert K to opad -- 0x6A = 0x36 ^ 0x5C */
     262        2595 :         for(i=0; i < ops->block_size; i++) {
     263        2552 :                 K[i] ^= 0x6A;
     264             :         }
     265             : 
     266             :         /* Feed this result into the outter hash */
     267          43 :         ops->hash_init(context);
     268          43 :         ops->hash_update(context, (unsigned char *) K, ops->block_size);
     269          43 :         ops->hash_update(context, (unsigned char *) digest, ops->digest_size);
     270          43 :         ops->hash_final((unsigned char *) digest, context);
     271             : 
     272             :         /* Zero the key */
     273          43 :         memset(K, 0, ops->block_size);
     274          43 :         efree(K);
     275          43 :         efree(context);
     276             : 
     277          43 :         if (raw_output) {
     278           6 :                 digest[ops->digest_size] = 0;
     279           6 :                 RETURN_STRINGL(digest, ops->digest_size, 0);
     280             :         } else {
     281          37 :                 char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);
     282             : 
     283          37 :                 php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
     284          37 :                 hex_digest[2 * ops->digest_size] = 0;
     285          37 :                 efree(digest);
     286          37 :                 RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
     287             :         }
     288             : }
     289             : /* }}} */
     290             : 
     291             : /* {{{ proto string hash_hmac(string algo, string data, string key[, bool raw_output = false])
     292             : Generate a hash of a given input string with a key using HMAC
     293             : Returns lowercase hexits by default */
     294          27 : PHP_FUNCTION(hash_hmac)
     295             : {
     296          27 :         php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
     297          27 : }
     298             : /* }}} */
     299             : 
     300             : /* {{{ proto string hash_hmac_file(string algo, string filename, string key[, bool raw_output = false])
     301             : Generate a hash of a given file with a key using HMAC
     302             : Returns lowercase hexits by default */
     303          29 : PHP_FUNCTION(hash_hmac_file)
     304             : {
     305          29 :         php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
     306          29 : }
     307             : /* }}} */
     308             : 
     309             : 
     310             : /* {{{ proto resource hash_init(string algo[, int options, string key])
     311             : Initialize a hashing context */
     312          88 : PHP_FUNCTION(hash_init)
     313             : {
     314          88 :         char *algo, *key = NULL;
     315          88 :         int algo_len, key_len = 0, argc = ZEND_NUM_ARGS();
     316          88 :         long options = 0;
     317             :         void *context;
     318             :         const php_hash_ops *ops;
     319             :         php_hash_data *hash;
     320             : 
     321          88 :         if (zend_parse_parameters(argc TSRMLS_CC, "s|ls", &algo, &algo_len, &options, &key, &key_len) == FAILURE) {
     322           0 :                 return;
     323             :         }
     324             : 
     325          88 :         ops = php_hash_fetch_ops(algo, algo_len);
     326          88 :         if (!ops) {
     327           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
     328           0 :                 RETURN_FALSE;
     329             :         }
     330             : 
     331          91 :         if (options & PHP_HASH_HMAC &&
     332           3 :                 key_len <= 0) {
     333             :                 /* Note: a zero length key is no key at all */
     334           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "HMAC requested without a key");
     335           0 :                 RETURN_FALSE;
     336             :         }
     337             : 
     338          88 :         context = emalloc(ops->context_size);
     339          88 :         ops->hash_init(context);
     340             : 
     341          88 :         hash = emalloc(sizeof(php_hash_data));
     342          88 :         hash->ops = ops;
     343          88 :         hash->context = context;
     344          88 :         hash->options = options;
     345          88 :         hash->key = NULL;
     346             : 
     347          88 :         if (options & PHP_HASH_HMAC) {
     348           3 :                 char *K = emalloc(ops->block_size);
     349             :                 int i;
     350             : 
     351           3 :                 memset(K, 0, ops->block_size);
     352             : 
     353           3 :                 if (key_len > ops->block_size) {
     354             :                         /* Reduce the key first */
     355           1 :                         ops->hash_update(context, (unsigned char *) key, key_len);
     356           1 :                         ops->hash_final((unsigned char *) K, context);
     357             :                         /* Make the context ready to start over */
     358           1 :                         ops->hash_init(context);
     359             :                 } else {
     360           2 :                         memcpy(K, key, key_len);
     361             :                 }
     362             :                         
     363             :                 /* XOR ipad */
     364         135 :                 for(i=0; i < ops->block_size; i++) {
     365         132 :                         K[i] ^= 0x36;
     366             :                 }
     367           3 :                 ops->hash_update(context, (unsigned char *) K, ops->block_size);
     368           3 :                 hash->key = (unsigned char *) K;
     369             :         }
     370             : 
     371          88 :         ZEND_REGISTER_RESOURCE(return_value, hash, php_hash_le_hash);
     372             : }
     373             : /* }}} */
     374             : 
     375             : /* {{{ proto bool hash_update(resource context, string data)
     376             : Pump data into the hashing algorithm */
     377         128 : PHP_FUNCTION(hash_update)
     378             : {
     379             :         zval *zhash;
     380             :         php_hash_data *hash;
     381             :         char *data;
     382             :         int data_len;
     383             : 
     384         128 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &zhash, &data, &data_len) == FAILURE) {
     385           0 :                 return;
     386             :         }
     387             : 
     388         128 :         ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
     389             : 
     390         128 :         hash->ops->hash_update(hash->context, (unsigned char *) data, data_len);
     391             : 
     392         128 :         RETURN_TRUE;
     393             : }
     394             : /* }}} */
     395             : 
     396             : /* {{{ proto int hash_update_stream(resource context, resource handle[, integer length])
     397             : Pump data into the hashing algorithm from an open stream */
     398           0 : PHP_FUNCTION(hash_update_stream)
     399             : {
     400             :         zval *zhash, *zstream;
     401             :         php_hash_data *hash;
     402           0 :         php_stream *stream = NULL;
     403           0 :         long length = -1, didread = 0;
     404             : 
     405           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|l", &zhash, &zstream, &length) == FAILURE) {
     406           0 :                 return;
     407             :         }
     408             : 
     409           0 :         ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
     410           0 :         php_stream_from_zval(stream, &zstream);
     411             : 
     412           0 :         while (length) {
     413             :                 char buf[1024];
     414           0 :                 long n, toread = 1024;
     415             : 
     416           0 :                 if (length > 0 && toread > length) {
     417           0 :                         toread = length;
     418             :                 }
     419             : 
     420           0 :                 if ((n = php_stream_read(stream, buf, toread)) <= 0) {
     421             :                         /* Nada mas */
     422           0 :                         RETURN_LONG(didread);
     423             :                 }
     424           0 :                 hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
     425           0 :                 length -= n;
     426           0 :                 didread += n;
     427             :         } 
     428             : 
     429           0 :         RETURN_LONG(didread);
     430             : }
     431             : /* }}} */
     432             : 
     433             : /* {{{ proto bool hash_update_file(resource context, string filename[, resource context])
     434             : Pump data into the hashing algorithm from a file */
     435           0 : PHP_FUNCTION(hash_update_file)
     436             : {
     437           0 :         zval *zhash, *zcontext = NULL;
     438             :         php_hash_data *hash;
     439             :         php_stream_context *context;
     440             :         php_stream *stream;
     441             :         char *filename, buf[1024];
     442             :         int filename_len, n;
     443             : 
     444           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|r", &zhash, &filename, &filename_len, &zcontext) == FAILURE) {
     445           0 :                 return;
     446             :         }
     447             : 
     448           0 :         ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
     449           0 :         context = php_stream_context_from_zval(zcontext, 0);
     450             : 
     451           0 :         stream = php_stream_open_wrapper_ex(filename, "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL, context);
     452           0 :         if (!stream) {
     453             :                 /* Stream will report errors opening file */
     454           0 :                 RETURN_FALSE;
     455             :         }
     456             : 
     457           0 :         while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     458           0 :                 hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
     459             :         }
     460           0 :         php_stream_close(stream);
     461             : 
     462           0 :         RETURN_TRUE;
     463             : }
     464             : /* }}} */
     465             : 
     466             : /* {{{ proto string hash_final(resource context[, bool raw_output=false])
     467             : Output resulting digest */
     468         173 : PHP_FUNCTION(hash_final)
     469             : {
     470             :         zval *zhash;
     471             :         php_hash_data *hash;
     472         173 :         zend_bool raw_output = 0;
     473             :         zend_rsrc_list_entry *le;
     474             :         char *digest;
     475             :         int digest_len;
     476             : 
     477         173 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &zhash, &raw_output) == FAILURE) {
     478           0 :                 return;
     479             :         }
     480             : 
     481         173 :         ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
     482             : 
     483         173 :         digest_len = hash->ops->digest_size;
     484         173 :         digest = emalloc(digest_len + 1);
     485         173 :         hash->ops->hash_final((unsigned char *) digest, hash->context);
     486         173 :         if (hash->options & PHP_HASH_HMAC) {
     487             :                 int i;
     488             : 
     489             :                 /* Convert K to opad -- 0x6A = 0x36 ^ 0x5C */
     490         145 :                 for(i=0; i < hash->ops->block_size; i++) {
     491         140 :                         hash->key[i] ^= 0x6A;
     492             :                 }
     493             : 
     494             :                 /* Feed this result into the outter hash */
     495           5 :                 hash->ops->hash_init(hash->context);
     496           5 :                 hash->ops->hash_update(hash->context, (unsigned char *) hash->key, hash->ops->block_size);
     497           5 :                 hash->ops->hash_update(hash->context, (unsigned char *) digest, hash->ops->digest_size);
     498           5 :                 hash->ops->hash_final((unsigned char *) digest, hash->context);
     499             : 
     500             :                 /* Zero the key */
     501           5 :                 memset(hash->key, 0, hash->ops->block_size);
     502           5 :                 efree(hash->key);
     503           5 :                 hash->key = NULL;
     504             :         }
     505         173 :         digest[digest_len] = 0;
     506         173 :         efree(hash->context);
     507         173 :         hash->context = NULL;
     508             : 
     509             :         /* zend_list_REAL_delete() */
     510         173 :         if (zend_hash_index_find(&EG(regular_list), Z_RESVAL_P(zhash), (void *) &le)==SUCCESS) {
     511             :                 /* This is a hack to avoid letting the resource hide elsewhere (like in separated vars)
     512             :                         FETCH_RESOURCE is intelligent enough to handle dealing with any issues this causes */
     513         173 :                 le->refcount = 1;
     514             :         } /* FAILURE is not an option */
     515         173 :         zend_list_delete(Z_RESVAL_P(zhash));
     516             : 
     517         173 :         if (raw_output) {
     518           0 :                 RETURN_STRINGL(digest, digest_len, 0);
     519             :         } else {
     520         173 :                 char *hex_digest = safe_emalloc(digest_len,2,1);
     521             : 
     522         173 :                 php_hash_bin2hex(hex_digest, (unsigned char *) digest, digest_len);
     523         173 :                 hex_digest[2 * digest_len] = 0;
     524         173 :                 efree(digest);
     525         173 :                 RETURN_STRINGL(hex_digest, 2 * digest_len, 0);          
     526             :         }
     527             : }
     528             : /* }}} */
     529             : 
     530             : /* {{{ proto resource hash_copy(resource context)
     531             : Copy hash resource */
     532          89 : PHP_FUNCTION(hash_copy)
     533             : {
     534             :         zval *zhash;
     535             :         php_hash_data *hash, *copy_hash;
     536             :         void *context;
     537             :         int res;
     538             : 
     539          89 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zhash) == FAILURE) {
     540           2 :                 return;
     541             :         }
     542             : 
     543          87 :         ZEND_FETCH_RESOURCE(hash, php_hash_data*, &zhash, -1, PHP_HASH_RESNAME, php_hash_le_hash);
     544             : 
     545             : 
     546          87 :         context = emalloc(hash->ops->context_size);
     547          87 :         hash->ops->hash_init(context);
     548             : 
     549          87 :         res = hash->ops->hash_copy(hash->ops, hash->context, context);
     550          87 :         if (res != SUCCESS) {
     551           0 :                 efree(context);
     552           0 :                 RETURN_FALSE;
     553             :         }
     554             : 
     555          87 :         copy_hash = emalloc(sizeof(php_hash_data));
     556          87 :         copy_hash->ops = hash->ops;
     557          87 :         copy_hash->context = context;
     558          87 :         copy_hash->options = hash->options;
     559          87 :         copy_hash->key = ecalloc(1, hash->ops->block_size);
     560          87 :         if (hash->key) {
     561           2 :                 memcpy(copy_hash->key, hash->key, hash->ops->block_size);
     562             :         }
     563          87 :         ZEND_REGISTER_RESOURCE(return_value, copy_hash, php_hash_le_hash);
     564             : }
     565             : /* }}} */
     566             : 
     567             : /* {{{ proto array hash_algos(void)
     568             : Return a list of registered hashing algorithms */
     569           2 : PHP_FUNCTION(hash_algos)
     570             : {
     571             :         HashPosition pos;
     572             :         char *str;
     573             :         uint str_len;
     574             :         long type;
     575             :         ulong idx;
     576             : 
     577           2 :         array_init(return_value);
     578          88 :         for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
     579          86 :                 (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, &str_len, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT;
     580          84 :                 zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
     581          84 :                 add_next_index_stringl(return_value, str, str_len-1, 1);
     582             :         }
     583           2 : }
     584             : /* }}} */
     585             : 
     586             : /* Module Housekeeping */
     587             : 
     588         175 : static void php_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
     589             : {
     590         175 :         php_hash_data *hash = (php_hash_data*)rsrc->ptr;
     591             : 
     592             :         /* Just in case the algo has internally allocated resources */
     593         175 :         if (hash->context) {
     594           2 :                 unsigned char *dummy = emalloc(hash->ops->digest_size);
     595           2 :                 hash->ops->hash_final(dummy, hash->context);
     596           2 :                 efree(dummy);
     597           2 :                 efree(hash->context);
     598             :         }
     599             : 
     600         175 :         if (hash->key) {
     601          85 :                 memset(hash->key, 0, hash->ops->block_size);
     602          85 :                 efree(hash->key);
     603             :         }
     604         175 :         efree(hash);
     605         175 : }
     606             : /* }}} */
     607             : 
     608             : #define PHP_HASH_HAVAL_REGISTER(p,b)    php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops);
     609             : 
     610             : #ifdef PHP_MHASH_BC
     611             : 
     612         148 : PHP_MINFO_FUNCTION(mhash)
     613             : {
     614         148 :         php_info_print_table_start();
     615         148 :         php_info_print_table_row(2, "MHASH support", "Enabled");
     616         148 :         php_info_print_table_row(2, "MHASH API Version", "Emulated Support");
     617         148 :         php_info_print_table_end();
     618         148 : }
     619             : 
     620             : zend_module_entry mhash_module_entry = {
     621             :         STANDARD_MODULE_HEADER,
     622             :         "mhash",
     623             :         NULL,
     624             :         NULL,
     625             :         NULL,
     626             :         NULL,
     627             :         NULL,
     628             :         PHP_MINFO(mhash),
     629             :         NO_VERSION_YET,
     630             :         STANDARD_MODULE_PROPERTIES,
     631             : };
     632             : 
     633       19341 : static void mhash_init(INIT_FUNC_ARGS)
     634             : {
     635             :         char buf[128];
     636             :         int len;
     637       19341 :         int algo_number = 0;
     638             : 
     639      580230 :         for (algo_number = 0; algo_number < MHASH_NUM_ALGOS; algo_number++) {
     640      560889 :                 struct mhash_bc_entry algorithm = mhash_to_hash[algo_number];
     641      560889 :                 if (algorithm.mhash_name == NULL) {
     642       58023 :                         continue;
     643             :                 }
     644             : 
     645      502866 :                 len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name, strlen(algorithm.mhash_name));
     646      502866 :                 zend_register_long_constant(buf, len + 1, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
     647             :         }
     648       19341 :         zend_register_internal_module(&mhash_module_entry TSRMLS_CC);
     649       19341 : }
     650             : 
     651             : /* {{{ proto string mhash(int hash, string data [, string key])
     652             :    Hash data with hash */
     653          12 : PHP_FUNCTION(mhash)
     654             : {
     655             :         zval **z_algorithm;
     656             :         long algorithm;
     657             : 
     658          12 :         if (zend_parse_parameters(1 TSRMLS_CC, "Z", &z_algorithm) == FAILURE) {
     659           0 :                 return;
     660             :         }
     661             : 
     662          26 :         SEPARATE_ZVAL(z_algorithm);
     663          12 :         convert_to_long_ex(z_algorithm);
     664          12 :         algorithm = Z_LVAL_PP(z_algorithm);
     665             : 
     666             :         /* need to convert the first parameter from int constant to string algorithm name */
     667          12 :         if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
     668          12 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     669          12 :                 if (algorithm_lookup.hash_name) {
     670          12 :                         ZVAL_STRING(*z_algorithm, algorithm_lookup.hash_name, 1);
     671             :                 }
     672             :         }
     673             : 
     674          12 :         if (ZEND_NUM_ARGS() == 3) {
     675           0 :                 php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
     676          12 :         } else if (ZEND_NUM_ARGS() == 2) {
     677          12 :                 php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
     678             :         } else {
     679           0 :                 WRONG_PARAM_COUNT;
     680             :         }
     681             : }
     682             : /* }}} */
     683             : 
     684             : /* {{{ proto string mhash_get_hash_name(int hash)
     685             :    Gets the name of hash */
     686          29 : PHP_FUNCTION(mhash_get_hash_name)
     687             : {
     688             :         long algorithm;
     689             : 
     690          29 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) {
     691           0 :                 return;
     692             :         }
     693             : 
     694          29 :         if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
     695          29 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     696          29 :                 if (algorithm_lookup.mhash_name) {
     697          26 :                         RETURN_STRING(algorithm_lookup.mhash_name, 1);
     698             :                 }
     699             :         }
     700           3 :         RETURN_FALSE;
     701             : }
     702             : /* }}} */
     703             : 
     704             : /* {{{ proto int mhash_count(void)
     705             :    Gets the number of available hashes */
     706           1 : PHP_FUNCTION(mhash_count)
     707             : {
     708           1 :         if (zend_parse_parameters_none() == FAILURE) {
     709           0 :                 return;
     710             :         }
     711           1 :         RETURN_LONG(MHASH_NUM_ALGOS - 1);
     712             : }
     713             : /* }}} */
     714             : 
     715             : /* {{{ proto int mhash_get_block_size(int hash)
     716             :    Gets the block size of hash */
     717          17 : PHP_FUNCTION(mhash_get_block_size)
     718             : {
     719             :         long algorithm;
     720             : 
     721          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &algorithm) == FAILURE) {
     722           0 :                 return;
     723             :         }
     724          17 :         RETVAL_FALSE;
     725             : 
     726          17 :         if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
     727          17 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     728          17 :                 if (algorithm_lookup.mhash_name) {
     729          17 :                         const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name));
     730          17 :                         if (ops) {
     731          17 :                                 RETVAL_LONG(ops->digest_size);
     732             :                         }
     733             :                 }
     734             :         }
     735             : }
     736             : /* }}} */
     737             : 
     738             : #define SALT_SIZE 8
     739             : 
     740             : /* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string salt, int bytes)
     741             :    Generates a key using hash functions */
     742          11 : PHP_FUNCTION(mhash_keygen_s2k)
     743             : {
     744             :         long algorithm, l_bytes;
     745             :         int bytes;
     746             :         char *password, *salt;
     747             :         int password_len, salt_len;
     748             :         char padded_salt[SALT_SIZE];
     749             : 
     750          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lssl", &algorithm, &password, &password_len, &salt, &salt_len, &l_bytes) == FAILURE) {
     751           0 :                 return;
     752             :         }
     753             : 
     754          11 :         bytes = (int)l_bytes;
     755          11 :         if (bytes <= 0){
     756           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "the byte parameter must be greater than 0");
     757           0 :                 RETURN_FALSE;
     758             :         }
     759             : 
     760          11 :         salt_len = MIN(salt_len, SALT_SIZE);
     761             : 
     762          11 :         memcpy(padded_salt, salt, salt_len);
     763          11 :         if (salt_len < SALT_SIZE) {
     764           0 :                 memset(padded_salt + salt_len, 0, SALT_SIZE - salt_len);
     765             :         }
     766          11 :         salt_len = SALT_SIZE;
     767             : 
     768          11 :         RETVAL_FALSE;
     769          11 :         if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
     770          11 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     771          11 :                 if (algorithm_lookup.mhash_name) {
     772          11 :                         const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name));
     773          11 :                         if (ops) {
     774          11 :                                 unsigned char null = '\0';
     775             :                                 void *context;
     776             :                                 char *key, *digest;
     777          11 :                                 int i = 0, j = 0;
     778          11 :                                 int block_size = ops->digest_size;
     779          11 :                                 int times = bytes / block_size;
     780          11 :                                 if (bytes % block_size  != 0) times++;
     781             : 
     782          11 :                                 context = emalloc(ops->context_size);
     783          11 :                                 ops->hash_init(context);
     784             : 
     785          11 :                                 key = ecalloc(1, times * block_size);
     786          11 :                                 digest = emalloc(ops->digest_size + 1);
     787             : 
     788         105 :                                 for (i = 0; i < times; i++) {
     789          94 :                                         ops->hash_init(context);
     790             : 
     791         783 :                                         for (j=0;j<i;j++) {
     792         689 :                                                 ops->hash_update(context, &null, 1);
     793             :                                         }
     794          94 :                                         ops->hash_update(context, (unsigned char *)padded_salt, salt_len);
     795          94 :                                         ops->hash_update(context, (unsigned char *)password, password_len);
     796          94 :                                         ops->hash_final((unsigned char *)digest, context);
     797          94 :                                         memcpy( &key[i*block_size], digest, block_size);
     798             :                                 }
     799             : 
     800          11 :                                 RETVAL_STRINGL(key, bytes, 1);
     801          11 :                                 memset(key, 0, bytes);
     802          11 :                                 efree(digest);
     803          11 :                                 efree(context);
     804          11 :                                 efree(key);
     805             :                         }
     806             :                 }
     807             :         }
     808             : }
     809             : /* }}} */
     810             : 
     811             : #endif
     812             : 
     813             : /* {{{ PHP_MINIT_FUNCTION
     814             :  */
     815       19341 : PHP_MINIT_FUNCTION(hash)
     816             : {
     817       19341 :         php_hash_le_hash = zend_register_list_destructors_ex(php_hash_dtor, NULL, PHP_HASH_RESNAME, module_number);
     818             : 
     819       19341 :         zend_hash_init(&php_hash_hashtable, 35, NULL, NULL, 1);
     820             : 
     821       19341 :         php_hash_register_algo("md2",                 &php_hash_md2_ops);
     822       19341 :         php_hash_register_algo("md4",                 &php_hash_md4_ops);
     823       19341 :         php_hash_register_algo("md5",                 &php_hash_md5_ops);
     824       19341 :         php_hash_register_algo("sha1",                        &php_hash_sha1_ops);
     825       19341 :         php_hash_register_algo("sha224",              &php_hash_sha224_ops);
     826       19341 :         php_hash_register_algo("sha256",              &php_hash_sha256_ops);
     827       19341 :         php_hash_register_algo("sha384",              &php_hash_sha384_ops);
     828       19341 :         php_hash_register_algo("sha512",              &php_hash_sha512_ops);
     829       19341 :         php_hash_register_algo("ripemd128",           &php_hash_ripemd128_ops);
     830       19341 :         php_hash_register_algo("ripemd160",           &php_hash_ripemd160_ops);
     831       19341 :         php_hash_register_algo("ripemd256",           &php_hash_ripemd256_ops);
     832       19341 :         php_hash_register_algo("ripemd320",           &php_hash_ripemd320_ops);
     833       19341 :         php_hash_register_algo("whirlpool",           &php_hash_whirlpool_ops);
     834       19341 :         php_hash_register_algo("tiger128,3",  &php_hash_3tiger128_ops);
     835       19341 :         php_hash_register_algo("tiger160,3",  &php_hash_3tiger160_ops);
     836       19341 :         php_hash_register_algo("tiger192,3",  &php_hash_3tiger192_ops);
     837       19341 :         php_hash_register_algo("tiger128,4",  &php_hash_4tiger128_ops);
     838       19341 :         php_hash_register_algo("tiger160,4",  &php_hash_4tiger160_ops);
     839       19341 :         php_hash_register_algo("tiger192,4",  &php_hash_4tiger192_ops);
     840       19341 :         php_hash_register_algo("snefru",              &php_hash_snefru_ops);
     841       19341 :         php_hash_register_algo("snefru256",           &php_hash_snefru_ops);
     842       19341 :         php_hash_register_algo("gost",                        &php_hash_gost_ops);
     843       19341 :         php_hash_register_algo("adler32",             &php_hash_adler32_ops);
     844       19341 :         php_hash_register_algo("crc32",                       &php_hash_crc32_ops);
     845       19341 :         php_hash_register_algo("crc32b",              &php_hash_crc32b_ops);
     846       19341 :         php_hash_register_algo("salsa10",             &php_hash_salsa10_ops);
     847       19341 :         php_hash_register_algo("salsa20",             &php_hash_salsa20_ops);
     848             : 
     849       19341 :         PHP_HASH_HAVAL_REGISTER(3,128);
     850       19341 :         PHP_HASH_HAVAL_REGISTER(3,160);
     851       19341 :         PHP_HASH_HAVAL_REGISTER(3,192);
     852       19341 :         PHP_HASH_HAVAL_REGISTER(3,224);
     853       19341 :         PHP_HASH_HAVAL_REGISTER(3,256);
     854             : 
     855       19341 :         PHP_HASH_HAVAL_REGISTER(4,128);
     856       19341 :         PHP_HASH_HAVAL_REGISTER(4,160);
     857       19341 :         PHP_HASH_HAVAL_REGISTER(4,192);
     858       19341 :         PHP_HASH_HAVAL_REGISTER(4,224);
     859       19341 :         PHP_HASH_HAVAL_REGISTER(4,256);
     860             : 
     861       19341 :         PHP_HASH_HAVAL_REGISTER(5,128);
     862       19341 :         PHP_HASH_HAVAL_REGISTER(5,160);
     863       19341 :         PHP_HASH_HAVAL_REGISTER(5,192);
     864       19341 :         PHP_HASH_HAVAL_REGISTER(5,224);
     865       19341 :         PHP_HASH_HAVAL_REGISTER(5,256);
     866             : 
     867       19341 :         REGISTER_LONG_CONSTANT("HASH_HMAC",           PHP_HASH_HMAC,  CONST_CS | CONST_PERSISTENT);
     868             : 
     869             : #ifdef PHP_MHASH_BC
     870       19341 :         mhash_init(INIT_FUNC_ARGS_PASSTHRU);
     871             : #endif
     872             : 
     873       19341 :         return SUCCESS;
     874             : }
     875             : /* }}} */
     876             : 
     877             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     878             :  */
     879       19376 : PHP_MSHUTDOWN_FUNCTION(hash)
     880             : {
     881       19376 :         zend_hash_destroy(&php_hash_hashtable);
     882             : 
     883       19376 :         return SUCCESS;
     884             : }
     885             : /* }}} */
     886             : 
     887             : /* {{{ PHP_MINFO_FUNCTION
     888             :  */
     889         148 : PHP_MINFO_FUNCTION(hash)
     890             : {
     891             :         HashPosition pos;
     892             :         char buffer[2048];
     893         148 :         char *s = buffer, *e = s + sizeof(buffer), *str;
     894             :         ulong idx;
     895             :         long type;
     896             : 
     897        6512 :         for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
     898        6364 :                 (type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, NULL, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT;
     899        6216 :                 zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
     900        6216 :                 s += slprintf(s, e - s, "%s ", str);
     901             :         }
     902         148 :         *s = 0;
     903             : 
     904         148 :         php_info_print_table_start();
     905         148 :         php_info_print_table_row(2, "hash support", "enabled");
     906         148 :         php_info_print_table_row(2, "Hashing Engines", buffer);
     907         148 :         php_info_print_table_end();
     908         148 : }
     909             : /* }}} */
     910             : 
     911             : /* {{{ arginfo */
     912             : #ifdef PHP_HASH_MD5_NOT_IN_CORE
     913             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5, 0, 0, 1)
     914             :         ZEND_ARG_INFO(0, str)
     915             :         ZEND_ARG_INFO(0, raw_output)
     916             : ZEND_END_ARG_INFO()
     917             : 
     918             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5_file, 0, 0, 1)
     919             :         ZEND_ARG_INFO(0, filename)
     920             :         ZEND_ARG_INFO(0, raw_output)
     921             : ZEND_END_ARG_INFO()
     922             : #endif
     923             : 
     924             : #ifdef PHP_HASH_SHA1_NOT_IN_CORE
     925             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1, 0, 0, 1)
     926             :         ZEND_ARG_INFO(0, str)
     927             :         ZEND_ARG_INFO(0, raw_output)
     928             : ZEND_END_ARG_INFO()
     929             : 
     930             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1_file, 0, 0, 1)
     931             :         ZEND_ARG_INFO(0, filename)
     932             :         ZEND_ARG_INFO(0, raw_output)
     933             : ZEND_END_ARG_INFO()
     934             : #endif
     935             : 
     936             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash, 0, 0, 2)
     937             :         ZEND_ARG_INFO(0, algo)
     938             :         ZEND_ARG_INFO(0, data)
     939             :         ZEND_ARG_INFO(0, raw_output)
     940             : ZEND_END_ARG_INFO()
     941             : 
     942             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_file, 0, 0, 2)
     943             :         ZEND_ARG_INFO(0, algo)
     944             :         ZEND_ARG_INFO(0, filename)
     945             :         ZEND_ARG_INFO(0, raw_output)
     946             : ZEND_END_ARG_INFO()
     947             : 
     948             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_hmac, 0, 0, 3)
     949             :         ZEND_ARG_INFO(0, algo)
     950             :         ZEND_ARG_INFO(0, data)
     951             :         ZEND_ARG_INFO(0, key)
     952             :         ZEND_ARG_INFO(0, raw_output)
     953             : ZEND_END_ARG_INFO()
     954             : 
     955             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_hmac_file, 0, 0, 3)
     956             :         ZEND_ARG_INFO(0, algo)
     957             :         ZEND_ARG_INFO(0, filename)
     958             :         ZEND_ARG_INFO(0, key)
     959             :         ZEND_ARG_INFO(0, raw_output)
     960             : ZEND_END_ARG_INFO()
     961             : 
     962             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_init, 0, 0, 1)
     963             :         ZEND_ARG_INFO(0, algo)
     964             :         ZEND_ARG_INFO(0, options)
     965             :         ZEND_ARG_INFO(0, key)
     966             : ZEND_END_ARG_INFO()
     967             : 
     968             : ZEND_BEGIN_ARG_INFO(arginfo_hash_update, 0)
     969             :         ZEND_ARG_INFO(0, context)
     970             :         ZEND_ARG_INFO(0, data)
     971             : ZEND_END_ARG_INFO()
     972             : 
     973             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_update_stream, 0, 0, 2)
     974             :         ZEND_ARG_INFO(0, context)
     975             :         ZEND_ARG_INFO(0, handle)
     976             :         ZEND_ARG_INFO(0, length)
     977             : ZEND_END_ARG_INFO()
     978             : 
     979             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_update_file, 0, 0, 2)
     980             :         ZEND_ARG_INFO(0, context)
     981             :         ZEND_ARG_INFO(0, filename)
     982             :         ZEND_ARG_INFO(0, context)
     983             : ZEND_END_ARG_INFO()
     984             : 
     985             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_final, 0, 0, 1)
     986             :         ZEND_ARG_INFO(0, context)
     987             :         ZEND_ARG_INFO(0, raw_output)
     988             : ZEND_END_ARG_INFO()
     989             : 
     990             : ZEND_BEGIN_ARG_INFO(arginfo_hash_copy, 0)
     991             :         ZEND_ARG_INFO(0, context)
     992             : ZEND_END_ARG_INFO()
     993             : 
     994             : ZEND_BEGIN_ARG_INFO(arginfo_hash_algos, 0)
     995             : ZEND_END_ARG_INFO()
     996             : 
     997             : /* BC Land */
     998             : #ifdef PHP_MHASH_BC
     999             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_block_size, 0)
    1000             :         ZEND_ARG_INFO(0, hash)
    1001             : ZEND_END_ARG_INFO()
    1002             : 
    1003             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_hash_name, 0)
    1004             :         ZEND_ARG_INFO(0, hash)
    1005             : ZEND_END_ARG_INFO()
    1006             : 
    1007             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_keygen_s2k, 0)
    1008             :         ZEND_ARG_INFO(0, hash)
    1009             :         ZEND_ARG_INFO(0, input_password)
    1010             :         ZEND_ARG_INFO(0, salt)
    1011             :         ZEND_ARG_INFO(0, bytes)
    1012             : ZEND_END_ARG_INFO()
    1013             : 
    1014             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_count, 0)
    1015             : ZEND_END_ARG_INFO()
    1016             : 
    1017             : ZEND_BEGIN_ARG_INFO_EX(arginfo_mhash, 0, 0, 2)
    1018             :         ZEND_ARG_INFO(0, hash)
    1019             :         ZEND_ARG_INFO(0, data)
    1020             :         ZEND_ARG_INFO(0, key)
    1021             : ZEND_END_ARG_INFO()
    1022             : #endif
    1023             : 
    1024             : /* }}} */
    1025             : 
    1026             : /* {{{ hash_functions[]
    1027             :  */
    1028             : const zend_function_entry hash_functions[] = {
    1029             :         PHP_FE(hash,                                                                    arginfo_hash)
    1030             :         PHP_FE(hash_file,                                                               arginfo_hash_file)
    1031             : 
    1032             :         PHP_FE(hash_hmac,                                                               arginfo_hash_hmac)
    1033             :         PHP_FE(hash_hmac_file,                                                  arginfo_hash_hmac_file)
    1034             : 
    1035             :         PHP_FE(hash_init,                                                               arginfo_hash_init)
    1036             :         PHP_FE(hash_update,                                                             arginfo_hash_update)
    1037             :         PHP_FE(hash_update_stream,                                              arginfo_hash_update_stream)
    1038             :         PHP_FE(hash_update_file,                                                arginfo_hash_update_file)
    1039             :         PHP_FE(hash_final,                                                              arginfo_hash_final)
    1040             :         PHP_FE(hash_copy,                                                               arginfo_hash_copy)
    1041             : 
    1042             :         PHP_FE(hash_algos,                                                              arginfo_hash_algos)
    1043             : 
    1044             :         /* BC Land */
    1045             : #ifdef PHP_HASH_MD5_NOT_IN_CORE
    1046             :         PHP_NAMED_FE(md5, php_if_md5,                                   arginfo_hash_md5)
    1047             :         PHP_NAMED_FE(md5_file, php_if_md5_file,                 arginfo_hash_md5_file)
    1048             : #endif /* PHP_HASH_MD5_NOT_IN_CORE */
    1049             : 
    1050             : #ifdef PHP_HASH_SHA1_NOT_IN_CORE
    1051             :         PHP_NAMED_FE(sha1, php_if_sha1,                                 arginfo_hash_sha1)
    1052             :         PHP_NAMED_FE(sha1_file, php_if_sha1_file,               arginfo_hash_sha1_file)
    1053             : #endif /* PHP_HASH_SHA1_NOT_IN_CORE */
    1054             : 
    1055             : #ifdef PHP_MHASH_BC
    1056             :         PHP_FE(mhash_keygen_s2k, arginfo_mhash_keygen_s2k)
    1057             :         PHP_FE(mhash_get_block_size, arginfo_mhash_get_block_size)
    1058             :         PHP_FE(mhash_get_hash_name, arginfo_mhash_get_hash_name)
    1059             :         PHP_FE(mhash_count, arginfo_mhash_count)
    1060             :         PHP_FE(mhash, arginfo_mhash)
    1061             : #endif
    1062             : 
    1063             :         PHP_FE_END
    1064             : };
    1065             : /* }}} */
    1066             : 
    1067             : /* {{{ hash_module_entry
    1068             :  */
    1069             : zend_module_entry hash_module_entry = {
    1070             : #if ZEND_MODULE_API_NO >= 20010901
    1071             :         STANDARD_MODULE_HEADER,
    1072             : #endif
    1073             :         PHP_HASH_EXTNAME,
    1074             :         hash_functions,
    1075             :         PHP_MINIT(hash),
    1076             :         PHP_MSHUTDOWN(hash),
    1077             :         NULL, /* RINIT */
    1078             :         NULL, /* RSHUTDOWN */
    1079             :         PHP_MINFO(hash),
    1080             : #if ZEND_MODULE_API_NO >= 20010901
    1081             :         PHP_HASH_EXTVER, /* Replace with version number for your extension */
    1082             : #endif
    1083             :         STANDARD_MODULE_PROPERTIES
    1084             : };
    1085             : /* }}} */
    1086             : 
    1087             : #ifdef COMPILE_DL_HASH
    1088             : ZEND_GET_MODULE(hash)
    1089             : #endif
    1090             : 
    1091             : /*
    1092             :  * Local variables:
    1093             :  * tab-width: 4
    1094             :  * c-basic-offset: 4
    1095             :  * End:
    1096             :  * vim600: noet sw=4 ts=4 fdm=marker
    1097             :  * vim<600: noet sw=4 ts=4
    1098             :  */

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:27 +0000 (5 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.