| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Safe; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\Safe\Exceptions\HashException; |
| 6 |
|
| 7 |
/** |
| 8 |
* |
| 9 |
* |
| 10 |
* @param string $algo Name of selected hashing algorithm (i.e. "sha256", "sha512", "haval160,4", etc..) |
| 11 |
* See hash_algos for a list of supported algorithms. |
| 12 |
* |
| 13 |
* |
| 14 |
* Non-cryptographic hash functions are not allowed. |
| 15 |
* |
| 16 |
* |
| 17 |
* |
| 18 |
* Non-cryptographic hash functions are not allowed. |
| 19 |
* @param string $ikm Input keying material (raw binary). Cannot be empty. |
| 20 |
* @param int $length Desired output length in bytes. |
| 21 |
* Cannot be greater than 255 times the chosen hash function size. |
| 22 |
* |
| 23 |
* If length is 0, the output length |
| 24 |
* will default to the chosen hash function size. |
| 25 |
* @param string $info Application/context-specific info string. |
| 26 |
* @param string $salt Salt to use during derivation. |
| 27 |
* |
| 28 |
* While optional, adding random salt significantly improves the strength of HKDF. |
| 29 |
* @return string Returns a string containing a raw binary representation of the derived key |
| 30 |
* (also known as output keying material - OKM);. |
| 31 |
* @throws HashException |
| 32 |
* |
| 33 |
*/ |
| 34 |
function hash_hkdf(string $algo, string $ikm, int $length = 0, string $info = '', string $salt = ''): string |
| 35 |
{ |
| 36 |
error_clear_last(); |
| 37 |
$result = \hash_hkdf($algo, $ikm, $length, $info, $salt); |
| 38 |
if ($result === false) { |
| 39 |
throw HashException::createFromPhpError(); |
| 40 |
} |
| 41 |
return $result; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
/** |
| 46 |
* |
| 47 |
* |
| 48 |
* @param \HashContext $hcontext Hashing context returned by hash_init. |
| 49 |
* @param string $filename URL describing location of file to be hashed; Supports fopen wrappers. |
| 50 |
* @param \HashContext|null $scontext Stream context as returned by stream_context_create. |
| 51 |
* @throws HashException |
| 52 |
* |
| 53 |
*/ |
| 54 |
function hash_update_file(\HashContext $hcontext, string $filename, ?\HashContext $scontext = null): void |
| 55 |
{ |
| 56 |
error_clear_last(); |
| 57 |
$result = \hash_update_file($hcontext, $filename, $scontext); |
| 58 |
if ($result === false) { |
| 59 |
throw HashException::createFromPhpError(); |
| 60 |
} |
| 61 |
} |
| 62 |
|