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