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: 569 609 93.4 %
Date: 2019-05-06 Functions: 36 37 97.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 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             : #ifdef HAVE_CONFIG_H
      21             : #include "config.h"
      22             : #endif
      23             : 
      24             : #include <math.h>
      25             : #include "php_hash.h"
      26             : #include "ext/standard/info.h"
      27             : #include "ext/standard/file.h"
      28             : 
      29             : #include "zend_interfaces.h"
      30             : #include "zend_exceptions.h"
      31             : 
      32             : HashTable php_hash_hashtable;
      33             : zend_class_entry *php_hashcontext_ce;
      34             : static zend_object_handlers php_hashcontext_handlers;
      35             : 
      36             : #ifdef PHP_MHASH_BC
      37             : struct mhash_bc_entry {
      38             :         char *mhash_name;
      39             :         char *hash_name;
      40             :         int value;
      41             : };
      42             : 
      43             : #define MHASH_NUM_ALGOS 35
      44             : 
      45             : static struct mhash_bc_entry mhash_to_hash[MHASH_NUM_ALGOS] = {
      46             :         {"CRC32", "crc32", 0}, /* used by bzip */
      47             :         {"MD5", "md5", 1},
      48             :         {"SHA1", "sha1", 2},
      49             :         {"HAVAL256", "haval256,3", 3},
      50             :         {NULL, NULL, 4},
      51             :         {"RIPEMD160", "ripemd160", 5},
      52             :         {NULL, NULL, 6},
      53             :         {"TIGER", "tiger192,3", 7},
      54             :         {"GOST", "gost", 8},
      55             :         {"CRC32B", "crc32b", 9}, /* used by ethernet (IEEE 802.3), gzip, zip, png, etc */
      56             :         {"HAVAL224", "haval224,3", 10},
      57             :         {"HAVAL192", "haval192,3", 11},
      58             :         {"HAVAL160", "haval160,3", 12},
      59             :         {"HAVAL128", "haval128,3", 13},
      60             :         {"TIGER128", "tiger128,3", 14},
      61             :         {"TIGER160", "tiger160,3", 15},
      62             :         {"MD4", "md4", 16},
      63             :         {"SHA256", "sha256", 17},
      64             :         {"ADLER32", "adler32", 18},
      65             :         {"SHA224", "sha224", 19},
      66             :         {"SHA512", "sha512", 20},
      67             :         {"SHA384", "sha384", 21},
      68             :         {"WHIRLPOOL", "whirlpool", 22},
      69             :         {"RIPEMD128", "ripemd128", 23},
      70             :         {"RIPEMD256", "ripemd256", 24},
      71             :         {"RIPEMD320", "ripemd320", 25},
      72             :         {NULL, NULL, 26}, /* support needs to be added for snefru 128 */
      73             :         {"SNEFRU256", "snefru256", 27},
      74             :         {"MD2", "md2", 28},
      75             :         {"FNV132", "fnv132", 29},
      76             :         {"FNV1A32", "fnv1a32", 30},
      77             :         {"FNV164", "fnv164", 31},
      78             :         {"FNV1A64", "fnv1a64", 32},
      79             :         {"JOAAT", "joaat", 33},
      80             :         {"CRC32C", "crc32c", 34}, /* Castagnoli's CRC, used by iSCSI, SCTP, Btrfs, ext4, etc */
      81             : };
      82             : #endif
      83             : 
      84             : /* Hash Registry Access */
      85             : 
      86        1604 : PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(const char *algo, size_t algo_len) /* {{{ */
      87             : {
      88        1604 :         char *lower = zend_str_tolower_dup(algo, algo_len);
      89        1604 :         php_hash_ops *ops = zend_hash_str_find_ptr(&php_hash_hashtable, lower, algo_len);
      90        1604 :         efree(lower);
      91             : 
      92        1604 :         return ops;
      93             : }
      94             : /* }}} */
      95             : 
      96     1221279 : PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */
      97             : {
      98     1221279 :         size_t algo_len = strlen(algo);
      99     1221279 :         char *lower = zend_str_tolower_dup(algo, algo_len);
     100     1221279 :         zend_hash_add_ptr(&php_hash_hashtable, zend_string_init_interned(lower, algo_len, 1), (void *) ops);
     101     1221279 :         efree(lower);
     102     1221279 : }
     103             : /* }}} */
     104             : 
     105         182 : PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context) /* {{{ */
     106             : {
     107         182 :         php_hash_ops *hash_ops = (php_hash_ops *)ops;
     108             : 
     109         182 :         memcpy(dest_context, orig_context, hash_ops->context_size);
     110         182 :         return SUCCESS;
     111             : }
     112             : /* }}} */
     113             : 
     114             : /* Userspace */
     115             : 
     116        1234 : static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
     117             : {
     118             :         zend_string *digest;
     119             :         char *algo, *data;
     120             :         size_t algo_len, data_len;
     121        1234 :         zend_bool raw_output = raw_output_default;
     122             :         const php_hash_ops *ops;
     123             :         void *context;
     124        1234 :         php_stream *stream = NULL;
     125             : 
     126        1234 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
     127           0 :                 return;
     128             :         }
     129             : 
     130        1234 :         ops = php_hash_fetch_ops(algo, algo_len);
     131        1234 :         if (!ops) {
     132           2 :                 php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
     133           2 :                 RETURN_FALSE;
     134             :         }
     135        1232 :         if (isfilename) {
     136          27 :                 if (CHECK_NULL_PATH(data, data_len)) {
     137           0 :                         php_error_docref(NULL, E_WARNING, "Invalid path");
     138           0 :                         RETURN_FALSE;
     139             :                 }
     140          27 :                 stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
     141          27 :                 if (!stream) {
     142             :                         /* Stream will report errors opening file */
     143           1 :                         RETURN_FALSE;
     144             :                 }
     145             :         }
     146             : 
     147        1231 :         context = emalloc(ops->context_size);
     148        1231 :         ops->hash_init(context);
     149             : 
     150        1231 :         if (isfilename) {
     151             :                 char buf[1024];
     152             :                 size_t n;
     153             : 
     154          78 :                 while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     155          26 :                         ops->hash_update(context, (unsigned char *) buf, n);
     156             :                 }
     157          26 :                 php_stream_close(stream);
     158             :         } else {
     159        1205 :                 ops->hash_update(context, (unsigned char *) data, data_len);
     160             :         }
     161             : 
     162        2462 :         digest = zend_string_alloc(ops->digest_size, 0);
     163        1231 :         ops->hash_final((unsigned char *) ZSTR_VAL(digest), context);
     164        1231 :         efree(context);
     165             : 
     166        1231 :         if (raw_output) {
     167          16 :                 ZSTR_VAL(digest)[ops->digest_size] = 0;
     168          16 :                 RETURN_NEW_STR(digest);
     169             :         } else {
     170        2430 :                 zend_string *hex_digest = zend_string_safe_alloc(ops->digest_size, 2, 0, 0);
     171             : 
     172        1215 :                 php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), ops->digest_size);
     173        1215 :                 ZSTR_VAL(hex_digest)[2 * ops->digest_size] = 0;
     174             :                 zend_string_release_ex(digest, 0);
     175        1215 :                 RETURN_NEW_STR(hex_digest);
     176             :         }
     177             : }
     178             : /* }}} */
     179             : 
     180             : /* {{{ proto string hash(string algo, string data[, bool raw_output = false])
     181             : Generate a hash of a given input string
     182             : Returns lowercase hexits by default */
     183        1194 : PHP_FUNCTION(hash)
     184             : {
     185        1194 :         php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
     186        1194 : }
     187             : /* }}} */
     188             : 
     189             : /* {{{ proto string hash_file(string algo, string filename[, bool raw_output = false])
     190             : Generate a hash of a given file
     191             : Returns lowercase hexits by default */
     192          28 : PHP_FUNCTION(hash_file)
     193             : {
     194          28 :         php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
     195          28 : }
     196             : /* }}} */
     197             : 
     198         316 : static inline void php_hash_string_xor_char(unsigned char *out, const unsigned char *in, const unsigned char xor_with, const size_t length) {
     199             :         size_t i;
     200       24636 :         for (i=0; i < length; i++) {
     201       24320 :                 out[i] = in[i] ^ xor_with;
     202             :         }
     203         316 : }
     204             : 
     205       24570 : static inline void php_hash_string_xor(unsigned char *out, const unsigned char *in, const unsigned char *xor_with, const size_t length) {
     206             :         size_t i;
     207      663390 :         for (i=0; i < length; i++) {
     208      638820 :                 out[i] = in[i] ^ xor_with[i];
     209             :         }
     210       24570 : }
     211             : 
     212         158 : static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *ops, void *context, const unsigned char *key, const size_t key_len) {
     213         158 :         memset(K, 0, ops->block_size);
     214         158 :         if (key_len > ops->block_size) {
     215             :                 /* Reduce the key first */
     216           2 :                 ops->hash_init(context);
     217           2 :                 ops->hash_update(context, key, key_len);
     218           2 :                 ops->hash_final(K, context);
     219             :         } else {
     220         156 :                 memcpy(K, key, key_len);
     221             :         }
     222             :         /* XOR the key with 0x36 to get the ipad) */
     223         158 :         php_hash_string_xor_char(K, K, 0x36, ops->block_size);
     224         158 : }
     225             : 
     226       49380 : static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops *ops, void *context, const unsigned char *key, const unsigned char *data, const zend_long data_size) {
     227       49380 :         ops->hash_init(context);
     228       49380 :         ops->hash_update(context, key, ops->block_size);
     229       49380 :         ops->hash_update(context, data, data_size);
     230       49380 :         ops->hash_final(final, context);
     231       49380 : }
     232             : 
     233          42 : static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
     234             : {
     235             :         zend_string *digest;
     236             :         char *algo, *data, *key;
     237             :         unsigned char *K;
     238             :         size_t algo_len, data_len, key_len;
     239          42 :         zend_bool raw_output = raw_output_default;
     240             :         const php_hash_ops *ops;
     241             :         void *context;
     242          42 :         php_stream *stream = NULL;
     243             : 
     244          42 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|b", &algo, &algo_len, &data, &data_len,
     245             :                                                                                                                                   &key, &key_len, &raw_output) == FAILURE) {
     246           0 :                 return;
     247             :         }
     248             : 
     249          42 :         ops = php_hash_fetch_ops(algo, algo_len);
     250          42 :         if (!ops) {
     251           2 :                 php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
     252           2 :                 RETURN_FALSE;
     253             :         }
     254          40 :         else if (!ops->is_crypto) {
     255           2 :                 php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
     256           2 :                 RETURN_FALSE;
     257             :         }
     258             : 
     259          38 :         if (isfilename) {
     260          19 :                 if (CHECK_NULL_PATH(data, data_len)) {
     261           1 :                         php_error_docref(NULL, E_WARNING, "Invalid path");
     262           1 :                         RETURN_FALSE;
     263             :                 }
     264          18 :                 stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context));
     265          18 :                 if (!stream) {
     266             :                         /* Stream will report errors opening file */
     267           0 :                         RETURN_FALSE;
     268             :                 }
     269             :         }
     270             : 
     271          37 :         context = emalloc(ops->context_size);
     272             : 
     273          37 :         K = emalloc(ops->block_size);
     274          74 :         digest = zend_string_alloc(ops->digest_size, 0);
     275             : 
     276          37 :         php_hash_hmac_prep_key(K, ops, context, (unsigned char *) key, key_len);
     277             : 
     278          37 :         if (isfilename) {
     279             :                 char buf[1024];
     280             :                 size_t n;
     281          18 :                 ops->hash_init(context);
     282          18 :                 ops->hash_update(context, K, ops->block_size);
     283          54 :                 while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     284          18 :                         ops->hash_update(context, (unsigned char *) buf, n);
     285             :                 }
     286          18 :                 php_stream_close(stream);
     287          18 :                 ops->hash_final((unsigned char *) ZSTR_VAL(digest), context);
     288             :         } else {
     289          19 :                 php_hash_hmac_round((unsigned char *) ZSTR_VAL(digest), ops, context, K, (unsigned char *) data, data_len);
     290             :         }
     291             : 
     292          37 :         php_hash_string_xor_char(K, K, 0x6A, ops->block_size);
     293             : 
     294          37 :         php_hash_hmac_round((unsigned char *) ZSTR_VAL(digest), ops, context, K, (unsigned char *) ZSTR_VAL(digest), ops->digest_size);
     295             : 
     296             :         /* Zero the key */
     297          37 :         ZEND_SECURE_ZERO(K, ops->block_size);
     298          37 :         efree(K);
     299          37 :         efree(context);
     300             : 
     301          37 :         if (raw_output) {
     302           4 :                 ZSTR_VAL(digest)[ops->digest_size] = 0;
     303           4 :                 RETURN_NEW_STR(digest);
     304             :         } else {
     305          66 :                 zend_string *hex_digest = zend_string_safe_alloc(ops->digest_size, 2, 0, 0);
     306             : 
     307          33 :                 php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), ops->digest_size);
     308          33 :                 ZSTR_VAL(hex_digest)[2 * ops->digest_size] = 0;
     309             :                 zend_string_release_ex(digest, 0);
     310          33 :                 RETURN_NEW_STR(hex_digest);
     311             :         }
     312             : }
     313             : /* }}} */
     314             : 
     315             : /* {{{ proto string hash_hmac(string algo, string data, string key[, bool raw_output = false])
     316             : Generate a hash of a given input string with a key using HMAC
     317             : Returns lowercase hexits by default */
     318          21 : PHP_FUNCTION(hash_hmac)
     319             : {
     320          21 :         php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
     321          21 : }
     322             : /* }}} */
     323             : 
     324             : /* {{{ proto string hash_hmac_file(string algo, string filename, string key[, bool raw_output = false])
     325             : Generate a hash of a given file with a key using HMAC
     326             : Returns lowercase hexits by default */
     327          21 : PHP_FUNCTION(hash_hmac_file)
     328             : {
     329          21 :         php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
     330          21 : }
     331             : /* }}} */
     332             : 
     333             : /* {{{ proto HashContext hash_init(string algo[, int options, string key])
     334             : Initialize a hashing context */
     335         223 : PHP_FUNCTION(hash_init)
     336             : {
     337         223 :         zend_string *algo, *key = NULL;
     338         223 :         zend_long options = 0;
     339         223 :         int argc = ZEND_NUM_ARGS();
     340             :         void *context;
     341             :         const php_hash_ops *ops;
     342             :         php_hashcontext_object *hash;
     343             : 
     344         223 :         if (zend_parse_parameters(argc, "S|lS", &algo, &options, &key) == FAILURE) {
     345           4 :                 RETURN_NULL();
     346             :         }
     347             : 
     348         223 :         ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo));
     349         223 :         if (!ops) {
     350           1 :                 php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
     351           1 :                 RETURN_FALSE;
     352             :         }
     353             : 
     354         222 :         if (options & PHP_HASH_HMAC) {
     355           6 :                 if (!ops->is_crypto) {
     356           1 :                         php_error_docref(NULL, E_WARNING, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
     357           1 :                         RETURN_FALSE;
     358             :                 }
     359           5 :                 if (!key || (ZSTR_LEN(key) == 0)) {
     360             :                         /* Note: a zero length key is no key at all */
     361           2 :                         php_error_docref(NULL, E_WARNING, "HMAC requested without a key");
     362           2 :                         RETURN_FALSE;
     363             :                 }
     364             :         }
     365             : 
     366         219 :         object_init_ex(return_value, php_hashcontext_ce);
     367         219 :         hash = php_hashcontext_from_object(Z_OBJ_P(return_value));
     368             : 
     369         219 :         context = emalloc(ops->context_size);
     370         219 :         ops->hash_init(context);
     371             : 
     372         219 :         hash->ops = ops;
     373         219 :         hash->context = context;
     374         219 :         hash->options = options;
     375         219 :         hash->key = NULL;
     376             : 
     377         219 :         if (options & PHP_HASH_HMAC) {
     378           3 :                 char *K = emalloc(ops->block_size);
     379             :                 size_t i, block_size;
     380             : 
     381           3 :                 memset(K, 0, ops->block_size);
     382             : 
     383           3 :                 if (ZSTR_LEN(key) > ops->block_size) {
     384             :                         /* Reduce the key first */
     385           0 :                         ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key));
     386           0 :                         ops->hash_final((unsigned char *) K, context);
     387             :                         /* Make the context ready to start over */
     388           0 :                         ops->hash_init(context);
     389             :                 } else {
     390           3 :                         memcpy(K, ZSTR_VAL(key), ZSTR_LEN(key));
     391             :                 }
     392             : 
     393             :                 /* XOR ipad */
     394           3 :                 block_size = ops->block_size;
     395         195 :                 for(i = 0; i < block_size; i++) {
     396         192 :                         K[i] ^= 0x36;
     397             :                 }
     398           3 :                 ops->hash_update(context, (unsigned char *) K, ops->block_size);
     399           3 :                 hash->key = (unsigned char *) K;
     400             :         }
     401             : }
     402             : /* }}} */
     403             : 
     404             : #define PHP_HASHCONTEXT_VERIFY(func, hash) { \
     405             :         if (!hash->context) { \
     406             :                 php_error(E_WARNING, "%s(): supplied resource is not a valid Hash Context resource", func); \
     407             :                 RETURN_NULL(); \
     408             :         } \
     409             : }
     410             : 
     411             : /* {{{ proto bool hash_update(HashContext context, string data)
     412             : Pump data into the hashing algorithm */
     413         321 : PHP_FUNCTION(hash_update)
     414             : {
     415             :         zval *zhash;
     416             :         php_hashcontext_object *hash;
     417             :         zend_string *data;
     418             : 
     419         321 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &zhash, php_hashcontext_ce, &data) == FAILURE) {
     420           0 :                 return;
     421             :         }
     422             : 
     423         321 :         hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
     424         321 :         PHP_HASHCONTEXT_VERIFY("hash_update", hash);
     425         320 :         hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(data), ZSTR_LEN(data));
     426             : 
     427         320 :         RETURN_TRUE;
     428             : }
     429             : /* }}} */
     430             : 
     431             : /* {{{ proto int hash_update_stream(HashContext context, resource handle[, int length])
     432             : Pump data into the hashing algorithm from an open stream */
     433           1 : PHP_FUNCTION(hash_update_stream)
     434             : {
     435             :         zval *zhash, *zstream;
     436             :         php_hashcontext_object *hash;
     437           1 :         php_stream *stream = NULL;
     438           1 :         zend_long length = -1, didread = 0;
     439             : 
     440           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "Or|l", &zhash, php_hashcontext_ce, &zstream, &length) == FAILURE) {
     441           0 :                 return;
     442             :         }
     443             : 
     444           1 :         hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
     445           1 :         PHP_HASHCONTEXT_VERIFY("hash_update_stream", hash);
     446           1 :         php_stream_from_zval(stream, zstream);
     447             : 
     448           3 :         while (length) {
     449             :                 char buf[1024];
     450           2 :                 zend_long n, toread = 1024;
     451             : 
     452           2 :                 if (length > 0 && toread > length) {
     453           0 :                         toread = length;
     454             :                 }
     455             : 
     456           2 :                 if ((n = php_stream_read(stream, buf, toread)) <= 0) {
     457             :                         /* Nada mas */
     458           1 :                         RETURN_LONG(didread);
     459             :                 }
     460           1 :                 hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
     461           1 :                 length -= n;
     462           1 :                 didread += n;
     463             :         }
     464             : 
     465           0 :         RETURN_LONG(didread);
     466             : }
     467             : /* }}} */
     468             : 
     469             : /* {{{ proto bool hash_update_file(HashContext context, string filename[, resource context])
     470             : Pump data into the hashing algorithm from a file */
     471           1 : PHP_FUNCTION(hash_update_file)
     472             : {
     473           1 :         zval *zhash, *zcontext = NULL;
     474             :         php_hashcontext_object *hash;
     475             :         php_stream_context *context;
     476             :         php_stream *stream;
     477             :         zend_string *filename;
     478             :         char buf[1024];
     479             :         size_t n;
     480             : 
     481           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|r", &zhash, php_hashcontext_ce, &filename, &zcontext) == FAILURE) {
     482           0 :                 return;
     483             :         }
     484             : 
     485           1 :         hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
     486           1 :         PHP_HASHCONTEXT_VERIFY("hash_update_file", hash);
     487           1 :         context = php_stream_context_from_zval(zcontext, 0);
     488             : 
     489           1 :         stream = php_stream_open_wrapper_ex(ZSTR_VAL(filename), "rb", REPORT_ERRORS, NULL, context);
     490           1 :         if (!stream) {
     491             :                 /* Stream will report errors opening file */
     492           0 :                 RETURN_FALSE;
     493             :         }
     494             : 
     495           3 :         while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
     496           1 :                 hash->ops->hash_update(hash->context, (unsigned char *) buf, n);
     497             :         }
     498           1 :         php_stream_close(stream);
     499             : 
     500           1 :         RETURN_TRUE;
     501             : }
     502             : /* }}} */
     503             : 
     504             : /* {{{ proto string hash_final(HashContext context[, bool raw_output=false])
     505             : Output resulting digest */
     506         432 : PHP_FUNCTION(hash_final)
     507             : {
     508             :         zval *zhash;
     509             :         php_hashcontext_object *hash;
     510         432 :         zend_bool raw_output = 0;
     511             :         zend_string *digest;
     512             :         size_t digest_len;
     513             : 
     514         432 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &zhash, php_hashcontext_ce, &raw_output) == FAILURE) {
     515           0 :                 return;
     516             :         }
     517             : 
     518         432 :         hash = php_hashcontext_from_object(Z_OBJ_P(zhash));
     519         432 :         PHP_HASHCONTEXT_VERIFY("hash_final", hash);
     520             : 
     521         432 :         digest_len = hash->ops->digest_size;
     522         432 :         digest = zend_string_alloc(digest_len, 0);
     523         432 :         hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context);
     524         432 :         if (hash->options & PHP_HASH_HMAC) {
     525             :                 size_t i, block_size;
     526             : 
     527             :                 /* Convert K to opad -- 0x6A = 0x36 ^ 0x5C */
     528           5 :                 block_size = hash->ops->block_size;
     529         325 :                 for(i = 0; i < block_size; i++) {
     530         320 :                         hash->key[i] ^= 0x6A;
     531             :                 }
     532             : 
     533             :                 /* Feed this result into the outter hash */
     534           5 :                 hash->ops->hash_init(hash->context);
     535           5 :                 hash->ops->hash_update(hash->context, hash->key, hash->ops->block_size);
     536           5 :                 hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(digest), hash->ops->digest_size);
     537           5 :                 hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context);
     538             : 
     539             :                 /* Zero the key */
     540           5 :                 ZEND_SECURE_ZERO(hash->key, hash->ops->block_size);
     541           5 :                 efree(hash->key);
     542           5 :                 hash->key = NULL;
     543             :         }
     544         432 :         ZSTR_VAL(digest)[digest_len] = 0;
     545             : 
     546             :         /* Invalidate the object from further use */
     547         432 :         efree(hash->context);
     548         432 :         hash->context = NULL;
     549             : 
     550         432 :         if (raw_output) {
     551           0 :                 RETURN_NEW_STR(digest);
     552             :         } else {
     553         432 :                 zend_string *hex_digest = zend_string_safe_alloc(digest_len, 2, 0, 0);
     554             : 
     555         432 :                 php_hash_bin2hex(ZSTR_VAL(hex_digest), (unsigned char *) ZSTR_VAL(digest), digest_len);
     556         432 :                 ZSTR_VAL(hex_digest)[2 * digest_len] = 0;
     557             :                 zend_string_release_ex(digest, 0);
     558         432 :                 RETURN_NEW_STR(hex_digest);
     559             :         }
     560             : }
     561             : /* }}} */
     562             : 
     563             : /* {{{ proto HashContext hash_copy(HashContext context)
     564             : Copy hash object */
     565         108 : PHP_FUNCTION(hash_copy)
     566             : {
     567             :         zval *zhash;
     568             : 
     569         108 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zhash, php_hashcontext_ce) == FAILURE) {
     570           0 :                 return;
     571             :         }
     572             : 
     573         108 :         RETVAL_OBJ(Z_OBJ_HANDLER_P(zhash, clone_obj)(Z_OBJ_P(zhash)));
     574             : 
     575         108 :         if (php_hashcontext_from_object(Z_OBJ_P(return_value))->context == NULL) {
     576           0 :                 zval_ptr_dtor(return_value);
     577           0 :                 RETURN_FALSE;
     578             :         }
     579             : }
     580             : /* }}} */
     581             : 
     582             : /* {{{ proto array hash_algos(void)
     583             : Return a list of registered hashing algorithms */
     584           3 : PHP_FUNCTION(hash_algos)
     585             : {
     586             :         zend_string *str;
     587             : 
     588           3 :         array_init(return_value);
     589         321 :         ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) {
     590         159 :                 add_next_index_str(return_value, zend_string_copy(str));
     591             :         } ZEND_HASH_FOREACH_END();
     592           3 : }
     593             : /* }}} */
     594             : 
     595             : /* {{{ proto array hash_hmac_algos(void)
     596             : Return a list of registered hashing algorithms suitable for hash_hmac() */
     597           1 : PHP_FUNCTION(hash_hmac_algos)
     598             : {
     599             :         zend_string *str;
     600             :         const php_hash_ops *ops;
     601             : 
     602           1 :         array_init(return_value);
     603         107 :         ZEND_HASH_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) {
     604          53 :                 if (ops->is_crypto) {
     605          44 :                         add_next_index_str(return_value, zend_string_copy(str));
     606             :                 }
     607             :         } ZEND_HASH_FOREACH_END();
     608           1 : }
     609             : /* }}} */
     610             : 
     611             : /* {{{ proto string hash_hkdf(string algo, string ikm [, int length = 0, string info = '', string salt = ''])
     612             : RFC5869 HMAC-based key derivation function */
     613          60 : PHP_FUNCTION(hash_hkdf)
     614             : {
     615          60 :         zend_string *returnval, *ikm, *algo, *info = NULL, *salt = NULL;
     616          60 :         zend_long length = 0;
     617             :         unsigned char *prk, *digest, *K;
     618             :         size_t i;
     619             :         size_t rounds;
     620             :         const php_hash_ops *ops;
     621             :         void *context;
     622             : 
     623          60 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|lSS", &algo, &ikm, &length, &info, &salt) == FAILURE) {
     624           0 :                 return;
     625             :         }
     626             : 
     627          60 :         ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo));
     628          60 :         if (!ops) {
     629           1 :                 php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", ZSTR_VAL(algo));
     630           1 :                 RETURN_FALSE;
     631             :         }
     632             : 
     633          59 :         if (!ops->is_crypto) {
     634           9 :                 php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo));
     635           9 :                 RETURN_FALSE;
     636             :         }
     637             : 
     638          50 :         if (ZSTR_LEN(ikm) == 0) {
     639           1 :                 php_error_docref(NULL, E_WARNING, "Input keying material cannot be empty");
     640           1 :                 RETURN_FALSE;
     641             :         }
     642             : 
     643          49 :         if (length < 0) {
     644           1 :                 php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length);
     645           1 :                 RETURN_FALSE;
     646          48 :         } else if (length == 0) {
     647          37 :                 length = ops->digest_size;
     648          11 :         } else if (length > (zend_long) (ops->digest_size * 255)) {
     649           1 :                 php_error_docref(NULL, E_WARNING, "Length must be less than or equal to %zd: " ZEND_LONG_FMT, ops->digest_size * 255, length);
     650           1 :                 RETURN_FALSE;
     651             :         }
     652             : 
     653          47 :         context = emalloc(ops->context_size);
     654             : 
     655             :         // Extract
     656          47 :         ops->hash_init(context);
     657          47 :         K = emalloc(ops->block_size);
     658         106 :         php_hash_hmac_prep_key(K, ops, context,
     659         106 :                 (unsigned char *) (salt ? ZSTR_VAL(salt) : ""), salt ? ZSTR_LEN(salt) : 0);
     660             : 
     661          47 :         prk = emalloc(ops->digest_size);
     662          47 :         php_hash_hmac_round(prk, ops, context, K, (unsigned char *) ZSTR_VAL(ikm), ZSTR_LEN(ikm));
     663          47 :         php_hash_string_xor_char(K, K, 0x6A, ops->block_size);
     664          47 :         php_hash_hmac_round(prk, ops, context, K, prk, ops->digest_size);
     665          47 :         ZEND_SECURE_ZERO(K, ops->block_size);
     666             : 
     667             :         // Expand
     668          94 :         returnval = zend_string_alloc(length, 0);
     669          47 :         digest = emalloc(ops->digest_size);
     670         109 :         for (i = 1, rounds = (length - 1) / ops->digest_size + 1; i <= rounds; i++) {
     671             :                 // chr(i)
     672             :                 unsigned char c[1];
     673          62 :                 c[0] = (i & 0xFF);
     674             : 
     675          62 :                 php_hash_hmac_prep_key(K, ops, context, prk, ops->digest_size);
     676          62 :                 ops->hash_init(context);
     677          62 :                 ops->hash_update(context, K, ops->block_size);
     678             : 
     679          62 :                 if (i > 1) {
     680          15 :                         ops->hash_update(context, digest, ops->digest_size);
     681             :                 }
     682             : 
     683          62 :                 if (info != NULL && ZSTR_LEN(info) > 0) {
     684          13 :                         ops->hash_update(context, (unsigned char *) ZSTR_VAL(info), ZSTR_LEN(info));
     685             :                 }
     686             : 
     687          62 :                 ops->hash_update(context, c, 1);
     688          62 :                 ops->hash_final(digest, context);
     689          62 :                 php_hash_string_xor_char(K, K, 0x6A, ops->block_size);
     690          62 :                 php_hash_hmac_round(digest, ops, context, K, digest, ops->digest_size);
     691         171 :                 memcpy(
     692          62 :                         ZSTR_VAL(returnval) + ((i - 1) * ops->digest_size),
     693             :                         digest,
     694          47 :                         (i == rounds ? length - ((i - 1) * ops->digest_size) : ops->digest_size)
     695             :                 );
     696             :         }
     697             : 
     698          47 :         ZEND_SECURE_ZERO(K, ops->block_size);
     699          47 :         ZEND_SECURE_ZERO(digest, ops->digest_size);
     700          47 :         ZEND_SECURE_ZERO(prk, ops->digest_size);
     701          47 :         efree(K);
     702          47 :         efree(context);
     703          47 :         efree(prk);
     704          47 :         efree(digest);
     705          47 :         ZSTR_VAL(returnval)[length] = 0;
     706          94 :         RETURN_STR(returnval);
     707             : }
     708             : 
     709             : /* {{{ proto string hash_pbkdf2(string algo, string password, string salt, int iterations [, int length = 0, bool raw_output = false])
     710             : Generate a PBKDF2 hash of the given password and salt
     711             : Returns lowercase hexits by default */
     712          17 : PHP_FUNCTION(hash_pbkdf2)
     713             : {
     714             :         zend_string *returnval;
     715          17 :         char *algo, *salt, *pass = NULL;
     716          17 :         unsigned char *computed_salt, *digest, *temp, *result, *K1, *K2 = NULL;
     717          17 :         zend_long loops, i, j, iterations, digest_length = 0, length = 0;
     718          17 :         size_t algo_len, pass_len, salt_len = 0;
     719          17 :         zend_bool raw_output = 0;
     720             :         const php_hash_ops *ops;
     721             :         void *context;
     722             : 
     723          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "sssl|lb", &algo, &algo_len, &pass, &pass_len, &salt, &salt_len, &iterations, &length, &raw_output) == FAILURE) {
     724           0 :                 return;
     725             :         }
     726             : 
     727          17 :         ops = php_hash_fetch_ops(algo, algo_len);
     728          17 :         if (!ops) {
     729           1 :                 php_error_docref(NULL, E_WARNING, "Unknown hashing algorithm: %s", algo);
     730           1 :                 RETURN_FALSE;
     731             :         }
     732          16 :         else if (!ops->is_crypto) {
     733           1 :                 php_error_docref(NULL, E_WARNING, "Non-cryptographic hashing algorithm: %s", algo);
     734           1 :                 RETURN_FALSE;
     735             :         }
     736             : 
     737          15 :         if (iterations <= 0) {
     738           2 :                 php_error_docref(NULL, E_WARNING, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations);
     739           2 :                 RETURN_FALSE;
     740             :         }
     741             : 
     742          13 :         if (length < 0) {
     743           1 :                 php_error_docref(NULL, E_WARNING, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length);
     744           1 :                 RETURN_FALSE;
     745             :         }
     746             : 
     747          12 :         if (salt_len > INT_MAX - 4) {
     748           0 :                 php_error_docref(NULL, E_WARNING, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len);
     749           0 :                 RETURN_FALSE;
     750             :         }
     751             : 
     752          12 :         context = emalloc(ops->context_size);
     753          12 :         ops->hash_init(context);
     754             : 
     755          12 :         K1 = emalloc(ops->block_size);
     756          12 :         K2 = emalloc(ops->block_size);
     757          12 :         digest = emalloc(ops->digest_size);
     758          12 :         temp = emalloc(ops->digest_size);
     759             : 
     760             :         /* Setup Keys that will be used for all hmac rounds */
     761          12 :         php_hash_hmac_prep_key(K1, ops, context, (unsigned char *) pass, pass_len);
     762             :         /* Convert K1 to opad -- 0x6A = 0x36 ^ 0x5C */
     763          12 :         php_hash_string_xor_char(K2, K1, 0x6A, ops->block_size);
     764             : 
     765             :         /* Setup Main Loop to build a long enough result */
     766          12 :         if (length == 0) {
     767           4 :                 length = ops->digest_size;
     768           4 :                 if (!raw_output) {
     769           3 :                         length = length * 2;
     770             :                 }
     771             :         }
     772          12 :         digest_length = length;
     773          12 :         if (!raw_output) {
     774           7 :                 digest_length = (zend_long) ceil((float) length / 2.0);
     775             :         }
     776             : 
     777          12 :         loops = (zend_long) ceil((float) digest_length / (float) ops->digest_size);
     778             : 
     779          12 :         result = safe_emalloc(loops, ops->digest_size, 0);
     780             : 
     781          12 :         computed_salt = safe_emalloc(salt_len, 1, 4);
     782          12 :         memcpy(computed_salt, (unsigned char *) salt, salt_len);
     783             : 
     784          26 :         for (i = 1; i <= loops; i++) {
     785             :                 /* digest = hash_hmac(salt + pack('N', i), password) { */
     786             : 
     787             :                 /* pack("N", i) */
     788          14 :                 computed_salt[salt_len] = (unsigned char) (i >> 24);
     789          14 :                 computed_salt[salt_len + 1] = (unsigned char) ((i & 0xFF0000) >> 16);
     790          14 :                 computed_salt[salt_len + 2] = (unsigned char) ((i & 0xFF00) >> 8);
     791          14 :                 computed_salt[salt_len + 3] = (unsigned char) (i & 0xFF);
     792             : 
     793          14 :                 php_hash_hmac_round(digest, ops, context, K1, computed_salt, (zend_long) salt_len + 4);
     794          14 :                 php_hash_hmac_round(digest, ops, context, K2, digest, ops->digest_size);
     795             :                 /* } */
     796             : 
     797             :                 /* temp = digest */
     798          14 :                 memcpy(temp, digest, ops->digest_size);
     799             : 
     800             :                 /*
     801             :                  * Note that the loop starting at 1 is intentional, since we've already done
     802             :                  * the first round of the algorithm.
     803             :                  */
     804       24584 :                 for (j = 1; j < iterations; j++) {
     805             :                         /* digest = hash_hmac(digest, password) { */
     806       24570 :                         php_hash_hmac_round(digest, ops, context, K1, digest, ops->digest_size);
     807       24570 :                         php_hash_hmac_round(digest, ops, context, K2, digest, ops->digest_size);
     808             :                         /* } */
     809             :                         /* temp ^= digest */
     810       24570 :                         php_hash_string_xor(temp, temp, digest, ops->digest_size);
     811             :                 }
     812             :                 /* result += temp */
     813          14 :                 memcpy(result + ((i - 1) * ops->digest_size), temp, ops->digest_size);
     814             :         }
     815             :         /* Zero potentially sensitive variables */
     816          12 :         ZEND_SECURE_ZERO(K1, ops->block_size);
     817          12 :         ZEND_SECURE_ZERO(K2, ops->block_size);
     818          12 :         ZEND_SECURE_ZERO(computed_salt, salt_len + 4);
     819          12 :         efree(K1);
     820          12 :         efree(K2);
     821          12 :         efree(computed_salt);
     822          12 :         efree(context);
     823          12 :         efree(digest);
     824          12 :         efree(temp);
     825             : 
     826          24 :         returnval = zend_string_alloc(length, 0);
     827          12 :         if (raw_output) {
     828           5 :                 memcpy(ZSTR_VAL(returnval), result, length);
     829             :         } else {
     830           7 :                 php_hash_bin2hex(ZSTR_VAL(returnval), result, digest_length);
     831             :         }
     832          12 :         ZSTR_VAL(returnval)[length] = 0;
     833          12 :         efree(result);
     834          12 :         RETURN_NEW_STR(returnval);
     835             : }
     836             : /* }}} */
     837             : 
     838             : /* {{{ proto bool hash_equals(string known_string, string user_string)
     839             :    Compares two strings using the same time whether they're equal or not.
     840             :    A difference in length will leak */
     841          13 : PHP_FUNCTION(hash_equals)
     842             : {
     843             :         zval *known_zval, *user_zval;
     844             :         char *known_str, *user_str;
     845          13 :         int result = 0;
     846             :         size_t j;
     847             : 
     848          13 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &known_zval, &user_zval) == FAILURE) {
     849           0 :                 return;
     850             :         }
     851             : 
     852             :         /* We only allow comparing string to prevent unexpected results. */
     853          26 :         if (Z_TYPE_P(known_zval) != IS_STRING) {
     854           5 :                 php_error_docref(NULL, E_WARNING, "Expected known_string to be a string, %s given", zend_zval_type_name(known_zval));
     855           5 :                 RETURN_FALSE;
     856             :         }
     857             : 
     858          16 :         if (Z_TYPE_P(user_zval) != IS_STRING) {
     859           1 :                 php_error_docref(NULL, E_WARNING, "Expected user_string to be a string, %s given", zend_zval_type_name(user_zval));
     860           1 :                 RETURN_FALSE;
     861             :         }
     862             : 
     863           7 :         if (Z_STRLEN_P(known_zval) != Z_STRLEN_P(user_zval)) {
     864           4 :                 RETURN_FALSE;
     865             :         }
     866             : 
     867           3 :         known_str = Z_STRVAL_P(known_zval);
     868           3 :         user_str = Z_STRVAL_P(user_zval);
     869             : 
     870             :         /* This is security sensitive code. Do not optimize this for speed. */
     871          15 :         for (j = 0; j < Z_STRLEN_P(known_zval); j++) {
     872          12 :                 result |= known_str[j] ^ user_str[j];
     873             :         }
     874             : 
     875           3 :         RETURN_BOOL(0 == result);
     876             : }
     877             : /* }}} */
     878             : 
     879             : /* {{{ proto HashContext::__construct() */
     880           0 : static PHP_METHOD(HashContext, __construct) {
     881             :         /* Normally unreachable as private/final */
     882           0 :         zend_throw_exception(zend_ce_error, "Illegal call to private/final constructor", 0);
     883           0 : }
     884             : /* }}} */
     885             : 
     886             : static const zend_function_entry php_hashcontext_methods[] = {
     887             :         PHP_ME(HashContext, __construct, NULL, ZEND_ACC_PRIVATE)
     888             :         PHP_FE_END
     889             : };
     890             : 
     891             : /* Module Housekeeping */
     892             : 
     893             : #define PHP_HASH_HAVAL_REGISTER(p,b)    php_hash_register_algo("haval" #b "," #p , &php_hash_##p##haval##b##_ops);
     894             : 
     895             : #ifdef PHP_MHASH_BC
     896             : 
     897             : #if 0
     898             : /* See #69823, we should not insert module into module_registry while doing startup */
     899             : 
     900             : PHP_MINFO_FUNCTION(mhash)
     901             : {
     902             :         php_info_print_table_start();
     903             :         php_info_print_table_row(2, "MHASH support", "Enabled");
     904             :         php_info_print_table_row(2, "MHASH API Version", "Emulated Support");
     905             :         php_info_print_table_end();
     906             : }
     907             : 
     908             : zend_module_entry mhash_module_entry = {
     909             :         STANDARD_MODULE_HEADER,
     910             :         "mhash",
     911             :         NULL,
     912             :         NULL,
     913             :         NULL,
     914             :         NULL,
     915             :         NULL,
     916             :         PHP_MINFO(mhash),
     917             :         PHP_MHASH_VERSION,
     918             :         STANDARD_MODULE_PROPERTIES,
     919             : };
     920             : #endif
     921             : 
     922       23043 : static void mhash_init(INIT_FUNC_ARGS)
     923             : {
     924             :         char buf[128];
     925             :         int len;
     926       23043 :         int algo_number = 0;
     927             : 
     928      829548 :         for (algo_number = 0; algo_number < MHASH_NUM_ALGOS; algo_number++) {
     929      806505 :                 struct mhash_bc_entry algorithm = mhash_to_hash[algo_number];
     930      806505 :                 if (algorithm.mhash_name == NULL) {
     931       69129 :                         continue;
     932             :                 }
     933             : 
     934      737376 :                 len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name);
     935      737376 :                 zend_register_long_constant(buf, len, algorithm.value, CONST_CS | CONST_PERSISTENT, module_number);
     936             :         }
     937             : 
     938             :         /* TODO: this cause #69823 zend_register_internal_module(&mhash_module_entry); */
     939       23043 : }
     940             : 
     941             : /* {{{ proto string mhash(int hash, string data [, string key])
     942             :    Hash data with hash */
     943          12 : PHP_FUNCTION(mhash)
     944             : {
     945             :         zval *z_algorithm;
     946             :         zend_long algorithm;
     947             : 
     948          12 :         if (zend_parse_parameters(1, "z", &z_algorithm) == FAILURE) {
     949           0 :                 return;
     950             :         }
     951             : 
     952          24 :         algorithm = zval_get_long(z_algorithm);
     953             : 
     954             :         /* need to convert the first parameter from int constant to string algorithm name */
     955          12 :         if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
     956          12 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     957          12 :                 if (algorithm_lookup.hash_name) {
     958          24 :                         ZVAL_STRING(z_algorithm, algorithm_lookup.hash_name);
     959             :                 }
     960             :         }
     961             : 
     962          12 :         if (ZEND_NUM_ARGS() == 3) {
     963           0 :                 php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
     964          12 :         } else if (ZEND_NUM_ARGS() == 2) {
     965          12 :                 php_hash_do_hash(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
     966             :         } else {
     967           0 :                 WRONG_PARAM_COUNT;
     968             :         }
     969             : }
     970             : /* }}} */
     971             : 
     972             : /* {{{ proto string mhash_get_hash_name(int hash)
     973             :    Gets the name of hash */
     974          35 : PHP_FUNCTION(mhash_get_hash_name)
     975             : {
     976             :         zend_long algorithm;
     977             : 
     978          35 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &algorithm) == FAILURE) {
     979           0 :                 return;
     980             :         }
     981             : 
     982          35 :         if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
     983          35 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
     984          35 :                 if (algorithm_lookup.mhash_name) {
     985          64 :                         RETURN_STRING(algorithm_lookup.mhash_name);
     986             :                 }
     987             :         }
     988           3 :         RETURN_FALSE;
     989             : }
     990             : /* }}} */
     991             : 
     992             : /* {{{ proto int mhash_count(void)
     993             :    Gets the number of available hashes */
     994           1 : PHP_FUNCTION(mhash_count)
     995             : {
     996           1 :         if (zend_parse_parameters_none() == FAILURE) {
     997           0 :                 return;
     998             :         }
     999           1 :         RETURN_LONG(MHASH_NUM_ALGOS - 1);
    1000             : }
    1001             : /* }}} */
    1002             : 
    1003             : /* {{{ proto int mhash_get_block_size(int hash)
    1004             :    Gets the block size of hash */
    1005          17 : PHP_FUNCTION(mhash_get_block_size)
    1006             : {
    1007             :         zend_long algorithm;
    1008             : 
    1009          17 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &algorithm) == FAILURE) {
    1010           0 :                 return;
    1011             :         }
    1012          17 :         RETVAL_FALSE;
    1013             : 
    1014          17 :         if (algorithm >= 0 && algorithm  < MHASH_NUM_ALGOS) {
    1015          17 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
    1016          17 :                 if (algorithm_lookup.mhash_name) {
    1017          17 :                         const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name));
    1018          17 :                         if (ops) {
    1019          17 :                                 RETVAL_LONG(ops->digest_size);
    1020             :                         }
    1021             :                 }
    1022             :         }
    1023             : }
    1024             : /* }}} */
    1025             : 
    1026             : #define SALT_SIZE 8
    1027             : 
    1028             : /* {{{ proto string mhash_keygen_s2k(int hash, string input_password, string salt, int bytes)
    1029             :    Generates a key using hash functions */
    1030          11 : PHP_FUNCTION(mhash_keygen_s2k)
    1031             : {
    1032             :         zend_long algorithm, l_bytes;
    1033             :         int bytes;
    1034             :         char *password, *salt;
    1035             :         size_t password_len, salt_len;
    1036             :         char padded_salt[SALT_SIZE];
    1037             : 
    1038          11 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "lssl", &algorithm, &password, &password_len, &salt, &salt_len, &l_bytes) == FAILURE) {
    1039           0 :                 return;
    1040             :         }
    1041             : 
    1042          11 :         bytes = (int)l_bytes;
    1043          11 :         if (bytes <= 0){
    1044           0 :                 php_error_docref(NULL, E_WARNING, "the byte parameter must be greater than 0");
    1045           0 :                 RETURN_FALSE;
    1046             :         }
    1047             : 
    1048          11 :         salt_len = MIN(salt_len, SALT_SIZE);
    1049             : 
    1050          11 :         memcpy(padded_salt, salt, salt_len);
    1051          11 :         if (salt_len < SALT_SIZE) {
    1052           0 :                 memset(padded_salt + salt_len, 0, SALT_SIZE - salt_len);
    1053             :         }
    1054          11 :         salt_len = SALT_SIZE;
    1055             : 
    1056          11 :         RETVAL_FALSE;
    1057          11 :         if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
    1058          11 :                 struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
    1059          11 :                 if (algorithm_lookup.mhash_name) {
    1060          11 :                         const php_hash_ops *ops = php_hash_fetch_ops(algorithm_lookup.hash_name, strlen(algorithm_lookup.hash_name));
    1061          11 :                         if (ops) {
    1062          11 :                                 unsigned char null = '\0';
    1063             :                                 void *context;
    1064             :                                 char *key, *digest;
    1065          11 :                                 int i = 0, j = 0;
    1066          11 :                                 size_t block_size = ops->digest_size;
    1067          11 :                                 size_t times = bytes / block_size;
    1068             : 
    1069          11 :                                 if ((bytes % block_size) != 0) {
    1070           6 :                                         times++;
    1071             :                                 }
    1072             : 
    1073          11 :                                 context = emalloc(ops->context_size);
    1074          11 :                                 ops->hash_init(context);
    1075             : 
    1076          11 :                                 key = ecalloc(1, times * block_size);
    1077          11 :                                 digest = emalloc(ops->digest_size + 1);
    1078             : 
    1079         105 :                                 for (i = 0; i < times; i++) {
    1080          94 :                                         ops->hash_init(context);
    1081             : 
    1082         783 :                                         for (j=0;j<i;j++) {
    1083         689 :                                                 ops->hash_update(context, &null, 1);
    1084             :                                         }
    1085          94 :                                         ops->hash_update(context, (unsigned char *)padded_salt, salt_len);
    1086          94 :                                         ops->hash_update(context, (unsigned char *)password, password_len);
    1087          94 :                                         ops->hash_final((unsigned char *)digest, context);
    1088          94 :                                         memcpy( &key[i*block_size], digest, block_size);
    1089             :                                 }
    1090             : 
    1091          22 :                                 RETVAL_STRINGL(key, bytes);
    1092          11 :                                 ZEND_SECURE_ZERO(key, bytes);
    1093          11 :                                 efree(digest);
    1094          11 :                                 efree(context);
    1095          11 :                                 efree(key);
    1096             :                         }
    1097             :                 }
    1098             :         }
    1099             : }
    1100             : /* }}} */
    1101             : 
    1102             : #endif
    1103             : 
    1104             : /* ----------------------------------------------------------------------- */
    1105             : 
    1106             : /* {{{ php_hashcontext_create */
    1107         434 : static zend_object* php_hashcontext_create(zend_class_entry *ce) {
    1108         434 :         php_hashcontext_object *objval = zend_object_alloc(sizeof(php_hashcontext_object), ce);
    1109         434 :         zend_object *zobj = &objval->std;
    1110             : 
    1111         434 :         zend_object_std_init(zobj, ce);
    1112         434 :         object_properties_init(zobj, ce);
    1113         434 :         zobj->handlers = &php_hashcontext_handlers;
    1114             : 
    1115         434 :         return zobj;
    1116             : }
    1117             : /* }}} */
    1118             : 
    1119             : /* {{{ php_hashcontext_dtor */
    1120         434 : static void php_hashcontext_dtor(zend_object *obj) {
    1121         434 :         php_hashcontext_object *hash = php_hashcontext_from_object(obj);
    1122             : 
    1123             :         /* Just in case the algo has internally allocated resources */
    1124         434 :         if (hash->context) {
    1125           1 :                 unsigned char *dummy = emalloc(hash->ops->digest_size);
    1126           1 :                 hash->ops->hash_final(dummy, hash->context);
    1127           1 :                 efree(dummy);
    1128           1 :                 efree(hash->context);
    1129           1 :                 hash->context = NULL;
    1130             :         }
    1131             : 
    1132         434 :         if (hash->key) {
    1133         212 :                 ZEND_SECURE_ZERO(hash->key, hash->ops->block_size);
    1134         212 :                 efree(hash->key);
    1135         212 :                 hash->key = NULL;
    1136             :         }
    1137         434 : }
    1138             : /* }}} */
    1139             : 
    1140             : /* {{{ php_hashcontext_clone */
    1141         214 : static zend_object *php_hashcontext_clone(zend_object *zobj) {
    1142         214 :         php_hashcontext_object *oldobj = php_hashcontext_from_object(zobj);
    1143         214 :         zend_object *znew = php_hashcontext_create(zobj->ce);
    1144         214 :         php_hashcontext_object *newobj = php_hashcontext_from_object(znew);
    1145             : 
    1146         214 :         zend_objects_clone_members(znew, zobj);
    1147             : 
    1148         214 :         newobj->ops = oldobj->ops;
    1149         214 :         newobj->options = oldobj->options;
    1150         214 :         newobj->context = emalloc(newobj->ops->context_size);
    1151         214 :         newobj->ops->hash_init(newobj->context);
    1152             : 
    1153         214 :         if (SUCCESS != newobj->ops->hash_copy(newobj->ops, oldobj->context, newobj->context)) {
    1154           0 :                 efree(newobj->context);
    1155           0 :                 newobj->context = NULL;
    1156           0 :                 return znew;
    1157             :         }
    1158             : 
    1159         214 :         newobj->key = ecalloc(1, newobj->ops->block_size);
    1160         214 :         if (oldobj->key) {
    1161           2 :                 memcpy(newobj->key, oldobj->key, newobj->ops->block_size);
    1162             :         }
    1163             : 
    1164         214 :         return znew;
    1165             : }
    1166             : /* }}} */
    1167             : 
    1168             : /* {{{ PHP_MINIT_FUNCTION
    1169             :  */
    1170       23043 : PHP_MINIT_FUNCTION(hash)
    1171             : {
    1172             :         zend_class_entry ce;
    1173             : 
    1174       23043 :         zend_hash_init(&php_hash_hashtable, 35, NULL, NULL, 1);
    1175             : 
    1176       23043 :         php_hash_register_algo("md2",                 &php_hash_md2_ops);
    1177       23043 :         php_hash_register_algo("md4",                 &php_hash_md4_ops);
    1178       23043 :         php_hash_register_algo("md5",                 &php_hash_md5_ops);
    1179       23043 :         php_hash_register_algo("sha1",                        &php_hash_sha1_ops);
    1180       23043 :         php_hash_register_algo("sha224",              &php_hash_sha224_ops);
    1181       23043 :         php_hash_register_algo("sha256",              &php_hash_sha256_ops);
    1182       23043 :         php_hash_register_algo("sha384",              &php_hash_sha384_ops);
    1183       23043 :         php_hash_register_algo("sha512/224",            &php_hash_sha512_224_ops);
    1184       23043 :         php_hash_register_algo("sha512/256",            &php_hash_sha512_256_ops);
    1185       23043 :         php_hash_register_algo("sha512",              &php_hash_sha512_ops);
    1186       23043 :         php_hash_register_algo("sha3-224",            &php_hash_sha3_224_ops);
    1187       23043 :         php_hash_register_algo("sha3-256",            &php_hash_sha3_256_ops);
    1188       23043 :         php_hash_register_algo("sha3-384",            &php_hash_sha3_384_ops);
    1189       23043 :         php_hash_register_algo("sha3-512",            &php_hash_sha3_512_ops);
    1190       23043 :         php_hash_register_algo("ripemd128",           &php_hash_ripemd128_ops);
    1191       23043 :         php_hash_register_algo("ripemd160",           &php_hash_ripemd160_ops);
    1192       23043 :         php_hash_register_algo("ripemd256",           &php_hash_ripemd256_ops);
    1193       23043 :         php_hash_register_algo("ripemd320",           &php_hash_ripemd320_ops);
    1194       23043 :         php_hash_register_algo("whirlpool",           &php_hash_whirlpool_ops);
    1195       23043 :         php_hash_register_algo("tiger128,3",  &php_hash_3tiger128_ops);
    1196       23043 :         php_hash_register_algo("tiger160,3",  &php_hash_3tiger160_ops);
    1197       23043 :         php_hash_register_algo("tiger192,3",  &php_hash_3tiger192_ops);
    1198       23043 :         php_hash_register_algo("tiger128,4",  &php_hash_4tiger128_ops);
    1199       23043 :         php_hash_register_algo("tiger160,4",  &php_hash_4tiger160_ops);
    1200       23043 :         php_hash_register_algo("tiger192,4",  &php_hash_4tiger192_ops);
    1201       23043 :         php_hash_register_algo("snefru",              &php_hash_snefru_ops);
    1202       23043 :         php_hash_register_algo("snefru256",           &php_hash_snefru_ops);
    1203       23043 :         php_hash_register_algo("gost",                        &php_hash_gost_ops);
    1204       23043 :         php_hash_register_algo("gost-crypto",         &php_hash_gost_crypto_ops);
    1205       23043 :         php_hash_register_algo("adler32",             &php_hash_adler32_ops);
    1206       23043 :         php_hash_register_algo("crc32",                       &php_hash_crc32_ops);
    1207       23043 :         php_hash_register_algo("crc32b",              &php_hash_crc32b_ops);
    1208       23043 :         php_hash_register_algo("crc32c",              &php_hash_crc32c_ops);
    1209       23043 :         php_hash_register_algo("fnv132",              &php_hash_fnv132_ops);
    1210       23043 :         php_hash_register_algo("fnv1a32",             &php_hash_fnv1a32_ops);
    1211       23043 :         php_hash_register_algo("fnv164",              &php_hash_fnv164_ops);
    1212       23043 :         php_hash_register_algo("fnv1a64",             &php_hash_fnv1a64_ops);
    1213       23043 :         php_hash_register_algo("joaat",                       &php_hash_joaat_ops);
    1214             : 
    1215       23043 :         PHP_HASH_HAVAL_REGISTER(3,128);
    1216       23043 :         PHP_HASH_HAVAL_REGISTER(3,160);
    1217       23043 :         PHP_HASH_HAVAL_REGISTER(3,192);
    1218       23043 :         PHP_HASH_HAVAL_REGISTER(3,224);
    1219       23043 :         PHP_HASH_HAVAL_REGISTER(3,256);
    1220             : 
    1221       23043 :         PHP_HASH_HAVAL_REGISTER(4,128);
    1222       23043 :         PHP_HASH_HAVAL_REGISTER(4,160);
    1223       23043 :         PHP_HASH_HAVAL_REGISTER(4,192);
    1224       23043 :         PHP_HASH_HAVAL_REGISTER(4,224);
    1225       23043 :         PHP_HASH_HAVAL_REGISTER(4,256);
    1226             : 
    1227       23043 :         PHP_HASH_HAVAL_REGISTER(5,128);
    1228       23043 :         PHP_HASH_HAVAL_REGISTER(5,160);
    1229       23043 :         PHP_HASH_HAVAL_REGISTER(5,192);
    1230       23043 :         PHP_HASH_HAVAL_REGISTER(5,224);
    1231       23043 :         PHP_HASH_HAVAL_REGISTER(5,256);
    1232             : 
    1233       23043 :         REGISTER_LONG_CONSTANT("HASH_HMAC",           PHP_HASH_HMAC,  CONST_CS | CONST_PERSISTENT);
    1234             : 
    1235       23043 :         INIT_CLASS_ENTRY(ce, "HashContext", php_hashcontext_methods);
    1236       23043 :         php_hashcontext_ce = zend_register_internal_class(&ce);
    1237       23043 :         php_hashcontext_ce->ce_flags |= ZEND_ACC_FINAL;
    1238       23043 :         php_hashcontext_ce->create_object = php_hashcontext_create;
    1239       23043 :         php_hashcontext_ce->serialize = zend_class_serialize_deny;
    1240       23043 :         php_hashcontext_ce->unserialize = zend_class_unserialize_deny;
    1241             : 
    1242       23043 :         memcpy(&php_hashcontext_handlers, &std_object_handlers,
    1243             :                sizeof(zend_object_handlers));
    1244       23043 :         php_hashcontext_handlers.offset = XtOffsetOf(php_hashcontext_object, std);
    1245       23043 :         php_hashcontext_handlers.dtor_obj = php_hashcontext_dtor;
    1246       23043 :         php_hashcontext_handlers.clone_obj = php_hashcontext_clone;
    1247             : 
    1248             : #ifdef PHP_MHASH_BC
    1249       23043 :         mhash_init(INIT_FUNC_ARGS_PASSTHRU);
    1250             : #endif
    1251             : 
    1252       23043 :         return SUCCESS;
    1253             : }
    1254             : /* }}} */
    1255             : 
    1256             : /* {{{ PHP_MSHUTDOWN_FUNCTION
    1257             :  */
    1258       23105 : PHP_MSHUTDOWN_FUNCTION(hash)
    1259             : {
    1260       23105 :         zend_hash_destroy(&php_hash_hashtable);
    1261             : 
    1262       23105 :         return SUCCESS;
    1263             : }
    1264             : /* }}} */
    1265             : 
    1266             : /* {{{ PHP_MINFO_FUNCTION
    1267             :  */
    1268         146 : PHP_MINFO_FUNCTION(hash)
    1269             : {
    1270             :         char buffer[2048];
    1271             :         zend_string *str;
    1272         146 :         char *s = buffer, *e = s + sizeof(buffer);
    1273             : 
    1274       15622 :         ZEND_HASH_FOREACH_STR_KEY(&php_hash_hashtable, str) {
    1275        7738 :                 s += slprintf(s, e - s, "%s ", ZSTR_VAL(str));
    1276             :         } ZEND_HASH_FOREACH_END();
    1277         146 :         *s = 0;
    1278             : 
    1279         146 :         php_info_print_table_start();
    1280         146 :         php_info_print_table_row(2, "hash support", "enabled");
    1281         146 :         php_info_print_table_row(2, "Hashing Engines", buffer);
    1282         146 :         php_info_print_table_end();
    1283             : 
    1284             : #ifdef PHP_MHASH_BC
    1285         146 :         php_info_print_table_start();
    1286         146 :         php_info_print_table_row(2, "MHASH support", "Enabled");
    1287         146 :         php_info_print_table_row(2, "MHASH API Version", "Emulated Support");
    1288         146 :         php_info_print_table_end();
    1289             : #endif
    1290             : 
    1291         146 : }
    1292             : /* }}} */
    1293             : 
    1294             : /* {{{ arginfo */
    1295             : #ifdef PHP_HASH_MD5_NOT_IN_CORE
    1296             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5, 0, 0, 1)
    1297             :         ZEND_ARG_INFO(0, str)
    1298             :         ZEND_ARG_INFO(0, raw_output)
    1299             : ZEND_END_ARG_INFO()
    1300             : 
    1301             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5_file, 0, 0, 1)
    1302             :         ZEND_ARG_INFO(0, filename)
    1303             :         ZEND_ARG_INFO(0, raw_output)
    1304             : ZEND_END_ARG_INFO()
    1305             : #endif
    1306             : 
    1307             : #ifdef PHP_HASH_SHA1_NOT_IN_CORE
    1308             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1, 0, 0, 1)
    1309             :         ZEND_ARG_INFO(0, str)
    1310             :         ZEND_ARG_INFO(0, raw_output)
    1311             : ZEND_END_ARG_INFO()
    1312             : 
    1313             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1_file, 0, 0, 1)
    1314             :         ZEND_ARG_INFO(0, filename)
    1315             :         ZEND_ARG_INFO(0, raw_output)
    1316             : ZEND_END_ARG_INFO()
    1317             : #endif
    1318             : 
    1319             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash, 0, 0, 2)
    1320             :         ZEND_ARG_INFO(0, algo)
    1321             :         ZEND_ARG_INFO(0, data)
    1322             :         ZEND_ARG_INFO(0, raw_output)
    1323             : ZEND_END_ARG_INFO()
    1324             : 
    1325             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_file, 0, 0, 2)
    1326             :         ZEND_ARG_INFO(0, algo)
    1327             :         ZEND_ARG_INFO(0, filename)
    1328             :         ZEND_ARG_INFO(0, raw_output)
    1329             : ZEND_END_ARG_INFO()
    1330             : 
    1331             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_hmac, 0, 0, 3)
    1332             :         ZEND_ARG_INFO(0, algo)
    1333             :         ZEND_ARG_INFO(0, data)
    1334             :         ZEND_ARG_INFO(0, key)
    1335             :         ZEND_ARG_INFO(0, raw_output)
    1336             : ZEND_END_ARG_INFO()
    1337             : 
    1338             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_hmac_file, 0, 0, 3)
    1339             :         ZEND_ARG_INFO(0, algo)
    1340             :         ZEND_ARG_INFO(0, filename)
    1341             :         ZEND_ARG_INFO(0, key)
    1342             :         ZEND_ARG_INFO(0, raw_output)
    1343             : ZEND_END_ARG_INFO()
    1344             : 
    1345             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_init, 0, 0, 1)
    1346             :         ZEND_ARG_INFO(0, algo)
    1347             :         ZEND_ARG_INFO(0, options)
    1348             :         ZEND_ARG_INFO(0, key)
    1349             : ZEND_END_ARG_INFO()
    1350             : 
    1351             : ZEND_BEGIN_ARG_INFO(arginfo_hash_update, 0)
    1352             :         ZEND_ARG_INFO(0, context)
    1353             :         ZEND_ARG_INFO(0, data)
    1354             : ZEND_END_ARG_INFO()
    1355             : 
    1356             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_update_stream, 0, 0, 2)
    1357             :         ZEND_ARG_INFO(0, context)
    1358             :         ZEND_ARG_INFO(0, handle)
    1359             :         ZEND_ARG_INFO(0, length)
    1360             : ZEND_END_ARG_INFO()
    1361             : 
    1362             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_update_file, 0, 0, 2)
    1363             :         ZEND_ARG_INFO(0, context)
    1364             :         ZEND_ARG_INFO(0, filename)
    1365             :         ZEND_ARG_INFO(0, stream_context)
    1366             : ZEND_END_ARG_INFO()
    1367             : 
    1368             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_final, 0, 0, 1)
    1369             :         ZEND_ARG_INFO(0, context)
    1370             :         ZEND_ARG_INFO(0, raw_output)
    1371             : ZEND_END_ARG_INFO()
    1372             : 
    1373             : ZEND_BEGIN_ARG_INFO(arginfo_hash_copy, 0)
    1374             :         ZEND_ARG_INFO(0, context)
    1375             : ZEND_END_ARG_INFO()
    1376             : 
    1377             : ZEND_BEGIN_ARG_INFO(arginfo_hash_algos, 0)
    1378             : ZEND_END_ARG_INFO()
    1379             : 
    1380             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_pbkdf2, 0, 0, 4)
    1381             :         ZEND_ARG_INFO(0, algo)
    1382             :         ZEND_ARG_INFO(0, password)
    1383             :         ZEND_ARG_INFO(0, salt)
    1384             :         ZEND_ARG_INFO(0, iterations)
    1385             :         ZEND_ARG_INFO(0, length)
    1386             :         ZEND_ARG_INFO(0, raw_output)
    1387             : ZEND_END_ARG_INFO()
    1388             : 
    1389             : ZEND_BEGIN_ARG_INFO(arginfo_hash_equals, 0)
    1390             :         ZEND_ARG_INFO(0, known_string)
    1391             :         ZEND_ARG_INFO(0, user_string)
    1392             : ZEND_END_ARG_INFO()
    1393             : 
    1394             : ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_hkdf, 0, 0, 2)
    1395             :         ZEND_ARG_INFO(0, ikm)
    1396             :         ZEND_ARG_INFO(0, algo)
    1397             :         ZEND_ARG_INFO(0, length)
    1398             :         ZEND_ARG_INFO(0, string)
    1399             :         ZEND_ARG_INFO(0, salt)
    1400             : ZEND_END_ARG_INFO()
    1401             : 
    1402             : /* BC Land */
    1403             : #ifdef PHP_MHASH_BC
    1404             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_block_size, 0)
    1405             :         ZEND_ARG_INFO(0, hash)
    1406             : ZEND_END_ARG_INFO()
    1407             : 
    1408             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_get_hash_name, 0)
    1409             :         ZEND_ARG_INFO(0, hash)
    1410             : ZEND_END_ARG_INFO()
    1411             : 
    1412             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_keygen_s2k, 0)
    1413             :         ZEND_ARG_INFO(0, hash)
    1414             :         ZEND_ARG_INFO(0, input_password)
    1415             :         ZEND_ARG_INFO(0, salt)
    1416             :         ZEND_ARG_INFO(0, bytes)
    1417             : ZEND_END_ARG_INFO()
    1418             : 
    1419             : ZEND_BEGIN_ARG_INFO(arginfo_mhash_count, 0)
    1420             : ZEND_END_ARG_INFO()
    1421             : 
    1422             : ZEND_BEGIN_ARG_INFO_EX(arginfo_mhash, 0, 0, 2)
    1423             :         ZEND_ARG_INFO(0, hash)
    1424             :         ZEND_ARG_INFO(0, data)
    1425             :         ZEND_ARG_INFO(0, key)
    1426             : ZEND_END_ARG_INFO()
    1427             : #endif
    1428             : 
    1429             : /* }}} */
    1430             : 
    1431             : /* {{{ hash_functions[]
    1432             :  */
    1433             : static const zend_function_entry hash_functions[] = {
    1434             :         PHP_FE(hash,                                                                    arginfo_hash)
    1435             :         PHP_FE(hash_file,                                                               arginfo_hash_file)
    1436             : 
    1437             :         PHP_FE(hash_hmac,                                                               arginfo_hash_hmac)
    1438             :         PHP_FE(hash_hmac_file,                                                  arginfo_hash_hmac_file)
    1439             : 
    1440             :         PHP_FE(hash_init,                                                               arginfo_hash_init)
    1441             :         PHP_FE(hash_update,                                                             arginfo_hash_update)
    1442             :         PHP_FE(hash_update_stream,                                              arginfo_hash_update_stream)
    1443             :         PHP_FE(hash_update_file,                                                arginfo_hash_update_file)
    1444             :         PHP_FE(hash_final,                                                              arginfo_hash_final)
    1445             :         PHP_FE(hash_copy,                                                               arginfo_hash_copy)
    1446             : 
    1447             :         PHP_FE(hash_algos,                                                              arginfo_hash_algos)
    1448             :         PHP_FE(hash_hmac_algos,                                                 arginfo_hash_algos)
    1449             :         PHP_FE(hash_pbkdf2,                                                             arginfo_hash_pbkdf2)
    1450             :         PHP_FE(hash_equals,                                                             arginfo_hash_equals)
    1451             :         PHP_FE(hash_hkdf,                                                               arginfo_hash_hkdf)
    1452             : 
    1453             :         /* BC Land */
    1454             : #ifdef PHP_HASH_MD5_NOT_IN_CORE
    1455             :         PHP_NAMED_FE(md5, php_if_md5,                                   arginfo_hash_md5)
    1456             :         PHP_NAMED_FE(md5_file, php_if_md5_file,                 arginfo_hash_md5_file)
    1457             : #endif /* PHP_HASH_MD5_NOT_IN_CORE */
    1458             : 
    1459             : #ifdef PHP_HASH_SHA1_NOT_IN_CORE
    1460             :         PHP_NAMED_FE(sha1, php_if_sha1,                                 arginfo_hash_sha1)
    1461             :         PHP_NAMED_FE(sha1_file, php_if_sha1_file,               arginfo_hash_sha1_file)
    1462             : #endif /* PHP_HASH_SHA1_NOT_IN_CORE */
    1463             : 
    1464             : #ifdef PHP_MHASH_BC
    1465             :         PHP_FE(mhash_keygen_s2k, arginfo_mhash_keygen_s2k)
    1466             :         PHP_FE(mhash_get_block_size, arginfo_mhash_get_block_size)
    1467             :         PHP_FE(mhash_get_hash_name, arginfo_mhash_get_hash_name)
    1468             :         PHP_FE(mhash_count, arginfo_mhash_count)
    1469             :         PHP_FE(mhash, arginfo_mhash)
    1470             : #endif
    1471             : 
    1472             :         PHP_FE_END
    1473             : };
    1474             : /* }}} */
    1475             : 
    1476             : /* {{{ hash_module_entry
    1477             :  */
    1478             : zend_module_entry hash_module_entry = {
    1479             :         STANDARD_MODULE_HEADER,
    1480             :         PHP_HASH_EXTNAME,
    1481             :         hash_functions,
    1482             :         PHP_MINIT(hash),
    1483             :         PHP_MSHUTDOWN(hash),
    1484             :         NULL, /* RINIT */
    1485             :         NULL, /* RSHUTDOWN */
    1486             :         PHP_MINFO(hash),
    1487             :         PHP_HASH_VERSION,
    1488             :         STANDARD_MODULE_PROPERTIES
    1489             : };
    1490             : /* }}} */

Generated by: LCOV version 1.10

Generated at Mon, 06 May 2019 17:58:15 +0000 (998 days ago)

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