Skip to content

Commit bcf2f94

Browse files
committed
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.
1 parent 4aa7416 commit bcf2f94

File tree

3 files changed

+75
-56
lines changed

3 files changed

+75
-56
lines changed

ext/sodium/libsodium.stub.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,47 @@ function sodium_crypto_auth(string $message, string $key): string {}
3636

3737
function sodium_crypto_auth_keygen(): string {}
3838

39-
function sodium_crypto_auth_verify(string $signature, string $message, string $key): bool {}
39+
function sodium_crypto_auth_verify(string $mac, string $message, string $key): bool {}
4040

41-
function sodium_crypto_box(string $message, string $nonce, string $key): string {}
41+
function sodium_crypto_box(string $message, string $nonce, string $key_pair): string {}
4242

4343
function sodium_crypto_box_keypair(): string {}
4444

45-
function sodium_crypto_box_seed_keypair(string $key): string {}
45+
function sodium_crypto_box_seed_keypair(string $seed): string {}
4646

4747
function sodium_crypto_box_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {}
4848

49-
function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key): string|false {}
49+
function sodium_crypto_box_open(string $ciphertext, string $nonce, string $key_pair): string|false {}
5050

51-
function sodium_crypto_box_publickey(string $key): string {}
51+
function sodium_crypto_box_publickey(string $key_pair): string {}
5252

53-
function sodium_crypto_box_publickey_from_secretkey(string $key): string {}
53+
function sodium_crypto_box_publickey_from_secretkey(string $secret_key): string {}
5454

55-
function sodium_crypto_box_seal(string $message, string $key): string {}
55+
function sodium_crypto_box_seal(string $message, string $key_pair): string {}
5656

57-
function sodium_crypto_box_seal_open(string $ciphertext, string $key): string|false {}
57+
function sodium_crypto_box_seal_open(string $ciphertext, string $key_pair): string|false {}
5858

59-
function sodium_crypto_box_secretkey(string $key): string {}
59+
function sodium_crypto_box_secretkey(string $key_pair): string {}
6060

6161
function sodium_crypto_kx_keypair(): string {}
6262

63-
function sodium_crypto_kx_publickey(string $key): string {}
63+
function sodium_crypto_kx_publickey(string $key_pair): string {}
6464

65-
function sodium_crypto_kx_secretkey(string $key): string {}
65+
function sodium_crypto_kx_secretkey(string $key_pair): string {}
6666

6767
function sodium_crypto_kx_seed_keypair(string $seed): string {}
6868

69-
function sodium_crypto_kx_client_session_keys(string $client_keypair, string $server_key): array {}
69+
function sodium_crypto_kx_client_session_keys(string $client_key_pair, string $server_key): array {}
7070

71-
function sodium_crypto_kx_server_session_keys(string $server_keypair, string $client_key): array {}
71+
function sodium_crypto_kx_server_session_keys(string $server_key_pair, string $client_key): array {}
7272

7373
function sodium_crypto_generichash(string $message, string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}
7474

7575
function sodium_crypto_generichash_keygen(): string {}
7676

7777
function sodium_crypto_generichash_init(string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}
7878

79-
function sodium_crypto_generichash_update(string &$state, string $string): bool {}
79+
function sodium_crypto_generichash_update(string &$state, string $message): bool {}
8080

8181
function sodium_crypto_generichash_final(string &$state, int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}
8282

@@ -130,29 +130,29 @@ function sodium_crypto_shorthash(string $message, string $key): string {}
130130

131131
function sodium_crypto_shorthash_keygen(): string {}
132132

133-
function sodium_crypto_sign(string $message, string $keypair): string {}
133+
function sodium_crypto_sign(string $message, string $secret_key): string {}
134134

135-
function sodium_crypto_sign_detached(string $message, string $keypair): string {}
135+
function sodium_crypto_sign_detached(string $message, string $secret_key): string {}
136136

137-
function sodium_crypto_sign_ed25519_pk_to_curve25519(string $key): string {}
137+
function sodium_crypto_sign_ed25519_pk_to_curve25519(string $public_key): string {}
138138

139-
function sodium_crypto_sign_ed25519_sk_to_curve25519(string $key): string {}
139+
function sodium_crypto_sign_ed25519_sk_to_curve25519(string $secret_key): string {}
140140

141141
function sodium_crypto_sign_keypair(): string {}
142142

143143
function sodium_crypto_sign_keypair_from_secretkey_and_publickey(string $secret_key, string $public_key): string {}
144144

145-
function sodium_crypto_sign_open(string $ciphertext, string $keypair): string|false {}
145+
function sodium_crypto_sign_open(string $ciphertext, string $public_key): string|false {}
146146

147-
function sodium_crypto_sign_publickey(string $key): string {}
147+
function sodium_crypto_sign_publickey(string $key_pair): string {}
148148

