1
0
mirror of https://github.com/php/php-src.git synced 2026-04-18 13:31:27 +02:00
Files
archived-php-src/ext/hash/hash.stub.php
Anatol Belski 110b4e9094 hash: Support custom algo parameters
The concrete need on this change is to support passing an initial seed
to the murmur hash. Passing a custom seed is important in terms of
randomizing the hash function.

The suggested implementation adds a HashTable parameter to all the
init callbacks. Further on, an array with custom arguments is accepted
from `hash` or `hash_init` from the user land. Currently several things
like `hash_hkdf` are not touched, as they don't need passing custom
args.

Some convenience macros have been added to the SHA/MD families of
functions, so the consuming code doesn't have to be changed widely.

Another way to implement this is to add another type of the init that
would accept a HT with arguments. However, that would still require
touching all the context structs in all the algos. That would also
increase the size of those structs. As an init function is called just
once, the way of modifying the existing init callback has been seen
as more preferrable.

Closes GH-6400.

Signed-off-by: Anatol Belski <ab@php.net>
Co-Developed-by: Nikita Popov <nikita.ppv@googlemail.com>
Signed-off-by: Nikita Popov <nikita.ppv@googlemail.com>
Acked-by: Michael Wallner <mike@php.net>
Reviewed-by: Máté Kocsis <kocsismate@woohoolabs.com>
Reviewed-by: Eddie Kohler <ekohler@gmail.com>
2020-12-13 14:14:07 +01:00

57 lines
1.9 KiB
PHP

<?php
/** @generate-function-entries */
function hash(string $algo, string $data, bool $binary = false, array $options = []): string|false {}
function hash_file(string $algo, string $filename, bool $binary = false, array $options = []): string|false {}
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string|false {}
function hash_hmac_file(string $algo, string $data, string $key, bool $binary = false): string|false {}
function hash_init(string $algo, int $flags = 0, string $key = "", array $options = []): HashContext {}
function hash_update(HashContext $context, string $data): bool {}
/** @param resource $stream */
function hash_update_stream(HashContext $context, $stream, int $length = -1): int {}
/** @param resource|null $stream_context */
function hash_update_file(HashContext $context, string $filename, $stream_context = null): bool {}
function hash_final(HashContext $context, bool $binary = false): string {}
function hash_copy(HashContext $context): HashContext {}
function hash_algos(): array {}
function hash_hmac_algos(): array {}
function hash_pbkdf2(string $algo, string $password, string $salt, int $iterations, int $length = 0, bool $binary = false): string {}
function hash_equals(string $known_string, string $user_string): bool {}
function hash_hkdf(string $algo, string $key, int $length = 0, string $info = "", string $salt = ""): string {}
#ifdef PHP_MHASH_BC
function mhash_get_block_size(int $algo): int|false {}
function mhash_get_hash_name(int $algo): string|false {}
function mhash_keygen_s2k(int $algo, string $password, string $salt, int $length): string|false {}
function mhash_count(): int {}
function mhash(int $algo, string $data, ?string $key = null): string|false {}
#endif
final class HashContext
{
private function __construct() {}
public function __serialize(): array {}
public function __unserialize(array $data): void {}
}