From 2c7d4946ac722bce74e33ff9cda047591e129f1d Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 7 Oct 2026 14:00:19 -0700 Subject: [PATCH] ext/sodium: revert addition of extendable output functions The extendable output functions treated the state as a string, rather than an opaque object, and only validated the lengths of the strings before converting them to the underlying libsodium objects. Thus, incorrect state values could be used to trigger out of bounds reads or updates. The following constants are removed: - `SODIUM_CRYPTO_XOF_SHAKE128_BLOCKBYTES` - `SODIUM_CRYPTO_XOF_SHAKE128_STATEBYTES` - `SODIUM_CRYPTO_XOF_SHAKE256_BLOCKBYTES` - `SODIUM_CRYPTO_XOF_SHAKE256_STATEBYTES` - `SODIUM_CRYPTO_XOF_TURBOSHAKE128_BLOCKBYTES` - `SODIUM_CRYPTO_XOF_TURBOSHAKE128_STATEBYTES` - `SODIUM_CRYPTO_XOF_TURBOSHAKE256_BLOCKBYTES` - `SODIUM_CRYPTO_XOF_TURBOSHAKE256_STATEBYTES` The following functions are removed: - `sodium_crypto_xof_shake128()` - `sodium_crypto_xof_shake128_init()` - `sodium_crypto_xof_shake128_update()` - `sodium_crypto_xof_shake128_squeeze()` - `sodium_crypto_xof_shake256()` - `sodium_crypto_xof_shake256_init()` - `sodium_crypto_xof_shake256_update()` - `sodium_crypto_xof_shake256_squeeze()` - `sodium_crypto_xof_turboshake128()` - `sodium_crypto_xof_turboshake128_init()` - `sodium_crypto_xof_turboshake128_update()` - `sodium_crypto_xof_turboshake128_squeeze()` - `sodium_crypto_xof_turboshake256()` - `sodium_crypto_xof_turboshake256_init()` - `sodium_crypto_xof_turboshake256_update()` - `sodium_crypto_xof_turboshake256_squeeze()` --- ext/sodium/libsodium.c | 574 -------------------- ext/sodium/libsodium.stub.php | 75 --- ext/sodium/libsodium_arginfo.h | 93 +--- ext/sodium/tests/crypto_xof_shake128.phpt | 104 ---- ext/sodium/tests/crypto_xof_shake256.phpt | 80 --- ext/sodium/tests/crypto_xof_turboshake.phpt | 112 ---- 6 files changed, 1 insertion(+), 1037 deletions(-) delete mode 100644 ext/sodium/tests/crypto_xof_shake128.phpt delete mode 100644 ext/sodium/tests/crypto_xof_shake256.phpt delete mode 100644 ext/sodium/tests/crypto_xof_turboshake.phpt diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index f54d35506ab1..c60a6920c169 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -4256,580 +4256,6 @@ PHP_FUNCTION(sodium_ip2bin) } #endif -#ifdef crypto_xof_shake128_STATEBYTES -PHP_FUNCTION(sodium_crypto_xof_shake128) -{ - zend_string *out; - unsigned char *msg; - zend_long out_len; - size_t msg_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", - &out_len, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 1, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - if (crypto_xof_shake128((unsigned char *) ZSTR_VAL(out), (size_t) out_len, - msg, (unsigned long long) msg_len) != 0) { - zend_string_efree(out); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_shake128_init) -{ - crypto_xof_shake128_state state_tmp; - zend_string *state; - zend_long domain = -1; - bool domain_is_null = 1; - - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_LONG_OR_NULL(domain, domain_is_null) - ZEND_PARSE_PARAMETERS_END(); - - memset(&state_tmp, 0, sizeof state_tmp); - if (domain_is_null) { - if (crypto_xof_shake128_init(&state_tmp) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } else { - if (domain < 0x01 || domain > 0x7f) { - zend_argument_error(sodium_exception_ce, 1, "must be between 0x01 and 0x7f"); - RETURN_THROWS(); - } - if (crypto_xof_shake128_init_with_domain(&state_tmp, (unsigned char) domain) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } - state = zend_string_alloc(sizeof state_tmp, 0); - memcpy(ZSTR_VAL(state), &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(state)[sizeof state_tmp] = 0; - RETURN_STR(state); -} - -PHP_FUNCTION(sodium_crypto_xof_shake128_update) -{ - crypto_xof_shake128_state state_tmp; - zval *state_zv; - unsigned char *msg; - unsigned char *state; - size_t msg_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", - &state_zv, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_shake128_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_shake128_update(&state_tmp, msg, (unsigned long long) msg_len) != 0) { - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - RETURN_TRUE; -} - -PHP_FUNCTION(sodium_crypto_xof_shake128_squeeze) -{ - crypto_xof_shake128_state state_tmp; - zval *state_zv; - zend_string *out; - unsigned char *state; - zend_long out_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", - &state_zv, &out_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_shake128_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 2, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_shake128_squeeze(&state_tmp, (unsigned char *) ZSTR_VAL(out), (size_t) out_len) != 0) { - zend_string_efree(out); - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_shake256) -{ - zend_string *out; - unsigned char *msg; - zend_long out_len; - size_t msg_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", - &out_len, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 1, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - if (crypto_xof_shake256((unsigned char *) ZSTR_VAL(out), (size_t) out_len, - msg, (unsigned long long) msg_len) != 0) { - zend_string_efree(out); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_shake256_init) -{ - crypto_xof_shake256_state state_tmp; - zend_string *state; - zend_long domain = -1; - bool domain_is_null = 1; - - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_LONG_OR_NULL(domain, domain_is_null) - ZEND_PARSE_PARAMETERS_END(); - - memset(&state_tmp, 0, sizeof state_tmp); - if (domain_is_null) { - if (crypto_xof_shake256_init(&state_tmp) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } else { - if (domain < 0x01 || domain > 0x7f) { - zend_argument_error(sodium_exception_ce, 1, "must be between 0x01 and 0x7f"); - RETURN_THROWS(); - } - if (crypto_xof_shake256_init_with_domain(&state_tmp, (unsigned char) domain) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } - state = zend_string_alloc(sizeof state_tmp, 0); - memcpy(ZSTR_VAL(state), &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(state)[sizeof state_tmp] = 0; - RETURN_STR(state); -} - -PHP_FUNCTION(sodium_crypto_xof_shake256_update) -{ - crypto_xof_shake256_state state_tmp; - zval *state_zv; - unsigned char *msg; - unsigned char *state; - size_t msg_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", - &state_zv, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_shake256_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_shake256_update(&state_tmp, msg, (unsigned long long) msg_len) != 0) { - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - RETURN_TRUE; -} - -PHP_FUNCTION(sodium_crypto_xof_shake256_squeeze) -{ - crypto_xof_shake256_state state_tmp; - zval *state_zv; - zend_string *out; - unsigned char *state; - zend_long out_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", - &state_zv, &out_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_shake256_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 2, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_shake256_squeeze(&state_tmp, (unsigned char *) ZSTR_VAL(out), (size_t) out_len) != 0) { - zend_string_efree(out); - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake128) -{ - zend_string *out; - unsigned char *msg; - zend_long out_len; - size_t msg_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", - &out_len, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 1, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - if (crypto_xof_turboshake128((unsigned char *) ZSTR_VAL(out), (size_t) out_len, - msg, (unsigned long long) msg_len) != 0) { - zend_string_efree(out); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake128_init) -{ - crypto_xof_turboshake128_state state_tmp; - zend_string *state; - zend_long domain = -1; - bool domain_is_null = 1; - - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_LONG_OR_NULL(domain, domain_is_null) - ZEND_PARSE_PARAMETERS_END(); - - memset(&state_tmp, 0, sizeof state_tmp); - if (domain_is_null) { - if (crypto_xof_turboshake128_init(&state_tmp) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } else { - if (domain < 0x01 || domain > 0x7f) { - zend_argument_error(sodium_exception_ce, 1, "must be between 0x01 and 0x7f"); - RETURN_THROWS(); - } - if (crypto_xof_turboshake128_init_with_domain(&state_tmp, (unsigned char) domain) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } - state = zend_string_alloc(sizeof state_tmp, 0); - memcpy(ZSTR_VAL(state), &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(state)[sizeof state_tmp] = 0; - RETURN_STR(state); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake128_update) -{ - crypto_xof_turboshake128_state state_tmp; - zval *state_zv; - unsigned char *msg; - unsigned char *state; - size_t msg_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", - &state_zv, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_turboshake128_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_turboshake128_update(&state_tmp, msg, (unsigned long long) msg_len) != 0) { - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - RETURN_TRUE; -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake128_squeeze) -{ - crypto_xof_turboshake128_state state_tmp; - zval *state_zv; - zend_string *out; - unsigned char *state; - zend_long out_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", - &state_zv, &out_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_turboshake128_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 2, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_turboshake128_squeeze(&state_tmp, (unsigned char *) ZSTR_VAL(out), (size_t) out_len) != 0) { - zend_string_efree(out); - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake256) -{ - zend_string *out; - unsigned char *msg; - zend_long out_len; - size_t msg_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", - &out_len, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 1, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - if (crypto_xof_turboshake256((unsigned char *) ZSTR_VAL(out), (size_t) out_len, - msg, (unsigned long long) msg_len) != 0) { - zend_string_efree(out); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake256_init) -{ - crypto_xof_turboshake256_state state_tmp; - zend_string *state; - zend_long domain = -1; - bool domain_is_null = 1; - - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_LONG_OR_NULL(domain, domain_is_null) - ZEND_PARSE_PARAMETERS_END(); - - memset(&state_tmp, 0, sizeof state_tmp); - if (domain_is_null) { - if (crypto_xof_turboshake256_init(&state_tmp) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } else { - if (domain < 0x01 || domain > 0x7f) { - zend_argument_error(sodium_exception_ce, 1, "must be between 0x01 and 0x7f"); - RETURN_THROWS(); - } - if (crypto_xof_turboshake256_init_with_domain(&state_tmp, (unsigned char) domain) != 0) { - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - } - state = zend_string_alloc(sizeof state_tmp, 0); - memcpy(ZSTR_VAL(state), &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(state)[sizeof state_tmp] = 0; - RETURN_STR(state); -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake256_update) -{ - crypto_xof_turboshake256_state state_tmp; - zval *state_zv; - unsigned char *msg; - unsigned char *state; - size_t msg_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", - &state_zv, &msg, &msg_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_turboshake256_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_turboshake256_update(&state_tmp, msg, (unsigned long long) msg_len) != 0) { - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - RETURN_TRUE; -} - -PHP_FUNCTION(sodium_crypto_xof_turboshake256_squeeze) -{ - crypto_xof_turboshake256_state state_tmp; - zval *state_zv; - zend_string *out; - unsigned char *state; - zend_long out_len; - size_t state_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zl", - &state_zv, &out_len) == FAILURE) { - sodium_remove_param_values_from_backtrace(EG(exception)); - RETURN_THROWS(); - } - ZVAL_DEREF(state_zv); - if (Z_TYPE_P(state_zv) != IS_STRING) { - zend_argument_error(sodium_exception_ce, 1, "must be a reference to a state"); - RETURN_THROWS(); - } - sodium_separate_string(state_zv); - state = (unsigned char *) Z_STRVAL(*state_zv); - state_len = Z_STRLEN(*state_zv); - if (state_len != sizeof (crypto_xof_turboshake256_state)) { - zend_argument_error(sodium_exception_ce, 1, "must have a correct state length"); - RETURN_THROWS(); - } - if (out_len <= 0 || out_len > ZSTR_MAX_LEN) { - zend_argument_error(sodium_exception_ce, 2, "must be a positive integer"); - RETURN_THROWS(); - } - out = zend_string_alloc((size_t) out_len, 0); - memcpy(&state_tmp, state, sizeof state_tmp); - if (crypto_xof_turboshake256_squeeze(&state_tmp, (unsigned char *) ZSTR_VAL(out), (size_t) out_len) != 0) { - zend_string_efree(out); - sodium_memzero(&state_tmp, sizeof state_tmp); - zend_throw_exception(sodium_exception_ce, "internal error", 0); - RETURN_THROWS(); - } - memcpy(state, &state_tmp, sizeof state_tmp); - sodium_memzero(&state_tmp, sizeof state_tmp); - ZSTR_VAL(out)[out_len] = 0; - RETURN_NEW_STR(out); -} -#endif - #ifdef crypto_kem_PUBLICKEYBYTES PHP_FUNCTION(sodium_crypto_kem_keypair) { diff --git a/ext/sodium/libsodium.stub.php b/ext/sodium/libsodium.stub.php index f1fefefe65e9..6a23cf23d80a 100644 --- a/ext/sodium/libsodium.stub.php +++ b/ext/sodium/libsodium.stub.php @@ -892,81 +892,6 @@ function sodium_bin2ip(string $bin): string {} function sodium_ip2bin(string $ip): string {} #endif -#ifdef crypto_xof_shake128_STATEBYTES -/** - * @var int - * @cvalue crypto_xof_shake128_BLOCKBYTES - */ -const SODIUM_CRYPTO_XOF_SHAKE128_BLOCKBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_shake128_STATEBYTES - */ -const SODIUM_CRYPTO_XOF_SHAKE128_STATEBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_shake256_BLOCKBYTES - */ -const SODIUM_CRYPTO_XOF_SHAKE256_BLOCKBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_shake256_STATEBYTES - */ -const SODIUM_CRYPTO_XOF_SHAKE256_STATEBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_turboshake128_BLOCKBYTES - */ -const SODIUM_CRYPTO_XOF_TURBOSHAKE128_BLOCKBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_turboshake128_STATEBYTES - */ -const SODIUM_CRYPTO_XOF_TURBOSHAKE128_STATEBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_turboshake256_BLOCKBYTES - */ -const SODIUM_CRYPTO_XOF_TURBOSHAKE256_BLOCKBYTES = UNKNOWN; -/** - * @var int - * @cvalue crypto_xof_turboshake256_STATEBYTES - */ -const SODIUM_CRYPTO_XOF_TURBOSHAKE256_STATEBYTES = UNKNOWN; - -function sodium_crypto_xof_shake128(int $length, string $message): string {} - -function sodium_crypto_xof_shake128_init(?int $domain = null): string {} - -function sodium_crypto_xof_shake128_update(string &$state, string $message): true {} - -function sodium_crypto_xof_shake128_squeeze(string &$state, int $length): string {} - -function sodium_crypto_xof_shake256(int $length, string $message): string {} - -function sodium_crypto_xof_shake256_init(?int $domain = null): string {} - -function sodium_crypto_xof_shake256_update(string &$state, string $message): true {} - -function sodium_crypto_xof_shake256_squeeze(string &$state, int $length): string {} - -function sodium_crypto_xof_turboshake128(int $length, string $message): string {} - -function sodium_crypto_xof_turboshake128_init(?int $domain = null): string {} - -function sodium_crypto_xof_turboshake128_update(string &$state, string $message): true {} - -function sodium_crypto_xof_turboshake128_squeeze(string &$state, int $length): string {} - -function sodium_crypto_xof_turboshake256(int $length, string $message): string {} - -function sodium_crypto_xof_turboshake256_init(?int $domain = null): string {} - -function sodium_crypto_xof_turboshake256_update(string &$state, string $message): true {} - -function sodium_crypto_xof_turboshake256_squeeze(string &$state, int $length): string {} -#endif - #ifdef crypto_kem_PUBLICKEYBYTES /** * @var int diff --git a/ext/sodium/libsodium_arginfo.h b/ext/sodium/libsodium_arginfo.h index d13759fd75f1..3c14e43bc8d4 100644 --- a/ext/sodium/libsodium_arginfo.h +++ b/ext/sodium/libsodium_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit libsodium.stub.php instead. - * Stub hash: 3660efaec3ee273ff570540c372d284c72468abb */ + * Stub hash: 87ab07c7c7e991336f98c141933ea0b0dc152b38 */ #include "zend_attributes.h" #include "zend_constants.h" @@ -530,51 +530,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_ip2bin, 0, 1, IS_STRING, ZEND_END_ARG_INFO() #endif -#if defined(crypto_xof_shake128_STATEBYTES) -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_xof_shake128, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_xof_shake128_init, 0, 0, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_LONG, 1, "null") -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_xof_shake128_update, 0, 2, IS_TRUE, 0) - ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_xof_shake128_squeeze, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) -ZEND_END_ARG_INFO() - -#define arginfo_sodium_crypto_xof_shake256 arginfo_sodium_crypto_xof_shake128 - -#define arginfo_sodium_crypto_xof_shake256_init arginfo_sodium_crypto_xof_shake128_init - -#define arginfo_sodium_crypto_xof_shake256_update arginfo_sodium_crypto_xof_shake128_update - -#define arginfo_sodium_crypto_xof_shake256_squeeze arginfo_sodium_crypto_xof_shake128_squeeze - -#define arginfo_sodium_crypto_xof_turboshake128 arginfo_sodium_crypto_xof_shake128 - -#define arginfo_sodium_crypto_xof_turboshake128_init arginfo_sodium_crypto_xof_shake128_init - -#define arginfo_sodium_crypto_xof_turboshake128_update arginfo_sodium_crypto_xof_shake128_update - -#define arginfo_sodium_crypto_xof_turboshake128_squeeze arginfo_sodium_crypto_xof_shake128_squeeze - -#define arginfo_sodium_crypto_xof_turboshake256 arginfo_sodium_crypto_xof_shake128 - -#define arginfo_sodium_crypto_xof_turboshake256_init arginfo_sodium_crypto_xof_shake128_init - -#define arginfo_sodium_crypto_xof_turboshake256_update arginfo_sodium_crypto_xof_shake128_update - -#define arginfo_sodium_crypto_xof_turboshake256_squeeze arginfo_sodium_crypto_xof_shake128_squeeze -#endif - #if defined(crypto_kem_PUBLICKEYBYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kem_keypair, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -772,24 +727,6 @@ ZEND_FUNCTION(sodium_crypto_ipcrypt_pfx_decrypt); ZEND_FUNCTION(sodium_bin2ip); ZEND_FUNCTION(sodium_ip2bin); #endif -#if defined(crypto_xof_shake128_STATEBYTES) -ZEND_FUNCTION(sodium_crypto_xof_shake128); -ZEND_FUNCTION(sodium_crypto_xof_shake128_init); -ZEND_FUNCTION(sodium_crypto_xof_shake128_update); -ZEND_FUNCTION(sodium_crypto_xof_shake128_squeeze); -ZEND_FUNCTION(sodium_crypto_xof_shake256); -ZEND_FUNCTION(sodium_crypto_xof_shake256_init); -ZEND_FUNCTION(sodium_crypto_xof_shake256_update); -ZEND_FUNCTION(sodium_crypto_xof_shake256_squeeze); -ZEND_FUNCTION(sodium_crypto_xof_turboshake128); -ZEND_FUNCTION(sodium_crypto_xof_turboshake128_init); -ZEND_FUNCTION(sodium_crypto_xof_turboshake128_update); -ZEND_FUNCTION(sodium_crypto_xof_turboshake128_squeeze); -ZEND_FUNCTION(sodium_crypto_xof_turboshake256); -ZEND_FUNCTION(sodium_crypto_xof_turboshake256_init); -ZEND_FUNCTION(sodium_crypto_xof_turboshake256_update); -ZEND_FUNCTION(sodium_crypto_xof_turboshake256_squeeze); -#endif #if defined(crypto_kem_PUBLICKEYBYTES) ZEND_FUNCTION(sodium_crypto_kem_keypair); ZEND_FUNCTION(sodium_crypto_kem_seed_keypair); @@ -958,24 +895,6 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(sodium_bin2ip, arginfo_sodium_bin2ip) ZEND_FE(sodium_ip2bin, arginfo_sodium_ip2bin) #endif -#if defined(crypto_xof_shake128_STATEBYTES) - ZEND_FE(sodium_crypto_xof_shake128, arginfo_sodium_crypto_xof_shake128) - ZEND_FE(sodium_crypto_xof_shake128_init, arginfo_sodium_crypto_xof_shake128_init) - ZEND_FE(sodium_crypto_xof_shake128_update, arginfo_sodium_crypto_xof_shake128_update) - ZEND_FE(sodium_crypto_xof_shake128_squeeze, arginfo_sodium_crypto_xof_shake128_squeeze) - ZEND_FE(sodium_crypto_xof_shake256, arginfo_sodium_crypto_xof_shake256) - ZEND_FE(sodium_crypto_xof_shake256_init, arginfo_sodium_crypto_xof_shake256_init) - ZEND_FE(sodium_crypto_xof_shake256_update, arginfo_sodium_crypto_xof_shake256_update) - ZEND_FE(sodium_crypto_xof_shake256_squeeze, arginfo_sodium_crypto_xof_shake256_squeeze) - ZEND_FE(sodium_crypto_xof_turboshake128, arginfo_sodium_crypto_xof_turboshake128) - ZEND_FE(sodium_crypto_xof_turboshake128_init, arginfo_sodium_crypto_xof_turboshake128_init) - ZEND_FE(sodium_crypto_xof_turboshake128_update, arginfo_sodium_crypto_xof_turboshake128_update) - ZEND_FE(sodium_crypto_xof_turboshake128_squeeze, arginfo_sodium_crypto_xof_turboshake128_squeeze) - ZEND_FE(sodium_crypto_xof_turboshake256, arginfo_sodium_crypto_xof_turboshake256) - ZEND_FE(sodium_crypto_xof_turboshake256_init, arginfo_sodium_crypto_xof_turboshake256_init) - ZEND_FE(sodium_crypto_xof_turboshake256_update, arginfo_sodium_crypto_xof_turboshake256_update) - ZEND_FE(sodium_crypto_xof_turboshake256_squeeze, arginfo_sodium_crypto_xof_turboshake256_squeeze) -#endif #if defined(crypto_kem_PUBLICKEYBYTES) ZEND_FE(sodium_crypto_kem_keypair, arginfo_sodium_crypto_kem_keypair) ZEND_FE(sodium_crypto_kem_seed_keypair, arginfo_sodium_crypto_kem_seed_keypair) @@ -1137,16 +1056,6 @@ static void register_libsodium_symbols(int module_number) REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_IPCRYPT_PFX_KEYBYTES", crypto_ipcrypt_PFX_KEYBYTES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_IPCRYPT_PFX_BYTES", crypto_ipcrypt_PFX_BYTES, CONST_PERSISTENT); #endif -#if defined(crypto_xof_shake128_STATEBYTES) - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_SHAKE128_BLOCKBYTES", crypto_xof_shake128_BLOCKBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_SHAKE128_STATEBYTES", crypto_xof_shake128_STATEBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_SHAKE256_BLOCKBYTES", crypto_xof_shake256_BLOCKBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_SHAKE256_STATEBYTES", crypto_xof_shake256_STATEBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_TURBOSHAKE128_BLOCKBYTES", crypto_xof_turboshake128_BLOCKBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_TURBOSHAKE128_STATEBYTES", crypto_xof_turboshake128_STATEBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_TURBOSHAKE256_BLOCKBYTES", crypto_xof_turboshake256_BLOCKBYTES, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_XOF_TURBOSHAKE256_STATEBYTES", crypto_xof_turboshake256_STATEBYTES, CONST_PERSISTENT); -#endif #if defined(crypto_kem_PUBLICKEYBYTES) REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_KEM_PUBLICKEYBYTES", crypto_kem_PUBLICKEYBYTES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SODIUM_CRYPTO_KEM_SECRETKEYBYTES", crypto_kem_SECRETKEYBYTES, CONST_PERSISTENT); diff --git a/ext/sodium/tests/crypto_xof_shake128.phpt b/ext/sodium/tests/crypto_xof_shake128.phpt deleted file mode 100644 index cb075b7ec285..000000000000 --- a/ext/sodium/tests/crypto_xof_shake128.phpt +++ /dev/null @@ -1,104 +0,0 @@ ---TEST-- -Check for libsodium XOF SHAKE128 ---EXTENSIONS-- -sodium ---SKIPIF-- -= 1.0.21)"; -?> ---FILE-- -getMessage() . "\n"; -} - -/* Error: negative length */ -try { - sodium_crypto_xof_shake128(-1, "test"); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} - -/* Error: domain out of range (0x00) */ -try { - sodium_crypto_xof_shake128_init(0); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} - -/* Error: domain out of range (0x80) */ -try { - sodium_crypto_xof_shake128_init(0x80); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} - -/* Error: bad state */ -try { - $bad = "not_a_state"; - sodium_crypto_xof_shake128_update($bad, "test"); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} -?> ---EXPECT-- -string(64) "7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26" -string(64) "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" -int(16) -int(64) -bool(true) -string(64) "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" -string(64) "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" -string(64) "5881092dd818bf5cf8a3ddb793fbcba74097d5c526a6d35f97b83351940f2cc8" -string(64) "f3a3a89c329e644a7d2351744d9a28c953698b64102e912085ce1f6d79fa311e" -bool(true) -sodium_crypto_xof_shake128(): Argument #1 ($length) must be a positive integer -sodium_crypto_xof_shake128(): Argument #1 ($length) must be a positive integer -sodium_crypto_xof_shake128_init(): Argument #1 ($domain) must be between 0x01 and 0x7f -sodium_crypto_xof_shake128_init(): Argument #1 ($domain) must be between 0x01 and 0x7f -sodium_crypto_xof_shake128_update(): Argument #1 ($state) must have a correct state length diff --git a/ext/sodium/tests/crypto_xof_shake256.phpt b/ext/sodium/tests/crypto_xof_shake256.phpt deleted file mode 100644 index 3e6916713328..000000000000 --- a/ext/sodium/tests/crypto_xof_shake256.phpt +++ /dev/null @@ -1,80 +0,0 @@ ---TEST-- -Check for libsodium XOF SHAKE256 ---EXTENSIONS-- -sodium ---SKIPIF-- -= 1.0.21)"; -?> ---FILE-- -getMessage() . "\n"; -} - -/* Error: bad state */ -try { - $bad = "not_a_state"; - sodium_crypto_xof_shake256_update($bad, "test"); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} - -/* Error: squeeze bad length */ -try { - $state = sodium_crypto_xof_shake256_init(); - sodium_crypto_xof_shake256_update($state, "abc"); - sodium_crypto_xof_shake256_squeeze($state, 0); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} -?> ---EXPECT-- -string(64) "46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f" -string(64) "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739" -int(16) -int(64) -bool(true) -string(64) "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739" -string(64) "483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739" -string(64) "1259d63c872d50fee4500685419f489966971c0a77e2058fab0e48dfb12d24bc" -sodium_crypto_xof_shake256(): Argument #1 ($length) must be a positive integer -sodium_crypto_xof_shake256_update(): Argument #1 ($state) must have a correct state length -sodium_crypto_xof_shake256_squeeze(): Argument #2 ($length) must be a positive integer diff --git a/ext/sodium/tests/crypto_xof_turboshake.phpt b/ext/sodium/tests/crypto_xof_turboshake.phpt deleted file mode 100644 index 1f404140cc0b..000000000000 --- a/ext/sodium/tests/crypto_xof_turboshake.phpt +++ /dev/null @@ -1,112 +0,0 @@ ---TEST-- -Check for libsodium XOF TurboSHAKE128 and TurboSHAKE256 ---EXTENSIONS-- -sodium ---SKIPIF-- -= 1.0.21)"; -?> ---FILE-- -getMessage() . "\n"; -} - -/* TurboSHAKE256 error: bad state */ -try { - $bad = "not_a_state"; - sodium_crypto_xof_turboshake256_update($bad, "test"); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} - -/* TurboSHAKE128 error: domain out of range */ -try { - sodium_crypto_xof_turboshake128_init(0); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} -try { - sodium_crypto_xof_turboshake256_init(0x80); -} catch (SodiumException $e) { - echo $e->getMessage() . "\n"; -} -?> ---EXPECT-- -string(64) "1e415f1c5983aff2169217277d17bb538cd945a397ddec541f1ce41af2c1b74c" -string(64) "dcf1646dfe993a8eb6b782d1faaca6d82416a5dcf1de98ee3c6dbc5e1dc63018" -string(64) "367a329dafea871c7802ec67f905ae13c57695dc2c6663c61035f59a18f8e7db" -string(64) "63824b1431a7372e85edc022c9d7afdd027472fcfa33c887d6f5aaf8dc5d4db6" -string(64) "dcf1646dfe993a8eb6b782d1faaca6d82416a5dcf1de98ee3c6dbc5e1dc63018" -string(64) "63824b1431a7372e85edc022c9d7afdd027472fcfa33c887d6f5aaf8dc5d4db6" -string(64) "dcf1646dfe993a8eb6b782d1faaca6d82416a5dcf1de98ee3c6dbc5e1dc63018" -string(64) "63824b1431a7372e85edc022c9d7afdd027472fcfa33c887d6f5aaf8dc5d4db6" -string(64) "3f7566fb02630888cba2af090aaf544ac6e85484d8662335b0c0fd6b3c83ea1b" -string(64) "0137a7e8cca0b99e9bdd557a7caac1f21d65bc2a2ccbde1e1f8c702352a2bf30" -int(16) -int(64) -bool(true) -sodium_crypto_xof_turboshake128(): Argument #1 ($length) must be a positive integer -sodium_crypto_xof_turboshake256_update(): Argument #1 ($state) must have a correct state length -sodium_crypto_xof_turboshake128_init(): Argument #1 ($domain) must be between 0x01 and 0x7f -sodium_crypto_xof_turboshake256_init(): Argument #1 ($domain) must be between 0x01 and 0x7f