1--TEST--
2Hash: serialize()/unserialize() with HASH_HMAC
3--FILE--
4<?php
5
6$algos = hash_algos();
7$non_crypto = ["adler32", "crc32", "crc32b", "crc32c", "fnv132", "fnv1a32", "fnv164", "fnv1a64", "joaat", "murmur3a", "murmur3c", "murmur3f", "xxh32", "xxh64", "xxh3", "xxh128"];
8$key = "This is the key that I have";
9
10foreach ($algos as $algo) {
11    if (in_array($algo, $non_crypto)) {
12        continue;
13    }
14
15    var_dump($algo);
16    $ctx0 = hash_init($algo, HASH_HMAC, $key);
17    try {
18        $serial = serialize($ctx0);
19        assert(is_string($serial));
20    } catch (Throwable $e) {
21        echo $e->getMessage(), "\n";
22    }
23}
24
25echo "Done\n";
26?>
27--EXPECT--
28string(3) "md2"
29HashContext with HASH_HMAC option cannot be serialized
30string(3) "md4"
31HashContext with HASH_HMAC option cannot be serialized
32string(3) "md5"
33HashContext with HASH_HMAC option cannot be serialized
34string(4) "sha1"
35HashContext with HASH_HMAC option cannot be serialized
36string(6) "sha224"
37HashContext with HASH_HMAC option cannot be serialized
38string(6) "sha256"
39HashContext with HASH_HMAC option cannot be serialized
40string(6) "sha384"
41HashContext with HASH_HMAC option cannot be serialized
42string(10) "sha512/224"
43HashContext with HASH_HMAC option cannot be serialized
44string(10) "sha512/256"
45HashContext with HASH_HMAC option cannot be serialized
46string(6) "sha512"
47HashContext with HASH_HMAC option cannot be serialized
48string(8) "sha3-224"
49HashContext with HASH_HMAC option cannot be serialized
50string(8) "sha3-256"
51HashContext with HASH_HMAC option cannot be serialized
52string(8) "sha3-384"
53HashContext with HASH_HMAC option cannot be serialized
54string(8) "sha3-512"
55HashContext with HASH_HMAC option cannot be serialized
56string(9) "ripemd128"
57HashContext with HASH_HMAC option cannot be serialized
58string(9) "ripemd160"
59HashContext with HASH_HMAC option cannot be serialized
60string(9) "ripemd256"
61HashContext with HASH_HMAC option cannot be serialized
62string(9) "ripemd320"
63HashContext with HASH_HMAC option cannot be serialized
64string(9) "whirlpool"
65HashContext with HASH_HMAC option cannot be serialized
66string(10) "tiger128,3"
67HashContext with HASH_HMAC option cannot be serialized
68string(10) "tiger160,3"
69HashContext with HASH_HMAC option cannot be serialized
70string(10) "tiger192,3"
71HashContext with HASH_HMAC option cannot be serialized
72string(10) "tiger128,4"
73HashContext with HASH_HMAC option cannot be serialized
74string(10) "tiger160,4"
75HashContext with HASH_HMAC option cannot be serialized
76string(10) "tiger192,4"
77HashContext with HASH_HMAC option cannot be serialized
78string(6) "snefru"
79HashContext with HASH_HMAC option cannot be serialized
80string(9) "snefru256"
81HashContext with HASH_HMAC option cannot be serialized
82string(4) "gost"
83HashContext with HASH_HMAC option cannot be serialized
84string(11) "gost-crypto"
85HashContext with HASH_HMAC option cannot be serialized
86string(10) "haval128,3"
87HashContext with HASH_HMAC option cannot be serialized
88string(10) "haval160,3"
89HashContext with HASH_HMAC option cannot be serialized
90string(10) "haval192,3"
91HashContext with HASH_HMAC option cannot be serialized
92string(10) "haval224,3"
93HashContext with HASH_HMAC option cannot be serialized
94string(10) "haval256,3"
95HashContext with HASH_HMAC option cannot be serialized
96string(10) "haval128,4"
97HashContext with HASH_HMAC option cannot be serialized
98string(10) "haval160,4"
99HashContext with HASH_HMAC option cannot be serialized
100string(10) "haval192,4"
101HashContext with HASH_HMAC option cannot be serialized
102string(10) "haval224,4"
103HashContext with HASH_HMAC option cannot be serialized
104string(10) "haval256,4"
105HashContext with HASH_HMAC option cannot be serialized
106string(10) "haval128,5"
107HashContext with HASH_HMAC option cannot be serialized
108string(10) "haval160,5"
109HashContext with HASH_HMAC option cannot be serialized
110string(10) "haval192,5"
111HashContext with HASH_HMAC option cannot be serialized
112string(10) "haval224,5"
113HashContext with HASH_HMAC option cannot be serialized
114string(10) "haval256,5"
115HashContext with HASH_HMAC option cannot be serialized
116Done
117