1--TEST--
2Check for libsodium generichash
3--SKIPIF--
4<?php if (!extension_loaded("sodium")) print "skip"; ?>
5--FILE--
6<?php
7$q = sodium_crypto_generichash('msg');
8var_dump(bin2hex($q));
9$q = sodium_crypto_generichash('msg', '0123456789abcdef');
10var_dump(bin2hex($q));
11$q = sodium_crypto_generichash('msg', '0123456789abcdef', 64);
12var_dump(bin2hex($q));
13$q = sodium_crypto_generichash('msg', '0123456789abcdef0123456789abcdef', 64);
14var_dump(bin2hex($q));
15$state = sodium_crypto_generichash_init();
16$q = sodium_crypto_generichash_final($state);
17var_dump(bin2hex($q));
18$state = sodium_crypto_generichash_init();
19sodium_crypto_generichash_update($state, 'm');
20sodium_crypto_generichash_update($state, 'sg');
21$q = sodium_crypto_generichash_final($state);
22var_dump(bin2hex($q));
23$state = sodium_crypto_generichash_init('0123456789abcdef');
24sodium_crypto_generichash_update($state, 'm');
25sodium_crypto_generichash_update($state, 'sg');
26$q = sodium_crypto_generichash_final($state);
27var_dump(bin2hex($q));
28$state = sodium_crypto_generichash_init('0123456789abcdef', 64);
29sodium_crypto_generichash_update($state, 'm');
30sodium_crypto_generichash_update($state, 'sg');
31$state2 = '' . $state;
32$q = sodium_crypto_generichash_final($state, 64);
33var_dump(bin2hex($q));
34sodium_crypto_generichash_update($state2, '2');
35$q = sodium_crypto_generichash_final($state2, 64);
36$exp = bin2hex($q);
37var_dump($exp);
38$act = bin2hex(
39    sodium_crypto_generichash('msg2', '0123456789abcdef', 64)
40);
41var_dump($act);
42var_dump($exp === $act);
43try {
44    $hash = sodium_crypto_generichash('test', '', 128);
45} catch (SodiumException $ex) {
46    var_dump(true);
47}
48?>
49--EXPECT--
50string(64) "96a7ed8861db0abc006f473f9e64687875f3d9df8e723adae9f53a02b2aec378"
51string(64) "ba03e32a94ece425a77b350f029e0a3d37e6383158aa7cefa2b1b9470a7fcb7a"
52string(128) "8ccd640462e7380010c5722d7f3c2354781d1360430197ff233509c27353fd2597c8d689bfe769467056a0655b3faba6af4e4ade248558f7c53538c4d5b94806"
53string(128) "30f0e5f1e3beb7e0340976ac05a94043cce082d870e28e03c906e8fe9a88786271c6ba141eee2885e7444a870fac498cc78a13b0c53aefaec01bf38ebfe73b3f"
54string(64) "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8"
55string(64) "96a7ed8861db0abc006f473f9e64687875f3d9df8e723adae9f53a02b2aec378"
56string(64) "ba03e32a94ece425a77b350f029e0a3d37e6383158aa7cefa2b1b9470a7fcb7a"
57string(128) "8ccd640462e7380010c5722d7f3c2354781d1360430197ff233509c27353fd2597c8d689bfe769467056a0655b3faba6af4e4ade248558f7c53538c4d5b94806"
58string(128) "9ef702f51114c9dc2cc7521746e8beebe0a3ca9bb29ec729e16682ca982e7f69ff70235a46659a9a6c28f92fbd990288301b9a6b5517f1f2ba6518074af19a5a"
59string(128) "9ef702f51114c9dc2cc7521746e8beebe0a3ca9bb29ec729e16682ca982e7f69ff70235a46659a9a6c28f92fbd990288301b9a6b5517f1f2ba6518074af19a5a"
60bool(true)
61bool(true)
62