-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add crypto_stream_xchacha20 to ext/sodium #6868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
86254fd
ede48d5
f6bddc3
f99a196
bc9e80b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* This is a generated file, edit the .stub.php file instead. | ||
* Stub hash: 457c4c5a0243f815d859bdc9728709b4a8dc84d7 */ | ||
* Stub hash: 55ce0e93db5fac4311ba90693668a92001167573 */ | ||
|
||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) | ||
ZEND_END_ARG_INFO() | ||
|
@@ -348,6 +348,27 @@ ZEND_END_ARG_INFO() | |
|
||
#define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_secretbox | ||
|
||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream_xchacha20, 0, 3, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) | ||
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) | ||
ZEND_END_ARG_INFO() | ||
#endif | ||
|
||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream_xchacha20_keygen, 0, 0, IS_STRING, 0) | ||
ZEND_END_ARG_INFO() | ||
#endif | ||
|
||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream_xchacha20_xor, 0, 3, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) | ||
ZEND_END_ARG_INFO() | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a generated file, run build/gen_stub.php ext/sodium to regenerate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function isn't guaranteed to exist on older versions (1.0.11 and earlier) of libsodium. Does 3v4l.org in particular seems to use an ancient version of the library (possibly 1.0.8). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you need to add the corresponding |
||
|
||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_add, 0, 2, IS_VOID, 0) | ||
ZEND_ARG_TYPE_INFO(1, string1, IS_STRING, 0) | ||
ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) | ||
|
@@ -514,6 +535,15 @@ ZEND_FUNCTION(sodium_crypto_sign_verify_detached); | |
ZEND_FUNCTION(sodium_crypto_stream); | ||
ZEND_FUNCTION(sodium_crypto_stream_keygen); | ||
ZEND_FUNCTION(sodium_crypto_stream_xor); | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FUNCTION(sodium_crypto_stream_xchacha20); | ||
#endif | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FUNCTION(sodium_crypto_stream_xchacha20_keygen); | ||
#endif | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FUNCTION(sodium_crypto_stream_xchacha20_xor); | ||
#endif | ||
ZEND_FUNCTION(sodium_add); | ||
ZEND_FUNCTION(sodium_compare); | ||
ZEND_FUNCTION(sodium_increment); | ||
|
@@ -643,6 +673,15 @@ static const zend_function_entry ext_functions[] = { | |
ZEND_FE(sodium_crypto_stream, arginfo_sodium_crypto_stream) | ||
ZEND_FE(sodium_crypto_stream_keygen, arginfo_sodium_crypto_stream_keygen) | ||
ZEND_FE(sodium_crypto_stream_xor, arginfo_sodium_crypto_stream_xor) | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FE(sodium_crypto_stream_xchacha20, arginfo_sodium_crypto_stream_xchacha20) | ||
#endif | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FE(sodium_crypto_stream_xchacha20_keygen, arginfo_sodium_crypto_stream_xchacha20_keygen) | ||
#endif | ||
#if defined(crypto_stream_xchacha20_KEYBYTES) | ||
ZEND_FE(sodium_crypto_stream_xchacha20_xor, arginfo_sodium_crypto_stream_xchacha20_xor) | ||
#endif | ||
ZEND_FE(sodium_add, arginfo_sodium_add) | ||
ZEND_FE(sodium_compare, arginfo_sodium_compare) | ||
ZEND_FE(sodium_increment, arginfo_sodium_increment) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--TEST-- | ||
Check for libsodium stream | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("sodium") || !defined('CRYPTO_STREAM_XCHACHA20_KEYBYTES')) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES); | ||
$key = sodium_crypto_stream_xchacha20_keygen(); | ||
|
||
$len = 100; | ||
$stream = sodium_crypto_stream_xchacha20($len, $nonce, $key); | ||
var_dump(strlen($stream)); | ||
|
||
$stream2 = sodium_crypto_stream_xchacha20($len, $nonce, $key); | ||
|
||
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES); | ||
$stream3 = sodium_crypto_stream_xchacha20($len, $nonce, $key); | ||
|
||
$key = sodium_crypto_stream_keygen(); | ||
$stream4 = sodium_crypto_stream_xchacha20($len, $nonce, $key); | ||
|
||
var_dump($stream === $stream2); | ||
var_dump($stream !== $stream3); | ||
var_dump($stream !== $stream4); | ||
var_dump($stream2 !== $stream3); | ||
var_dump($stream2 !== $stream4); | ||
var_dump($stream3 !== $stream4); | ||
|
||
$stream5 = sodium_crypto_stream_xchacha20_xor($stream, $nonce, $key); | ||
var_dump($stream5 !== $stream); | ||
$stream6 = sodium_crypto_stream_xchacha20_xor($stream5, $nonce, $key); | ||
|
||
var_dump($stream6 === $stream); | ||
|
||
try { | ||
sodium_crypto_stream_xchacha20($len, substr($nonce, 1), $key); | ||
} catch (SodiumException $ex) { | ||
var_dump(true); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
int(100) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it looks like this function was added in the PECL extension in jedisct1/libsodium-php@75701f2, but is missing here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./configure
doesn't work locally, otherwise we would have caught these without having to depend on CI.