wp/wp-includes/sodium_compat/lib/php72compat.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    12 foreach (array(
    12 foreach (array(
    13     'BASE64_VARIANT_ORIGINAL',
    13     'BASE64_VARIANT_ORIGINAL',
    14     'BASE64_VARIANT_ORIGINAL_NO_PADDING',
    14     'BASE64_VARIANT_ORIGINAL_NO_PADDING',
    15     'BASE64_VARIANT_URLSAFE',
    15     'BASE64_VARIANT_URLSAFE',
    16     'BASE64_VARIANT_URLSAFE_NO_PADDING',
    16     'BASE64_VARIANT_URLSAFE_NO_PADDING',
       
    17     'CRYPTO_AEAD_AES256GCM_KEYBYTES',
       
    18     'CRYPTO_AEAD_AES256GCM_NSECBYTES',
       
    19     'CRYPTO_AEAD_AES256GCM_NPUBBYTES',
       
    20     'CRYPTO_AEAD_AES256GCM_ABYTES',
    17     'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES',
    21     'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES',
    18     'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES',
    22     'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES',
    19     'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES',
    23     'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES',
    20     'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES',
    24     'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES',
    21     'CRYPTO_AEAD_AES256GCM_KEYBYTES',
       
    22     'CRYPTO_AEAD_AES256GCM_NSECBYTES',
       
    23     'CRYPTO_AEAD_AES256GCM_NPUBBYTES',
       
    24     'CRYPTO_AEAD_AES256GCM_ABYTES',
       
    25     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES',
    25     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES',
    26     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES',
    26     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES',
    27     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES',
    27     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES',
    28     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES',
    28     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES',
    29     'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES',
    29     'CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES',
   113      * @param string $string1
   113      * @param string $string1
   114      * @param string $string2
   114      * @param string $string2
   115      * @return void
   115      * @return void
   116      * @throws SodiumException
   116      * @throws SodiumException
   117      */
   117      */
   118     function sodium_add(&$string1, $string2)
   118     function sodium_add(
   119     {
   119         #[\SensitiveParameter]
       
   120         &$string1,
       
   121         #[\SensitiveParameter]
       
   122         $string2
       
   123     ) {
   120         ParagonIE_Sodium_Compat::add($string1, $string2);
   124         ParagonIE_Sodium_Compat::add($string1, $string2);
   121     }
   125     }
   122 }
   126 }
   123 if (!is_callable('sodium_base642bin')) {
   127 if (!is_callable('sodium_base642bin')) {
   124     /**
   128     /**
   128      * @param string $ignore
   132      * @param string $ignore
   129      * @return string
   133      * @return string
   130      * @throws SodiumException
   134      * @throws SodiumException
   131      * @throws TypeError
   135      * @throws TypeError
   132      */
   136      */
   133     function sodium_base642bin($string, $variant, $ignore ='')
   137     function sodium_base642bin(
   134     {
   138         #[\SensitiveParameter]
       
   139         $string,
       
   140         $variant,
       
   141         $ignore =''
       
   142     ) {
   135         return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore);
   143         return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore);
   136     }
   144     }
   137 }
   145 }
   138 if (!is_callable('sodium_bin2base64')) {
   146 if (!is_callable('sodium_bin2base64')) {
   139     /**
   147     /**
   142      * @param int $variant
   150      * @param int $variant
   143      * @return string
   151      * @return string
   144      * @throws SodiumException
   152      * @throws SodiumException
   145      * @throws TypeError
   153      * @throws TypeError
   146      */
   154      */
   147     function sodium_bin2base64($string, $variant)
   155     function sodium_bin2base64(
   148     {
   156         #[\SensitiveParameter]
       
   157         $string,
       
   158         $variant
       
   159     ) {
   149         return ParagonIE_Sodium_Compat::bin2base64($string, $variant);
   160         return ParagonIE_Sodium_Compat::bin2base64($string, $variant);
   150     }
   161     }
   151 }
   162 }
   152 if (!is_callable('sodium_bin2hex')) {
   163 if (!is_callable('sodium_bin2hex')) {
   153     /**
   164     /**
   155      * @param string $string
   166      * @param string $string
   156      * @return string
   167      * @return string
   157      * @throws SodiumException
   168      * @throws SodiumException
   158      * @throws TypeError
   169      * @throws TypeError
   159      */
   170      */
   160     function sodium_bin2hex($string)
   171     function sodium_bin2hex(
   161     {
   172         #[\SensitiveParameter]
       
   173         $string
       
   174     ) {
   162         return ParagonIE_Sodium_Compat::bin2hex($string);
   175         return ParagonIE_Sodium_Compat::bin2hex($string);
   163     }
   176     }
   164 }
   177 }
   165 if (!is_callable('sodium_compare')) {
   178 if (!is_callable('sodium_compare')) {
   166     /**
   179     /**
   169      * @param string $string2
   182      * @param string $string2
   170      * @return int
   183      * @return int
   171      * @throws SodiumException
   184      * @throws SodiumException
   172      * @throws TypeError
   185      * @throws TypeError
   173      */
   186      */
   174     function sodium_compare($string1, $string2)
   187     function sodium_compare(
   175     {
   188         #[\SensitiveParameter]
       
   189         $string1,
       
   190         #[\SensitiveParameter]
       
   191         $string2
       
   192     ) {
   176         return ParagonIE_Sodium_Compat::compare($string1, $string2);
   193         return ParagonIE_Sodium_Compat::compare($string1, $string2);
   177     }
   194     }
   178 }
   195 }
   179 if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) {
   196 if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) {
   180     /**
   197     /**
   183      * @param string $additional_data
   200      * @param string $additional_data
   184      * @param string $nonce
   201      * @param string $nonce
   185      * @param string $key
   202      * @param string $key
   186      * @return string|bool
   203      * @return string|bool
   187      */
   204      */
   188     function sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $additional_data, $nonce, $key)
   205     function sodium_crypto_aead_aes256gcm_decrypt(
   189     {
   206         $ciphertext,
       
   207         $additional_data,
       
   208         $nonce,
       
   209         #[\SensitiveParameter]
       
   210         $key
       
   211     ) {
   190         try {
   212         try {
   191             return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt(
   213             return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt(
   192                 $ciphertext,
   214                 $ciphertext,
   193                 $additional_data,
   215                 $additional_data,
   194                 $nonce,
   216                 $nonce,
   213      * @param string $key
   235      * @param string $key
   214      * @return string
   236      * @return string
   215      * @throws SodiumException
   237      * @throws SodiumException
   216      * @throws TypeError
   238      * @throws TypeError
   217      */
   239      */
   218     function sodium_crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key)
   240     function sodium_crypto_aead_aes256gcm_encrypt(
   219     {
   241         #[\SensitiveParameter]
       
   242         $message,
       
   243         $additional_data,
       
   244         $nonce,
       
   245         #[\SensitiveParameter]
       
   246         $key
       
   247     ) {
   220         return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key);
   248         return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $additional_data, $nonce, $key);
   221     }
   249     }
   222 }
   250 }
   223 if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) {
   251 if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) {
   224     /**
   252     /**
   237      * @param string $additional_data
   265      * @param string $additional_data
   238      * @param string $nonce
   266      * @param string $nonce
   239      * @param string $key
   267      * @param string $key
   240      * @return string|bool
   268      * @return string|bool
   241      */
   269      */
   242     function sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $additional_data, $nonce, $key)
   270     function sodium_crypto_aead_chacha20poly1305_decrypt(
   243     {
   271         $ciphertext,
       
   272         $additional_data,
       
   273         $nonce,
       
   274         #[\SensitiveParameter]
       
   275         $key
       
   276     ) {
   244         try {
   277         try {
   245             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt(
   278             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt(
   246                 $ciphertext,
   279                 $ciphertext,
   247                 $additional_data,
   280                 $additional_data,
   248                 $nonce,
   281                 $nonce,
   264      * @param string $key
   297      * @param string $key
   265      * @return string
   298      * @return string
   266      * @throws SodiumException
   299      * @throws SodiumException
   267      * @throws TypeError
   300      * @throws TypeError
   268      */
   301      */
   269     function sodium_crypto_aead_chacha20poly1305_encrypt($message, $additional_data, $nonce, $key)
   302     function sodium_crypto_aead_chacha20poly1305_encrypt(
   270     {
   303         #[\SensitiveParameter]
       
   304         $message,
       
   305         $additional_data,
       
   306         $nonce,
       
   307         #[\SensitiveParameter]
       
   308         $key
       
   309     ) {
   271         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt(
   310         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt(
   272             $message,
   311             $message,
   273             $additional_data,
   312             $additional_data,
   274             $nonce,
   313             $nonce,
   275             $key
   314             $key
   294      * @param string $additional_data
   333      * @param string $additional_data
   295      * @param string $nonce
   334      * @param string $nonce
   296      * @param string $key
   335      * @param string $key
   297      * @return string|bool
   336      * @return string|bool
   298      */
   337      */
   299     function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $additional_data, $nonce, $key)
   338     function sodium_crypto_aead_chacha20poly1305_ietf_decrypt(
   300     {
   339         $message,
       
   340         $additional_data,
       
   341         $nonce,
       
   342         #[\SensitiveParameter]
       
   343         $key
       
   344     ) {
   301         try {
   345         try {
   302             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt(
   346             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt(
   303                 $message,
   347                 $message,
   304                 $additional_data,
   348                 $additional_data,
   305                 $nonce,
   349                 $nonce,
   321      * @param string $key
   365      * @param string $key
   322      * @return string
   366      * @return string
   323      * @throws SodiumException
   367      * @throws SodiumException
   324      * @throws TypeError
   368      * @throws TypeError
   325      */
   369      */
   326     function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $additional_data, $nonce, $key)
   370     function sodium_crypto_aead_chacha20poly1305_ietf_encrypt(
   327     {
   371         #[\SensitiveParameter]
       
   372         $message,
       
   373         $additional_data,
       
   374         $nonce,
       
   375         #[\SensitiveParameter]
       
   376         $key
       
   377     ) {
   328         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt(
   378         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt(
   329             $message,
   379             $message,
   330             $additional_data,
   380             $additional_data,
   331             $nonce,
   381             $nonce,
   332             $key
   382             $key
   351      * @param string $additional_data
   401      * @param string $additional_data
   352      * @param string $nonce
   402      * @param string $nonce
   353      * @param string $key
   403      * @param string $key
   354      * @return string|bool
   404      * @return string|bool
   355      */
   405      */
   356     function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $additional_data, $nonce, $key)
   406     function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt(
   357     {
   407         $ciphertext,
       
   408         $additional_data,
       
   409         $nonce,
       
   410         #[\SensitiveParameter]
       
   411         $key
       
   412     ) {
   358         try {
   413         try {
   359             return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
   414             return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
   360                 $ciphertext,
   415                 $ciphertext,
   361                 $additional_data,
   416                 $additional_data,
   362                 $nonce,
   417                 $nonce,
   380      * @return string
   435      * @return string
   381      * @throws SodiumException
   436      * @throws SodiumException
   382      * @throws TypeError
   437      * @throws TypeError
   383      */
   438      */
   384     function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(
   439     function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(
       
   440         #[\SensitiveParameter]
   385         $message,
   441         $message,
   386         $additional_data,
   442         $additional_data,
   387         $nonce,
   443         $nonce,
       
   444         #[\SensitiveParameter]
   388         $key
   445         $key
   389     ) {
   446     ) {
   390         return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
   447         return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
   391             $message,
   448             $message,
   392             $additional_data,
   449             $additional_data,
   414      * @param string $key
   471      * @param string $key
   415      * @return string
   472      * @return string
   416      * @throws SodiumException
   473      * @throws SodiumException
   417      * @throws TypeError
   474      * @throws TypeError
   418      */
   475      */
   419     function sodium_crypto_auth($message, $key)
   476     function sodium_crypto_auth(
   420     {
   477         $message,
       
   478         #[\SensitiveParameter]
       
   479         $key
       
   480     ) {
   421         return ParagonIE_Sodium_Compat::crypto_auth($message, $key);
   481         return ParagonIE_Sodium_Compat::crypto_auth($message, $key);
   422     }
   482     }
   423 }
   483 }
   424 if (!is_callable('sodium_crypto_auth_keygen')) {
   484 if (!is_callable('sodium_crypto_auth_keygen')) {
   425     /**
   485     /**
   440      * @param string $key
   500      * @param string $key
   441      * @return bool
   501      * @return bool
   442      * @throws SodiumException
   502      * @throws SodiumException
   443      * @throws TypeError
   503      * @throws TypeError
   444      */
   504      */
   445     function sodium_crypto_auth_verify($mac, $message, $key)
   505     function sodium_crypto_auth_verify(
   446     {
   506         $mac,
       
   507         $message,
       
   508         #[\SensitiveParameter]
       
   509         $key
       
   510     ) {
   447         return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key);
   511         return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key);
   448     }
   512     }
   449 }
   513 }
   450 if (!is_callable('sodium_crypto_box')) {
   514 if (!is_callable('sodium_crypto_box')) {
   451     /**
   515     /**
   455      * @param string $key_pair
   519      * @param string $key_pair
   456      * @return string
   520      * @return string
   457      * @throws SodiumException
   521      * @throws SodiumException
   458      * @throws TypeError
   522      * @throws TypeError
   459      */
   523      */
   460     function sodium_crypto_box($message, $nonce, $key_pair)
   524     function sodium_crypto_box(
   461     {
   525         #[\SensitiveParameter]
       
   526         $message,
       
   527         $nonce,
       
   528         #[\SensitiveParameter]
       
   529         $key_pair
       
   530     ) {
   462         return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $key_pair);
   531         return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $key_pair);
   463     }
   532     }
   464 }
   533 }
   465 if (!is_callable('sodium_crypto_box_keypair')) {
   534 if (!is_callable('sodium_crypto_box_keypair')) {
   466     /**
   535     /**
   481      * @param string $public_key
   550      * @param string $public_key
   482      * @return string
   551      * @return string
   483      * @throws SodiumException
   552      * @throws SodiumException
   484      * @throws TypeError
   553      * @throws TypeError
   485      */
   554      */
   486     function sodium_crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key)
   555     function sodium_crypto_box_keypair_from_secretkey_and_publickey(
   487     {
   556         #[\SensitiveParameter]
       
   557         $secret_key,
       
   558         $public_key
       
   559     ) {
   488         return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key);
   560         return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($secret_key, $public_key);
   489     }
   561     }
   490 }
   562 }
   491 if (!is_callable('sodium_crypto_box_open')) {
   563 if (!is_callable('sodium_crypto_box_open')) {
   492     /**
   564     /**
   494      * @param string $ciphertext
   566      * @param string $ciphertext
   495      * @param string $nonce
   567      * @param string $nonce
   496      * @param string $key_pair
   568      * @param string $key_pair
   497      * @return string|bool
   569      * @return string|bool
   498      */
   570      */
   499     function sodium_crypto_box_open($ciphertext, $nonce, $key_pair)
   571     function sodium_crypto_box_open(
   500     {
   572         $ciphertext,
       
   573         $nonce,
       
   574         #[\SensitiveParameter]
       
   575         $key_pair
       
   576     ) {
   501         try {
   577         try {
   502             return ParagonIE_Sodium_Compat::crypto_box_open($ciphertext, $nonce, $key_pair);
   578             return ParagonIE_Sodium_Compat::crypto_box_open($ciphertext, $nonce, $key_pair);
   503         } catch (Error $ex) {
   579         } catch (Error $ex) {
   504             return false;
   580             return false;
   505         } catch (Exception $ex) {
   581         } catch (Exception $ex) {
   513      * @param string $key_pair
   589      * @param string $key_pair
   514      * @return string
   590      * @return string
   515      * @throws SodiumException
   591      * @throws SodiumException
   516      * @throws TypeError
   592      * @throws TypeError
   517      */
   593      */
   518     function sodium_crypto_box_publickey($key_pair)
   594     function sodium_crypto_box_publickey(
   519     {
   595         #[\SensitiveParameter]
       
   596         $key_pair
       
   597     ) {
   520         return ParagonIE_Sodium_Compat::crypto_box_publickey($key_pair);
   598         return ParagonIE_Sodium_Compat::crypto_box_publickey($key_pair);
   521     }
   599     }
   522 }
   600 }
   523 if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) {
   601 if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) {
   524     /**
   602     /**
   526      * @param string $secret_key
   604      * @param string $secret_key
   527      * @return string
   605      * @return string
   528      * @throws SodiumException
   606      * @throws SodiumException
   529      * @throws TypeError
   607      * @throws TypeError
   530      */
   608      */
   531     function sodium_crypto_box_publickey_from_secretkey($secret_key)
   609     function sodium_crypto_box_publickey_from_secretkey(
   532     {
   610         #[\SensitiveParameter]
       
   611         $secret_key
       
   612     ) {
   533         return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($secret_key);
   613         return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($secret_key);
   534     }
   614     }
   535 }
   615 }
   536 if (!is_callable('sodium_crypto_box_seal')) {
   616 if (!is_callable('sodium_crypto_box_seal')) {
   537     /**
   617     /**
   540      * @param string $public_key
   620      * @param string $public_key
   541      * @return string
   621      * @return string
   542      * @throws SodiumException
   622      * @throws SodiumException
   543      * @throws TypeError
   623      * @throws TypeError
   544      */
   624      */
   545     function sodium_crypto_box_seal($message, $public_key)
   625     function sodium_crypto_box_seal(
   546     {
   626         #[\SensitiveParameter]
       
   627         $message,
       
   628         $public_key
       
   629     ) {
   547         return ParagonIE_Sodium_Compat::crypto_box_seal($message, $public_key);
   630         return ParagonIE_Sodium_Compat::crypto_box_seal($message, $public_key);
   548     }
   631     }
   549 }
   632 }
   550 if (!is_callable('sodium_crypto_box_seal_open')) {
   633 if (!is_callable('sodium_crypto_box_seal_open')) {
   551     /**
   634     /**
   553      * @param string $message
   636      * @param string $message
   554      * @param string $key_pair
   637      * @param string $key_pair
   555      * @return string|bool
   638      * @return string|bool
   556      * @throws SodiumException
   639      * @throws SodiumException
   557      */
   640      */
   558     function sodium_crypto_box_seal_open($message, $key_pair)
   641     function sodium_crypto_box_seal_open(
   559     {
   642         $message,
       
   643         #[\SensitiveParameter]
       
   644         $key_pair
       
   645     ) {
   560         try {
   646         try {
   561             return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $key_pair);
   647             return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $key_pair);
   562         } catch (SodiumException $ex) {
   648         } catch (SodiumException $ex) {
   563             if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') {
   649             if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') {
   564                 throw $ex;
   650                 throw $ex;
   573      * @param string $key_pair
   659      * @param string $key_pair
   574      * @return string
   660      * @return string
   575      * @throws SodiumException
   661      * @throws SodiumException
   576      * @throws TypeError
   662      * @throws TypeError
   577      */
   663      */
   578     function sodium_crypto_box_secretkey($key_pair)
   664     function sodium_crypto_box_secretkey(
   579     {
   665         #[\SensitiveParameter]
       
   666         $key_pair
       
   667     ) {
   580         return ParagonIE_Sodium_Compat::crypto_box_secretkey($key_pair);
   668         return ParagonIE_Sodium_Compat::crypto_box_secretkey($key_pair);
   581     }
   669     }
   582 }
   670 }
   583 if (!is_callable('sodium_crypto_box_seed_keypair')) {
   671 if (!is_callable('sodium_crypto_box_seed_keypair')) {
   584     /**
   672     /**
   586      * @param string $seed
   674      * @param string $seed
   587      * @return string
   675      * @return string
   588      * @throws SodiumException
   676      * @throws SodiumException
   589      * @throws TypeError
   677      * @throws TypeError
   590      */
   678      */
   591     function sodium_crypto_box_seed_keypair($seed)
   679     function sodium_crypto_box_seed_keypair(
   592     {
   680         #[\SensitiveParameter]
       
   681         $seed
       
   682     ) {
   593         return ParagonIE_Sodium_Compat::crypto_box_seed_keypair($seed);
   683         return ParagonIE_Sodium_Compat::crypto_box_seed_keypair($seed);
   594     }
   684     }
   595 }
   685 }
   596 if (!is_callable('sodium_crypto_generichash')) {
   686 if (!is_callable('sodium_crypto_generichash')) {
   597     /**
   687     /**
   601      * @param int $length
   691      * @param int $length
   602      * @return string
   692      * @return string
   603      * @throws SodiumException
   693      * @throws SodiumException
   604      * @throws TypeError
   694      * @throws TypeError
   605      */
   695      */
   606     function sodium_crypto_generichash($message, $key = null, $length = 32)
   696     function sodium_crypto_generichash(
   607     {
   697         $message,
       
   698         #[\SensitiveParameter]
       
   699         $key = null,
       
   700         $length = 32
       
   701     ) {
   608         return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $length);
   702         return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $length);
   609     }
   703     }
   610 }
   704 }
   611 if (!is_callable('sodium_crypto_generichash_final')) {
   705 if (!is_callable('sodium_crypto_generichash_final')) {
   612     /**
   706     /**
   629      * @param int $length
   723      * @param int $length
   630      * @return string
   724      * @return string
   631      * @throws SodiumException
   725      * @throws SodiumException
   632      * @throws TypeError
   726      * @throws TypeError
   633      */
   727      */
   634     function sodium_crypto_generichash_init($key = null, $length = 32)
   728     function sodium_crypto_generichash_init(
   635     {
   729         #[\SensitiveParameter]
       
   730         $key = null,
       
   731         $length = 32
       
   732     ) {
   636         return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $length);
   733         return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $length);
   637     }
   734     }
   638 }
   735 }
   639 if (!is_callable('sodium_crypto_generichash_keygen')) {
   736 if (!is_callable('sodium_crypto_generichash_keygen')) {
   640     /**
   737     /**
   654      * @param string $message
   751      * @param string $message
   655      * @return void
   752      * @return void
   656      * @throws SodiumException
   753      * @throws SodiumException
   657      * @throws TypeError
   754      * @throws TypeError
   658      */
   755      */
   659     function sodium_crypto_generichash_update(&$state, $message = '')
   756     function sodium_crypto_generichash_update(
   660     {
   757         #[\SensitiveParameter]
       
   758         &$state,
       
   759         $message = ''
       
   760     ) {
   661         ParagonIE_Sodium_Compat::crypto_generichash_update($state, $message);
   761         ParagonIE_Sodium_Compat::crypto_generichash_update($state, $message);
   662     }
   762     }
   663 }
   763 }
   664 if (!is_callable('sodium_crypto_kdf_keygen')) {
   764 if (!is_callable('sodium_crypto_kdf_keygen')) {
   665     /**
   765     /**
   680      * @param string $context
   780      * @param string $context
   681      * @param string $key
   781      * @param string $key
   682      * @return string
   782      * @return string
   683      * @throws Exception
   783      * @throws Exception
   684      */
   784      */
   685     function sodium_crypto_kdf_derive_from_key($subkey_length, $subkey_id, $context, $key)
   785     function sodium_crypto_kdf_derive_from_key(
   686     {
   786         $subkey_length,
       
   787         $subkey_id,
       
   788         $context,
       
   789         #[\SensitiveParameter]
       
   790         $key
       
   791     ) {
   687         return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key(
   792         return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key(
   688             $subkey_length,
   793             $subkey_length,
   689             $subkey_id,
   794             $subkey_id,
   690             $context,
   795             $context,
   691             $key
   796             $key
   701      * @param string $server_public
   806      * @param string $server_public
   702      * @return string
   807      * @return string
   703      * @throws SodiumException
   808      * @throws SodiumException
   704      * @throws TypeError
   809      * @throws TypeError
   705      */
   810      */
   706     function sodium_crypto_kx($my_secret, $their_public, $client_public, $server_public)
   811     function sodium_crypto_kx(
   707     {
   812         #[\SensitiveParameter]
       
   813         $my_secret,
       
   814         $their_public,
       
   815         $client_public,
       
   816         $server_public
       
   817     ) {
   708         return ParagonIE_Sodium_Compat::crypto_kx(
   818         return ParagonIE_Sodium_Compat::crypto_kx(
   709             $my_secret,
   819             $my_secret,
   710             $their_public,
   820             $their_public,
   711             $client_public,
   821             $client_public,
   712             $server_public
   822             $server_public
   717     /**
   827     /**
   718      * @param string $seed
   828      * @param string $seed
   719      * @return string
   829      * @return string
   720      * @throws Exception
   830      * @throws Exception
   721      */
   831      */
   722     function sodium_crypto_kx_seed_keypair($seed)
   832     function sodium_crypto_kx_seed_keypair(
   723     {
   833         #[\SensitiveParameter]
       
   834         $seed
       
   835     ) {
   724         return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed);
   836         return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed);
   725     }
   837     }
   726 }
   838 }
   727 if (!is_callable('sodium_crypto_kx_keypair')) {
   839 if (!is_callable('sodium_crypto_kx_keypair')) {
   728     /**
   840     /**
   739      * @param string $client_key_pair
   851      * @param string $client_key_pair
   740      * @param string $server_key
   852      * @param string $server_key
   741      * @return array{0: string, 1: string}
   853      * @return array{0: string, 1: string}
   742      * @throws SodiumException
   854      * @throws SodiumException
   743      */
   855      */
   744     function sodium_crypto_kx_client_session_keys($client_key_pair, $server_key)
   856     function sodium_crypto_kx_client_session_keys(
   745     {
   857         #[\SensitiveParameter]
       
   858         $client_key_pair,
       
   859         $server_key
       
   860     ) {
   746         return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($client_key_pair, $server_key);
   861         return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($client_key_pair, $server_key);
   747     }
   862     }
   748 }
   863 }
   749 if (!is_callable('sodium_crypto_kx_server_session_keys')) {
   864 if (!is_callable('sodium_crypto_kx_server_session_keys')) {
   750     /**
   865     /**
   751      * @param string $server_key_pair
   866      * @param string $server_key_pair
   752      * @param string $client_key
   867      * @param string $client_key
   753      * @return array{0: string, 1: string}
   868      * @return array{0: string, 1: string}
   754      * @throws SodiumException
   869      * @throws SodiumException
   755      */
   870      */
   756     function sodium_crypto_kx_server_session_keys($server_key_pair, $client_key)
   871     function sodium_crypto_kx_server_session_keys(
   757     {
   872         #[\SensitiveParameter]
       
   873         $server_key_pair,
       
   874         $client_key
       
   875     ) {
   758         return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($server_key_pair, $client_key);
   876         return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($server_key_pair, $client_key);
   759     }
   877     }
   760 }
   878 }
   761 if (!is_callable('sodium_crypto_kx_secretkey')) {
   879 if (!is_callable('sodium_crypto_kx_secretkey')) {
   762     /**
   880     /**
   763      * @param string $key_pair
   881      * @param string $key_pair
   764      * @return string
   882      * @return string
   765      * @throws Exception
   883      * @throws Exception
   766      */
   884      */
   767     function sodium_crypto_kx_secretkey($key_pair)
   885     function sodium_crypto_kx_secretkey(
   768     {
   886         #[\SensitiveParameter]
       
   887         $key_pair
       
   888     ) {
   769         return ParagonIE_Sodium_Compat::crypto_kx_secretkey($key_pair);
   889         return ParagonIE_Sodium_Compat::crypto_kx_secretkey($key_pair);
   770     }
   890     }
   771 }
   891 }
   772 if (!is_callable('sodium_crypto_kx_publickey')) {
   892 if (!is_callable('sodium_crypto_kx_publickey')) {
   773     /**
   893     /**
   774      * @param string $key_pair
   894      * @param string $key_pair
   775      * @return string
   895      * @return string
   776      * @throws Exception
   896      * @throws Exception
   777      */
   897      */
   778     function sodium_crypto_kx_publickey($key_pair)
   898     function sodium_crypto_kx_publickey(
   779     {
   899         #[\SensitiveParameter]
       
   900         $key_pair
       
   901     ) {
   780         return ParagonIE_Sodium_Compat::crypto_kx_publickey($key_pair);
   902         return ParagonIE_Sodium_Compat::crypto_kx_publickey($key_pair);
   781     }
   903     }
   782 }
   904 }
   783 if (!is_callable('sodium_crypto_pwhash')) {
   905 if (!is_callable('sodium_crypto_pwhash')) {
   784     /**
   906     /**
   791      * @param int|null $algo
   913      * @param int|null $algo
   792      * @return string
   914      * @return string
   793      * @throws SodiumException
   915      * @throws SodiumException
   794      * @throws TypeError
   916      * @throws TypeError
   795      */
   917      */
   796     function sodium_crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo = null)
   918     function sodium_crypto_pwhash(
   797     {
   919         $length,
       
   920         #[\SensitiveParameter]
       
   921         $passwd,
       
   922         $salt,
       
   923         $opslimit,
       
   924         $memlimit,
       
   925         $algo = null
       
   926     ) {
   798         return ParagonIE_Sodium_Compat::crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo);
   927         return ParagonIE_Sodium_Compat::crypto_pwhash($length, $passwd, $salt, $opslimit, $memlimit, $algo);
   799     }
   928     }
   800 }
   929 }
   801 if (!is_callable('sodium_crypto_pwhash_str')) {
   930 if (!is_callable('sodium_crypto_pwhash_str')) {
   802     /**
   931     /**
   806      * @param int $memlimit
   935      * @param int $memlimit
   807      * @return string
   936      * @return string
   808      * @throws SodiumException
   937      * @throws SodiumException
   809      * @throws TypeError
   938      * @throws TypeError
   810      */
   939      */
   811     function sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit)
   940     function sodium_crypto_pwhash_str(
   812     {
   941         #[\SensitiveParameter]
       
   942         $passwd,
       
   943         $opslimit,
       
   944         $memlimit
       
   945     ) {
   813         return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit);
   946         return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit);
   814     }
   947     }
   815 }
   948 }
   816 if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) {
   949 if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) {
   817     /**
   950     /**
   821      * @param int $memlimit
   954      * @param int $memlimit
   822      * @return bool
   955      * @return bool
   823      *
   956      *
   824      * @throws SodiumException
   957      * @throws SodiumException
   825      */
   958      */
   826     function sodium_crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit)
   959     function sodium_crypto_pwhash_str_needs_rehash(
   827     {
   960         #[\SensitiveParameter]
       
   961         $hash,
       
   962         $opslimit,
       
   963         $memlimit
       
   964     ) {
   828         return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit);
   965         return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit);
   829     }
   966     }
   830 }
   967 }
   831 if (!is_callable('sodium_crypto_pwhash_str_verify')) {
   968 if (!is_callable('sodium_crypto_pwhash_str_verify')) {
   832     /**
   969     /**
   835      * @param string $hash
   972      * @param string $hash
   836      * @return bool
   973      * @return bool
   837      * @throws SodiumException
   974      * @throws SodiumException
   838      * @throws TypeError
   975      * @throws TypeError
   839      */
   976      */
   840     function sodium_crypto_pwhash_str_verify($passwd, $hash)
   977     function sodium_crypto_pwhash_str_verify(
   841     {
   978         #[\SensitiveParameter]
       
   979         $passwd,
       
   980         #[\SensitiveParameter]
       
   981         $hash
       
   982     ) {
   842         return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash);
   983         return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash);
   843     }
   984     }
   844 }
   985 }
   845 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) {
   986 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) {
   846     /**
   987     /**
   852      * @param int $memlimit
   993      * @param int $memlimit
   853      * @return string
   994      * @return string
   854      * @throws SodiumException
   995      * @throws SodiumException
   855      * @throws TypeError
   996      * @throws TypeError
   856      */
   997      */
   857     function sodium_crypto_pwhash_scryptsalsa208sha256($length, $passwd, $salt, $opslimit, $memlimit)
   998     function sodium_crypto_pwhash_scryptsalsa208sha256(
   858     {
   999         $length,
       
  1000         #[\SensitiveParameter]
       
  1001         $passwd,
       
  1002         $salt,
       
  1003         $opslimit,
       
  1004         $memlimit
       
  1005     ) {
   859         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256(
  1006         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256(
   860             $length,
  1007             $length,
   861             $passwd,
  1008             $passwd,
   862             $salt,
  1009             $salt,
   863             $opslimit,
  1010             $opslimit,
   873      * @param int $memlimit
  1020      * @param int $memlimit
   874      * @return string
  1021      * @return string
   875      * @throws SodiumException
  1022      * @throws SodiumException
   876      * @throws TypeError
  1023      * @throws TypeError
   877      */
  1024      */
   878     function sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit)
  1025     function sodium_crypto_pwhash_scryptsalsa208sha256_str(
   879     {
  1026         #[\SensitiveParameter]
       
  1027         $passwd,
       
  1028         $opslimit,
       
  1029         $memlimit
       
  1030     ) {
   880         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit);
  1031         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit);
   881     }
  1032     }
   882 }
  1033 }
   883 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) {
  1034 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) {
   884     /**
  1035     /**
   887      * @param string $hash
  1038      * @param string $hash
   888      * @return bool
  1039      * @return bool
   889      * @throws SodiumException
  1040      * @throws SodiumException
   890      * @throws TypeError
  1041      * @throws TypeError
   891      */
  1042      */
   892     function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash)
  1043     function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify(
   893     {
  1044         #[\SensitiveParameter]
       
  1045         $passwd,
       
  1046         #[\SensitiveParameter]
       
  1047         $hash
       
  1048     ) {
   894         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash);
  1049         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash);
   895     }
  1050     }
   896 }
  1051 }
   897 if (!is_callable('sodium_crypto_scalarmult')) {
  1052 if (!is_callable('sodium_crypto_scalarmult')) {
   898     /**
  1053     /**
   901      * @param string $p
  1056      * @param string $p
   902      * @return string
  1057      * @return string
   903      * @throws SodiumException
  1058      * @throws SodiumException
   904      * @throws TypeError
  1059      * @throws TypeError
   905      */
  1060      */
   906     function sodium_crypto_scalarmult($n, $p)
  1061     function sodium_crypto_scalarmult(
   907     {
  1062         #[\SensitiveParameter]
       
  1063         $n,
       
  1064         $p
       
  1065     ) {
   908         return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p);
  1066         return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p);
   909     }
  1067     }
   910 }
  1068 }
   911 if (!is_callable('sodium_crypto_scalarmult_base')) {
  1069 if (!is_callable('sodium_crypto_scalarmult_base')) {
   912     /**
  1070     /**
   914      * @param string $n
  1072      * @param string $n
   915      * @return string
  1073      * @return string
   916      * @throws SodiumException
  1074      * @throws SodiumException
   917      * @throws TypeError
  1075      * @throws TypeError
   918      */
  1076      */
   919     function sodium_crypto_scalarmult_base($n)
  1077     function sodium_crypto_scalarmult_base(
   920     {
  1078         #[\SensitiveParameter]
       
  1079         $n
       
  1080     ) {
   921         return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n);
  1081         return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n);
   922     }
  1082     }
   923 }
  1083 }
   924 if (!is_callable('sodium_crypto_secretbox')) {
  1084 if (!is_callable('sodium_crypto_secretbox')) {
   925     /**
  1085     /**
   929      * @param string $key
  1089      * @param string $key
   930      * @return string
  1090      * @return string
   931      * @throws SodiumException
  1091      * @throws SodiumException
   932      * @throws TypeError
  1092      * @throws TypeError
   933      */
  1093      */
   934     function sodium_crypto_secretbox($message, $nonce, $key)
  1094     function sodium_crypto_secretbox(
   935     {
  1095         #[\SensitiveParameter]
       
  1096         $message,
       
  1097         $nonce,
       
  1098         #[\SensitiveParameter]
       
  1099         $key
       
  1100     ) {
   936         return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key);
  1101         return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key);
   937     }
  1102     }
   938 }
  1103 }
   939 if (!is_callable('sodium_crypto_secretbox_keygen')) {
  1104 if (!is_callable('sodium_crypto_secretbox_keygen')) {
   940     /**
  1105     /**
   953      * @param string $ciphertext
  1118      * @param string $ciphertext
   954      * @param string $nonce
  1119      * @param string $nonce
   955      * @param string $key
  1120      * @param string $key
   956      * @return string|bool
  1121      * @return string|bool
   957      */
  1122      */
   958     function sodium_crypto_secretbox_open($ciphertext, $nonce, $key)
  1123     function sodium_crypto_secretbox_open(
   959     {
  1124         $ciphertext,
       
  1125         $nonce,
       
  1126         #[\SensitiveParameter]
       
  1127         $key
       
  1128     ) {
   960         try {
  1129         try {
   961             return ParagonIE_Sodium_Compat::crypto_secretbox_open($ciphertext, $nonce, $key);
  1130             return ParagonIE_Sodium_Compat::crypto_secretbox_open($ciphertext, $nonce, $key);
   962         } catch (Error $ex) {
  1131         } catch (Error $ex) {
   963             return false;
  1132             return false;
   964         } catch (Exception $ex) {
  1133         } catch (Exception $ex) {
   970     /**
  1139     /**
   971      * @param string $key
  1140      * @param string $key
   972      * @return array<int, string>
  1141      * @return array<int, string>
   973      * @throws SodiumException
  1142      * @throws SodiumException
   974      */
  1143      */
   975     function sodium_crypto_secretstream_xchacha20poly1305_init_push($key)
  1144     function sodium_crypto_secretstream_xchacha20poly1305_init_push(
   976     {
  1145         #[\SensitiveParameter]
       
  1146         $key
       
  1147     ) {
   977         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key);
  1148         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key);
   978     }
  1149     }
   979 }
  1150 }
   980 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) {
  1151 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) {
   981     /**
  1152     /**
   985      * @param int $tag
  1156      * @param int $tag
   986      * @return string
  1157      * @return string
   987      * @throws SodiumException
  1158      * @throws SodiumException
   988      */
  1159      */
   989     function sodium_crypto_secretstream_xchacha20poly1305_push(
  1160     function sodium_crypto_secretstream_xchacha20poly1305_push(
       
  1161         #[\SensitiveParameter]
   990         &$state,
  1162         &$state,
       
  1163         #[\SensitiveParameter]
   991         $message,
  1164         $message,
   992         $additional_data = '',
  1165         $additional_data = '',
   993         $tag = 0
  1166         $tag = 0
   994     ) {
  1167     ) {
   995         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push(
  1168         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push(
  1005      * @param string $header
  1178      * @param string $header
  1006      * @param string $key
  1179      * @param string $key
  1007      * @return string
  1180      * @return string
  1008      * @throws Exception
  1181      * @throws Exception
  1009      */
  1182      */
  1010     function sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key)
  1183     function sodium_crypto_secretstream_xchacha20poly1305_init_pull(
  1011     {
  1184         $header,
       
  1185         #[\SensitiveParameter]
       
  1186         $key
       
  1187     ) {
  1012         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
  1188         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
  1013     }
  1189     }
  1014 }
  1190 }
  1015 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) {
  1191 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) {
  1016     /**
  1192     /**
  1018      * @param string $ciphertext
  1194      * @param string $ciphertext
  1019      * @param string $additional_data
  1195      * @param string $additional_data
  1020      * @return bool|array{0: string, 1: int}
  1196      * @return bool|array{0: string, 1: int}
  1021      * @throws SodiumException
  1197      * @throws SodiumException
  1022      */
  1198      */
  1023     function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $ciphertext, $additional_data = '')
  1199     function sodium_crypto_secretstream_xchacha20poly1305_pull(
  1024     {
  1200         #[\SensitiveParameter]
       
  1201         &$state,
       
  1202         $ciphertext,
       
  1203         $additional_data = ''
       
  1204     ) {
  1025         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull(
  1205         return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull(
  1026             $state,
  1206             $state,
  1027             $ciphertext,
  1207             $ciphertext,
  1028             $additional_data
  1208             $additional_data
  1029         );
  1209         );
  1033     /**
  1213     /**
  1034      * @param string $state
  1214      * @param string $state
  1035      * @return void
  1215      * @return void
  1036      * @throws SodiumException
  1216      * @throws SodiumException
  1037      */
  1217      */
  1038     function sodium_crypto_secretstream_xchacha20poly1305_rekey(&$state)
  1218     function sodium_crypto_secretstream_xchacha20poly1305_rekey(
  1039     {
  1219         #[\SensitiveParameter]
       
  1220         &$state
       
  1221     ) {
  1040         ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state);
  1222         ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state);
  1041     }
  1223     }
  1042 }
  1224 }
  1043 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) {
  1225 if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) {
  1044     /**
  1226     /**
  1057      * @param string $key
  1239      * @param string $key
  1058      * @return string
  1240      * @return string
  1059      * @throws SodiumException
  1241      * @throws SodiumException
  1060      * @throws TypeError
  1242      * @throws TypeError
  1061      */
  1243      */
  1062     function sodium_crypto_shorthash($message, $key = '')
  1244     function sodium_crypto_shorthash(
  1063     {
  1245         $message,
       
  1246         #[\SensitiveParameter]
       
  1247         $key = ''
       
  1248     ) {
  1064         return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key);
  1249         return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key);
  1065     }
  1250     }
  1066 }
  1251 }
  1067 if (!is_callable('sodium_crypto_shorthash_keygen')) {
  1252 if (!is_callable('sodium_crypto_shorthash_keygen')) {
  1068     /**
  1253     /**
  1082      * @param string $secret_key
  1267      * @param string $secret_key
  1083      * @return string
  1268      * @return string
  1084      * @throws SodiumException
  1269      * @throws SodiumException
  1085      * @throws TypeError
  1270      * @throws TypeError
  1086      */
  1271      */
  1087     function sodium_crypto_sign($message, $secret_key)
  1272     function sodium_crypto_sign(
  1088     {
  1273         $message,
       
  1274         #[\SensitiveParameter]
       
  1275         $secret_key
       
  1276     ) {
  1089         return ParagonIE_Sodium_Compat::crypto_sign($message, $secret_key);
  1277         return ParagonIE_Sodium_Compat::crypto_sign($message, $secret_key);
  1090     }
  1278     }
  1091 }
  1279 }
  1092 if (!is_callable('sodium_crypto_sign_detached')) {
  1280 if (!is_callable('sodium_crypto_sign_detached')) {
  1093     /**
  1281     /**
  1096      * @param string $secret_key
  1284      * @param string $secret_key
  1097      * @return string
  1285      * @return string
  1098      * @throws SodiumException
  1286      * @throws SodiumException
  1099      * @throws TypeError
  1287      * @throws TypeError
  1100      */
  1288      */
  1101     function sodium_crypto_sign_detached($message, $secret_key)
  1289     function sodium_crypto_sign_detached(
  1102     {
  1290         $message,
       
  1291         #[\SensitiveParameter]
       
  1292         $secret_key
       
  1293     ) {
  1103         return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $secret_key);
  1294         return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $secret_key);
  1104     }
  1295     }
  1105 }
  1296 }
  1106 if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) {
  1297 if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) {
  1107     /**
  1298     /**
  1110      * @param string $public_key
  1301      * @param string $public_key
  1111      * @return string
  1302      * @return string
  1112      * @throws SodiumException
  1303      * @throws SodiumException
  1113      * @throws TypeError
  1304      * @throws TypeError
  1114      */
  1305      */
  1115     function sodium_crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key)
  1306     function sodium_crypto_sign_keypair_from_secretkey_and_publickey(
  1116     {
  1307         #[\SensitiveParameter]
       
  1308         $secret_key,
       
  1309         $public_key
       
  1310     ) {
  1117         return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key);
  1311         return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($secret_key, $public_key);
  1118     }
  1312     }
  1119 }
  1313 }
  1120 if (!is_callable('sodium_crypto_sign_keypair')) {
  1314 if (!is_callable('sodium_crypto_sign_keypair')) {
  1121     /**
  1315     /**
  1153      * @param string $key_pair
  1347      * @param string $key_pair
  1154      * @return string
  1348      * @return string
  1155      * @throws SodiumException
  1349      * @throws SodiumException
  1156      * @throws TypeError
  1350      * @throws TypeError
  1157      */
  1351      */
  1158     function sodium_crypto_sign_publickey($key_pair)
  1352     function sodium_crypto_sign_publickey(
  1159     {
  1353         #[\SensitiveParameter]
       
  1354         $key_pair
       
  1355     ) {
  1160         return ParagonIE_Sodium_Compat::crypto_sign_publickey($key_pair);
  1356         return ParagonIE_Sodium_Compat::crypto_sign_publickey($key_pair);
  1161     }
  1357     }
  1162 }
  1358 }
  1163 if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) {
  1359 if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) {
  1164     /**
  1360     /**
  1166      * @param string $secret_key
  1362      * @param string $secret_key
  1167      * @return string
  1363      * @return string
  1168      * @throws SodiumException
  1364      * @throws SodiumException
  1169      * @throws TypeError
  1365      * @throws TypeError
  1170      */
  1366      */
  1171     function sodium_crypto_sign_publickey_from_secretkey($secret_key)
  1367     function sodium_crypto_sign_publickey_from_secretkey(
  1172     {
  1368         #[\SensitiveParameter]
       
  1369         $secret_key
       
  1370     ) {
  1173         return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($secret_key);
  1371         return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($secret_key);
  1174     }
  1372     }
  1175 }
  1373 }
  1176 if (!is_callable('sodium_crypto_sign_secretkey')) {
  1374 if (!is_callable('sodium_crypto_sign_secretkey')) {
  1177     /**
  1375     /**
  1179      * @param string $key_pair
  1377      * @param string $key_pair
  1180      * @return string
  1378      * @return string
  1181      * @throws SodiumException
  1379      * @throws SodiumException
  1182      * @throws TypeError
  1380      * @throws TypeError
  1183      */
  1381      */
  1184     function sodium_crypto_sign_secretkey($key_pair)
  1382     function sodium_crypto_sign_secretkey(
  1185     {
  1383         #[\SensitiveParameter]
       
  1384         $key_pair
       
  1385     ) {
  1186         return ParagonIE_Sodium_Compat::crypto_sign_secretkey($key_pair);
  1386         return ParagonIE_Sodium_Compat::crypto_sign_secretkey($key_pair);
  1187     }
  1387     }
  1188 }
  1388 }
  1189 if (!is_callable('sodium_crypto_sign_seed_keypair')) {
  1389 if (!is_callable('sodium_crypto_sign_seed_keypair')) {
  1190     /**
  1390     /**
  1192      * @param string $seed
  1392      * @param string $seed
  1193      * @return string
  1393      * @return string
  1194      * @throws SodiumException
  1394      * @throws SodiumException
  1195      * @throws TypeError
  1395      * @throws TypeError
  1196      */
  1396      */
  1197     function sodium_crypto_sign_seed_keypair($seed)
  1397     function sodium_crypto_sign_seed_keypair(
  1198     {
  1398         #[\SensitiveParameter]
       
  1399         $seed
       
  1400     ) {
  1199         return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
  1401         return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
  1200     }
  1402     }
  1201 }
  1403 }
  1202 if (!is_callable('sodium_crypto_sign_verify_detached')) {
  1404 if (!is_callable('sodium_crypto_sign_verify_detached')) {
  1203     /**
  1405     /**
  1233      * @param string $secret_key
  1435      * @param string $secret_key
  1234      * @return string
  1436      * @return string
  1235      * @throws SodiumException
  1437      * @throws SodiumException
  1236      * @throws TypeError
  1438      * @throws TypeError
  1237      */
  1439      */
  1238     function sodium_crypto_sign_ed25519_sk_to_curve25519($secret_key)
  1440     function sodium_crypto_sign_ed25519_sk_to_curve25519(
  1239     {
  1441         #[\SensitiveParameter]
       
  1442         $secret_key
       
  1443     ) {
  1240         return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($secret_key);
  1444         return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($secret_key);
  1241     }
  1445     }
  1242 }
  1446 }
  1243 if (!is_callable('sodium_crypto_stream')) {
  1447 if (!is_callable('sodium_crypto_stream')) {
  1244     /**
  1448     /**
  1248      * @param string $key
  1452      * @param string $key
  1249      * @return string
  1453      * @return string
  1250      * @throws SodiumException
  1454      * @throws SodiumException
  1251      * @throws TypeError
  1455      * @throws TypeError
  1252      */
  1456      */
  1253     function sodium_crypto_stream($length, $nonce, $key)
  1457     function sodium_crypto_stream(
  1254     {
  1458         $length,
       
  1459         $nonce,
       
  1460         #[\SensitiveParameter]
       
  1461         $key
       
  1462     ) {
  1255         return ParagonIE_Sodium_Compat::crypto_stream($length, $nonce, $key);
  1463         return ParagonIE_Sodium_Compat::crypto_stream($length, $nonce, $key);
  1256     }
  1464     }
  1257 }
  1465 }
  1258 if (!is_callable('sodium_crypto_stream_keygen')) {
  1466 if (!is_callable('sodium_crypto_stream_keygen')) {
  1259     /**
  1467     /**
  1274      * @param string $key
  1482      * @param string $key
  1275      * @return string
  1483      * @return string
  1276      * @throws SodiumException
  1484      * @throws SodiumException
  1277      * @throws TypeError
  1485      * @throws TypeError
  1278      */
  1486      */
  1279     function sodium_crypto_stream_xor($message, $nonce, $key)
  1487     function sodium_crypto_stream_xor(
  1280     {
  1488         #[\SensitiveParameter]
       
  1489         $message,
       
  1490         $nonce,
       
  1491         #[\SensitiveParameter]
       
  1492         $key
       
  1493     ) {
  1281         return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
  1494         return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
  1282     }
  1495     }
  1283 }
  1496 }
  1284 require_once dirname(__FILE__) . '/stream-xchacha20.php';
  1497 require_once dirname(__FILE__) . '/stream-xchacha20.php';
  1285 if (!is_callable('sodium_hex2bin')) {
  1498 if (!is_callable('sodium_hex2bin')) {
  1289      * @param string $ignore
  1502      * @param string $ignore
  1290      * @return string
  1503      * @return string
  1291      * @throws SodiumException
  1504      * @throws SodiumException
  1292      * @throws TypeError
  1505      * @throws TypeError
  1293      */
  1506      */
  1294     function sodium_hex2bin($string, $ignore = '')
  1507     function sodium_hex2bin(
  1295     {
  1508         #[\SensitiveParameter]
       
  1509         $string,
       
  1510         $ignore = ''
       
  1511     ) {
  1296         return ParagonIE_Sodium_Compat::hex2bin($string, $ignore);
  1512         return ParagonIE_Sodium_Compat::hex2bin($string, $ignore);
  1297     }
  1513     }
  1298 }
  1514 }
  1299 if (!is_callable('sodium_increment')) {
  1515 if (!is_callable('sodium_increment')) {
  1300     /**
  1516     /**
  1302      * @param string $string
  1518      * @param string $string
  1303      * @return void
  1519      * @return void
  1304      * @throws SodiumException
  1520      * @throws SodiumException
  1305      * @throws TypeError
  1521      * @throws TypeError
  1306      */
  1522      */
  1307     function sodium_increment(&$string)
  1523     function sodium_increment(
  1308     {
  1524         #[\SensitiveParameter]
       
  1525         &$string
       
  1526     ) {
  1309         ParagonIE_Sodium_Compat::increment($string);
  1527         ParagonIE_Sodium_Compat::increment($string);
  1310     }
  1528     }
  1311 }
  1529 }
  1312 if (!is_callable('sodium_library_version_major')) {
  1530 if (!is_callable('sodium_library_version_major')) {
  1313     /**
  1531     /**
  1346      * @param string $string2
  1564      * @param string $string2
  1347      * @return int
  1565      * @return int
  1348      * @throws SodiumException
  1566      * @throws SodiumException
  1349      * @throws TypeError
  1567      * @throws TypeError
  1350      */
  1568      */
  1351     function sodium_memcmp($string1, $string2)
  1569     function sodium_memcmp(
  1352     {
  1570         #[\SensitiveParameter]
       
  1571         $string1,
       
  1572         #[\SensitiveParameter]
       
  1573         $string2
       
  1574     ) {
  1353         return ParagonIE_Sodium_Compat::memcmp($string1, $string2);
  1575         return ParagonIE_Sodium_Compat::memcmp($string1, $string2);
  1354     }
  1576     }
  1355 }
  1577 }
  1356 if (!is_callable('sodium_memzero')) {
  1578 if (!is_callable('sodium_memzero')) {
  1357     /**
  1579     /**
  1361      * @throws SodiumException
  1583      * @throws SodiumException
  1362      * @throws TypeError
  1584      * @throws TypeError
  1363      *
  1585      *
  1364      * @psalm-suppress ReferenceConstraintViolation
  1586      * @psalm-suppress ReferenceConstraintViolation
  1365      */
  1587      */
  1366     function sodium_memzero(&$string)
  1588     function sodium_memzero(
  1367     {
  1589         #[\SensitiveParameter]
       
  1590         &$string
       
  1591     ) {
  1368         ParagonIE_Sodium_Compat::memzero($string);
  1592         ParagonIE_Sodium_Compat::memzero($string);
  1369     }
  1593     }
  1370 }
  1594 }
  1371 if (!is_callable('sodium_pad')) {
  1595 if (!is_callable('sodium_pad')) {
  1372     /**
  1596     /**
  1375      * @param int $block_size
  1599      * @param int $block_size
  1376      * @return string
  1600      * @return string
  1377      * @throws SodiumException
  1601      * @throws SodiumException
  1378      * @throws TypeError
  1602      * @throws TypeError
  1379      */
  1603      */
  1380     function sodium_pad($unpadded, $block_size)
  1604     function sodium_pad(
  1381     {
  1605         #[\SensitiveParameter]
       
  1606         $unpadded,
       
  1607         $block_size
       
  1608     ) {
  1382         return ParagonIE_Sodium_Compat::pad($unpadded, $block_size, true);
  1609         return ParagonIE_Sodium_Compat::pad($unpadded, $block_size, true);
  1383     }
  1610     }
  1384 }
  1611 }
  1385 if (!is_callable('sodium_unpad')) {
  1612 if (!is_callable('sodium_unpad')) {
  1386     /**
  1613     /**
  1389      * @param int $block_size
  1616      * @param int $block_size
  1390      * @return string
  1617      * @return string
  1391      * @throws SodiumException
  1618      * @throws SodiumException
  1392      * @throws TypeError
  1619      * @throws TypeError
  1393      */
  1620      */
  1394     function sodium_unpad($padded, $block_size)
  1621     function sodium_unpad(
  1395     {
  1622         #[\SensitiveParameter]
       
  1623         $padded,
       
  1624         $block_size
       
  1625     ) {
  1396         return ParagonIE_Sodium_Compat::unpad($padded, $block_size, true);
  1626         return ParagonIE_Sodium_Compat::unpad($padded, $block_size, true);
  1397     }
  1627     }
  1398 }
  1628 }
  1399 if (!is_callable('sodium_randombytes_buf')) {
  1629 if (!is_callable('sodium_randombytes_buf')) {
  1400     /**
  1630     /**