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