]> granicus.if.org Git - php/blob
ceb21631d1
[php] /
1 --TEST--
2 Hash: hash_hkdf() function: edge cases
3 --FILE--
4 <?php
5
6 /* Prototype  : string hkdf  ( string $algo  , string $ikm  [, int $length  , string $info = '' , string $salt = ''  ] )
7  * Description: HMAC-based Key Derivation Function
8  * Source code: ext/hash/hash.c
9 */
10
11 echo "*** Testing hash_hkdf(): edge cases ***\n";
12
13 $ikm = 'input key material';
14
15 echo 'Length < digestSize: ', bin2hex(hash_hkdf('md5', $ikm, 7)), "\n";
16 echo 'Length % digestSize != 0: ', bin2hex(hash_hkdf('md5', $ikm, 17)), "\n";
17 echo 'Algo name case-sensitivity: ', (bin2hex(hash_hkdf('Md5', $ikm, 7)) === '98b16391063ece' ? 'true' : 'false'), "\n";
18 echo "Non-crypto algo name case-sensitivity:\n";
19
20 try {
21     var_dump(hash_hkdf('jOaAt', $ikm));
22 }
23 catch (\Error $e) {
24     echo '[Error] ' . $e->getMessage() . "\n";
25 }
26
27 ?>
28 --EXPECT--
29 *** Testing hash_hkdf(): edge cases ***
30 Length < digestSize: 98b16391063ece
31 Length % digestSize != 0: 98b16391063ecee006a3ca8ee5776b1e5f
32 Algo name case-sensitivity: true
33 Non-crypto algo name case-sensitivity:
34 [Error] hash_hkdf(): Argument #1 ($algo) must be a valid cryptographic hashing algorithm