|
1 <?php |
|
2 namespace Sodium; |
|
3 |
|
4 use ParagonIE_Sodium_Compat; |
|
5 |
|
6 /** |
|
7 * This file will monkey patch the pure-PHP implementation in place of the |
|
8 * PECL functions, but only if they do not already exist. |
|
9 * |
|
10 * Thus, the functions just proxy to the appropriate ParagonIE_Sodium_Compat |
|
11 * method. |
|
12 */ |
|
13 if (!is_callable('\\Sodium\\bin2hex')) { |
|
14 /** |
|
15 * @see ParagonIE_Sodium_Compat::bin2hex() |
|
16 * @param string $string |
|
17 * @return string |
|
18 * @throws \SodiumException |
|
19 * @throws \TypeError |
|
20 */ |
|
21 function bin2hex($string) |
|
22 { |
|
23 return ParagonIE_Sodium_Compat::bin2hex($string); |
|
24 } |
|
25 } |
|
26 if (!is_callable('\\Sodium\\compare')) { |
|
27 /** |
|
28 * @see ParagonIE_Sodium_Compat::compare() |
|
29 * @param string $a |
|
30 * @param string $b |
|
31 * @return int |
|
32 * @throws \SodiumException |
|
33 * @throws \TypeError |
|
34 */ |
|
35 function compare($a, $b) |
|
36 { |
|
37 return ParagonIE_Sodium_Compat::compare($a, $b); |
|
38 } |
|
39 } |
|
40 if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_decrypt')) { |
|
41 /** |
|
42 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt() |
|
43 * @param string $message |
|
44 * @param string $assocData |
|
45 * @param string $nonce |
|
46 * @param string $key |
|
47 * @return string|bool |
|
48 */ |
|
49 function crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key) |
|
50 { |
|
51 try { |
|
52 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key); |
|
53 } catch (\TypeError $ex) { |
|
54 return false; |
|
55 } catch (\SodiumException $ex) { |
|
56 return false; |
|
57 } |
|
58 } |
|
59 } |
|
60 if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_encrypt')) { |
|
61 /** |
|
62 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() |
|
63 * @param string $message |
|
64 * @param string $assocData |
|
65 * @param string $nonce |
|
66 * @param string $key |
|
67 * @return string |
|
68 * @throws \SodiumException |
|
69 * @throws \TypeError |
|
70 */ |
|
71 function crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key) |
|
72 { |
|
73 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key); |
|
74 } |
|
75 } |
|
76 if (!is_callable('\\Sodium\\crypto_aead_aes256gcm_is_available')) { |
|
77 /** |
|
78 * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available() |
|
79 * @return bool |
|
80 */ |
|
81 function crypto_aead_aes256gcm_is_available() |
|
82 { |
|
83 return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available(); |
|
84 } |
|
85 } |
|
86 if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_decrypt')) { |
|
87 /** |
|
88 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt() |
|
89 * @param string $message |
|
90 * @param string $assocData |
|
91 * @param string $nonce |
|
92 * @param string $key |
|
93 * @return string|bool |
|
94 */ |
|
95 function crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key) |
|
96 { |
|
97 try { |
|
98 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key); |
|
99 } catch (\TypeError $ex) { |
|
100 return false; |
|
101 } catch (\SodiumException $ex) { |
|
102 return false; |
|
103 } |
|
104 } |
|
105 } |
|
106 if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_encrypt')) { |
|
107 /** |
|
108 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt() |
|
109 * @param string $message |
|
110 * @param string $assocData |
|
111 * @param string $nonce |
|
112 * @param string $key |
|
113 * @return string |
|
114 * @throws \SodiumException |
|
115 * @throws \TypeError |
|
116 */ |
|
117 function crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key) |
|
118 { |
|
119 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key); |
|
120 } |
|
121 } |
|
122 if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_decrypt')) { |
|
123 /** |
|
124 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt() |
|
125 * @param string $message |
|
126 * @param string $assocData |
|
127 * @param string $nonce |
|
128 * @param string $key |
|
129 * @return string|bool |
|
130 */ |
|
131 function crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key) |
|
132 { |
|
133 try { |
|
134 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key); |
|
135 } catch (\TypeError $ex) { |
|
136 return false; |
|
137 } catch (\SodiumException $ex) { |
|
138 return false; |
|
139 } |
|
140 } |
|
141 } |
|
142 if (!is_callable('\\Sodium\\crypto_aead_chacha20poly1305_ietf_encrypt')) { |
|
143 /** |
|
144 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt() |
|
145 * @param string $message |
|
146 * @param string $assocData |
|
147 * @param string $nonce |
|
148 * @param string $key |
|
149 * @return string |
|
150 * @throws \SodiumException |
|
151 * @throws \TypeError |
|
152 */ |
|
153 function crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key) |
|
154 { |
|
155 return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key); |
|
156 } |
|
157 } |
|
158 if (!is_callable('\\Sodium\\crypto_auth')) { |
|
159 /** |
|
160 * @see ParagonIE_Sodium_Compat::crypto_auth() |
|
161 * @param string $message |
|
162 * @param string $key |
|
163 * @return string |
|
164 * @throws \SodiumException |
|
165 * @throws \TypeError |
|
166 */ |
|
167 function crypto_auth($message, $key) |
|
168 { |
|
169 return ParagonIE_Sodium_Compat::crypto_auth($message, $key); |
|
170 } |
|
171 } |
|
172 if (!is_callable('\\Sodium\\crypto_auth_verify')) { |
|
173 /** |
|
174 * @see ParagonIE_Sodium_Compat::crypto_auth_verify() |
|
175 * @param string $mac |
|
176 * @param string $message |
|
177 * @param string $key |
|
178 * @return bool |
|
179 * @throws \SodiumException |
|
180 * @throws \TypeError |
|
181 */ |
|
182 function crypto_auth_verify($mac, $message, $key) |
|
183 { |
|
184 return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key); |
|
185 } |
|
186 } |
|
187 if (!is_callable('\\Sodium\\crypto_box')) { |
|
188 /** |
|
189 * @see ParagonIE_Sodium_Compat::crypto_box() |
|
190 * @param string $message |
|
191 * @param string $nonce |
|
192 * @param string $kp |
|
193 * @return string |
|
194 * @throws \SodiumException |
|
195 * @throws \TypeError |
|
196 */ |
|
197 function crypto_box($message, $nonce, $kp) |
|
198 { |
|
199 return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp); |
|
200 } |
|
201 } |
|
202 if (!is_callable('\\Sodium\\crypto_box_keypair')) { |
|
203 /** |
|
204 * @see ParagonIE_Sodium_Compat::crypto_box_keypair() |
|
205 * @return string |
|
206 * @throws \SodiumException |
|
207 * @throws \TypeError |
|
208 */ |
|
209 function crypto_box_keypair() |
|
210 { |
|
211 return ParagonIE_Sodium_Compat::crypto_box_keypair(); |
|
212 } |
|
213 } |
|
214 if (!is_callable('\\Sodium\\crypto_box_keypair_from_secretkey_and_publickey')) { |
|
215 /** |
|
216 * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey() |
|
217 * @param string $sk |
|
218 * @param string $pk |
|
219 * @return string |
|
220 * @throws \SodiumException |
|
221 * @throws \TypeError |
|
222 */ |
|
223 function crypto_box_keypair_from_secretkey_and_publickey($sk, $pk) |
|
224 { |
|
225 return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk); |
|
226 } |
|
227 } |
|
228 if (!is_callable('\\Sodium\\crypto_box_open')) { |
|
229 /** |
|
230 * @see ParagonIE_Sodium_Compat::crypto_box_open() |
|
231 * @param string $message |
|
232 * @param string $nonce |
|
233 * @param string $kp |
|
234 * @return string|bool |
|
235 */ |
|
236 function crypto_box_open($message, $nonce, $kp) |
|
237 { |
|
238 try { |
|
239 return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp); |
|
240 } catch (\TypeError $ex) { |
|
241 return false; |
|
242 } catch (\SodiumException $ex) { |
|
243 return false; |
|
244 } |
|
245 } |
|
246 } |
|
247 if (!is_callable('\\Sodium\\crypto_box_publickey')) { |
|
248 /** |
|
249 * @see ParagonIE_Sodium_Compat::crypto_box_publickey() |
|
250 * @param string $keypair |
|
251 * @return string |
|
252 * @throws \SodiumException |
|
253 * @throws \TypeError |
|
254 */ |
|
255 function crypto_box_publickey($keypair) |
|
256 { |
|
257 return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair); |
|
258 } |
|
259 } |
|
260 if (!is_callable('\\Sodium\\crypto_box_publickey_from_secretkey')) { |
|
261 /** |
|
262 * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey() |
|
263 * @param string $sk |
|
264 * @return string |
|
265 * @throws \SodiumException |
|
266 * @throws \TypeError |
|
267 */ |
|
268 function crypto_box_publickey_from_secretkey($sk) |
|
269 { |
|
270 return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk); |
|
271 } |
|
272 } |
|
273 if (!is_callable('\\Sodium\\crypto_box_seal')) { |
|
274 /** |
|
275 * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
276 * @param string $message |
|
277 * @param string $publicKey |
|
278 * @return string |
|
279 * @throws \SodiumException |
|
280 * @throws \TypeError |
|
281 */ |
|
282 function crypto_box_seal($message, $publicKey) |
|
283 { |
|
284 return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey); |
|
285 } |
|
286 } |
|
287 if (!is_callable('\\Sodium\\crypto_box_seal_open')) { |
|
288 /** |
|
289 * @see ParagonIE_Sodium_Compat::crypto_box_seal_open() |
|
290 * @param string $message |
|
291 * @param string $kp |
|
292 * @return string|bool |
|
293 */ |
|
294 function crypto_box_seal_open($message, $kp) |
|
295 { |
|
296 try { |
|
297 return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp); |
|
298 } catch (\TypeError $ex) { |
|
299 return false; |
|
300 } catch (\SodiumException $ex) { |
|
301 return false; |
|
302 } |
|
303 } |
|
304 } |
|
305 if (!is_callable('\\Sodium\\crypto_box_secretkey')) { |
|
306 /** |
|
307 * @see ParagonIE_Sodium_Compat::crypto_box_secretkey() |
|
308 * @param string $keypair |
|
309 * @return string |
|
310 * @throws \SodiumException |
|
311 * @throws \TypeError |
|
312 */ |
|
313 function crypto_box_secretkey($keypair) |
|
314 { |
|
315 return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair); |
|
316 } |
|
317 } |
|
318 if (!is_callable('\\Sodium\\crypto_generichash')) { |
|
319 /** |
|
320 * @see ParagonIE_Sodium_Compat::crypto_generichash() |
|
321 * @param string $message |
|
322 * @param string|null $key |
|
323 * @param int $outLen |
|
324 * @return string |
|
325 * @throws \SodiumException |
|
326 * @throws \TypeError |
|
327 */ |
|
328 function crypto_generichash($message, $key = null, $outLen = 32) |
|
329 { |
|
330 return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen); |
|
331 } |
|
332 } |
|
333 if (!is_callable('\\Sodium\\crypto_generichash_final')) { |
|
334 /** |
|
335 * @see ParagonIE_Sodium_Compat::crypto_generichash_final() |
|
336 * @param string|null $ctx |
|
337 * @param int $outputLength |
|
338 * @return string |
|
339 * @throws \SodiumException |
|
340 * @throws \TypeError |
|
341 */ |
|
342 function crypto_generichash_final(&$ctx, $outputLength = 32) |
|
343 { |
|
344 return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength); |
|
345 } |
|
346 } |
|
347 if (!is_callable('\\Sodium\\crypto_generichash_init')) { |
|
348 /** |
|
349 * @see ParagonIE_Sodium_Compat::crypto_generichash_init() |
|
350 * @param string|null $key |
|
351 * @param int $outLen |
|
352 * @return string |
|
353 * @throws \SodiumException |
|
354 * @throws \TypeError |
|
355 */ |
|
356 function crypto_generichash_init($key = null, $outLen = 32) |
|
357 { |
|
358 return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen); |
|
359 } |
|
360 } |
|
361 if (!is_callable('\\Sodium\\crypto_generichash_update')) { |
|
362 /** |
|
363 * @see ParagonIE_Sodium_Compat::crypto_generichash_update() |
|
364 * @param string|null $ctx |
|
365 * @param string $message |
|
366 * @return void |
|
367 * @throws \SodiumException |
|
368 * @throws \TypeError |
|
369 */ |
|
370 function crypto_generichash_update(&$ctx, $message = '') |
|
371 { |
|
372 ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); |
|
373 } |
|
374 } |
|
375 if (!is_callable('\\Sodium\\crypto_kx')) { |
|
376 /** |
|
377 * @see ParagonIE_Sodium_Compat::crypto_kx() |
|
378 * @param string $my_secret |
|
379 * @param string $their_public |
|
380 * @param string $client_public |
|
381 * @param string $server_public |
|
382 * @return string |
|
383 * @throws \SodiumException |
|
384 * @throws \TypeError |
|
385 */ |
|
386 function crypto_kx($my_secret, $their_public, $client_public, $server_public) |
|
387 { |
|
388 return ParagonIE_Sodium_Compat::crypto_kx( |
|
389 $my_secret, |
|
390 $their_public, |
|
391 $client_public, |
|
392 $server_public |
|
393 ); |
|
394 } |
|
395 } |
|
396 if (!is_callable('\\Sodium\\crypto_pwhash')) { |
|
397 /** |
|
398 * @see ParagonIE_Sodium_Compat::crypto_pwhash() |
|
399 * @param int $outlen |
|
400 * @param string $passwd |
|
401 * @param string $salt |
|
402 * @param int $opslimit |
|
403 * @param int $memlimit |
|
404 * @return string |
|
405 * @throws \SodiumException |
|
406 * @throws \TypeError |
|
407 */ |
|
408 function crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
409 { |
|
410 return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
411 } |
|
412 } |
|
413 if (!is_callable('\\Sodium\\crypto_pwhash_str')) { |
|
414 /** |
|
415 * @see ParagonIE_Sodium_Compat::crypto_pwhash_str() |
|
416 * @param string $passwd |
|
417 * @param int $opslimit |
|
418 * @param int $memlimit |
|
419 * @return string |
|
420 * @throws \SodiumException |
|
421 * @throws \TypeError |
|
422 */ |
|
423 function crypto_pwhash_str($passwd, $opslimit, $memlimit) |
|
424 { |
|
425 return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit); |
|
426 } |
|
427 } |
|
428 if (!is_callable('\\Sodium\\crypto_pwhash_str_verify')) { |
|
429 /** |
|
430 * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify() |
|
431 * @param string $passwd |
|
432 * @param string $hash |
|
433 * @return bool |
|
434 * @throws \SodiumException |
|
435 * @throws \TypeError |
|
436 */ |
|
437 function crypto_pwhash_str_verify($passwd, $hash) |
|
438 { |
|
439 return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash); |
|
440 } |
|
441 } |
|
442 if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256')) { |
|
443 /** |
|
444 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256() |
|
445 * @param int $outlen |
|
446 * @param string $passwd |
|
447 * @param string $salt |
|
448 * @param int $opslimit |
|
449 * @param int $memlimit |
|
450 * @return string |
|
451 * @throws \SodiumException |
|
452 * @throws \TypeError |
|
453 */ |
|
454 function crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit) |
|
455 { |
|
456 return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit); |
|
457 } |
|
458 } |
|
459 if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str')) { |
|
460 /** |
|
461 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str() |
|
462 * @param string $passwd |
|
463 * @param int $opslimit |
|
464 * @param int $memlimit |
|
465 * @return string |
|
466 * @throws \SodiumException |
|
467 * @throws \TypeError |
|
468 */ |
|
469 function crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit) |
|
470 { |
|
471 return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit); |
|
472 } |
|
473 } |
|
474 if (!is_callable('\\Sodium\\crypto_pwhash_scryptsalsa208sha256_str_verify')) { |
|
475 /** |
|
476 * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify() |
|
477 * @param string $passwd |
|
478 * @param string $hash |
|
479 * @return bool |
|
480 * @throws \SodiumException |
|
481 * @throws \TypeError |
|
482 */ |
|
483 function crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash) |
|
484 { |
|
485 return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash); |
|
486 } |
|
487 } |
|
488 if (!is_callable('\\Sodium\\crypto_scalarmult')) { |
|
489 /** |
|
490 * @see ParagonIE_Sodium_Compat::crypto_scalarmult() |
|
491 * @param string $n |
|
492 * @param string $p |
|
493 * @return string |
|
494 * @throws \SodiumException |
|
495 * @throws \TypeError |
|
496 */ |
|
497 function crypto_scalarmult($n, $p) |
|
498 { |
|
499 return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p); |
|
500 } |
|
501 } |
|
502 if (!is_callable('\\Sodium\\crypto_scalarmult_base')) { |
|
503 /** |
|
504 * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base() |
|
505 * @param string $n |
|
506 * @return string |
|
507 * @throws \SodiumException |
|
508 * @throws \TypeError |
|
509 */ |
|
510 function crypto_scalarmult_base($n) |
|
511 { |
|
512 return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n); |
|
513 } |
|
514 } |
|
515 if (!is_callable('\\Sodium\\crypto_secretbox')) { |
|
516 /** |
|
517 * @see ParagonIE_Sodium_Compat::crypto_secretbox() |
|
518 * @param string $message |
|
519 * @param string $nonce |
|
520 * @param string $key |
|
521 * @return string |
|
522 * @throws \SodiumException |
|
523 * @throws \TypeError |
|
524 */ |
|
525 function crypto_secretbox($message, $nonce, $key) |
|
526 { |
|
527 return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key); |
|
528 } |
|
529 } |
|
530 if (!is_callable('\\Sodium\\crypto_secretbox_open')) { |
|
531 /** |
|
532 * @see ParagonIE_Sodium_Compat::crypto_secretbox_open() |
|
533 * @param string $message |
|
534 * @param string $nonce |
|
535 * @param string $key |
|
536 * @return string|bool |
|
537 */ |
|
538 function crypto_secretbox_open($message, $nonce, $key) |
|
539 { |
|
540 try { |
|
541 return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key); |
|
542 } catch (\TypeError $ex) { |
|
543 return false; |
|
544 } catch (\SodiumException $ex) { |
|
545 return false; |
|
546 } |
|
547 } |
|
548 } |
|
549 if (!is_callable('\\Sodium\\crypto_shorthash')) { |
|
550 /** |
|
551 * @see ParagonIE_Sodium_Compat::crypto_shorthash() |
|
552 * @param string $message |
|
553 * @param string $key |
|
554 * @return string |
|
555 * @throws \SodiumException |
|
556 * @throws \TypeError |
|
557 */ |
|
558 function crypto_shorthash($message, $key = '') |
|
559 { |
|
560 return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key); |
|
561 } |
|
562 } |
|
563 if (!is_callable('\\Sodium\\crypto_sign')) { |
|
564 /** |
|
565 * @see ParagonIE_Sodium_Compat::crypto_sign() |
|
566 * @param string $message |
|
567 * @param string $sk |
|
568 * @return string |
|
569 * @throws \SodiumException |
|
570 * @throws \TypeError |
|
571 */ |
|
572 function crypto_sign($message, $sk) |
|
573 { |
|
574 return ParagonIE_Sodium_Compat::crypto_sign($message, $sk); |
|
575 } |
|
576 } |
|
577 if (!is_callable('\\Sodium\\crypto_sign_detached')) { |
|
578 /** |
|
579 * @see ParagonIE_Sodium_Compat::crypto_sign_detached() |
|
580 * @param string $message |
|
581 * @param string $sk |
|
582 * @return string |
|
583 * @throws \SodiumException |
|
584 * @throws \TypeError |
|
585 */ |
|
586 function crypto_sign_detached($message, $sk) |
|
587 { |
|
588 return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); |
|
589 } |
|
590 } |
|
591 if (!is_callable('\\Sodium\\crypto_sign_keypair')) { |
|
592 /** |
|
593 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair() |
|
594 * @return string |
|
595 * @throws \SodiumException |
|
596 * @throws \TypeError |
|
597 */ |
|
598 function crypto_sign_keypair() |
|
599 { |
|
600 return ParagonIE_Sodium_Compat::crypto_sign_keypair(); |
|
601 } |
|
602 } |
|
603 if (!is_callable('\\Sodium\\crypto_sign_open')) { |
|
604 /** |
|
605 * @see ParagonIE_Sodium_Compat::crypto_sign_open() |
|
606 * @param string $signedMessage |
|
607 * @param string $pk |
|
608 * @return string|bool |
|
609 */ |
|
610 function crypto_sign_open($signedMessage, $pk) |
|
611 { |
|
612 try { |
|
613 return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk); |
|
614 } catch (\TypeError $ex) { |
|
615 return false; |
|
616 } catch (\SodiumException $ex) { |
|
617 return false; |
|
618 } |
|
619 } |
|
620 } |
|
621 if (!is_callable('\\Sodium\\crypto_sign_publickey')) { |
|
622 /** |
|
623 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey() |
|
624 * @param string $keypair |
|
625 * @return string |
|
626 * @throws \SodiumException |
|
627 * @throws \TypeError |
|
628 */ |
|
629 function crypto_sign_publickey($keypair) |
|
630 { |
|
631 return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair); |
|
632 } |
|
633 } |
|
634 if (!is_callable('\\Sodium\\crypto_sign_publickey_from_secretkey')) { |
|
635 /** |
|
636 * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey() |
|
637 * @param string $sk |
|
638 * @return string |
|
639 * @throws \SodiumException |
|
640 * @throws \TypeError |
|
641 */ |
|
642 function crypto_sign_publickey_from_secretkey($sk) |
|
643 { |
|
644 return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk); |
|
645 } |
|
646 } |
|
647 if (!is_callable('\\Sodium\\crypto_sign_secretkey')) { |
|
648 /** |
|
649 * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey() |
|
650 * @param string $keypair |
|
651 * @return string |
|
652 * @throws \SodiumException |
|
653 * @throws \TypeError |
|
654 */ |
|
655 function crypto_sign_secretkey($keypair) |
|
656 { |
|
657 return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair); |
|
658 } |
|
659 } |
|
660 if (!is_callable('\\Sodium\\crypto_sign_seed_keypair')) { |
|
661 /** |
|
662 * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair() |
|
663 * @param string $seed |
|
664 * @return string |
|
665 * @throws \SodiumException |
|
666 * @throws \TypeError |
|
667 */ |
|
668 function crypto_sign_seed_keypair($seed) |
|
669 { |
|
670 return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed); |
|
671 } |
|
672 } |
|
673 if (!is_callable('\\Sodium\\crypto_sign_verify_detached')) { |
|
674 /** |
|
675 * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached() |
|
676 * @param string $signature |
|
677 * @param string $message |
|
678 * @param string $pk |
|
679 * @return bool |
|
680 * @throws \SodiumException |
|
681 * @throws \TypeError |
|
682 */ |
|
683 function crypto_sign_verify_detached($signature, $message, $pk) |
|
684 { |
|
685 return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk); |
|
686 } |
|
687 } |
|
688 if (!is_callable('\\Sodium\\crypto_sign_ed25519_pk_to_curve25519')) { |
|
689 /** |
|
690 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519() |
|
691 * @param string $pk |
|
692 * @return string |
|
693 * @throws \SodiumException |
|
694 * @throws \TypeError |
|
695 */ |
|
696 function crypto_sign_ed25519_pk_to_curve25519($pk) |
|
697 { |
|
698 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk); |
|
699 } |
|
700 } |
|
701 if (!is_callable('\\Sodium\\crypto_sign_ed25519_sk_to_curve25519')) { |
|
702 /** |
|
703 * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519() |
|
704 * @param string $sk |
|
705 * @return string |
|
706 * @throws \SodiumException |
|
707 * @throws \TypeError |
|
708 */ |
|
709 function crypto_sign_ed25519_sk_to_curve25519($sk) |
|
710 { |
|
711 return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk); |
|
712 } |
|
713 } |
|
714 if (!is_callable('\\Sodium\\crypto_stream')) { |
|
715 /** |
|
716 * @see ParagonIE_Sodium_Compat::crypto_stream() |
|
717 * @param int $len |
|
718 * @param string $nonce |
|
719 * @param string $key |
|
720 * @return string |
|
721 * @throws \SodiumException |
|
722 * @throws \TypeError |
|
723 */ |
|
724 function crypto_stream($len, $nonce, $key) |
|
725 { |
|
726 return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key); |
|
727 } |
|
728 } |
|
729 if (!is_callable('\\Sodium\\crypto_stream_xor')) { |
|
730 /** |
|
731 * @see ParagonIE_Sodium_Compat::crypto_stream_xor() |
|
732 * @param string $message |
|
733 * @param string $nonce |
|
734 * @param string $key |
|
735 * @return string |
|
736 * @throws \SodiumException |
|
737 * @throws \TypeError |
|
738 */ |
|
739 function crypto_stream_xor($message, $nonce, $key) |
|
740 { |
|
741 return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key); |
|
742 } |
|
743 } |
|
744 if (!is_callable('\\Sodium\\hex2bin')) { |
|
745 /** |
|
746 * @see ParagonIE_Sodium_Compat::hex2bin() |
|
747 * @param string $string |
|
748 * @return string |
|
749 * @throws \SodiumException |
|
750 * @throws \TypeError |
|
751 */ |
|
752 function hex2bin($string) |
|
753 { |
|
754 return ParagonIE_Sodium_Compat::hex2bin($string); |
|
755 } |
|
756 } |
|
757 if (!is_callable('\\Sodium\\memcmp')) { |
|
758 /** |
|
759 * @see ParagonIE_Sodium_Compat::memcmp() |
|
760 * @param string $a |
|
761 * @param string $b |
|
762 * @return int |
|
763 * @throws \SodiumException |
|
764 * @throws \TypeError |
|
765 */ |
|
766 function memcmp($a, $b) |
|
767 { |
|
768 return ParagonIE_Sodium_Compat::memcmp($a, $b); |
|
769 } |
|
770 } |
|
771 if (!is_callable('\\Sodium\\memzero')) { |
|
772 /** |
|
773 * @see ParagonIE_Sodium_Compat::memzero() |
|
774 * @param string $str |
|
775 * @return void |
|
776 * @throws \SodiumException |
|
777 * @throws \TypeError |
|
778 */ |
|
779 function memzero(&$str) |
|
780 { |
|
781 ParagonIE_Sodium_Compat::memzero($str); |
|
782 } |
|
783 } |
|
784 if (!is_callable('\\Sodium\\randombytes_buf')) { |
|
785 /** |
|
786 * @see ParagonIE_Sodium_Compat::randombytes_buf() |
|
787 * @param int $amount |
|
788 * @return string |
|
789 * @throws \TypeError |
|
790 */ |
|
791 function randombytes_buf($amount) |
|
792 { |
|
793 return ParagonIE_Sodium_Compat::randombytes_buf($amount); |
|
794 } |
|
795 } |
|
796 |
|
797 if (!is_callable('\\Sodium\\randombytes_uniform')) { |
|
798 /** |
|
799 * @see ParagonIE_Sodium_Compat::randombytes_uniform() |
|
800 * @param int $upperLimit |
|
801 * @return int |
|
802 * @throws \SodiumException |
|
803 * @throws \Error |
|
804 */ |
|
805 function randombytes_uniform($upperLimit) |
|
806 { |
|
807 return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit); |
|
808 } |
|
809 } |
|
810 |
|
811 if (!is_callable('\\Sodium\\randombytes_random16')) { |
|
812 /** |
|
813 * @see ParagonIE_Sodium_Compat::randombytes_random16() |
|
814 * @return int |
|
815 */ |
|
816 function randombytes_random16() |
|
817 { |
|
818 return ParagonIE_Sodium_Compat::randombytes_random16(); |
|
819 } |
|
820 } |
|
821 |
|
822 if (!defined('\\Sodium\\CRYPTO_AUTH_BYTES')) { |
|
823 require_once dirname(__FILE__) . '/constants.php'; |
|
824 } |