summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2020-11-02 20:00:28 +0100
committerAnatol Belski <ab@php.net>2020-12-13 14:14:07 +0100
commit110b4e90946b6d46864c54c0e15b7a0deb6ad4b3 (patch)
tree709fa450d15d862e04866c213715f8791134f42c
parent70c22dec2812bb7fec9d248268207b95f9cd4215 (diff)
downloadphp-git-110b4e90946b6d46864c54c0e15b7a0deb6ad4b3.tar.gz
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>
-rw-r--r--ext/hash/hash.c48
-rw-r--r--ext/hash/hash.stub.php6
-rw-r--r--ext/hash/hash_adler32.c2
-rw-r--r--ext/hash/hash_arginfo.h5
-rw-r--r--ext/hash/hash_crc32.c2
-rw-r--r--ext/hash/hash_fnv.c4
-rw-r--r--ext/hash/hash_gost.c6
-rw-r--r--ext/hash/hash_haval.c2
-rw-r--r--ext/hash/hash_joaat.c2
-rw-r--r--ext/hash/hash_md.c12
-rw-r--r--ext/hash/hash_murmur.c51
-rw-r--r--ext/hash/hash_ripemd.c8
-rw-r--r--ext/hash/hash_sha.c38
-rw-r--r--ext/hash/hash_sha3.c4
-rw-r--r--ext/hash/hash_snefru.c2
-rw-r--r--ext/hash/hash_tiger.c4
-rw-r--r--ext/hash/hash_whirlpool.c2
-rw-r--r--ext/hash/php_hash.h2
-rw-r--r--ext/hash/php_hash_adler32.h2
-rw-r--r--ext/hash/php_hash_crc32.h2
-rw-r--r--ext/hash/php_hash_fnv.h4
-rw-r--r--ext/hash/php_hash_gost.h2
-rw-r--r--ext/hash/php_hash_haval.h2
-rw-r--r--ext/hash/php_hash_joaat.h2
-rw-r--r--ext/hash/php_hash_md.h6
-rw-r--r--ext/hash/php_hash_murmur.h6
-rw-r--r--ext/hash/php_hash_ripemd.h8
-rw-r--r--ext/hash/php_hash_sha.h18
-rw-r--r--ext/hash/php_hash_sha3.h8
-rw-r--r--ext/hash/php_hash_snefru.h2
-rw-r--r--ext/hash/php_hash_tiger.h4
-rw-r--r--ext/hash/php_hash_whirlpool.h2
-rw-r--r--ext/hash/tests/murmurhash3_seed.phpt52
-rw-r--r--ext/standard/md5.c2
-rw-r--r--ext/standard/md5.h3
-rw-r--r--ext/standard/sha1.c2
-rw-r--r--ext/standard/sha1.h3
37 files changed, 220 insertions, 110 deletions
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index f7b851f5a4..a337ef0489 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -349,7 +349,7 @@ PHP_HASH_API int php_hash_unserialize(php_hashcontext_object *hash, zend_long ma
/* Userspace */
static void php_hash_do_hash(
- zval *return_value, zend_string *algo, char *data, size_t data_len, zend_bool raw_output, bool isfilename
+ zval *return_value, zend_string *algo, char *data, size_t data_len, zend_bool raw_output, bool isfilename, HashTable *args
) /* {{{ */ {
zend_string *digest;
const php_hash_ops *ops;
@@ -374,7 +374,7 @@ static void php_hash_do_hash(
}
context = php_hash_alloc_context(ops);
- ops->hash_init(context);
+ ops->hash_init(context, args);
if (isfilename) {
char buf[1024];
@@ -418,15 +418,17 @@ PHP_FUNCTION(hash)
char *data;
size_t data_len;
zend_bool raw_output = 0;
+ HashTable *args = NULL;
- ZEND_PARSE_PARAMETERS_START(2, 3)
+ ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_STR(algo)
Z_PARAM_STRING(data, data_len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(raw_output)
+ Z_PARAM_ARRAY_HT(args)
ZEND_PARSE_PARAMETERS_END();
- php_hash_do_hash(return_value, algo, data, data_len, raw_output, 0);
+ php_hash_do_hash(return_value, algo, data, data_len, raw_output, 0, args);
}
/* }}} */
@@ -438,15 +440,17 @@ PHP_FUNCTION(hash_file)
char *data;
size_t data_len;
zend_bool raw_output = 0;
+ HashTable *args = NULL;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(algo)
Z_PARAM_STRING(data, data_len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(raw_output)
+ Z_PARAM_ARRAY_HT(args)
ZEND_PARSE_PARAMETERS_END();
- php_hash_do_hash(return_value, algo, data, data_len, raw_output, 1);
+ php_hash_do_hash(return_value, algo, data, data_len, raw_output, 1, args);
}
/* }}} */
@@ -468,7 +472,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
memset(K, 0, ops->block_size);
if (key_len > ops->block_size) {
/* Reduce the key first */
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
ops->hash_update(context, key, key_len);
ops->hash_final(K, context);
} else {
@@ -479,7 +483,7 @@ static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *
}
static inline void php_hash_hmac_round(unsigned char *final, const php_hash_ops *ops, void *context, const unsigned char *key, const unsigned char *data, const zend_long data_size) {
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
ops->hash_update(context, key, ops->block_size);
ops->hash_update(context, data, data_size);
ops->hash_final(final, context);
@@ -522,7 +526,7 @@ static void php_hash_do_hash_hmac(
if (isfilename) {
char buf[1024];
ssize_t n;
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
ops->hash_update(context, K, ops->block_size);
while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
ops->hash_update(context, (unsigned char *) buf, n);
@@ -605,8 +609,9 @@ PHP_FUNCTION(hash_init)
void *context;
const php_hash_ops *ops;
php_hashcontext_object *hash;
+ HashTable *args = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lS", &algo, &options, &key) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|lSh", &algo, &options, &key, &args) == FAILURE) {
RETURN_THROWS();
}
@@ -632,7 +637,7 @@ PHP_FUNCTION(hash_init)
hash = php_hashcontext_from_object(Z_OBJ_P(return_value));
context = php_hash_alloc_context(ops);
- ops->hash_init(context);
+ ops->hash_init(context, args);
hash->ops = ops;
hash->context = context;
@@ -650,7 +655,7 @@ PHP_FUNCTION(hash_init)
ops->hash_update(context, (unsigned char *) ZSTR_VAL(key), ZSTR_LEN(key));
ops->hash_final((unsigned char *) K, context);
/* Make the context ready to start over */
- ops->hash_init(context);
+ ops->hash_init(context, args);
} else {
memcpy(K, ZSTR_VAL(key), ZSTR_LEN(key));
}
@@ -792,7 +797,7 @@ PHP_FUNCTION(hash_final)
}
/* Feed this result into the outer hash */
- hash->ops->hash_init(hash->context);
+ hash->ops->hash_init(hash->context, NULL);
hash->ops->hash_update(hash->context, hash->key, hash->ops->block_size);
hash->ops->hash_update(hash->context, (unsigned char *) ZSTR_VAL(digest), hash->ops->digest_size);
hash->ops->hash_final((unsigned char *) ZSTR_VAL(digest), hash->context);
@@ -915,7 +920,7 @@ PHP_FUNCTION(hash_hkdf)
context = php_hash_alloc_context(ops);
// Extract
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
K = emalloc(ops->block_size);
php_hash_hmac_prep_key(K, ops, context,
(unsigned char *) (salt ? ZSTR_VAL(salt) : ""), salt ? ZSTR_LEN(salt) : 0);
@@ -935,7 +940,7 @@ PHP_FUNCTION(hash_hkdf)
c[0] = (i & 0xFF);
php_hash_hmac_prep_key(K, ops, context, prk, ops->digest_size);
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
ops->hash_update(context, K, ops->block_size);
if (i > 1) {
@@ -980,8 +985,9 @@ PHP_FUNCTION(hash_pbkdf2)
zend_bool raw_output = 0;
const php_hash_ops *ops;
void *context;
+ HashTable *args;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sssl|lb", &algo, &pass, &pass_len, &salt, &salt_len, &iterations, &length, &raw_output) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sssl|lbh", &algo, &pass, &pass_len, &salt, &salt_len, &iterations, &length, &raw_output, &args) == FAILURE) {
RETURN_THROWS();
}
@@ -1007,7 +1013,7 @@ PHP_FUNCTION(hash_pbkdf2)
}
context = php_hash_alloc_context(ops);
- ops->hash_init(context);
+ ops->hash_init(context, args);
K1 = emalloc(ops->block_size);
K2 = emalloc(ops->block_size);
@@ -1212,7 +1218,7 @@ PHP_FUNCTION(mhash)
if (key) {
php_hash_do_hash_hmac(return_value, algo, data, data_len, key, key_len, 1, 0);
} else {
- php_hash_do_hash(return_value, algo, data, data_len, 1, 0);
+ php_hash_do_hash(return_value, algo, data, data_len, 1, 0, NULL);
}
if (algo) {
@@ -1319,13 +1325,13 @@ PHP_FUNCTION(mhash_keygen_s2k)
}
context = php_hash_alloc_context(ops);
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
key = ecalloc(1, times * block_size);
digest = emalloc(ops->digest_size + 1);
for (i = 0; i < times; i++) {
- ops->hash_init(context);
+ ops->hash_init(context, NULL);
for (j=0;j<i;j++) {
ops->hash_update(context, &null, 1);
@@ -1392,7 +1398,7 @@ static zend_object *php_hashcontext_clone(zend_object *zobj) {
newobj->ops = oldobj->ops;
newobj->options = oldobj->options;
newobj->context = php_hash_alloc_context(newobj->ops);
- newobj->ops->hash_init(newobj->context);
+ newobj->ops->hash_init(newobj->context, NULL);
if (SUCCESS != newobj->ops->hash_copy(newobj->ops, oldobj->context, newobj->context)) {
efree(newobj->context);
@@ -1529,8 +1535,8 @@ PHP_METHOD(HashContext, __unserialize)
hash->ops = ops;
hash->context = php_hash_alloc_context(ops);
- ops->hash_init(hash->context);
hash->options = options;
+ ops->hash_init(hash->context, NULL);
unserialize_result = ops->hash_unserialize(hash, magic, hash_zv);
if (unserialize_result != SUCCESS) {
diff --git a/ext/hash/hash.stub.php b/ext/hash/hash.stub.php
index c0d4cbca7c..7eb3925c35 100644
--- a/ext/hash/hash.stub.php
+++ b/ext/hash/hash.stub.php
@@ -2,15 +2,15 @@
/** @generate-function-entries */
-function hash(string $algo, string $data, bool $binary = false): string|false {}
+function hash(string $algo, string $data, bool $binary = false, array $options = []): string|false {}
-function hash_file(string $algo, string $filename, bool $binary = false): 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 = ""): HashContext {}
+function hash_init(string $algo, int $flags = 0, string $key = "", array $options = []): HashContext {}
function hash_update(HashContext $context, string $data): bool {}
diff --git a/ext/hash/hash_adler32.c b/ext/hash/hash_adler32.c
index d45012f8e6..5acd621b2d 100644
--- a/ext/hash/hash_adler32.c
+++ b/ext/hash/hash_adler32.c
@@ -18,7 +18,7 @@
#include "php_hash.h"
#include "php_hash_adler32.h"
-PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context)
+PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->state = 1;
}
diff --git a/ext/hash/hash_arginfo.h b/ext/hash/hash_arginfo.h
index db043da97b..1d654b546e 100644
--- a/ext/hash/hash_arginfo.h
+++ b/ext/hash/hash_arginfo.h
@@ -1,16 +1,18 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 9352e0ac98e2ac53dc15d5024f9ef0c8092c4e9c */
+ * Stub hash: e8466049fca2eae179adbc19bb67e71f6486ec4e */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_file, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
@@ -26,6 +28,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_hash_init, 0, 1, HashContext, 0)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, key, IS_STRING, 0, "\"\"")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_update, 0, 2, _IS_BOOL, 0)
diff --git a/ext/hash/hash_crc32.c b/ext/hash/hash_crc32.c
index ade32a3b35..d77cdde013 100644
--- a/ext/hash/hash_crc32.c
+++ b/ext/hash/hash_crc32.c
@@ -20,7 +20,7 @@
#include "php_hash_crc32_tables.h"
#include "ext/standard/crc32_x86.h"
-PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context)
+PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->state = ~0;
}
diff --git a/ext/hash/hash_fnv.c b/ext/hash/hash_fnv.c
index 2ee81b9c86..3a48d40484 100644
--- a/ext/hash/hash_fnv.c
+++ b/ext/hash/hash_fnv.c
@@ -83,7 +83,7 @@ const php_hash_ops php_hash_fnv1a64_ops = {
/* {{{ PHP_FNV132Init
* 32-bit FNV-1 hash initialisation
*/
-PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context)
+PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->state = PHP_FNV1_32_INIT;
}
@@ -118,7 +118,7 @@ PHP_HASH_API void PHP_FNV132Final(unsigned char digest[4], PHP_FNV132_CTX * cont
/* {{{ PHP_FNV164Init
* 64-bit FNV-1 hash initialisation
*/
-PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context)
+PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->state = PHP_FNV1_64_INIT;
}
diff --git a/ext/hash/hash_gost.c b/ext/hash/hash_gost.c
index 46ea032c32..d1f4a31765 100644
--- a/ext/hash/hash_gost.c
+++ b/ext/hash/hash_gost.c
@@ -235,15 +235,15 @@ static inline void GostTransform(PHP_GOST_CTX *context, const unsigned char inpu
Gost(context, data);
}
-PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *context)
+PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(*context));
context->tables = &tables_test;
}
-PHP_HASH_API void PHP_GOSTInitCrypto(PHP_GOST_CTX *context)
+PHP_HASH_API void PHP_GOSTInitCrypto(PHP_GOST_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
- PHP_GOSTInit(context);
+ PHP_GOSTInit(context, NULL);
context->tables = &tables_crypto;
}
diff --git a/ext/hash/hash_haval.c b/ext/hash/hash_haval.c
index 84ff242bd9..9b117db8d9 100644
--- a/ext/hash/hash_haval.c
+++ b/ext/hash/hash_haval.c
@@ -253,7 +253,7 @@ const php_hash_ops php_hash_##p##haval##b##_ops = { \
php_hash_unserialize, \
PHP_HAVAL_SPEC, \
((b) / 8), 128, sizeof(PHP_HAVAL_CTX), 1 }; \
-PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *context) \
+PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) \
{ int i; context->count[0] = context->count[1] = 0; \
for(i = 0; i < 8; i++) context->state[i] = D0[i]; \
context->passes = p; context->output = b; \
diff --git a/ext/hash/hash_joaat.c b/ext/hash/hash_joaat.c
index 5d5a2e53b9..41fde52f30 100644
--- a/ext/hash/hash_joaat.c
+++ b/ext/hash/hash_joaat.c
@@ -36,7 +36,7 @@ const php_hash_ops php_hash_joaat_ops = {
0
};
-PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context)
+PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->state = 0;
}
diff --git a/ext/hash/hash_md.c b/ext/hash/hash_md.c
index 94fafbbf79..a34936d625 100644
--- a/ext/hash/hash_md.c
+++ b/ext/hash/hash_md.c
@@ -19,7 +19,7 @@
const php_hash_ops php_hash_md5_ops = {
"md5",
- (php_hash_init_func_t) PHP_MD5Init,
+ (php_hash_init_func_t) PHP_MD5InitArgs,
(php_hash_update_func_t) PHP_MD5Update,
(php_hash_final_func_t) PHP_MD5Final,
php_hash_copy,
@@ -34,7 +34,7 @@ const php_hash_ops php_hash_md5_ops = {
const php_hash_ops php_hash_md4_ops = {
"md4",
- (php_hash_init_func_t) PHP_MD4Init,
+ (php_hash_init_func_t) PHP_MD4InitArgs,
(php_hash_update_func_t) PHP_MD4Update,
(php_hash_final_func_t) PHP_MD4Final,
php_hash_copy,
@@ -51,7 +51,7 @@ static int php_md2_unserialize(php_hashcontext_object *hash, zend_long magic, co
const php_hash_ops php_hash_md2_ops = {
"md2",
- (php_hash_init_func_t) PHP_MD2Init,
+ (php_hash_init_func_t) PHP_MD2InitArgs,
(php_hash_update_func_t) PHP_MD2Update,
(php_hash_final_func_t) PHP_MD2Final,
php_hash_copy,
@@ -182,10 +182,10 @@ static void MD4Transform(uint32_t state[4], const unsigned char block[64])
state[3] += d;
}
-/* {{{ PHP_MD4Init
+/* {{{ PHP_MD4InitArgs
* MD4 initialization. Begins an MD4 operation, writing a new context.
*/
-PHP_HASH_API void PHP_MD4Init(PHP_MD4_CTX * context)
+PHP_HASH_API void PHP_MD4InitArgs(PHP_MD4_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -287,7 +287,7 @@ static const unsigned char MD2_S[256] = {
242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10,
49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 };
-PHP_HASH_API void PHP_MD2Init(PHP_MD2_CTX *context)
+PHP_HASH_API void PHP_MD2InitArgs(PHP_MD2_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(PHP_MD2_CTX));
}
diff --git a/ext/hash/hash_murmur.c b/ext/hash/hash_murmur.c
index ab01b4f19f..466231054c 100644
--- a/ext/hash/hash_murmur.c
+++ b/ext/hash/hash_murmur.c
@@ -36,9 +36,20 @@ const php_hash_ops php_hash_murmur3a_ops = {
0
};
-PHP_HASH_API void PHP_MURMUR3AInit(PHP_MURMUR3A_CTX *ctx)
+PHP_HASH_API void PHP_MURMUR3AInit(PHP_MURMUR3A_CTX *ctx, HashTable *args)
{
- ctx->h = 0;
+ if (args) {
+ zval *seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1);
+ /* This might be a bit too restrictive, but thinking that a seed might be set
+ once and for all, it should be done a clean way. */
+ if (seed && IS_LONG == Z_TYPE_P(seed)) {
+ ctx->h = (uint32_t)Z_LVAL_P(seed);
+ } else {
+ ctx->h = 0;
+ }
+ } else {
+ ctx->h = 0;
+ }
ctx->carry = 0;
ctx->len = 0;
}
@@ -82,9 +93,24 @@ const php_hash_ops php_hash_murmur3c_ops = {
0
};
-PHP_HASH_API void PHP_MURMUR3CInit(PHP_MURMUR3C_CTX *ctx)
+PHP_HASH_API void PHP_MURMUR3CInit(PHP_MURMUR3C_CTX *ctx, HashTable *args)
{
- memset(&ctx->h, 0, sizeof ctx->h);
+ if (args) {
+ zval *seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1);
+ /* This might be a bit too restrictive, but thinking that a seed might be set
+ once and for all, it should be done a clean way. */
+ if (seed && IS_LONG == Z_TYPE_P(seed)) {
+ uint32_t _seed = (uint32_t)Z_LVAL_P(seed);
+ ctx->h[0] = _seed;
+ ctx->h[1] = _seed;
+ ctx->h[2] = _seed;
+ ctx->h[3] = _seed;
+ } else {
+ memset(&ctx->h, 0, sizeof ctx->h);
+ }
+ } else {
+ memset(&ctx->h, 0, sizeof ctx->h);
+ }
memset(&ctx->carry, 0, sizeof ctx->carry);
ctx->len = 0;
}
@@ -141,9 +167,22 @@ const php_hash_ops php_hash_murmur3f_ops = {
0
};
-PHP_HASH_API void PHP_MURMUR3FInit(PHP_MURMUR3F_CTX *ctx)
+PHP_HASH_API void PHP_MURMUR3FInit(PHP_MURMUR3F_CTX *ctx, HashTable *args)
{
- memset(&ctx->h, 0, sizeof ctx->h);
+ if (args) {
+ zval *seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1);
+ /* This might be a bit too restrictive, but thinking that a seed might be set
+ once and for all, it should be done a clean way. */
+ if (seed && IS_LONG == Z_TYPE_P(seed)) {
+ uint64_t _seed = (uint64_t)Z_LVAL_P(seed);
+ ctx->h[0] = _seed;
+ ctx->h[1] = _seed;
+ } else {
+ memset(&ctx->h, 0, sizeof ctx->h);
+ }
+ } else {
+ memset(&ctx->h, 0, sizeof ctx->h);
+ }
memset(&ctx->carry, 0, sizeof ctx->carry);
ctx->len = 0;
}
diff --git a/ext/hash/hash_ripemd.c b/ext/hash/hash_ripemd.c
index db1d1dc02b..58c40b06a7 100644
--- a/ext/hash/hash_ripemd.c
+++ b/ext/hash/hash_ripemd.c
@@ -84,7 +84,7 @@ const php_hash_ops php_hash_ripemd320_ops = {
/* {{{ PHP_RIPEMD128Init
* ripemd128 initialization. Begins a ripemd128 operation, writing a new context.
*/
-PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX * context)
+PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -99,7 +99,7 @@ PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX * context)
/* {{{ PHP_RIPEMD256Init
* ripemd256 initialization. Begins a ripemd256 operation, writing a new context.
*/
-PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX * context)
+PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -118,7 +118,7 @@ PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX * context)
/* {{{ PHP_RIPEMD160Init
* ripemd160 initialization. Begins a ripemd160 operation, writing a new context.
*/
-PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX * context)
+PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -134,7 +134,7 @@ PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX * context)
/* {{{ PHP_RIPEMD320Init
* ripemd320 initialization. Begins a ripemd320 operation, writing a new context.
*/
-PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX * context)
+PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
diff --git a/ext/hash/hash_sha.c b/ext/hash/hash_sha.c
index 4ea5b768d7..acc23a21bf 100644
--- a/ext/hash/hash_sha.c
+++ b/ext/hash/hash_sha.c
@@ -64,7 +64,7 @@ static void SHADecode32(uint32_t *output, const unsigned char *input, unsigned i
const php_hash_ops php_hash_sha1_ops = {
"sha1",
- (php_hash_init_func_t) PHP_SHA1Init,
+ (php_hash_init_func_t) PHP_SHA1InitArgs,
(php_hash_update_func_t) PHP_SHA1Update,
(php_hash_final_func_t) PHP_SHA1Final,
php_hash_copy,
@@ -81,7 +81,7 @@ const php_hash_ops php_hash_sha1_ops = {
const php_hash_ops php_hash_sha256_ops = {
"sha256",
- (php_hash_init_func_t) PHP_SHA256Init,
+ (php_hash_init_func_t) PHP_SHA256InitArgs,
(php_hash_update_func_t) PHP_SHA256Update,
(php_hash_final_func_t) PHP_SHA256Final,
php_hash_copy,
@@ -96,7 +96,7 @@ const php_hash_ops php_hash_sha256_ops = {
const php_hash_ops php_hash_sha224_ops = {
"sha224",
- (php_hash_init_func_t) PHP_SHA224Init,
+ (php_hash_init_func_t) PHP_SHA224InitArgs,
(php_hash_update_func_t) PHP_SHA224Update,
(php_hash_final_func_t) PHP_SHA224Final,
php_hash_copy,
@@ -136,10 +136,10 @@ static const uint32_t SHA256_K[64] = {
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 };
-/* {{{ PHP_SHA256Init
+/* {{{ PHP_SHA256InitArgs
* SHA256 initialization. Begins an SHA256 operation, writing a new context.
*/
-PHP_HASH_API void PHP_SHA256Init(PHP_SHA256_CTX * context)
+PHP_HASH_API void PHP_SHA256InitArgs(PHP_SHA256_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -196,10 +196,10 @@ static void SHA256Transform(uint32_t state[8], const unsigned char block[64])
}
/* }}} */
-/* {{{ PHP_SHA224Init
+/* {{{ PHP_SHA224InitArgs
* SHA224 initialization. Begins an SHA224 operation, writing a new context.
*/
-PHP_HASH_API void PHP_SHA224Init(PHP_SHA224_CTX * context)
+PHP_HASH_API void PHP_SHA224InitArgs(PHP_SHA224_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -445,10 +445,10 @@ static void SHADecode64(uint64_t *output, const unsigned char *input, unsigned i
}
/* }}} */
-/* {{{ PHP_SHA384Init
+/* {{{ PHP_SHA384InitArgs
* SHA384 initialization. Begins an SHA384 operation, writing a new context.
*/
-PHP_HASH_API void PHP_SHA384Init(PHP_SHA384_CTX * context)
+PHP_HASH_API void PHP_SHA384InitArgs(PHP_SHA384_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -591,7 +591,7 @@ PHP_HASH_API void PHP_SHA384Final(unsigned char digest[48], PHP_SHA384_CTX * con
const php_hash_ops php_hash_sha384_ops = {
"sha384",
- (php_hash_init_func_t) PHP_SHA384Init,
+ (php_hash_init_func_t) PHP_SHA384InitArgs,
(php_hash_update_func_t) PHP_SHA384Update,
(php_hash_final_func_t) PHP_SHA384Final,
php_hash_copy,
@@ -604,10 +604,10 @@ const php_hash_ops php_hash_sha384_ops = {
1
};
-/* {{{ PHP_SHA512Init
+/* {{{ PHP_SHA512InitArgs
* SHA512 initialization. Begins an SHA512 operation, writing a new context.
*/
-PHP_HASH_API void PHP_SHA512Init(PHP_SHA512_CTX * context)
+PHP_HASH_API void PHP_SHA512InitArgs(PHP_SHA512_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
@@ -623,10 +623,10 @@ PHP_HASH_API void PHP_SHA512Init(PHP_SHA512_CTX * context)
}
/* }}} */
-/* {{{ PHP_SHA512_256Init
+/* {{{ PHP_SHA512_256InitArgs
* SHA512/245 initialization. Identical algorithm to SHA512, using alternate initval and truncation
*/
-PHP_HASH_API void PHP_SHA512_256Init(PHP_SHA512_CTX * context)
+PHP_HASH_API void PHP_SHA512_256InitArgs(PHP_SHA512_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
@@ -641,10 +641,10 @@ PHP_HASH_API void PHP_SHA512_256Init(PHP_SHA512_CTX * context)
}
/* }}} */
-/* {{{ PHP_SHA512_224Init
+/* {{{ PHP_SHA512_224InitArgs
* SHA512/224 initialization. Identical algorithm to SHA512, using alternate initval and truncation
*/
-PHP_HASH_API void PHP_SHA512_224Init(PHP_SHA512_CTX * context)
+PHP_HASH_API void PHP_SHA512_224InitArgs(PHP_SHA512_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
@@ -768,7 +768,7 @@ PHP_HASH_API void PHP_SHA512_224Final(unsigned char digest[28], PHP_SHA512_CTX *
const php_hash_ops php_hash_sha512_ops = {
"sha512",
- (php_hash_init_func_t) PHP_SHA512Init,
+ (php_hash_init_func_t) PHP_SHA512InitArgs,
(php_hash_update_func_t) PHP_SHA512Update,
(php_hash_final_func_t) PHP_SHA512Final,
php_hash_copy,
@@ -783,7 +783,7 @@ const php_hash_ops php_hash_sha512_ops = {
const php_hash_ops php_hash_sha512_256_ops = {
"sha512/256",
- (php_hash_init_func_t) PHP_SHA512_256Init,
+ (php_hash_init_func_t) PHP_SHA512_256InitArgs,
(php_hash_update_func_t) PHP_SHA512_256Update,
(php_hash_final_func_t) PHP_SHA512_256Final,
php_hash_copy,
@@ -798,7 +798,7 @@ const php_hash_ops php_hash_sha512_256_ops = {
const php_hash_ops php_hash_sha512_224_ops = {
"sha512/224",
- (php_hash_init_func_t) PHP_SHA512_224Init,
+ (php_hash_init_func_t) PHP_SHA512_224InitArgs,
(php_hash_update_func_t) PHP_SHA512_224Update,
(php_hash_final_func_t) PHP_SHA512_224Final,
php_hash_copy,
diff --git a/ext/hash/hash_sha3.c b/ext/hash/hash_sha3.c
index 52bd495f9d..123e599d04 100644
--- a/ext/hash/hash_sha3.c
+++ b/ext/hash/hash_sha3.c
@@ -220,7 +220,7 @@ static int php_sha3_unserialize(php_hashcontext_object *hash,
// ==========================================================================
#define DECLARE_SHA3_OPS(bits) \
-void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx) { \
+void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args) { \
PHP_SHA3_Init(ctx, bits); \
} \
void PHP_SHA3##bits##Update(PHP_SHA3_##bits##_CTX* ctx, \
@@ -315,7 +315,7 @@ static int php_keccak_unserialize(php_hashcontext_object *hash, zend_long magic,
// ==========================================================================
#define DECLARE_SHA3_OPS(bits) \
-void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx) { \
+void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args) { \
ZEND_ASSERT(sizeof(Keccak_HashInstance) <= sizeof(PHP_SHA3_##bits##_CTX)); \
Keccak_HashInitialize_SHA3_##bits((Keccak_HashInstance *)ctx); \
} \
diff --git a/ext/hash/hash_snefru.c b/ext/hash/hash_snefru.c
index 292bfef2cb..66f9300b11 100644
--- a/ext/hash/hash_snefru.c
+++ b/ext/hash/hash_snefru.c
@@ -128,7 +128,7 @@ static inline void SnefruTransform(PHP_SNEFRU_CTX *context, const unsigned char
ZEND_SECURE_ZERO(&context->state[8], sizeof(uint32_t) * 8);
}
-PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *context)
+PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(*context));
}
diff --git a/ext/hash/hash_tiger.c b/ext/hash/hash_tiger.c
index 8e0f365dc4..b360dd6ade 100644
--- a/ext/hash/hash_tiger.c
+++ b/ext/hash/hash_tiger.c
@@ -174,7 +174,7 @@ static inline void TigerDigest(unsigned char *digest_str, unsigned int digest_le
}
}
-PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context)
+PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(*context));
context->state[0] = L64(0x0123456789ABCDEF);
@@ -182,7 +182,7 @@ PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context)
context->state[2] = L64(0xF096A5B4C3B2E187);
}
-PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context)
+PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(*context));
context->passes = 1;
diff --git a/ext/hash/hash_whirlpool.c b/ext/hash/hash_whirlpool.c
index 8d5cbb7737..2a64e864c1 100644
--- a/ext/hash/hash_whirlpool.c
+++ b/ext/hash/hash_whirlpool.c
@@ -263,7 +263,7 @@ static void WhirlpoolTransform(PHP_WHIRLPOOL_CTX *context)
ZEND_SECURE_ZERO(state, sizeof(state));
}
-PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *context)
+PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
memset(context, 0, sizeof(*context));
}
diff --git a/ext/hash/php_hash.h b/ext/hash/php_hash.h
index 69d1330072..7f57fe567d 100644
--- a/ext/hash/php_hash.h
+++ b/ext/hash/php_hash.h
@@ -31,7 +31,7 @@
typedef struct _php_hashcontext_object php_hashcontext_object;
-typedef void (*php_hash_init_func_t)(void *context);
+typedef void (*php_hash_init_func_t)(void *context, HashTable *args);
typedef void (*php_hash_update_func_t)(void *context, const unsigned char *buf, size_t count);
typedef void (*php_hash_final_func_t)(unsigned char *digest, void *context);
typedef int (*php_hash_copy_func_t)(const void *ops, void *orig_context, void *dest_context);
diff --git a/ext/hash/php_hash_adler32.h b/ext/hash/php_hash_adler32.h
index 049f16b28e..db2db38114 100644
--- a/ext/hash/php_hash_adler32.h
+++ b/ext/hash/php_hash_adler32.h
@@ -24,7 +24,7 @@ typedef struct {
} PHP_ADLER32_CTX;
#define PHP_ADLER32_SPEC "l."
-PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context);
+PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len);
PHP_HASH_API void PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context);
PHP_HASH_API int PHP_ADLER32Copy(const php_hash_ops *ops, PHP_ADLER32_CTX *orig_context, PHP_ADLER32_CTX *copy_context);
diff --git a/ext/hash/php_hash_crc32.h b/ext/hash/php_hash_crc32.h
index 4c1b0fedc9..1003e4b39b 100644
--- a/ext/hash/php_hash_crc32.h
+++ b/ext/hash/php_hash_crc32.h
@@ -24,7 +24,7 @@ typedef struct {
} PHP_CRC32_CTX;
#define PHP_CRC32_SPEC "l."
-PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context);
+PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len);
PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len);
PHP_HASH_API void PHP_CRC32CUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len);
diff --git a/ext/hash/php_hash_fnv.h b/ext/hash/php_hash_fnv.h
index 6728b2e902..f4dacb223e 100644
--- a/ext/hash/php_hash_fnv.h
+++ b/ext/hash/php_hash_fnv.h
@@ -52,12 +52,12 @@ typedef struct {
#define PHP_FNV164_SPEC "q."
-PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context);
+PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_FNV132Update(PHP_FNV132_CTX *context, const unsigned char *input, size_t inputLen);
PHP_HASH_API void PHP_FNV1a32Update(PHP_FNV132_CTX *context, const unsigned char *input, size_t inputLen);
PHP_HASH_API void PHP_FNV132Final(unsigned char digest[16], PHP_FNV132_CTX * context);
-PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context);
+PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_FNV164Update(PHP_FNV164_CTX *context, const unsigned char *input, size_t inputLen);
PHP_HASH_API void PHP_FNV1a64Update(PHP_FNV164_CTX *context, const unsigned char *input, size_t inputLen);
PHP_HASH_API void PHP_FNV164Final(unsigned char digest[16], PHP_FNV164_CTX * context);
diff --git a/ext/hash/php_hash_gost.h b/ext/hash/php_hash_gost.h
index eb9441faa6..850b089506 100644
--- a/ext/hash/php_hash_gost.h
+++ b/ext/hash/php_hash_gost.h
@@ -29,7 +29,7 @@ typedef struct {
} PHP_GOST_CTX;
#define PHP_GOST_SPEC "l16l2bb32"
-PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *);
+PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_GOSTFinal(unsigned char[64], PHP_GOST_CTX *);
diff --git a/ext/hash/php_hash_haval.h b/ext/hash/php_hash_haval.h
index 43802b4183..2ae0af6bf8 100644
--- a/ext/hash/php_hash_haval.h
+++ b/ext/hash/php_hash_haval.h
@@ -30,7 +30,7 @@ typedef struct {
} PHP_HAVAL_CTX;
#define PHP_HAVAL_SPEC "l8l2b128"
-#define PHP_HASH_HAVAL_INIT_DECL(p,b) PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *); \
+#define PHP_HASH_HAVAL_INIT_DECL(p,b) PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); \
PHP_HASH_API void PHP_HAVAL##b##Final(unsigned char*, PHP_HAVAL_CTX *);
PHP_HASH_API void PHP_HAVALUpdate(PHP_HAVAL_CTX *, const unsigned char *, size_t);
diff --git a/ext/hash/php_hash_joaat.h b/ext/hash/php_hash_joaat.h
index b0df8a67b3..113983c2a4 100644
--- a/ext/hash/php_hash_joaat.h
+++ b/ext/hash/php_hash_joaat.h
@@ -22,7 +22,7 @@ typedef struct {
} PHP_JOAAT_CTX;
#define PHP_JOAAT_SPEC "l."
-PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context);
+PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_JOAATUpdate(PHP_JOAAT_CTX *context, const unsigned char *input, size_t inputLen);
PHP_HASH_API void PHP_JOAATFinal(unsigned char digest[16], PHP_JOAAT_CTX * context);
diff --git a/ext/hash/php_hash_md.h b/ext/hash/php_hash_md.h
index 2a677fe54d..ce155b3e1f 100644
--- a/ext/hash/php_hash_md.h
+++ b/ext/hash/php_hash_md.h
@@ -28,7 +28,8 @@ typedef struct {
} PHP_MD4_CTX;
#define PHP_MD4_SPEC "l4l2b64."
-PHP_HASH_API void PHP_MD4Init(PHP_MD4_CTX *);
+#define PHP_MD4Init(ctx) PHP_MD4InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_MD4InitArgs(PHP_MD4_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_MD4Update(PHP_MD4_CTX *context, const unsigned char *, size_t);
PHP_HASH_API void PHP_MD4Final(unsigned char[16], PHP_MD4_CTX *);
@@ -41,7 +42,8 @@ typedef struct {
} PHP_MD2_CTX;
#define PHP_MD2_SPEC "b48b16b16b."
-PHP_HASH_API void PHP_MD2Init(PHP_MD2_CTX *context);
+#define PHP_MD2Init(ctx) PHP_MD2InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_MD2InitArgs(PHP_MD2_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_MD2Update(PHP_MD2_CTX *context, const unsigned char *, size_t);
PHP_HASH_API void PHP_MD2Final(unsigned char[16], PHP_MD2_CTX *);
diff --git a/ext/hash/php_hash_murmur.h b/ext/hash/php_hash_murmur.h
index 100a8d1fa3..598912141b 100644
--- a/ext/hash/php_hash_murmur.h
+++ b/ext/hash/php_hash_murmur.h
@@ -24,7 +24,7 @@ typedef struct {
} PHP_MURMUR3A_CTX;
#define PHP_MURMUR3A_SPEC "lll"
-PHP_HASH_API void PHP_MURMUR3AInit(PHP_MURMUR3A_CTX *ctx);
+PHP_HASH_API void PHP_MURMUR3AInit(PHP_MURMUR3A_CTX *ctx, HashTable *args);
PHP_HASH_API void PHP_MURMUR3AUpdate(PHP_MURMUR3A_CTX *ctx, const unsigned char *in, size_t len);
PHP_HASH_API void PHP_MURMUR3AFinal(unsigned char digest[4], PHP_MURMUR3A_CTX *ctx);
PHP_HASH_API int PHP_MURMUR3ACopy(const php_hash_ops *ops, PHP_MURMUR3A_CTX *orig_context, PHP_MURMUR3A_CTX *copy_context);
@@ -36,7 +36,7 @@ typedef struct {
} PHP_MURMUR3C_CTX;
#define PHP_MURMUR3C_SPEC "lllllllll"
-PHP_HASH_API void PHP_MURMUR3CInit(PHP_MURMUR3C_CTX *ctx);
+PHP_HASH_API void PHP_MURMUR3CInit(PHP_MURMUR3C_CTX *ctx, HashTable *args);
PHP_HASH_API void PHP_MURMUR3CUpdate(PHP_MURMUR3C_CTX *ctx, const unsigned char *in, size_t len);
PHP_HASH_API void PHP_MURMUR3CFinal(unsigned char digest[16], PHP_MURMUR3C_CTX *ctx);
PHP_HASH_API int PHP_MURMUR3CCopy(const php_hash_ops *ops, PHP_MURMUR3C_CTX *orig_context, PHP_MURMUR3C_CTX *copy_context);
@@ -48,7 +48,7 @@ typedef struct {
} PHP_MURMUR3F_CTX;
#define PHP_MURMUR3F_SPEC "qqqql"
-PHP_HASH_API void PHP_MURMUR3FInit(PHP_MURMUR3F_CTX *ctx);
+PHP_HASH_API void PHP_MURMUR3FInit(PHP_MURMUR3F_CTX *ctx, HashTable *args);
PHP_HASH_API void PHP_MURMUR3FUpdate(PHP_MURMUR3F_CTX *ctx, const unsigned char *in, size_t len);
PHP_HASH_API void PHP_MURMUR3FFinal(unsigned char digest[16], PHP_MURMUR3F_CTX *ctx);
PHP_HASH_API int PHP_MURMUR3FCopy(const php_hash_ops *ops, PHP_MURMUR3F_CTX *orig_context, PHP_MURMUR3F_CTX *copy_context);
diff --git a/ext/hash/php_hash_ripemd.h b/ext/hash/php_hash_ripemd.h
index dd9913b85b..55a430a4f2 100644
--- a/ext/hash/php_hash_ripemd.h
+++ b/ext/hash/php_hash_ripemd.h
@@ -47,19 +47,19 @@ typedef struct {
} PHP_RIPEMD320_CTX;
#define PHP_RIPEMD320_SPEC "l10l2b64."
-PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX *);
+PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_RIPEMD128Update(PHP_RIPEMD128_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_RIPEMD128Final(unsigned char[16], PHP_RIPEMD128_CTX *);
-PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX *);
+PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_RIPEMD160Update(PHP_RIPEMD160_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_RIPEMD160Final(unsigned char[20], PHP_RIPEMD160_CTX *);
-PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX *);
+PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_RIPEMD256Update(PHP_RIPEMD256_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_RIPEMD256Final(unsigned char[32], PHP_RIPEMD256_CTX *);
-PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX *);
+PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_RIPEMD320Update(PHP_RIPEMD320_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_RIPEMD320Final(unsigned char[40], PHP_RIPEMD320_CTX *);
diff --git a/ext/hash/php_hash_sha.h b/ext/hash/php_hash_sha.h
index 16da927363..4240a6228e 100644
--- a/ext/hash/php_hash_sha.h
+++ b/ext/hash/php_hash_sha.h
@@ -29,7 +29,8 @@ typedef struct {
} PHP_SHA224_CTX;
#define PHP_SHA224_SPEC "l8l2b64."
-PHP_HASH_API void PHP_SHA224Init(PHP_SHA224_CTX *);
+#define PHP_SHA224Init(ctx) PHP_SHA224InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA224InitArgs(PHP_SHA224_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA224Update(PHP_SHA224_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_SHA224Final(unsigned char[28], PHP_SHA224_CTX *);
@@ -41,7 +42,8 @@ typedef struct {
} PHP_SHA256_CTX;
#define PHP_SHA256_SPEC "l8l2b64."
-PHP_HASH_API void PHP_SHA256Init(PHP_SHA256_CTX *);
+#define PHP_SHA256Init(ctx) PHP_SHA256InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA256InitArgs(PHP_SHA256_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_SHA256Final(unsigned char[32], PHP_SHA256_CTX *);
@@ -53,7 +55,8 @@ typedef struct {
} PHP_SHA384_CTX;
#define PHP_SHA384_SPEC "q8q2b128."
-PHP_HASH_API void PHP_SHA384Init(PHP_SHA384_CTX *);
+#define PHP_SHA384Init(ctx) PHP_SHA384InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA384InitArgs(PHP_SHA384_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA384Update(PHP_SHA384_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_SHA384Final(unsigned char[48], PHP_SHA384_CTX *);
@@ -65,15 +68,18 @@ typedef struct {
} PHP_SHA512_CTX;
#define PHP_SHA512_SPEC "q8q2b128."
-PHP_HASH_API void PHP_SHA512Init(PHP_SHA512_CTX *);
+#define PHP_SHA512Init(ctx) PHP_SHA512InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA512InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA512Update(PHP_SHA512_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_SHA512Final(unsigned char[64], PHP_SHA512_CTX *);
-PHP_HASH_API void PHP_SHA512_256Init(PHP_SHA512_CTX *);
+#define PHP_SHA512_256Init(ctx) PHP_SHA512_256InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA512_256InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
#define PHP_SHA512_256Update PHP_SHA512Update
PHP_HASH_API void PHP_SHA512_256Final(unsigned char[32], PHP_SHA512_CTX *);
-PHP_HASH_API void PHP_SHA512_224Init(PHP_SHA512_CTX *);
+#define PHP_SHA512_224Init(ctx) PHP_SHA512_224InitArgs(ctx, NULL)
+PHP_HASH_API void PHP_SHA512_224InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
#define PHP_SHA512_224Update PHP_SHA512Update
PHP_HASH_API void PHP_SHA512_224Final(unsigned char[28], PHP_SHA512_CTX *);
diff --git a/ext/hash/php_hash_sha3.h b/ext/hash/php_hash_sha3.h
index f75191f339..b8bd310cce 100644
--- a/ext/hash/php_hash_sha3.h
+++ b/ext/hash/php_hash_sha3.h
@@ -36,19 +36,19 @@ typedef PHP_SHA3_CTX PHP_SHA3_256_CTX;
typedef PHP_SHA3_CTX PHP_SHA3_384_CTX;
typedef PHP_SHA3_CTX PHP_SHA3_512_CTX;
-PHP_HASH_API void PHP_SHA3224Init(PHP_SHA3_224_CTX*);
+PHP_HASH_API void PHP_SHA3224Init(PHP_SHA3_224_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA3224Update(PHP_SHA3_224_CTX*, const unsigned char*, size_t);
PHP_HASH_API void PHP_SAH3224Final(unsigned char[32], PHP_SHA3_224_CTX*);
-PHP_HASH_API void PHP_SHA3256Init(PHP_SHA3_256_CTX*);
+PHP_HASH_API void PHP_SHA3256Init(PHP_SHA3_256_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA3256Update(PHP_SHA3_256_CTX*, const unsigned char*, size_t);
PHP_HASH_API void PHP_SAH3256Final(unsigned char[32], PHP_SHA3_256_CTX*);
-PHP_HASH_API void PHP_SHA3384Init(PHP_SHA3_384_CTX*);
+PHP_HASH_API void PHP_SHA3384Init(PHP_SHA3_384_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA3384Update(PHP_SHA3_384_CTX*, const unsigned char*, size_t);
PHP_HASH_API void PHP_SAH3384Final(unsigned char[32], PHP_SHA3_384_CTX*);
-PHP_HASH_API void PHP_SHA3512Init(PHP_SHA3_512_CTX*);
+PHP_HASH_API void PHP_SHA3512Init(PHP_SHA3_512_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SHA3512Update(PHP_SHA3_512_CTX*, const unsigned char*, size_t);
PHP_HASH_API void PHP_SAH3512Final(unsigned char[32], PHP_SHA3_512_CTX*);
diff --git a/ext/hash/php_hash_snefru.h b/ext/hash/php_hash_snefru.h
index 0f339e9309..c533b576a9 100644
--- a/ext/hash/php_hash_snefru.h
+++ b/ext/hash/php_hash_snefru.h
@@ -32,7 +32,7 @@ typedef struct {
} PHP_SNEFRU_CTX;
#define PHP_SNEFRU_SPEC "l16l2bb32"
-PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *);
+PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_SNEFRUFinal(unsigned char[32], PHP_SNEFRU_CTX *);
diff --git a/ext/hash/php_hash_tiger.h b/ext/hash/php_hash_tiger.h
index d30276ddea..6854c35887 100644
--- a/ext/hash/php_hash_tiger.h
+++ b/ext/hash/php_hash_tiger.h
@@ -27,8 +27,8 @@ typedef struct {
} PHP_TIGER_CTX;
#define PHP_TIGER_SPEC "q3qb64l"
-PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context);
-PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context);
+PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
+PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len);
PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context);
PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context);
diff --git a/ext/hash/php_hash_whirlpool.h b/ext/hash/php_hash_whirlpool.h
index fbd5948a48..376d75a940 100644
--- a/ext/hash/php_hash_whirlpool.h
+++ b/ext/hash/php_hash_whirlpool.h
@@ -29,7 +29,7 @@ typedef struct {
} PHP_WHIRLPOOL_CTX;
#define PHP_WHIRLPOOL_SPEC "q8b32iib64."
-PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *);
+PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHP_HASH_API void PHP_WHIRLPOOLUpdate(PHP_WHIRLPOOL_CTX *, const unsigned char *, size_t);
PHP_HASH_API void PHP_WHIRLPOOLFinal(unsigned char[64], PHP_WHIRLPOOL_CTX *);
diff --git a/ext/hash/tests/murmurhash3_seed.phpt b/ext/hash/tests/murmurhash3_seed.phpt
new file mode 100644
index 0000000000..68cc10a719
--- /dev/null
+++ b/ext/hash/tests/murmurhash3_seed.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Hash: MurmurHash3 seed
+--FILE--
+<?php
+
+$ctx = hash_init("murmur3f", options: ["seed" => 42]);
+hash_update($ctx, "Two");
+hash_update($ctx, " hashes");
+hash_update($ctx, " meet");
+hash_update($ctx, " in");
+hash_update($ctx, " a");
+hash_update($ctx, " bar.");
+$h0 = hash_final($ctx);
+echo $h0, "\n";
+
+$h0 = hash("murmur3f", "Two hashes meet in a bar.", options: ["seed" => 42]);
+echo $h0, "\n";
+
+$ctx = hash_init("murmur3c", options: ["seed" => 106]);
+hash_update($ctx, "Two");
+hash_update($ctx, " hashes");
+hash_update($ctx, " meet");
+hash_update($ctx, " in");
+hash_update($ctx, " a");
+hash_update($ctx, " bar.");
+$h0 = hash_final($ctx);
+echo $h0, "\n";
+
+$h0 = hash("murmur3c", "Two hashes meet in a bar.", options: ["seed" => 106]);
+echo $h0, "\n";
+
+$ctx = hash_init("murmur3a", options: ["seed" => 2345]);
+hash_update($ctx, "Two");
+hash_update($ctx, " hashes");
+hash_update($ctx, " meet");
+hash_update($ctx, " in");
+hash_update($ctx, " a");
+hash_update($ctx, " bar.");
+$h0 = hash_final($ctx);
+echo $h0, "\n";
+
+$h0 = hash("murmur3a", "Two hashes meet in a bar.", options: ["seed" => 2345]);
+echo $h0, "\n";
+
+?>
+--EXPECT--
+95855f9be0db784a5c37e878c4a4dcee
+95855f9be0db784a5c37e878c4a4dcee
+f64c9eb40287fa686575163893e283b2
+f64c9eb40287fa686575163893e283b2
+7f7ec59b
+7f7ec59b
diff --git a/ext/standard/md5.c b/ext/standard/md5.c
index ec07ae2ed3..83d43c4976 100644
--- a/ext/standard/md5.c
+++ b/ext/standard/md5.c
@@ -290,7 +290,7 @@ static const void *body(PHP_MD5_CTX *ctx, const void *data, size_t size)
return ptr;
}
-PHPAPI void PHP_MD5Init(PHP_MD5_CTX *ctx)
+PHPAPI void PHP_MD5InitArgs(PHP_MD5_CTX *ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
ctx->a = 0x67452301;
ctx->b = 0xefcdab89;
diff --git a/ext/standard/md5.h b/ext/standard/md5.h
index ac60d7fca4..09bcff1cf1 100644
--- a/ext/standard/md5.h
+++ b/ext/standard/md5.h
@@ -42,7 +42,8 @@ typedef struct {
} PHP_MD5_CTX;
#define PHP_MD5_SPEC "llllllb64l16."
-PHPAPI void PHP_MD5Init(PHP_MD5_CTX *ctx);
+#define PHP_MD5Init(ctx) PHP_MD5InitArgs(ctx, NULL)
+PHPAPI void PHP_MD5InitArgs(PHP_MD5_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args);
PHPAPI void PHP_MD5Update(PHP_MD5_CTX *ctx, const void *data, size_t size);
PHPAPI void PHP_MD5Final(unsigned char *result, PHP_MD5_CTX *ctx);
diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c
index 58bd91385c..f5668b9283 100644
--- a/ext/standard/sha1.c
+++ b/ext/standard/sha1.c
@@ -152,7 +152,7 @@ static const unsigned char PADDING[64] =
/* {{{ PHP_SHA1Init
* SHA1 initialization. Begins an SHA1 operation, writing a new context.
*/
-PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX * context)
+PHPAPI void PHP_SHA1InitArgs(PHP_SHA1_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
diff --git a/ext/standard/sha1.h b/ext/standard/sha1.h
index ef98ecc29c..3ae3ec219e 100644
--- a/ext/standard/sha1.h
+++ b/ext/standard/sha1.h
@@ -27,7 +27,8 @@ typedef struct {
} PHP_SHA1_CTX;
#define PHP_SHA1_SPEC "l5l2b64."
-PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX *);
+#define PHP_SHA1Init(ctx) PHP_SHA1InitArgs(ctx, NULL)
+PHPAPI void PHP_SHA1InitArgs(PHP_SHA1_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *);
PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, size_t);
PHPAPI void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *);
PHPAPI void make_sha1_digest(char *sha1str, const unsigned char *digest);