Skip to content

sodium: Use opaque objects for SHAKE state - #24351

Open
TimWolla wants to merge 3 commits into
php:PHP-8.6from
TimWolla:sodium-xof-opaque
Open

TimWolla wants to merge 3 commits into
php:PHP-8.6from
TimWolla:sodium-xof-opaque

Conversation

@TimWolla

Copy link
Copy Markdown
Member

Alternative to #24182.

@TimWolla
TimWolla requested review from a team, DanielEScherzer, edorian and jedisct1 October 15, 2026 13:38
@TimWolla
TimWolla requested a review from kocsismate as a code owner October 15, 2026 13:38
@TimWolla TimWolla changed the title Sodium xof opaque sodium: Use opaque objects for SHAKE state Oct 15, 2026
function sodium_crypto_xof_shake128_init(?int $domain = null): SodiumCryptoXofShake128State {}

function sodium_crypto_xof_shake128_update(string &$state, string $message): true {}
function sodium_crypto_xof_shake128_update(SodiumCryptoXofShake128State $state, string $message): void {}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should $message also have #[\SensitiveParameter]?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea.

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things likely missing:

  • Either support or disallow cloning the state.
  • Reject manual construction of state objects.

Comment thread ext/sodium/libsodium.c
if (out_len <= 0 || out_len > ZSTR_MAX_LEN) {
zend_argument_error(sodium_exception_ce, 2, "must be a positive integer");

if (out_len <= 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you still need the check against ZSTR_MAX_LEN, otherwise you will have a buffer overflow opportunity down below.

Comment thread ext/sodium/libsodium.c
}
if (out_len <= 0 || out_len > ZSTR_MAX_LEN) {
zend_argument_error(sodium_exception_ce, 1, "must be a positive integer");
if (out_len <= 0) {

@ndossche ndossche Oct 15, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the length check, and in a few other places. I'm not gonna mark them all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants