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