149-
function sodium_crypto_sign_secretkey(string $key): string {}
149+
function sodium_crypto_sign_secretkey(string $key_pair): string {}
150150

151-
function sodium_crypto_sign_publickey_from_secretkey(string $key): string {}
151+
function sodium_crypto_sign_publickey_from_secretkey(string $secret_key): string {}
152152

153-
function sodium_crypto_sign_seed_keypair(string $key): string {}
153+
function sodium_crypto_sign_seed_keypair(string $seed): string {}
154154

155-
function sodium_crypto_sign_verify_detached(string $signature, string $message, string $key): bool {}
155+
function sodium_crypto_sign_verify_detached(string $signature, string $message, string $public_key): bool {}
156156

157157
function sodium_crypto_stream(int $length, string $nonce, string $key): string {}
158158

@@ -185,4 +185,4 @@ function sodium_base642bin(string $string, int $id, string $ignore = ""): strin
185185
#endif
186186

187187
/** @alias sodium_crypto_box_publickey_from_secretkey */
188-
function sodium_crypto_scalarmult_base(string $key): string {}
188+
function sodium_crypto_scalarmult_base(string $secret_key): string {}

ext/sodium/libsodium_arginfo.h

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 1b4db83553e156fc38c6e83681f351639a39ac4f */
2+
* Stub hash: 60259c3fefaf8ba8ac22bf80147c3525387ec763 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0)
55
ZEND_END_ARG_INFO()
@@ -81,21 +81,21 @@ ZEND_END_ARG_INFO()
8181
#define arginfo_sodium_crypto_auth_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen
8282

8383
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth_verify, 0, 3, _IS_BOOL, 0)
84-
ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0)
84+
ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0)
8585
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
8686
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
8787
ZEND_END_ARG_INFO()
8888

8989
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box, 0, 3, IS_STRING, 0)
9090
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
9191
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0)
92-
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
92+
ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0)
9393
ZEND_END_ARG_INFO()
9494

9595
#define arginfo_sodium_crypto_box_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen
9696

9797
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seed_keypair, 0, 1, IS_STRING, 0)
98-
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
98+
ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0)
9999
ZEND_END_ARG_INFO()
100100

101101
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()
106106
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
107107
ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0)
108108
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0)
109-
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
109+
ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0)
110110
ZEND_END_ARG_INFO()
111111

112-
#define arginfo_sodium_crypto_box_publickey arginfo_sodium_crypto_box_seed_keypair
112+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey, 0, 1, IS_STRING, 0)
113+
ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0)
114+
ZEND_END_ARG_INFO()
113115

114-
#define arginfo_sodium_crypto_box_publickey_from_secretkey arginfo_sodium_crypto_box_seed_keypair
116+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey_from_secretkey, 0, 1, IS_STRING, 0)
117+
ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0)
118+
ZEND_END_ARG_INFO()
115119

116-
#define arginfo_sodium_crypto_box_seal arginfo_sodium_crypto_auth
120+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seal, 0, 2, IS_STRING, 0)
121+
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
122+
ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0)
123+
ZEND_END_ARG_INFO()
117124

118125
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_seal_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
119126
ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0)
120-
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
127+
ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0)
121128
ZEND_END_ARG_INFO()
122129

123-
#define arginfo_sodium_crypto_box_secretkey arginfo_sodium_crypto_box_seed_keypair
130+
#define arginfo_sodium_crypto_box_secretkey arginfo_sodium_crypto_box_publickey
124131

125132
#define arginfo_sodium_crypto_kx_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen
126133

127-
#define arginfo_sodium_crypto_kx_publickey arginfo_sodium_crypto_box_seed_keypair
134+
#define arginfo_sodium_crypto_kx_publickey arginfo_sodium_crypto_box_publickey
128135

129-
#define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_seed_keypair
136+
#define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_publickey
130137

131-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_seed_keypair, 0, 1, IS_STRING, 0)
132-
ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0)
133-
ZEND_END_ARG_INFO()
138+
#define arginfo_sodium_crypto_kx_seed_keypair arginfo_sodium_crypto_box_seed_keypair
134139

135140
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_client_session_keys, 0, 2, IS_ARRAY, 0)
136-
ZEND_ARG_TYPE_INFO(0, client_keypair, IS_STRING, 0)
141+
ZEND_ARG_TYPE_INFO(0, client_key_pair, IS_STRING, 0)
137142
ZEND_ARG_TYPE_INFO(0, server_key, IS_STRING, 0)
138143
ZEND_END_ARG_INFO()
139144

