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