From 2c6d1689a6bcbbd89c74ba46320a507701b5df2c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 6 Oct 2020 12:02:11 +0200 Subject: [PATCH 1/4] Update ext/sodium parameter names --- ext/sodium/libsodium.stub.php | 16 ++++++++-------- ext/sodium/libsodium_arginfo.h | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ext/sodium/libsodium.stub.php b/ext/sodium/libsodium.stub.php index 6429c3beba97f..96f57c537ab39 100644 --- a/ext/sodium/libsodium.stub.php +++ b/ext/sodium/libsodium.stub.php @@ -80,12 +80,12 @@ function sodium_crypto_generichash_update(string &$state, string $string): bool function sodium_crypto_generichash_final(string &$state, int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} -function sodium_crypto_kdf_derive_from_key(int $subkey_len, int $subkey_id, string $context, string $key): string {} +function sodium_crypto_kdf_derive_from_key(int $subkey_length, int $subkey_id, string $context, string $key): string {} function sodium_crypto_kdf_keygen(): string {} #ifdef crypto_pwhash_SALTBYTES -function sodium_crypto_pwhash(int $length, string $password, string $salt, int $opslimit, int $memlimit, int $alg = SODIUM_CRYPTO_PWHASH_ALG_DEFAULT): string {} +function sodium_crypto_pwhash(int $length, string $password, string $salt, int $opslimit, int $memlimit, int $algo = SODIUM_CRYPTO_PWHASH_ALG_DEFAULT): string {} function sodium_crypto_pwhash_str(string $password, int $opslimit, int $memlimit): string {} @@ -104,7 +104,7 @@ function sodium_crypto_pwhash_scryptsalsa208sha256_str(string $password, int $op function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify(string $hash, string $password): bool {} #endif -function sodium_crypto_scalarmult(string $string_1, string $string_2): string {} +function sodium_crypto_scalarmult(string $string1, string $string2): string {} function sodium_crypto_secretbox(string $string, string $nonce, string $key): string {} @@ -117,11 +117,11 @@ function sodium_crypto_secretstream_xchacha20poly1305_keygen(): string {} function sodium_crypto_secretstream_xchacha20poly1305_init_push(string $key): array {} -function sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, string $msg, string $ad = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE): string {} +function sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, string $message, string $ad = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE): string {} function sodium_crypto_secretstream_xchacha20poly1305_init_pull(string $string, string $key): string {} -function sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $c, string $ad = ""): array|false {} +function sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $ciphertext, string $ad = ""): array|false {} function sodium_crypto_secretstream_xchacha20poly1305_rekey(string &$state): void {} #endif @@ -160,13 +160,13 @@ function sodium_crypto_stream_keygen(): string {} function sodium_crypto_stream_xor(string $string, string $nonce, string $key): string {} -function sodium_add(string &$string_1, string $string_2): void {} +function sodium_add(string &$string1, string $string2): void {} -function sodium_compare(string $string_1, string $string_2): int {} +function sodium_compare(string $string1, string $string2): int {} function sodium_increment(string &$string): void {} -function sodium_memcmp(string $string_1, string $string_2): int {} +function sodium_memcmp(string $string1, string $string2): int {} function sodium_memzero(string &$reference): void {} diff --git a/ext/sodium/libsodium_arginfo.h b/ext/sodium/libsodium_arginfo.h index 4f06398bde2dd..3e456ce1c4e10 100644 --- a/ext/sodium/libsodium_arginfo.h +++ b/ext/sodium/libsodium_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 5d064655caf10f5e0dd126009755bf3552c63f59 */ + * Stub hash: bb8a7d9488d8871ba498e0bf2eeffd31b9402e4d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -166,7 +166,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_final, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kdf_derive_from_key, 0, 4, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, subkey_len, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, subkey_length, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, subkey_id, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, context, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -181,7 +181,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash, 0, 5, IS_S ZEND_ARG_TYPE_INFO(0, salt, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, alg, IS_LONG, 0, "SODIUM_CRYPTO_PWHASH_ALG_DEFAULT") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, algo, IS_LONG, 0, "SODIUM_CRYPTO_PWHASH_ALG_DEFAULT") ZEND_END_ARG_INFO() #endif @@ -234,8 +234,8 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string_1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string_2, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_secretbox arginfo_sodium_crypto_box @@ -258,7 +258,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_push, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, msg, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ad, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, tag, IS_LONG, 0, "SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE") ZEND_END_ARG_INFO() @@ -274,7 +274,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_pull, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, c, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ad, IS_STRING, 0, "\"\"") ZEND_END_ARG_INFO() #endif @@ -330,13 +330,13 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_box ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_add, 0, 2, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(1, string_1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string_2, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(1, string1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_compare, 0, 2, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, string_1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string_2, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_increment, 0, 1, IS_VOID, 0) From 3f5e3157dd9cb4a8836cc77331d166cc31d75aa0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 6 Oct 2020 12:02:38 +0200 Subject: [PATCH 2/4] Rename $ad to $additional_data --- ext/sodium/libsodium.stub.php | 20 ++++++++++---------- ext/sodium/libsodium_arginfo.h | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ext/sodium/libsodium.stub.php b/ext/sodium/libsodium.stub.php index 96f57c537ab39..cd60a9dbb1359 100644 --- a/ext/sodium/libsodium.stub.php +++ b/ext/sodium/libsodium.stub.php @@ -5,31 +5,31 @@ function sodium_crypto_aead_aes256gcm_is_available(): bool {} #ifdef HAVE_AESGCM -function sodium_crypto_aead_aes256gcm_decrypt(string $string, string $ad, string $nonce, string $key): string|false {} +function sodium_crypto_aead_aes256gcm_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_aes256gcm_encrypt(string $string, string $ad, string $nonce, string $key): string {} +function sodium_crypto_aead_aes256gcm_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_aes256gcm_keygen(): string {} #endif -function sodium_crypto_aead_chacha20poly1305_decrypt(string $string, string $ad, string $nonce, string $key): string|false {} +function sodium_crypto_aead_chacha20poly1305_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_chacha20poly1305_encrypt(string $string, string $ad, string $nonce, string $key): string {} +function sodium_crypto_aead_chacha20poly1305_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_chacha20poly1305_keygen(): string {} -function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $string, string $ad, string $nonce, string $key): string|false {} +function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(string $string, string $ad, string $nonce, string $key): string {} +function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_chacha20poly1305_ietf_keygen(): string {} #ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES -function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $string, string $ad, string $nonce, string $key): string|false {} +function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} function sodium_crypto_aead_xchacha20poly1305_ietf_keygen(): string {} -function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(string $string, string $ad, string $nonce, string $key): string {} +function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} #endif function sodium_crypto_auth(string $string, string $key): string {} @@ -117,11 +117,11 @@ function sodium_crypto_secretstream_xchacha20poly1305_keygen(): string {} function sodium_crypto_secretstream_xchacha20poly1305_init_push(string $key): array {} -function sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, string $message, string $ad = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE): string {} +function sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, string $message, string $additional_data = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE): string {} function sodium_crypto_secretstream_xchacha20poly1305_init_pull(string $string, string $key): string {} -function sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $ciphertext, string $ad = ""): array|false {} +function sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $ciphertext, string $additional_data = ""): array|false {} function sodium_crypto_secretstream_xchacha20poly1305_rekey(string &$state): void {} #endif diff --git a/ext/sodium/libsodium_arginfo.h b/ext/sodium/libsodium_arginfo.h index 3e456ce1c4e10..51df7ba9bd48c 100644 --- a/ext/sodium/libsodium_arginfo.h +++ b/ext/sodium/libsodium_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bb8a7d9488d8871ba498e0bf2eeffd31b9402e4d */ + * Stub hash: 43b654aceabe16a8d2114d1fa53cdc7b33072f9a */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -7,7 +7,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_AESGCM) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_aes256gcm_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() @@ -16,7 +16,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_AESGCM) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_encrypt, 0, 4, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() @@ -29,14 +29,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_chacha20poly1305_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_chacha20poly1305_encrypt, 0, 4, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() @@ -53,7 +53,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() @@ -67,7 +67,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt, 0, 4, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, ad, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, additional_data, 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() @@ -259,7 +259,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_push, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ad, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_data, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, tag, IS_LONG, 0, "SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE") ZEND_END_ARG_INFO() #endif @@ -275,7 +275,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_pull, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ad, IS_STRING, 0, "\"\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_data, IS_STRING, 0, "\"\"") ZEND_END_ARG_INFO() #endif From 4aa7416a78bf2ebc688fd058f3c4f120d94f71ae Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 7 Oct 2020 11:19:04 +0200 Subject: [PATCH 3/4] Use $ciphertext and $message --- ext/sodium/libsodium.stub.php | 54 +++++++++++++------------- ext/sodium/libsodium_arginfo.h | 46 +++++++++++----------- ext/sodium/tests/sodium_error_001.phpt | 2 +- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/ext/sodium/libsodium.stub.php b/ext/sodium/libsodium.stub.php index cd60a9dbb1359..6b1329f858974 100644 --- a/ext/sodium/libsodium.stub.php +++ b/ext/sodium/libsodium.stub.php @@ -5,40 +5,40 @@ function sodium_crypto_aead_aes256gcm_is_available(): bool {} #ifdef HAVE_AESGCM -function sodium_crypto_aead_aes256gcm_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} +function sodium_crypto_aead_aes256gcm_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_aes256gcm_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} +function sodium_crypto_aead_aes256gcm_encrypt(string $message, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_aes256gcm_keygen(): string {} #endif -function sodium_crypto_aead_chacha20poly1305_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} +function sodium_crypto_aead_chacha20poly1305_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_chacha20poly1305_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} +function sodium_crypto_aead_chacha20poly1305_encrypt(string $message, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_chacha20poly1305_keygen(): string {} -function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} +function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string|false {} -function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} +function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(string $message, string $additional_data, string $nonce, string $key): string {} function sodium_crypto_aead_chacha20poly1305_ietf_keygen(): string {} #ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES -function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $string, string $additional_data, string $nonce, string $key): string|false {} +function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string|false {} function sodium_crypto_aead_xchacha20poly1305_ietf_keygen(): string {} -function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(string $string, string $additional_data, string $nonce, string $key): string {} +function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(string $message, string $additional_data, string $nonce, string $key): string {} #endif -function sodium_crypto_auth(string $string, string $key): string {} +function sodium_crypto_auth(string $message, string $key): string {} function sodium_crypto_auth_keygen(): string {} -function sodium_crypto_auth_verify(string $signature, string $string, string $key): bool {} +function sodium_crypto_auth_verify(string $signature, string $message, string $key): bool {} -function sodium_crypto_box(string $string, string $nonce, string $key): string {} +function sodium_crypto_box(string $message, string $nonce, string $key): string {} function sodium_crypto_box_keypair(): string {} @@ -46,15 +46,15 @@ function sodium_crypto_box_seed_keypair(string $key): string {} function sodium_crypto_box_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {} -function sodium_crypto_box_open(string $string, string $nonce, string $key): string|false {} +function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key): string|false {} function sodium_crypto_box_publickey(string $key): string {} function sodium_crypto_box_publickey_from_secretkey(string $key): string {} -function sodium_crypto_box_seal(string $string, string $key): string {} +function sodium_crypto_box_seal(string $message, string $key): string {} -function sodium_crypto_box_seal_open(string $string, string $key): string|false {} +function sodium_crypto_box_seal_open(string $ciphertext, string $key): string|false {} function sodium_crypto_box_secretkey(string $key): string {} @@ -64,13 +64,13 @@ function sodium_crypto_kx_publickey(string $key): string {} function sodium_crypto_kx_secretkey(string $key): string {} -function sodium_crypto_kx_seed_keypair(string $string): string {} +function sodium_crypto_kx_seed_keypair(string $seed): string {} function sodium_crypto_kx_client_session_keys(string $client_keypair, string $server_key): array {} function sodium_crypto_kx_server_session_keys(string $server_keypair, string $client_key): array {} -function sodium_crypto_generichash(string $string, string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} +function sodium_crypto_generichash(string $message, string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} function sodium_crypto_generichash_keygen(): string {} @@ -104,13 +104,13 @@ function sodium_crypto_pwhash_scryptsalsa208sha256_str(string $password, int $op function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify(string $hash, string $password): bool {} #endif -function sodium_crypto_scalarmult(string $string1, string $string2): string {} +function sodium_crypto_scalarmult(string $n, string $p): string {} -function sodium_crypto_secretbox(string $string, string $nonce, string $key): string {} +function sodium_crypto_secretbox(string $message, string $nonce, string $key): string {} function sodium_crypto_secretbox_keygen(): string {} -function sodium_crypto_secretbox_open(string $string, string $nonce, string $key): string|false {} +function sodium_crypto_secretbox_open(string $ciphertext, string $nonce, string $key): string|false {} #ifdef crypto_secretstream_xchacha20poly1305_ABYTES function sodium_crypto_secretstream_xchacha20poly1305_keygen(): string {} @@ -119,20 +119,20 @@ function sodium_crypto_secretstream_xchacha20poly1305_init_push(string $key): ar function sodium_crypto_secretstream_xchacha20poly1305_push(string &$state, string $message, string $additional_data = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE): string {} -function sodium_crypto_secretstream_xchacha20poly1305_init_pull(string $string, string $key): string {} +function sodium_crypto_secretstream_xchacha20poly1305_init_pull(string $header, string $key): string {} function sodium_crypto_secretstream_xchacha20poly1305_pull(string &$state, string $ciphertext, string $additional_data = ""): array|false {} function sodium_crypto_secretstream_xchacha20poly1305_rekey(string &$state): void {} #endif -function sodium_crypto_shorthash(string $string, string $key): string {} +function sodium_crypto_shorthash(string $message, string $key): string {} function sodium_crypto_shorthash_keygen(): string {} -function sodium_crypto_sign(string $string, string $keypair): string {} +function sodium_crypto_sign(string $message, string $keypair): string {} -function sodium_crypto_sign_detached(string $string, string $keypair): string {} +function sodium_crypto_sign_detached(string $message, string $keypair): string {} function sodium_crypto_sign_ed25519_pk_to_curve25519(string $key): string {} @@ -142,7 +142,7 @@ function sodium_crypto_sign_keypair(): string {} function sodium_crypto_sign_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {} -function sodium_crypto_sign_open(string $string, string $keypair): string|false {} +function sodium_crypto_sign_open(string $ciphertext, string $keypair): string|false {} function sodium_crypto_sign_publickey(string $key): string {} @@ -152,13 +152,13 @@ function sodium_crypto_sign_publickey_from_secretkey(string $key): string {} function sodium_crypto_sign_seed_keypair(string $key): string {} -function sodium_crypto_sign_verify_detached(string $signature, string $string, string $key): bool {} +function sodium_crypto_sign_verify_detached(string $signature, string $message, string $key): bool {} function sodium_crypto_stream(int $length, string $nonce, string $key): string {} function sodium_crypto_stream_keygen(): string {} -function sodium_crypto_stream_xor(string $string, string $nonce, string $key): string {} +function sodium_crypto_stream_xor(string $message, string $nonce, string $key): string {} function sodium_add(string &$string1, string $string2): void {} @@ -168,7 +168,7 @@ function sodium_increment(string &$string): void {} function sodium_memcmp(string $string1, string $string2): int {} -function sodium_memzero(string &$reference): void {} +function sodium_memzero(string &$string): void {} function sodium_pad(string $string, int $length): string {} diff --git a/ext/sodium/libsodium_arginfo.h b/ext/sodium/libsodium_arginfo.h index 51df7ba9bd48c..93ce775d0f669 100644 --- a/ext/sodium/libsodium_arginfo.h +++ b/ext/sodium/libsodium_arginfo.h @@ -1,12 +1,12 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 43b654aceabe16a8d2114d1fa53cdc7b33072f9a */ + * Stub hash: 1b4db83553e156fc38c6e83681f351639a39ac4f */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() #if defined(HAVE_AESGCM) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_aes256gcm_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -15,7 +15,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_AESGCM) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_encrypt, 0, 4, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -28,14 +28,14 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_chacha20poly1305_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, 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() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_chacha20poly1305_encrypt, 0, 4, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -52,7 +52,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -66,7 +66,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt, 0, 4, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) @@ -74,7 +74,7 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -82,12 +82,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth_verify, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box, 0, 3, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, 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() @@ -104,7 +104,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_keypair_from_s ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, 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() @@ -116,7 +116,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_box_seal arginfo_sodium_crypto_auth ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_seal_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -129,7 +129,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_seed_keypair ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_seed_keypair, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_client_session_keys, 0, 2, IS_ARRAY, 0) @@ -143,7 +143,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_server_session_ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, key, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "SODIUM_CRYPTO_GENERICHASH_BYTES") ZEND_END_ARG_INFO() @@ -234,8 +234,8 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, n, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_secretbox arginfo_sodium_crypto_box @@ -266,7 +266,7 @@ ZEND_END_ARG_INFO() #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_init_pull, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, header, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_END_ARG_INFO() #endif @@ -290,7 +290,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_shorthash_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign, 0, 2, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -305,7 +305,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_sign_keypair_from_secretkey_and_publickey arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_sign_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -345,9 +345,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_memcmp arginfo_sodium_compare -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_memzero, 0, 1, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(1, reference, IS_STRING, 0) -ZEND_END_ARG_INFO() +#define arginfo_sodium_memzero arginfo_sodium_increment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_pad, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) @@ -359,7 +357,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_unpad, 0, 2, IS_STRING, 0 ZEND_ARG_TYPE_INFO(0, block_size, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_sodium_bin2hex arginfo_sodium_crypto_kx_seed_keypair +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_bin2hex, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_hex2bin, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) diff --git a/ext/sodium/tests/sodium_error_001.phpt b/ext/sodium/tests/sodium_error_001.phpt index 5ebcb8e80ef1a..a78d071a10eea 100644 --- a/ext/sodium/tests/sodium_error_001.phpt +++ b/ext/sodium/tests/sodium_error_001.phpt @@ -15,7 +15,7 @@ $key = random_bytes(SODIUM_CRYPTO_SHORTHASH_KEYBYTES); $hash = do_crypto_shorthash($m, $key); ?> --EXPECTF-- -Fatal error: Uncaught TypeError: sodium_crypto_shorthash(): Argument #1 ($string) must be of type string, int given in %s:%d +Fatal error: Uncaught TypeError: sodium_crypto_shorthash(): Argument #1 ($message) must be of type string, int given in %s:%d Stack trace: #0 %s(%d): sodium_crypto_shorthash() #1 %s(%d): do_crypto_shorthash() From bcf2f946284cc1a6fe38ed655dfc4ddcbcdb15a8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 13 Oct 2020 10:08:23 +0200 Subject: [PATCH 4/4] Review usage of public key, secret key and key pair Some of original parameter names weren't correct, e.g. some functions using $keypair even though they only accept a single key. Fix a number of such issues after cross-checking with the libsodium docs and the implementation. --- ext/sodium/libsodium.stub.php | 50 ++++++++++---------- ext/sodium/libsodium_arginfo.h | 79 ++++++++++++++++++++------------ ext/sodium/tests/crypto_box.phpt | 2 +- 3 files changed, 75 insertions(+), 56 deletions(-) diff --git a/ext/sodium/libsodium.stub.php b/ext/sodium/libsodium.stub.php index 6b1329f858974..b2bfd357309b5 100644 --- a/ext/sodium/libsodium.stub.php +++ b/ext/sodium/libsodium.stub.php @@ -36,39 +36,39 @@ function sodium_crypto_auth(string $message, string $key): string {} function sodium_crypto_auth_keygen(): string {} -function sodium_crypto_auth_verify(string $signature, string $message, string $key): bool {} +function sodium_crypto_auth_verify(string $mac, string $message, string $key): bool {} -function sodium_crypto_box(string $message, string $nonce, string $key): string {} +function sodium_crypto_box(string $message, string $nonce, string $key_pair): string {} function sodium_crypto_box_keypair(): string {} -function sodium_crypto_box_seed_keypair(string $key): string {} +function sodium_crypto_box_seed_keypair(string $seed): string {} function sodium_crypto_box_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {} -function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key): string|false {} +function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key_pair): string|false {} -function sodium_crypto_box_publickey(string $key): string {} +function sodium_crypto_box_publickey(string $key_pair): string {} -function sodium_crypto_box_publickey_from_secretkey(string $key): string {} +function sodium_crypto_box_publickey_from_secretkey(string $secret_key): string {} -function sodium_crypto_box_seal(string $message, string $key): string {} +function sodium_crypto_box_seal(string $message, string $key_pair): string {} -function sodium_crypto_box_seal_open(string $ciphertext, string $key): string|false {} +function sodium_crypto_box_seal_open(string $ciphertext, string $key_pair): string|false {} -function sodium_crypto_box_secretkey(string $key): string {} +function sodium_crypto_box_secretkey(string $key_pair): string {} function sodium_crypto_kx_keypair(): string {} -function sodium_crypto_kx_publickey(string $key): string {} +function sodium_crypto_kx_publickey(string $key_pair): string {} -function sodium_crypto_kx_secretkey(string $key): string {} +function sodium_crypto_kx_secretkey(string $key_pair): string {} function sodium_crypto_kx_seed_keypair(string $seed): string {} -function sodium_crypto_kx_client_session_keys(string $client_keypair, string $server_key): array {} +function sodium_crypto_kx_client_session_keys(string $client_key_pair, string $server_key): array {} -function sodium_crypto_kx_server_session_keys(string $server_keypair, string $client_key): array {} +function sodium_crypto_kx_server_session_keys(string $server_key_pair, string $client_key): array {} function sodium_crypto_generichash(string $message, string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} @@ -76,7 +76,7 @@ function sodium_crypto_generichash_keygen(): string {} function sodium_crypto_generichash_init(string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} -function sodium_crypto_generichash_update(string &$state, string $string): bool {} +function sodium_crypto_generichash_update(string &$state, string $message): bool {} function sodium_crypto_generichash_final(string &$state, int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {} @@ -130,29 +130,29 @@ function sodium_crypto_shorthash(string $message, string $key): string {} function sodium_crypto_shorthash_keygen(): string {} -function sodium_crypto_sign(string $message, string $keypair): string {} +function sodium_crypto_sign(string $message, string $secret_key): string {} -function sodium_crypto_sign_detached(string $message, string $keypair): string {} +function sodium_crypto_sign_detached(string $message, string $secret_key): string {} -function sodium_crypto_sign_ed25519_pk_to_curve25519(string $key): string {} +function sodium_crypto_sign_ed25519_pk_to_curve25519(string $public_key): string {} -function sodium_crypto_sign_ed25519_sk_to_curve25519(string $key): string {} +function sodium_crypto_sign_ed25519_sk_to_curve25519(string $secret_key): string {} function sodium_crypto_sign_keypair(): string {} function sodium_crypto_sign_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {} -function sodium_crypto_sign_open(string $ciphertext, string $keypair): string|false {} +function sodium_crypto_sign_open(string $ciphertext, string $public_key): string|false {} -function sodium_crypto_sign_publickey(string $key): string {} +function sodium_crypto_sign_publickey(string $key_pair): string {} -function sodium_crypto_sign_secretkey(string $key): string {} +function sodium_crypto_sign_secretkey(string $key_pair): string {} -function sodium_crypto_sign_publickey_from_secretkey(string $key): string {} +function sodium_crypto_sign_publickey_from_secretkey(string $secret_key): string {} -function sodium_crypto_sign_seed_keypair(string $key): string {} +function sodium_crypto_sign_seed_keypair(string $seed): string {} -function sodium_crypto_sign_verify_detached(string $signature, string $message, string $key): bool {} +function sodium_crypto_sign_verify_detached(string $signature, string $message, string $public_key): bool {} function sodium_crypto_stream(int $length, string $nonce, string $key): string {} @@ -185,4 +185,4 @@ function sodium_base642bin(string $string, int $id, string $ignore = ""): strin #endif /** @alias sodium_crypto_box_publickey_from_secretkey */ -function sodium_crypto_scalarmult_base(string $key): string {} +function sodium_crypto_scalarmult_base(string $secret_key): string {} diff --git a/ext/sodium/libsodium_arginfo.h b/ext/sodium/libsodium_arginfo.h index 93ce775d0f669..9b0d4b0f1d361 100644 --- a/ext/sodium/libsodium_arginfo.h +++ b/ext/sodium/libsodium_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 1b4db83553e156fc38c6e83681f351639a39ac4f */ + * Stub hash: 60259c3fefaf8ba8ac22bf80147c3525387ec763 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -81,7 +81,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_auth_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth_verify, 0, 3, _IS_BOOL, 0) - ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -89,13 +89,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box, 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_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_box_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seed_keypair, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey, 0, 2, IS_STRING, 0) @@ -106,39 +106,44 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_box_publickey arginfo_sodium_crypto_box_seed_keypair +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) +ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_box_publickey_from_secretkey arginfo_sodium_crypto_box_seed_keypair +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey_from_secretkey, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0) +ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_box_seal arginfo_sodium_crypto_auth +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seal, 0, 2, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_seal_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_box_secretkey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_box_secretkey arginfo_sodium_crypto_box_publickey #define arginfo_sodium_crypto_kx_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen -#define arginfo_sodium_crypto_kx_publickey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_kx_publickey arginfo_sodium_crypto_box_publickey -#define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_publickey -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_seed_keypair, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0) -ZEND_END_ARG_INFO() +#define arginfo_sodium_crypto_kx_seed_keypair arginfo_sodium_crypto_box_seed_keypair ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_client_session_keys, 0, 2, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO(0, client_keypair, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, client_key_pair, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, server_key, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_server_session_keys, 0, 2, IS_ARRAY, 0) - ZEND_ARG_TYPE_INFO(0, server_keypair, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, server_key_pair, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, client_key, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -157,7 +162,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_update, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, string, 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_generichash_final, 0, 1, IS_STRING, 0) @@ -238,11 +243,19 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult, 0, 2, ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_secretbox arginfo_sodium_crypto_box +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretbox, 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() #define arginfo_sodium_crypto_secretbox_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen -#define arginfo_sodium_crypto_secretbox_open arginfo_sodium_crypto_box_open +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretbox_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, ciphertext, 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() #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_keygen, 0, 0, IS_STRING, 0) @@ -291,14 +304,16 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_sign_detached arginfo_sodium_crypto_sign -#define arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519 arginfo_sodium_crypto_box_seed_keypair +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) +ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519 arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519 arginfo_sodium_crypto_box_publickey_from_secretkey #define arginfo_sodium_crypto_sign_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen @@ -306,18 +321,22 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_sign_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_sodium_crypto_sign_publickey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_sign_publickey arginfo_sodium_crypto_box_publickey -#define arginfo_sodium_crypto_sign_secretkey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_sign_secretkey arginfo_sodium_crypto_box_publickey -#define arginfo_sodium_crypto_sign_publickey_from_secretkey arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_sign_publickey_from_secretkey arginfo_sodium_crypto_box_publickey_from_secretkey #define arginfo_sodium_crypto_sign_seed_keypair arginfo_sodium_crypto_box_seed_keypair -#define arginfo_sodium_crypto_sign_verify_detached arginfo_sodium_crypto_auth_verify +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_verify_detached, 0, 3, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream, 0, 3, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) @@ -327,7 +346,7 @@ ZEND_END_ARG_INFO() #define arginfo_sodium_crypto_stream_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen -#define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_box +#define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_secretbox 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) @@ -381,7 +400,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_base642bin, 0, 2, IS_STRI ZEND_END_ARG_INFO() #endif -#define arginfo_sodium_crypto_scalarmult_base arginfo_sodium_crypto_box_seed_keypair +#define arginfo_sodium_crypto_scalarmult_base arginfo_sodium_crypto_box_publickey_from_secretkey ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_is_available); diff --git a/ext/sodium/tests/crypto_box.phpt b/ext/sodium/tests/crypto_box.phpt index b5c1d79d85098..3a55717d53ce6 100644 --- a/ext/sodium/tests/crypto_box.phpt +++ b/ext/sodium/tests/crypto_box.phpt @@ -142,7 +142,7 @@ bool(true) bool(true) bool(true) bool(true) -sodium_crypto_box(): Argument #3 ($key) must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long +sodium_crypto_box(): Argument #3 ($key_pair) must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long bool(true) string(17) "Hi, this is Alice" string(21) "Hi Alice! This is Bob"