Skip to content

Commit

Permalink
Add hash_hmac_algos() for filtered is_crypto methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sgolemon committed Jul 23, 2017
1 parent 706f0cf commit a6e4a71
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions ext/hash/tests/hash_hmac_algos.phpt
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit a6e4a71

Please sign in to comment.