diff options
author | Sara Golemon <pollita@php.net> | 2017-07-23 15:14:31 -0400 |
---|---|---|
committer | Sara Golemon <pollita@php.net> | 2017-07-23 15:17:09 -0400 |
commit | a6e4a713ea594137a100afd2c764aff1e21e5a58 (patch) | |
tree | cf70ef7b02b812214db21ad782416e32a1917d95 /ext/hash | |
parent | 706f0cf8a0a00bc024ff52dc3528c68dab90658b (diff) | |
download | php-git-a6e4a713ea594137a100afd2c764aff1e21e5a58.tar.gz |
Add hash_hmac_algos() for filtered is_crypto methods
Diffstat (limited to 'ext/hash')
-rw-r--r-- | ext/hash/hash.c | 17 | ||||
-rw-r--r-- | ext/hash/tests/hash_hmac_algos.phpt | 57 |
2 files changed, 74 insertions, 0 deletions
diff --git a/ext/hash/hash.c b/ext/hash/hash.c index e2e478fcda..5932ad9c6a 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -597,6 +597,22 @@ PHP_FUNCTION(hash_algos) } /* }}} */ +/* {{{ proto array hash_hmac_algos(void) +Return a list of registered hashing algorithms suitable for hash_hmac() */ +PHP_FUNCTION(hash_hmac_algos) +{ + zend_string *str; + const php_hash_ops *ops; + + array_init(return_value); + ZEND_HASH_FOREACH_STR_KEY_PTR(&php_hash_hashtable, str, ops) { + if (ops->is_crypto) { + add_next_index_str(return_value, zend_string_copy(str)); + } + } ZEND_HASH_FOREACH_END(); +} +/* }}} */ + /* {{{ proto string hash_hkdf(string algo, string ikm [, int length = 0, string info = '', string salt = '']) RFC5869 HMAC-based key derivation function */ PHP_FUNCTION(hash_hkdf) @@ -1429,6 +1445,7 @@ const zend_function_entry hash_functions[] = { PHP_FE(hash_copy, arginfo_hash_copy) PHP_FE(hash_algos, arginfo_hash_algos) + PHP_FE(hash_hmac_algos, arginfo_hash_algos) PHP_FE(hash_pbkdf2, arginfo_hash_pbkdf2) PHP_FE(hash_equals, arginfo_hash_equals) PHP_FE(hash_hkdf, arginfo_hash_hkdf) diff --git a/ext/hash/tests/hash_hmac_algos.phpt b/ext/hash/tests/hash_hmac_algos.phpt new file mode 100644 index 0000000000..89877b7c12 --- /dev/null +++ b/ext/hash/tests/hash_hmac_algos.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test hash_hmac_algos() function : basic functionality +--SKIPIF-- +<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?> +--FILE-- +<?php + +print_r(hash_hmac_algos()); + +--EXPECTF-- +Array +( + [%d] => md2 + [%d] => md4 + [%d] => md5 + [%d] => sha1 + [%d] => sha224 + [%d] => sha256 + [%d] => sha384 + [%d] => sha512/224 + [%d] => sha512/256 + [%d] => sha512 + [%d] => sha3-224 + [%d] => sha3-256 + [%d] => sha3-384 + [%d] => sha3-512 + [%d] => ripemd128 + [%d] => ripemd160 + [%d] => ripemd256 + [%d] => ripemd320 + [%d] => whirlpool + [%d] => tiger128,3 + [%d] => tiger160,3 + [%d] => tiger192,3 + [%d] => tiger128,4 + [%d] => tiger160,4 + [%d] => tiger192,4 + [%d] => snefru + [%d] => snefru256 + [%d] => gost + [%d] => gost-crypto + [%d] => haval128,3 + [%d] => haval160,3 + [%d] => haval192,3 + [%d] => haval224,3 + [%d] => haval256,3 + [%d] => haval128,4 + [%d] => haval160,4 + [%d] => haval192,4 + [%d] => haval224,4 + [%d] => haval256,4 + [%d] => haval128,5 + [%d] => haval160,5 + [%d] => haval192,5 + [%d] => haval224,5 + [%d] => haval256,5 +) |