PATH:
opt
/
alt
/
tests
/
alt-php55-pecl-libsodium_1.0.6-1.el8
/
tests
--TEST-- Check for libsodium auth --SKIPIF-- <?php if (!extension_loaded("libsodium")) print "skip"; ?> --FILE-- <?php $msg = \Sodium\randombytes_buf(1000); $key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AUTH_KEYBYTES); $mac = \Sodium\crypto_auth($msg, $key); // This should validate var_dump(\Sodium\crypto_auth_verify($mac, $msg, $key)); // Flip the first bit $badmsg = $msg; $badmsg[0] = \chr(\ord($badmsg[0]) ^ 0x80); var_dump(\Sodium\crypto_auth_verify($mac, $badmsg, $key)); // Let's flip a bit pseudo-randomly $badmsg = $msg; $badmsg[$i=mt_rand(0, 999)] = \chr( \ord($msg[$i]) ^ ( 1 << mt_rand(0, 7) ) ); var_dump(\Sodium\crypto_auth_verify($mac, $badmsg, $key)); // Now let's change a bit in the MAC $badmac = $mac; $badmac[0] = \chr(\ord($badmac[0]) ^ 0x80); var_dump(\Sodium\crypto_auth_verify($badmac, $msg, $key)); ?> --EXPECT-- bool(true) bool(false) bool(false) bool(false)
[-] crypto_hex.phpt
[edit]
[-] pwhash_scrypt.phpt
[edit]
[-] crypto_generichash.phpt
[edit]
[-] crypto_auth.phpt
[edit]
[-] randombytes.phpt
[edit]
[-] crypto_secretbox.phpt
[edit]
[-] crypto_aead.phpt
[edit]
[-] crypto_kx.phpt
[edit]
[-] crypto_box.phpt
[edit]
[-] crypto_scalarmult.phpt
[edit]
[-] installed.phpt
[edit]
[-] crypto_sign.phpt
[edit]
[+]
..
[-] version.phpt
[edit]
[-] crypto_stream.phpt
[edit]
[-] crypto_shorthash.phpt
[edit]
[-] utils.phpt
[edit]