wp/wp-includes/sodium_compat/lib/php72compat.php
changeset 9 177826044cd9
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * This file will monkey patch the pure-PHP implementation in place of the
       
     5  * PECL functions and constants, but only if they do not already exist.
       
     6  *
       
     7  * Thus, the functions or constants just proxy to the appropriate
       
     8  * ParagonIE_Sodium_Compat method or class constant, respectively.
       
     9  */
       
    10 foreach (array(
       
    11     'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES',
       
    12     'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES',
       
    13     'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES',
       
    14     'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES',
       
    15     'CRYPTO_AEAD_AES256GCM_KEYBYTES',
       
    16     'CRYPTO_AEAD_AES256GCM_NSECBYTES',
       
    17     'CRYPTO_AEAD_AES256GCM_NPUBBYTES',
       
    18     'CRYPTO_AEAD_AES256GCM_ABYTES',
       
    19     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES',
       
    20     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES',
       
    21     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES',
       
    22     'CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES',
       
    23     'CRYPTO_AUTH_BYTES',
       
    24     'CRYPTO_AUTH_KEYBYTES',
       
    25     'CRYPTO_BOX_SEALBYTES',
       
    26     'CRYPTO_BOX_SECRETKEYBYTES',
       
    27     'CRYPTO_BOX_PUBLICKEYBYTES',
       
    28     'CRYPTO_BOX_KEYPAIRBYTES',
       
    29     'CRYPTO_BOX_MACBYTES',
       
    30     'CRYPTO_BOX_NONCEBYTES',
       
    31     'CRYPTO_BOX_SEEDBYTES',
       
    32     'CRYPTO_KX_BYTES',
       
    33     'CRYPTO_KX_SEEDBYTES',
       
    34     'CRYPTO_KX_PUBLICKEYBYTES',
       
    35     'CRYPTO_KX_SECRETKEYBYTES',
       
    36     'CRYPTO_GENERICHASH_BYTES',
       
    37     'CRYPTO_GENERICHASH_BYTES_MIN',
       
    38     'CRYPTO_GENERICHASH_BYTES_MAX',
       
    39     'CRYPTO_GENERICHASH_KEYBYTES',
       
    40     'CRYPTO_GENERICHASH_KEYBYTES_MIN',
       
    41     'CRYPTO_GENERICHASH_KEYBYTES_MAX',
       
    42     'CRYPTO_PWHASH_SALTBYTES',
       
    43     'CRYPTO_PWHASH_STRPREFIX',
       
    44     'CRYPTO_PWHASH_ALG_ARGON2I13',
       
    45     'CRYPTO_PWHASH_ALG_ARGON2ID13',
       
    46     'CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE',
       
    47     'CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE',
       
    48     'CRYPTO_PWHASH_MEMLIMIT_MODERATE',
       
    49     'CRYPTO_PWHASH_OPSLIMIT_MODERATE',
       
    50     'CRYPTO_PWHASH_MEMLIMIT_SENSITIVE',
       
    51     'CRYPTO_PWHASH_OPSLIMIT_SENSITIVE',
       
    52     'CRYPTO_SCALARMULT_BYTES',
       
    53     'CRYPTO_SCALARMULT_SCALARBYTES',
       
    54     'CRYPTO_SHORTHASH_BYTES',
       
    55     'CRYPTO_SHORTHASH_KEYBYTES',
       
    56     'CRYPTO_SECRETBOX_KEYBYTES',
       
    57     'CRYPTO_SECRETBOX_MACBYTES',
       
    58     'CRYPTO_SECRETBOX_NONCEBYTES',
       
    59     'CRYPTO_SIGN_BYTES',
       
    60     'CRYPTO_SIGN_SEEDBYTES',
       
    61     'CRYPTO_SIGN_PUBLICKEYBYTES',
       
    62     'CRYPTO_SIGN_SECRETKEYBYTES',
       
    63     'CRYPTO_SIGN_KEYPAIRBYTES',
       
    64     'CRYPTO_STREAM_KEYBYTES',
       
    65     'CRYPTO_STREAM_NONCEBYTES',
       
    66     'LIBRARY_VERSION_MAJOR',
       
    67     'LIBRARY_VERSION_MINOR',
       
    68     'VERSION_STRING'
       
    69     ) as $constant
       
    70 ) {
       
    71     if (!defined("SODIUM_$constant")) {
       
    72         define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant"));
       
    73     }
       
    74 }
       
    75 
       
    76 if (!is_callable('sodium_bin2hex')) {
       
    77     /**
       
    78      * @see ParagonIE_Sodium_Compat::hex2bin()
       
    79      * @param string $string
       
    80      * @return string
       
    81      * @throws SodiumException
       
    82      * @throws TypeError
       
    83      */
       
    84     function sodium_bin2hex($string)
       
    85     {
       
    86         return ParagonIE_Sodium_Compat::bin2hex($string);
       
    87     }
       
    88 }
       
    89 if (!is_callable('sodium_compare')) {
       
    90     /**
       
    91      * @see ParagonIE_Sodium_Compat::compare()
       
    92      * @param string $a
       
    93      * @param string $b
       
    94      * @return int
       
    95      * @throws SodiumException
       
    96      * @throws TypeError
       
    97      */
       
    98     function sodium_compare($a, $b)
       
    99     {
       
   100         return ParagonIE_Sodium_Compat::compare($a, $b);
       
   101     }
       
   102 }
       
   103 if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) {
       
   104     /**
       
   105      * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt()
       
   106      * @param string $message
       
   107      * @param string $assocData
       
   108      * @param string $nonce
       
   109      * @param string $key
       
   110      * @return string|bool
       
   111      */
       
   112     function sodium_crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key)
       
   113     {
       
   114         try {
       
   115             return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key);
       
   116         } catch (Error $ex) {
       
   117             return false;
       
   118         } catch (Exception $ex) {
       
   119             return false;
       
   120         }
       
   121     }
       
   122 }
       
   123 if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) {
       
   124     /**
       
   125      * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt()
       
   126      * @param string $message
       
   127      * @param string $assocData
       
   128      * @param string $nonce
       
   129      * @param string $key
       
   130      * @return string
       
   131      * @throws SodiumException
       
   132      * @throws TypeError
       
   133      */
       
   134     function sodium_crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key)
       
   135     {
       
   136         return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key);
       
   137     }
       
   138 }
       
   139 if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) {
       
   140     /**
       
   141      * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available()
       
   142      * @return bool
       
   143      */
       
   144     function sodium_crypto_aead_aes256gcm_is_available()
       
   145     {
       
   146         return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available();
       
   147     }
       
   148 }
       
   149 if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) {
       
   150     /**
       
   151      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt()
       
   152      * @param string $message
       
   153      * @param string $assocData
       
   154      * @param string $nonce
       
   155      * @param string $key
       
   156      * @return string|bool
       
   157      */
       
   158     function sodium_crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key)
       
   159     {
       
   160         try {
       
   161             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key);
       
   162         } catch (Error $ex) {
       
   163             return false;
       
   164         } catch (Exception $ex) {
       
   165             return false;
       
   166         }
       
   167     }
       
   168 }
       
   169 if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) {
       
   170     /**
       
   171      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt()
       
   172      * @param string $message
       
   173      * @param string $assocData
       
   174      * @param string $nonce
       
   175      * @param string $key
       
   176      * @return string
       
   177      * @throws SodiumException
       
   178      * @throws TypeError
       
   179      */
       
   180     function sodium_crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key)
       
   181     {
       
   182         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key);
       
   183     }
       
   184 }
       
   185 if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) {
       
   186     /**
       
   187      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen()
       
   188      * @return string
       
   189      */
       
   190     function sodium_crypto_aead_chacha20poly1305_keygen()
       
   191     {
       
   192         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen();
       
   193     }
       
   194 }
       
   195 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) {
       
   196     /**
       
   197      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt()
       
   198      * @param string $message
       
   199      * @param string $assocData
       
   200      * @param string $nonce
       
   201      * @param string $key
       
   202      * @return string|bool
       
   203      */
       
   204     function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key)
       
   205     {
       
   206         try {
       
   207             return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key);
       
   208         } catch (Error $ex) {
       
   209             return false;
       
   210         } catch (Exception $ex) {
       
   211             return false;
       
   212         }
       
   213     }
       
   214 }
       
   215 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) {
       
   216     /**
       
   217      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt()
       
   218      * @param string $message
       
   219      * @param string $assocData
       
   220      * @param string $nonce
       
   221      * @param string $key
       
   222      * @return string
       
   223      * @throws SodiumException
       
   224      * @throws TypeError
       
   225      */
       
   226     function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key)
       
   227     {
       
   228         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key);
       
   229     }
       
   230 }
       
   231 if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) {
       
   232     /**
       
   233      * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen()
       
   234      * @return string
       
   235      */
       
   236     function sodium_crypto_aead_chacha20poly1305_ietf_keygen()
       
   237     {
       
   238         return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen();
       
   239     }
       
   240 }
       
   241 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) {
       
   242     /**
       
   243      * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt()
       
   244      * @param string $message
       
   245      * @param string $assocData
       
   246      * @param string $nonce
       
   247      * @param string $key
       
   248      * @return string|bool
       
   249      */
       
   250     function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key)
       
   251     {
       
   252         try {
       
   253             return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key, true);
       
   254         } catch (Error $ex) {
       
   255             return false;
       
   256         } catch (Exception $ex) {
       
   257             return false;
       
   258         }
       
   259     }
       
   260 }
       
   261 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) {
       
   262     /**
       
   263      * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt()
       
   264      * @param string $message
       
   265      * @param string $assocData
       
   266      * @param string $nonce
       
   267      * @param string $key
       
   268      * @return string
       
   269      * @throws SodiumException
       
   270      * @throws TypeError
       
   271      */
       
   272     function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key)
       
   273     {
       
   274         return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key, true);
       
   275     }
       
   276 }
       
   277 if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) {
       
   278     /**
       
   279      * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen()
       
   280      * @return string
       
   281      */
       
   282     function sodium_crypto_aead_xchacha20poly1305_ietf_keygen()
       
   283     {
       
   284         return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen();
       
   285     }
       
   286 }
       
   287 if (!is_callable('sodium_crypto_auth')) {
       
   288     /**
       
   289      * @see ParagonIE_Sodium_Compat::crypto_auth()
       
   290      * @param string $message
       
   291      * @param string $key
       
   292      * @return string
       
   293      * @throws SodiumException
       
   294      * @throws TypeError
       
   295      */
       
   296     function sodium_crypto_auth($message, $key)
       
   297     {
       
   298         return ParagonIE_Sodium_Compat::crypto_auth($message, $key);
       
   299     }
       
   300 }
       
   301 if (!is_callable('sodium_crypto_auth_keygen')) {
       
   302     /**
       
   303      * @see ParagonIE_Sodium_Compat::crypto_auth_keygen()
       
   304      * @return string
       
   305      */
       
   306     function sodium_crypto_auth_keygen()
       
   307     {
       
   308         return ParagonIE_Sodium_Compat::crypto_auth_keygen();
       
   309     }
       
   310 }
       
   311 if (!is_callable('sodium_crypto_auth_verify')) {
       
   312     /**
       
   313      * @see ParagonIE_Sodium_Compat::crypto_auth_verify()
       
   314      * @param string $mac
       
   315      * @param string $message
       
   316      * @param string $key
       
   317      * @return bool
       
   318      * @throws SodiumException
       
   319      * @throws TypeError
       
   320      */
       
   321     function sodium_crypto_auth_verify($mac, $message, $key)
       
   322     {
       
   323         return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key);
       
   324     }
       
   325 }
       
   326 if (!is_callable('sodium_crypto_box')) {
       
   327     /**
       
   328      * @see ParagonIE_Sodium_Compat::crypto_box()
       
   329      * @param string $message
       
   330      * @param string $nonce
       
   331      * @param string $kp
       
   332      * @return string
       
   333      * @throws SodiumException
       
   334      * @throws TypeError
       
   335      */
       
   336     function sodium_crypto_box($message, $nonce, $kp)
       
   337     {
       
   338         return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp);
       
   339     }
       
   340 }
       
   341 if (!is_callable('sodium_crypto_box_keypair')) {
       
   342     /**
       
   343      * @see ParagonIE_Sodium_Compat::crypto_box_keypair()
       
   344      * @return string
       
   345      * @throws SodiumException
       
   346      * @throws TypeError
       
   347      */
       
   348     function sodium_crypto_box_keypair()
       
   349     {
       
   350         return ParagonIE_Sodium_Compat::crypto_box_keypair();
       
   351     }
       
   352 }
       
   353 if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) {
       
   354     /**
       
   355      * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey()
       
   356      * @param string $sk
       
   357      * @param string $pk
       
   358      * @return string
       
   359      * @throws SodiumException
       
   360      * @throws TypeError
       
   361      */
       
   362     function sodium_crypto_box_keypair_from_secretkey_and_publickey($sk, $pk)
       
   363     {
       
   364         return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk);
       
   365     }
       
   366 }
       
   367 if (!is_callable('sodium_crypto_box_open')) {
       
   368     /**
       
   369      * @see ParagonIE_Sodium_Compat::crypto_box_open()
       
   370      * @param string $message
       
   371      * @param string $nonce
       
   372      * @param string $kp
       
   373      * @return string|bool
       
   374      */
       
   375     function sodium_crypto_box_open($message, $nonce, $kp)
       
   376     {
       
   377         try {
       
   378             return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp);
       
   379         } catch (Error $ex) {
       
   380             return false;
       
   381         } catch (Exception $ex) {
       
   382             return false;
       
   383         }
       
   384     }
       
   385 }
       
   386 if (!is_callable('sodium_crypto_box_publickey')) {
       
   387     /**
       
   388      * @see ParagonIE_Sodium_Compat::crypto_box_publickey()
       
   389      * @param string $keypair
       
   390      * @return string
       
   391      * @throws SodiumException
       
   392      * @throws TypeError
       
   393      */
       
   394     function sodium_crypto_box_publickey($keypair)
       
   395     {
       
   396         return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair);
       
   397     }
       
   398 }
       
   399 if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) {
       
   400     /**
       
   401      * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey()
       
   402      * @param string $sk
       
   403      * @return string
       
   404      * @throws SodiumException
       
   405      * @throws TypeError
       
   406      */
       
   407     function sodium_crypto_box_publickey_from_secretkey($sk)
       
   408     {
       
   409         return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk);
       
   410     }
       
   411 }
       
   412 if (!is_callable('sodium_crypto_box_seal')) {
       
   413     /**
       
   414      * @see ParagonIE_Sodium_Compat::crypto_box_seal()
       
   415      * @param string $message
       
   416      * @param string $publicKey
       
   417      * @return string
       
   418      * @throws SodiumException
       
   419      * @throws TypeError
       
   420      */
       
   421     function sodium_crypto_box_seal($message, $publicKey)
       
   422     {
       
   423         return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey);
       
   424     }
       
   425 }
       
   426 if (!is_callable('sodium_crypto_box_seal_open')) {
       
   427     /**
       
   428      * @see ParagonIE_Sodium_Compat::crypto_box_seal_open()
       
   429      * @param string $message
       
   430      * @param string $kp
       
   431      * @return string|bool
       
   432      * @throws SodiumException
       
   433      */
       
   434     function sodium_crypto_box_seal_open($message, $kp)
       
   435     {
       
   436         try {
       
   437             return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp);
       
   438         } catch (SodiumException $ex) {
       
   439             if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') {
       
   440                 throw $ex;
       
   441             }
       
   442             return false;
       
   443         }
       
   444     }
       
   445 }
       
   446 if (!is_callable('sodium_crypto_box_secretkey')) {
       
   447     /**
       
   448      * @see ParagonIE_Sodium_Compat::crypto_box_secretkey()
       
   449      * @param string $keypair
       
   450      * @return string
       
   451      * @throws SodiumException
       
   452      * @throws TypeError
       
   453      */
       
   454     function sodium_crypto_box_secretkey($keypair)
       
   455     {
       
   456         return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair);
       
   457     }
       
   458 }
       
   459 if (!is_callable('sodium_crypto_box_seed_keypair')) {
       
   460     /**
       
   461      * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair()
       
   462      * @param string $seed
       
   463      * @return string
       
   464      * @throws SodiumException
       
   465      * @throws TypeError
       
   466      */
       
   467     function sodium_crypto_box_seed_keypair($seed)
       
   468     {
       
   469         return ParagonIE_Sodium_Compat::crypto_box_seed_keypair($seed);
       
   470     }
       
   471 }
       
   472 if (!is_callable('sodium_crypto_generichash')) {
       
   473     /**
       
   474      * @see ParagonIE_Sodium_Compat::crypto_generichash()
       
   475      * @param string $message
       
   476      * @param string|null $key
       
   477      * @param int $outLen
       
   478      * @return string
       
   479      * @throws SodiumException
       
   480      * @throws TypeError
       
   481      */
       
   482     function sodium_crypto_generichash($message, $key = null, $outLen = 32)
       
   483     {
       
   484         return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen);
       
   485     }
       
   486 }
       
   487 if (!is_callable('sodium_crypto_generichash_final')) {
       
   488     /**
       
   489      * @see ParagonIE_Sodium_Compat::crypto_generichash_final()
       
   490      * @param string|null $ctx
       
   491      * @param int $outputLength
       
   492      * @return string
       
   493      * @throws SodiumException
       
   494      * @throws TypeError
       
   495      */
       
   496     function sodium_crypto_generichash_final(&$ctx, $outputLength = 32)
       
   497     {
       
   498         return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength);
       
   499     }
       
   500 }
       
   501 if (!is_callable('sodium_crypto_generichash_init')) {
       
   502     /**
       
   503      * @see ParagonIE_Sodium_Compat::crypto_generichash_init()
       
   504      * @param string|null $key
       
   505      * @param int $outLen
       
   506      * @return string
       
   507      * @throws SodiumException
       
   508      * @throws TypeError
       
   509      */
       
   510     function sodium_crypto_generichash_init($key = null, $outLen = 32)
       
   511     {
       
   512         return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen);
       
   513     }
       
   514 }
       
   515 if (!is_callable('sodium_crypto_generichash_keygen')) {
       
   516     /**
       
   517      * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen()
       
   518      * @return string
       
   519      */
       
   520     function sodium_crypto_generichash_keygen()
       
   521     {
       
   522         return ParagonIE_Sodium_Compat::crypto_generichash_keygen();
       
   523     }
       
   524 }
       
   525 if (!is_callable('sodium_crypto_generichash_update')) {
       
   526     /**
       
   527      * @see ParagonIE_Sodium_Compat::crypto_generichash_update()
       
   528      * @param string|null $ctx
       
   529      * @param string $message
       
   530      * @return void
       
   531      * @throws SodiumException
       
   532      * @throws TypeError
       
   533      */
       
   534     function sodium_crypto_generichash_update(&$ctx, $message = '')
       
   535     {
       
   536         ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message);
       
   537     }
       
   538 }
       
   539 if (!is_callable('sodium_crypto_kx')) {
       
   540     /**
       
   541      * @see ParagonIE_Sodium_Compat::crypto_kx()
       
   542      * @param string $my_secret
       
   543      * @param string $their_public
       
   544      * @param string $client_public
       
   545      * @param string $server_public
       
   546      * @return string
       
   547      * @throws SodiumException
       
   548      * @throws TypeError
       
   549      */
       
   550     function sodium_crypto_kx($my_secret, $their_public, $client_public, $server_public)
       
   551     {
       
   552         return ParagonIE_Sodium_Compat::crypto_kx(
       
   553             $my_secret,
       
   554             $their_public,
       
   555             $client_public,
       
   556             $server_public
       
   557         );
       
   558     }
       
   559 }
       
   560 if (!is_callable('sodium_crypto_pwhash')) {
       
   561     /**
       
   562      * @see ParagonIE_Sodium_Compat::crypto_pwhash()
       
   563      * @param int $outlen
       
   564      * @param string $passwd
       
   565      * @param string $salt
       
   566      * @param int $opslimit
       
   567      * @param int $memlimit
       
   568      * @param int|null $algo
       
   569      * @return string
       
   570      * @throws SodiumException
       
   571      * @throws TypeError
       
   572      */
       
   573     function sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo = null)
       
   574     {
       
   575         return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo);
       
   576     }
       
   577 }
       
   578 if (!is_callable('sodium_crypto_pwhash_str')) {
       
   579     /**
       
   580      * @see ParagonIE_Sodium_Compat::crypto_pwhash_str()
       
   581      * @param string $passwd
       
   582      * @param int $opslimit
       
   583      * @param int $memlimit
       
   584      * @return string
       
   585      * @throws SodiumException
       
   586      * @throws TypeError
       
   587      */
       
   588     function sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit)
       
   589     {
       
   590         return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit);
       
   591     }
       
   592 }
       
   593 if (!is_callable('sodium_crypto_pwhash_str_verify')) {
       
   594     /**
       
   595      * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify()
       
   596      * @param string $passwd
       
   597      * @param string $hash
       
   598      * @return bool
       
   599      * @throws SodiumException
       
   600      * @throws TypeError
       
   601      */
       
   602     function sodium_crypto_pwhash_str_verify($passwd, $hash)
       
   603     {
       
   604         return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash);
       
   605     }
       
   606 }
       
   607 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) {
       
   608     /**
       
   609      * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256()
       
   610      * @param int $outlen
       
   611      * @param string $passwd
       
   612      * @param string $salt
       
   613      * @param int $opslimit
       
   614      * @param int $memlimit
       
   615      * @return string
       
   616      * @throws SodiumException
       
   617      * @throws TypeError
       
   618      */
       
   619     function sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit)
       
   620     {
       
   621         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit);
       
   622     }
       
   623 }
       
   624 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) {
       
   625     /**
       
   626      * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str()
       
   627      * @param string $passwd
       
   628      * @param int $opslimit
       
   629      * @param int $memlimit
       
   630      * @return string
       
   631      * @throws SodiumException
       
   632      * @throws TypeError
       
   633      */
       
   634     function sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit)
       
   635     {
       
   636         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit);
       
   637     }
       
   638 }
       
   639 if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) {
       
   640     /**
       
   641      * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify()
       
   642      * @param string $passwd
       
   643      * @param string $hash
       
   644      * @return bool
       
   645      * @throws SodiumException
       
   646      * @throws TypeError
       
   647      */
       
   648     function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash)
       
   649     {
       
   650         return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash);
       
   651     }
       
   652 }
       
   653 if (!is_callable('sodium_crypto_scalarmult')) {
       
   654     /**
       
   655      * @see ParagonIE_Sodium_Compat::crypto_scalarmult()
       
   656      * @param string $n
       
   657      * @param string $p
       
   658      * @return string
       
   659      * @throws SodiumException
       
   660      * @throws TypeError
       
   661      */
       
   662     function sodium_crypto_scalarmult($n, $p)
       
   663     {
       
   664         return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p);
       
   665     }
       
   666 }
       
   667 if (!is_callable('sodium_crypto_scalarmult_base')) {
       
   668     /**
       
   669      * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base()
       
   670      * @param string $n
       
   671      * @return string
       
   672      * @throws SodiumException
       
   673      * @throws TypeError
       
   674      */
       
   675     function sodium_crypto_scalarmult_base($n)
       
   676     {
       
   677         return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n);
       
   678     }
       
   679 }
       
   680 if (!is_callable('sodium_crypto_secretbox')) {
       
   681     /**
       
   682      * @see ParagonIE_Sodium_Compat::crypto_secretbox()
       
   683      * @param string $message
       
   684      * @param string $nonce
       
   685      * @param string $key
       
   686      * @return string
       
   687      * @throws SodiumException
       
   688      * @throws TypeError
       
   689      */
       
   690     function sodium_crypto_secretbox($message, $nonce, $key)
       
   691     {
       
   692         return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key);
       
   693     }
       
   694 }
       
   695 if (!is_callable('sodium_crypto_secretbox_keygen')) {
       
   696     /**
       
   697      * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen()
       
   698      * @return string
       
   699      */
       
   700     function sodium_crypto_secretbox_keygen()
       
   701     {
       
   702         return ParagonIE_Sodium_Compat::crypto_secretbox_keygen();
       
   703     }
       
   704 }
       
   705 if (!is_callable('sodium_crypto_secretbox_open')) {
       
   706     /**
       
   707      * @see ParagonIE_Sodium_Compat::crypto_secretbox_open()
       
   708      * @param string $message
       
   709      * @param string $nonce
       
   710      * @param string $key
       
   711      * @return string|bool
       
   712      */
       
   713     function sodium_crypto_secretbox_open($message, $nonce, $key)
       
   714     {
       
   715         try {
       
   716             return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key);
       
   717         } catch (Error $ex) {
       
   718             return false;
       
   719         } catch (Exception $ex) {
       
   720             return false;
       
   721         }
       
   722     }
       
   723 }
       
   724 if (!is_callable('sodium_crypto_shorthash')) {
       
   725     /**
       
   726      * @see ParagonIE_Sodium_Compat::crypto_shorthash()
       
   727      * @param string $message
       
   728      * @param string $key
       
   729      * @return string
       
   730      * @throws SodiumException
       
   731      * @throws TypeError
       
   732      */
       
   733     function sodium_crypto_shorthash($message, $key = '')
       
   734     {
       
   735         return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key);
       
   736     }
       
   737 }
       
   738 if (!is_callable('sodium_crypto_shorthash_keygen')) {
       
   739     /**
       
   740      * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen()
       
   741      * @return string
       
   742      */
       
   743     function sodium_crypto_shorthash_keygen()
       
   744     {
       
   745         return ParagonIE_Sodium_Compat::crypto_shorthash_keygen();
       
   746     }
       
   747 }
       
   748 if (!is_callable('sodium_crypto_sign')) {
       
   749     /**
       
   750      * @see ParagonIE_Sodium_Compat::crypto_sign()
       
   751      * @param string $message
       
   752      * @param string $sk
       
   753      * @return string
       
   754      * @throws SodiumException
       
   755      * @throws TypeError
       
   756      */
       
   757     function sodium_crypto_sign($message, $sk)
       
   758     {
       
   759         return ParagonIE_Sodium_Compat::crypto_sign($message, $sk);
       
   760     }
       
   761 }
       
   762 if (!is_callable('sodium_crypto_sign_detached')) {
       
   763     /**
       
   764      * @see ParagonIE_Sodium_Compat::crypto_sign_detached()
       
   765      * @param string $message
       
   766      * @param string $sk
       
   767      * @return string
       
   768      * @throws SodiumException
       
   769      * @throws TypeError
       
   770      */
       
   771     function sodium_crypto_sign_detached($message, $sk)
       
   772     {
       
   773         return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk);
       
   774     }
       
   775 }
       
   776 if (!is_callable('sodium_crypto_sign_keypair')) {
       
   777     /**
       
   778      * @see ParagonIE_Sodium_Compat::crypto_sign_keypair()
       
   779      * @return string
       
   780      * @throws SodiumException
       
   781      * @throws TypeError
       
   782      */
       
   783     function sodium_crypto_sign_keypair()
       
   784     {
       
   785         return ParagonIE_Sodium_Compat::crypto_sign_keypair();
       
   786     }
       
   787 }
       
   788 if (!is_callable('sodium_crypto_sign_open')) {
       
   789     /**
       
   790      * @see ParagonIE_Sodium_Compat::crypto_sign_open()
       
   791      * @param string $signedMessage
       
   792      * @param string $pk
       
   793      * @return string|bool
       
   794      */
       
   795     function sodium_crypto_sign_open($signedMessage, $pk)
       
   796     {
       
   797         try {
       
   798             return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk);
       
   799         } catch (Error $ex) {
       
   800             return false;
       
   801         } catch (Exception $ex) {
       
   802             return false;
       
   803         }
       
   804     }
       
   805 }
       
   806 if (!is_callable('sodium_crypto_sign_publickey')) {
       
   807     /**
       
   808      * @see ParagonIE_Sodium_Compat::crypto_sign_publickey()
       
   809      * @param string $keypair
       
   810      * @return string
       
   811      * @throws SodiumException
       
   812      * @throws TypeError
       
   813      */
       
   814     function sodium_crypto_sign_publickey($keypair)
       
   815     {
       
   816         return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair);
       
   817     }
       
   818 }
       
   819 if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) {
       
   820     /**
       
   821      * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey()
       
   822      * @param string $sk
       
   823      * @return string
       
   824      * @throws SodiumException
       
   825      * @throws TypeError
       
   826      */
       
   827     function sodium_crypto_sign_publickey_from_secretkey($sk)
       
   828     {
       
   829         return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk);
       
   830     }
       
   831 }
       
   832 if (!is_callable('sodium_crypto_sign_secretkey')) {
       
   833     /**
       
   834      * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey()
       
   835      * @param string $keypair
       
   836      * @return string
       
   837      * @throws SodiumException
       
   838      * @throws TypeError
       
   839      */
       
   840     function sodium_crypto_sign_secretkey($keypair)
       
   841     {
       
   842         return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair);
       
   843     }
       
   844 }
       
   845 if (!is_callable('sodium_crypto_sign_seed_keypair')) {
       
   846     /**
       
   847      * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair()
       
   848      * @param string $seed
       
   849      * @return string
       
   850      * @throws SodiumException
       
   851      * @throws TypeError
       
   852      */
       
   853     function sodium_crypto_sign_seed_keypair($seed)
       
   854     {
       
   855         return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
       
   856     }
       
   857 }
       
   858 if (!is_callable('sodium_crypto_sign_verify_detached')) {
       
   859     /**
       
   860      * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached()
       
   861      * @param string $signature
       
   862      * @param string $message
       
   863      * @param string $pk
       
   864      * @return bool
       
   865      * @throws SodiumException
       
   866      * @throws TypeError
       
   867      */
       
   868     function sodium_crypto_sign_verify_detached($signature, $message, $pk)
       
   869     {
       
   870         return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk);
       
   871     }
       
   872 }
       
   873 if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) {
       
   874     /**
       
   875      * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519()
       
   876      * @param string $pk
       
   877      * @return string
       
   878      * @throws SodiumException
       
   879      * @throws TypeError
       
   880      */
       
   881     function sodium_crypto_sign_ed25519_pk_to_curve25519($pk)
       
   882     {
       
   883         return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk);
       
   884     }
       
   885 }
       
   886 if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) {
       
   887     /**
       
   888      * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519()
       
   889      * @param string $sk
       
   890      * @return string
       
   891      * @throws SodiumException
       
   892      * @throws TypeError
       
   893      */
       
   894     function sodium_crypto_sign_ed25519_sk_to_curve25519($sk)
       
   895     {
       
   896         return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk);
       
   897     }
       
   898 }
       
   899 if (!is_callable('sodium_crypto_stream')) {
       
   900     /**
       
   901      * @see ParagonIE_Sodium_Compat::crypto_stream()
       
   902      * @param int $len
       
   903      * @param string $nonce
       
   904      * @param string $key
       
   905      * @return string
       
   906      * @throws SodiumException
       
   907      * @throws TypeError
       
   908      */
       
   909     function sodium_crypto_stream($len, $nonce, $key)
       
   910     {
       
   911         return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key);
       
   912     }
       
   913 }
       
   914 if (!is_callable('sodium_crypto_stream_keygen')) {
       
   915     /**
       
   916      * @see ParagonIE_Sodium_Compat::crypto_stream_keygen()
       
   917      * @return string
       
   918      */
       
   919     function sodium_crypto_stream_keygen()
       
   920     {
       
   921         return ParagonIE_Sodium_Compat::crypto_stream_keygen();
       
   922     }
       
   923 }
       
   924 if (!is_callable('sodium_crypto_stream_xor')) {
       
   925     /**
       
   926      * @see ParagonIE_Sodium_Compat::crypto_stream_xor()
       
   927      * @param string $message
       
   928      * @param string $nonce
       
   929      * @param string $key
       
   930      * @return string
       
   931      * @throws SodiumException
       
   932      * @throws TypeError
       
   933      */
       
   934     function sodium_crypto_stream_xor($message, $nonce, $key)
       
   935     {
       
   936         return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
       
   937     }
       
   938 }
       
   939 if (!is_callable('sodium_hex2bin')) {
       
   940     /**
       
   941      * @see ParagonIE_Sodium_Compat::hex2bin()
       
   942      * @param string $string
       
   943      * @return string
       
   944      * @throws SodiumException
       
   945      * @throws TypeError
       
   946      */
       
   947     function sodium_hex2bin($string)
       
   948     {
       
   949         return ParagonIE_Sodium_Compat::hex2bin($string);
       
   950     }
       
   951 }
       
   952 if (!is_callable('sodium_increment')) {
       
   953     /**
       
   954      * @see ParagonIE_Sodium_Compat::increment()
       
   955      * @param string $string
       
   956      * @return void
       
   957      * @throws SodiumException
       
   958      * @throws TypeError
       
   959      */
       
   960     function sodium_increment(&$string)
       
   961     {
       
   962         ParagonIE_Sodium_Compat::increment($string);
       
   963     }
       
   964 }
       
   965 if (!is_callable('sodium_library_version_major')) {
       
   966     /**
       
   967      * @see ParagonIE_Sodium_Compat::library_version_major()
       
   968      * @return int
       
   969      */
       
   970     function sodium_library_version_major()
       
   971     {
       
   972         return ParagonIE_Sodium_Compat::library_version_major();
       
   973     }
       
   974 }
       
   975 if (!is_callable('sodium_library_version_minor')) {
       
   976     /**
       
   977      * @see ParagonIE_Sodium_Compat::library_version_minor()
       
   978      * @return int
       
   979      */
       
   980     function sodium_library_version_minor()
       
   981     {
       
   982         return ParagonIE_Sodium_Compat::library_version_minor();
       
   983     }
       
   984 }
       
   985 if (!is_callable('sodium_version_string')) {
       
   986     /**
       
   987      * @see ParagonIE_Sodium_Compat::version_string()
       
   988      * @return string
       
   989      */
       
   990     function sodium_version_string()
       
   991     {
       
   992         return ParagonIE_Sodium_Compat::version_string();
       
   993     }
       
   994 }
       
   995 if (!is_callable('sodium_memcmp')) {
       
   996     /**
       
   997      * @see ParagonIE_Sodium_Compat::memcmp()
       
   998      * @param string $a
       
   999      * @param string $b
       
  1000      * @return int
       
  1001      * @throws SodiumException
       
  1002      * @throws TypeError
       
  1003      */
       
  1004     function sodium_memcmp($a, $b)
       
  1005     {
       
  1006         return ParagonIE_Sodium_Compat::memcmp($a, $b);
       
  1007     }
       
  1008 }
       
  1009 if (!is_callable('sodium_memzero')) {
       
  1010     /**
       
  1011      * @see ParagonIE_Sodium_Compat::memzero()
       
  1012      * @param string $str
       
  1013      * @return void
       
  1014      * @throws SodiumException
       
  1015      * @throws TypeError
       
  1016      */
       
  1017     function sodium_memzero(&$str)
       
  1018     {
       
  1019         ParagonIE_Sodium_Compat::memzero($str);
       
  1020     }
       
  1021 }
       
  1022 if (!is_callable('sodium_randombytes_buf')) {
       
  1023     /**
       
  1024      * @see ParagonIE_Sodium_Compat::randombytes_buf()
       
  1025      * @param int $amount
       
  1026      * @return string
       
  1027      * @throws Exception
       
  1028      */
       
  1029     function sodium_randombytes_buf($amount)
       
  1030     {
       
  1031         return ParagonIE_Sodium_Compat::randombytes_buf($amount);
       
  1032     }
       
  1033 }
       
  1034 
       
  1035 if (!is_callable('sodium_randombytes_uniform')) {
       
  1036     /**
       
  1037      * @see ParagonIE_Sodium_Compat::randombytes_uniform()
       
  1038      * @param int $upperLimit
       
  1039      * @return int
       
  1040      * @throws Exception
       
  1041      */
       
  1042     function sodium_randombytes_uniform($upperLimit)
       
  1043     {
       
  1044         return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit);
       
  1045     }
       
  1046 }
       
  1047 
       
  1048 if (!is_callable('sodium_randombytes_random16')) {
       
  1049     /**
       
  1050      * @see ParagonIE_Sodium_Compat::randombytes_random16()
       
  1051      * @return int
       
  1052      */
       
  1053     function sodium_randombytes_random16()
       
  1054     {
       
  1055         return ParagonIE_Sodium_Compat::randombytes_random16();
       
  1056     }
       
  1057 }