1--TEST-- 2Check for libsodium KDF 3--EXTENSIONS-- 4sodium 5--FILE-- 6<?php 7$key = sodium_crypto_kdf_keygen(); 8try { 9 $subkey = sodium_crypto_kdf_derive_from_key(10, 0, "context!", $key); 10} catch (SodiumException $ex) { 11 var_dump(true); 12} 13try { 14 $subkey = sodium_crypto_kdf_derive_from_key(100, 0, "context!", $key); 15} catch (SodiumException $ex) { 16 var_dump(true); 17} 18try { 19 $subkey = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MAX, 0, "context", $key); 20} catch (SodiumException $ex) { 21 var_dump(true); 22} 23try { 24 $subkey = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MAX, -1, "context!", $key); 25} catch (SodiumException $ex) { 26 var_dump(true); 27} 28try { 29 $subkey = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MAX, 0, "context!", "short key"); 30} catch (SodiumException $ex) { 31 var_dump(true); 32} 33 34$subkey1 = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MIN, 0, "context!", $key); 35$subkey2 = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MIN, 1, "context!", $key); 36$subkey3 = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MIN, 2, "context2", $key); 37$subkey4 = sodium_crypto_kdf_derive_from_key(SODIUM_CRYPTO_KDF_BYTES_MIN, 0, "context!", $key); 38 39var_dump($subkey1 !== $subkey2); 40var_dump($subkey1 !== $subkey3); 41var_dump($subkey2 !== $subkey3); 42var_dump($subkey1 === $subkey4); 43 44?> 45--EXPECT-- 46bool(true) 47bool(true) 48bool(true) 49bool(true) 50bool(true) 51bool(true) 52bool(true) 53bool(true) 54bool(true) 55