xref: /PHP-7.2/ext/hash/tests/hash_hkdf_error.phpt (revision 4bf7ef08)
1--TEST--
2Test hash_hkdf() function: error conditions
3--SKIPIF--
4<?php extension_loaded('hash') or die('skip: hash extension not loaded.'); ?>
5--FILE--
6<?php
7
8/* Prototype  : string hkdf  ( string $algo  , string $ikm  [, int $length  , string $info = '' , string $salt = ''  ] )
9 * Description: HMAC-based Key Derivation Function
10 * Source code: ext/hash/hash.c
11*/
12
13$ikm = 'input key material';
14
15echo "*** Testing hash_hkdf(): error conditions ***\n";
16
17echo "\n-- Testing hash_hkdf() function with less than expected no. of arguments --\n";
18var_dump(hash_hkdf());
19var_dump(hash_hkdf('sha1'));
20
21echo "\n-- Testing hash_hkdf() function with more than expected no. of arguments --\n";
22var_dump(hash_hkdf('sha1', $ikm, 20, '', '', 'extra parameter'));
23
24echo "\n-- Testing hash_hkdf() function with invalid hash algorithm --\n";
25var_dump(hash_hkdf('foo', $ikm));
26
27echo "\n-- Testing hash_hkdf() function with non-cryptographic hash algorithm --\n";
28var_dump(hash_hkdf('adler32', $ikm));
29var_dump(hash_hkdf('crc32', $ikm));
30var_dump(hash_hkdf('crc32b', $ikm));
31var_dump(hash_hkdf('fnv132', $ikm));
32var_dump(hash_hkdf('fnv1a32', $ikm));
33var_dump(hash_hkdf('fnv164', $ikm));
34var_dump(hash_hkdf('fnv1a64', $ikm));
35var_dump(hash_hkdf('joaat', $ikm));
36
37echo "\n-- Testing hash_hkdf() function with invalid parameters --\n";
38var_dump(hash_hkdf('sha1', ''));
39var_dump(hash_hkdf('sha1', $ikm, -1));
40var_dump(hash_hkdf('sha1', $ikm, 20 * 255 + 1)); // Length can't be more than 255 times the hash digest size
41?>
42===Done===
43--EXPECTF--
44*** Testing hash_hkdf(): error conditions ***
45
46-- Testing hash_hkdf() function with less than expected no. of arguments --
47
48Warning: hash_hkdf() expects at least 2 parameters, 0 given in %s on line %d
49NULL
50
51Warning: hash_hkdf() expects at least 2 parameters, 1 given in %s on line %d
52NULL
53
54-- Testing hash_hkdf() function with more than expected no. of arguments --
55
56Warning: hash_hkdf() expects at most 5 parameters, 6 given in %s on line %d
57NULL
58
59-- Testing hash_hkdf() function with invalid hash algorithm --
60
61Warning: hash_hkdf(): Unknown hashing algorithm: foo in %s on line %d
62bool(false)
63
64-- Testing hash_hkdf() function with non-cryptographic hash algorithm --
65
66Warning: hash_hkdf(): Non-cryptographic hashing algorithm: adler32 in %s on line %d
67bool(false)
68
69Warning: hash_hkdf(): Non-cryptographic hashing algorithm: crc32 in %s on line %d
70bool(false)
71
72Warning: hash_hkdf(): Non-cryptographic hashing algorithm: crc32b in %s on line %d
73bool(false)
74
75Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv132 in %s on line %d
76bool(false)
77
78Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv1a32 in %s on line %d
79bool(false)
80
81Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv164 in %s on line %d
82bool(false)
83
84Warning: hash_hkdf(): Non-cryptographic hashing algorithm: fnv1a64 in %s on line %d
85bool(false)
86
87Warning: hash_hkdf(): Non-cryptographic hashing algorithm: joaat in %s on line %d
88bool(false)
89
90-- Testing hash_hkdf() function with invalid parameters --
91
92Warning: hash_hkdf(): Input keying material cannot be empty in %s on line %d
93bool(false)
94
95Warning: hash_hkdf(): Length must be greater than or equal to 0: -1 in %s on line %d
96bool(false)
97
98Warning: hash_hkdf(): Length must be less than or equal to 5100: 5101 in %s on line %d
99bool(false)
100===Done===
101