140145
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_server_session_keys, 0, 2, IS_ARRAY, 0)
141-
ZEND_ARG_TYPE_INFO(0, server_keypair, IS_STRING, 0)
146+
ZEND_ARG_TYPE_INFO(0, server_key_pair, IS_STRING, 0)
142147
ZEND_ARG_TYPE_INFO(0, client_key, IS_STRING, 0)
143148
ZEND_END_ARG_INFO()
144149

@@ -157,7 +162,7 @@ ZEND_END_ARG_INFO()
157162

158163
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_update, 0, 2, _IS_BOOL, 0)
159164
ZEND_ARG_TYPE_INFO(1, state, IS_STRING, 0)
160-
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
165+
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
161166
ZEND_END_ARG_INFO()
162167

163168
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,
238243
ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0)
239244
ZEND_END_ARG_INFO()
240245

241-
#define arginfo_sodium_crypto_secretbox arginfo_sodium_crypto_box
246+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretbox, 0, 3, IS_STRING, 0)
247+
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
248+
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0)
249+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
250+
ZEND_END_ARG_INFO()
242251

243252
#define arginfo_sodium_crypto_secretbox_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen
244253

245-
#define arginfo_sodium_crypto_secretbox_open arginfo_sodium_crypto_box_open
254+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretbox_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
255+
ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0)
256+
ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0)
257+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
258+
ZEND_END_ARG_INFO()
246259

247260
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
248261
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_keygen, 0, 0, IS_STRING, 0)
@@ -291,33 +304,39 @@ ZEND_END_ARG_INFO()
291304

292305
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign, 0, 2, IS_STRING, 0)
293306
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
294-
ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0)
307+
ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0)
295308
ZEND_END_ARG_INFO()
296309

297310
#define arginfo_sodium_crypto_sign_detached arginfo_sodium_crypto_sign
298311

299-
#define arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519 arginfo_sodium_crypto_box_seed_keypair
312+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519, 0, 1, IS_STRING, 0)
313+
ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0)
314+
ZEND_END_ARG_INFO()
300315

301-
#define arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519 arginfo_sodium_crypto_box_seed_keypair
316+
#define arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519 arginfo_sodium_crypto_box_publickey_from_secretkey
302317

303318
#define arginfo_sodium_crypto_sign_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen
304319

305320
#define arginfo_sodium_crypto_sign_keypair_from_secretkey_and_publickey arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey
306321

307322
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_sign_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
308323
ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0)
309-
ZEND_ARG_TYPE_INFO(0, keypair, IS_STRING, 0)
324+
ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0)
310325
ZEND_END_ARG_INFO()
311326

312-
#define arginfo_sodium_crypto_sign_publickey arginfo_sodium_crypto_box_seed_keypair
327+
#define arginfo_sodium_crypto_sign_publickey arginfo_sodium_crypto_box_publickey
313328

314-
#define arginfo_sodium_crypto_sign_secretkey arginfo_sodium_crypto_box_seed_keypair
329+
#define arginfo_sodium_crypto_sign_secretkey arginfo_sodium_crypto_box_publickey
315330

316-
#define arginfo_sodium_crypto_sign_publickey_from_secretkey arginfo_sodium_crypto_box_seed_keypair
331+
#define arginfo_sodium_crypto_sign_publickey_from_secretkey arginfo_sodium_crypto_box_publickey_from_secretkey
317332

318333
#define arginfo_sodium_crypto_sign_seed_keypair arginfo_sodium_crypto_box_seed_keypair
319334

320-
#define arginfo_sodium_crypto_sign_verify_detached arginfo_sodium_crypto_auth_verify
335+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_verify_detached, 0, 3, _IS_BOOL, 0)
336+
ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0)
337+
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
338+
ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0)
339+
ZEND_END_ARG_INFO()
321340

322341
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream, 0, 3, IS_STRING, 0)
323342
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
@@ -327,7 +346,7 @@ ZEND_END_ARG_INFO()
327346

328347
#define arginfo_sodium_crypto_stream_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen
329348

330-
#define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_box
349+
#define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_secretbox
331350

332351
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_add, 0, 2, IS_VOID, 0)
333352
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
381400
ZEND_END_ARG_INFO()
382401
#endif
383402

384-
#define arginfo_sodium_crypto_scalarmult_base arginfo_sodium_crypto_box_seed_keypair
403+
#define arginfo_sodium_crypto_scalarmult_base arginfo_sodium_crypto_box_publickey_from_secretkey
385404

386405

387406
ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_is_available);

ext/sodium/tests/crypto_box.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool(true)
142142
bool(true)
143143
bool(true)
144144
bool(true)
145-
sodium_crypto_box(): Argument #3 ($key) must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long
145+
sodium_crypto_box(): Argument #3 ($key_pair) must be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes long
146146
bool(true)
147147
string(17) "Hi, this is Alice"
148148
string(21) "Hi Alice! This is Bob"

0 commit comments

Comments
 (0)