Changeset 46858 for trunk/src/wp-includes/sodium_compat/lib/php72compat.php
- Timestamp:
- 12/09/2019 04:40:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sodium_compat/lib/php72compat.php
r46586 r46858 1 1 <?php 2 3 require_once dirname(dirname(__FILE__)) . '/autoload.php'; 2 4 3 5 /** … … 9 11 */ 10 12 foreach (array( 13 'BASE64_VARIANT_ORIGINAL', 14 'BASE64_VARIANT_ORIGINAL_NO_PADDING', 15 'BASE64_VARIANT_URLSAFE', 16 'BASE64_VARIANT_URLSAFE_NO_PADDING', 11 17 'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES', 12 18 'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES', … … 30 36 'CRYPTO_BOX_NONCEBYTES', 31 37 'CRYPTO_BOX_SEEDBYTES', 38 'CRYPTO_KDF_BYTES_MIN', 39 'CRYPTO_KDF_BYTES_MAX', 40 'CRYPTO_KDF_CONTEXTBYTES', 41 'CRYPTO_KDF_KEYBYTES', 32 42 'CRYPTO_KX_BYTES', 43 'CRYPTO_KX_KEYPAIRBYTES', 44 'CRYPTO_KX_PRIMITIVE', 33 45 'CRYPTO_KX_SEEDBYTES', 34 46 'CRYPTO_KX_PUBLICKEYBYTES', 35 47 'CRYPTO_KX_SECRETKEYBYTES', 48 'CRYPTO_KX_SESSIONKEYBYTES', 36 49 'CRYPTO_GENERICHASH_BYTES', 37 50 'CRYPTO_GENERICHASH_BYTES_MIN', … … 57 70 'CRYPTO_SECRETBOX_MACBYTES', 58 71 'CRYPTO_SECRETBOX_NONCEBYTES', 72 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES', 73 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES', 74 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES', 75 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PUSH', 76 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PULL', 77 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY', 78 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL', 79 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX', 59 80 'CRYPTO_SIGN_BYTES', 60 81 'CRYPTO_SIGN_SEEDBYTES', … … 69 90 ) as $constant 70 91 ) { 71 if (!defined("SODIUM_$constant") ) {92 if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) { 72 93 define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant")); 73 94 } 74 95 } 75 96 if (!is_callable('sodium_add')) { 97 /** 98 * @see ParagonIE_Sodium_Compat::add() 99 * @param string $val 100 * @param string $addv 101 * @return void 102 * @throws SodiumException 103 */ 104 function sodium_add(&$val, $addv) 105 { 106 ParagonIE_Sodium_Compat::add($val, $addv); 107 } 108 } 109 if (!is_callable('sodium_base642bin')) { 110 /** 111 * @see ParagonIE_Sodium_Compat::bin2base64() 112 * @param string $string 113 * @param int $variant 114 * @param string $ignore 115 * @return string 116 * @throws SodiumException 117 * @throws TypeError 118 */ 119 function sodium_base642bin($string, $variant, $ignore ='') 120 { 121 return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore); 122 } 123 } 124 if (!is_callable('sodium_bin2base64')) { 125 /** 126 * @see ParagonIE_Sodium_Compat::bin2base64() 127 * @param string $string 128 * @param int $variant 129 * @return string 130 * @throws SodiumException 131 * @throws TypeError 132 */ 133 function sodium_bin2base64($string, $variant) 134 { 135 return ParagonIE_Sodium_Compat::bin2base64($string, $variant); 136 } 137 } 76 138 if (!is_callable('sodium_bin2hex')) { 77 139 /** … … 187 249 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen() 188 250 * @return string 251 * @throws Exception 189 252 */ 190 253 function sodium_crypto_aead_chacha20poly1305_keygen() … … 233 296 * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen() 234 297 * @return string 298 * @throws Exception 235 299 */ 236 300 function sodium_crypto_aead_chacha20poly1305_ietf_keygen() … … 279 343 * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen() 280 344 * @return string 345 * @throws Exception 281 346 */ 282 347 function sodium_crypto_aead_xchacha20poly1305_ietf_keygen() … … 303 368 * @see ParagonIE_Sodium_Compat::crypto_auth_keygen() 304 369 * @return string 370 * @throws Exception 305 371 */ 306 372 function sodium_crypto_auth_keygen() … … 517 583 * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen() 518 584 * @return string 585 * @throws Exception 519 586 */ 520 587 function sodium_crypto_generichash_keygen() … … 535 602 { 536 603 ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message); 604 } 605 } 606 if (!is_callable('sodium_crypto_kdf_keygen')) { 607 /** 608 * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen() 609 * @return string 610 * @throws Exception 611 */ 612 function sodium_crypto_kdf_keygen() 613 { 614 return ParagonIE_Sodium_Compat::crypto_kdf_keygen(); 615 } 616 } 617 if (!is_callable('sodium_crypto_kdf_derive_from_key')) { 618 /** 619 * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key() 620 * @param int $subkey_len 621 * @param int $subkey_id 622 * @param string $context 623 * @param string $key 624 * @return string 625 * @throws Exception 626 */ 627 function sodium_crypto_kdf_derive_from_key($subkey_len, $subkey_id, $context, $key) 628 { 629 return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key( 630 $subkey_len, 631 $subkey_id, 632 $context, 633 $key 634 ); 537 635 } 538 636 } … … 556 654 $server_public 557 655 ); 656 } 657 } 658 if (!is_callable('sodium_crypto_kx_seed_keypair')) { 659 /** 660 * @param string $seed 661 * @return string 662 * @throws Exception 663 */ 664 function sodium_crypto_kx_seed_keypair($seed) 665 { 666 return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed); 667 } 668 } 669 if (!is_callable('sodium_crypto_kx_keypair')) { 670 /** 671 * @return string 672 * @throws Exception 673 */ 674 function sodium_crypto_kx_keypair() 675 { 676 return ParagonIE_Sodium_Compat::crypto_kx_keypair(); 677 } 678 } 679 if (!is_callable('sodium_crypto_kx_client_session_keys')) { 680 /** 681 * @param string $keypair 682 * @param string $serverPublicKey 683 * @return array{0: string, 1: string} 684 * @throws SodiumException 685 */ 686 function sodium_crypto_kx_client_session_keys($keypair, $serverPublicKey) 687 { 688 return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($keypair, $serverPublicKey); 689 } 690 } 691 if (!is_callable('sodium_crypto_kx_server_session_keys')) { 692 /** 693 * @param string $keypair 694 * @param string $clientPublicKey 695 * @return array{0: string, 1: string} 696 * @throws SodiumException 697 */ 698 function sodium_crypto_kx_server_session_keys($keypair, $clientPublicKey) 699 { 700 return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($keypair, $clientPublicKey); 701 } 702 } 703 if (!is_callable('sodium_crypto_kx_secretkey')) { 704 /** 705 * @param string $keypair 706 * @return string 707 * @throws Exception 708 */ 709 function sodium_crypto_kx_secretkey($keypair) 710 { 711 return ParagonIE_Sodium_Compat::crypto_kx_secretkey($keypair); 712 } 713 } 714 if (!is_callable('sodium_crypto_kx_publickey')) { 715 /** 716 * @param string $keypair 717 * @return string 718 * @throws Exception 719 */ 720 function sodium_crypto_kx_publickey($keypair) 721 { 722 return ParagonIE_Sodium_Compat::crypto_kx_publickey($keypair); 558 723 } 559 724 } … … 591 756 } 592 757 } 758 if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) { 759 /** 760 * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash() 761 * @param string $hash 762 * @param int $opslimit 763 * @param int $memlimit 764 * @return bool 765 * 766 * @throws SodiumException 767 */ 768 function sodium_crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit) 769 { 770 return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit); 771 } 772 } 593 773 if (!is_callable('sodium_crypto_pwhash_str_verify')) { 594 774 /** … … 697 877 * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen() 698 878 * @return string 879 * @throws Exception 699 880 */ 700 881 function sodium_crypto_secretbox_keygen() … … 722 903 } 723 904 } 905 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_push')) { 906 /** 907 * @param string $key 908 * @return array<int, string> 909 * @throws SodiumException 910 */ 911 function sodium_crypto_secretstream_xchacha20poly1305_init_push($key) 912 { 913 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key); 914 } 915 } 916 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) { 917 /** 918 * @param string $state 919 * @param string $msg 920 * @param string $aad 921 * @param int $tag 922 * @return string 923 * @throws SodiumException 924 */ 925 function sodium_crypto_secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) 926 { 927 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push($state, $msg, $aad, $tag); 928 } 929 } 930 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) { 931 /** 932 * @param string $header 933 * @param string $key 934 * @return string 935 * @throws Exception 936 */ 937 function sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key) 938 { 939 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key); 940 } 941 } 942 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) { 943 /** 944 * @param string $state 945 * @param string $cipher 946 * @param string $aad 947 * @return bool|array{0: string, 1: int} 948 * @throws SodiumException 949 */ 950 function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') 951 { 952 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull($state, $cipher, $aad); 953 } 954 } 955 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) { 956 /** 957 * @param string $state 958 * @return void 959 * @throws SodiumException 960 */ 961 function sodium_crypto_secretstream_xchacha20poly1305_rekey(&$state) 962 { 963 ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state); 964 } 965 } 966 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) { 967 /** 968 * @return string 969 * @throws Exception 970 */ 971 function sodium_crypto_secretstream_xchacha20poly1305_keygen() 972 { 973 return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_keygen(); 974 } 975 } 724 976 if (!is_callable('sodium_crypto_shorthash')) { 725 977 /** … … 740 992 * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen() 741 993 * @return string 994 * @throws Exception 742 995 */ 743 996 function sodium_crypto_shorthash_keygen() … … 772 1025 { 773 1026 return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk); 1027 } 1028 } 1029 if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) { 1030 /** 1031 * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey() 1032 * @param string $sk 1033 * @param string $pk 1034 * @return string 1035 * @throws SodiumException 1036 * @throws TypeError 1037 */ 1038 function sodium_crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk) 1039 { 1040 return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk); 774 1041 } 775 1042 } … … 916 1183 * @see ParagonIE_Sodium_Compat::crypto_stream_keygen() 917 1184 * @return string 1185 * @throws Exception 918 1186 */ 919 1187 function sodium_crypto_stream_keygen() … … 1020 1288 } 1021 1289 } 1290 if (!is_callable('sodium_pad')) { 1291 /** 1292 * @see ParagonIE_Sodium_Compat::pad() 1293 * @param string $unpadded 1294 * @param int $blockSize 1295 * @return int 1296 * @throws SodiumException 1297 * @throws TypeError 1298 */ 1299 function sodium_pad($unpadded, $blockSize) 1300 { 1301 return ParagonIE_Sodium_Compat::pad($unpadded, $blockSize, true); 1302 } 1303 } 1304 if (!is_callable('sodium_unpad')) { 1305 /** 1306 * @see ParagonIE_Sodium_Compat::pad() 1307 * @param string $padded 1308 * @param int $blockSize 1309 * @return int 1310 * @throws SodiumException 1311 * @throws TypeError 1312 */ 1313 function sodium_unpad($padded, $blockSize) 1314 { 1315 return ParagonIE_Sodium_Compat::unpad($padded, $blockSize, true); 1316 } 1317 } 1022 1318 if (!is_callable('sodium_randombytes_buf')) { 1023 1319 /** … … 1050 1346 * @see ParagonIE_Sodium_Compat::randombytes_random16() 1051 1347 * @return int 1348 * @throws Exception 1052 1349 */ 1053 1350 function sodium_randombytes_random16()
Note: See TracChangeset
for help on using the changeset viewer.