/htdocs/wp-includes/sodium_compat/lib/php72compat.php

https://gitlab.com/VTTE/sitios-vtte · PHP · 1354 lines · 691 code · 4 blank · 659 comment · 94 complexity · 95c319e795f3e761a42051f59338c7b1 MD5 · raw file

  1. <?php
  2. require_once dirname(dirname(__FILE__)) . '/autoload.php';
  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. 'BASE64_VARIANT_ORIGINAL',
  12. 'BASE64_VARIANT_ORIGINAL_NO_PADDING',
  13. 'BASE64_VARIANT_URLSAFE',
  14. 'BASE64_VARIANT_URLSAFE_NO_PADDING',
  15. 'CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES',
  16. 'CRYPTO_AEAD_CHACHA20POLY1305_NSECBYTES',
  17. 'CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES',
  18. 'CRYPTO_AEAD_CHACHA20POLY1305_ABYTES',
  19. 'CRYPTO_AEAD_AES256GCM_KEYBYTES',
  20. 'CRYPTO_AEAD_AES256GCM_NSECBYTES',
  21. 'CRYPTO_AEAD_AES256GCM_NPUBBYTES',
  22. 'CRYPTO_AEAD_AES256GCM_ABYTES',
  23. 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES',
  24. 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NSECBYTES',
  25. 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES',
  26. 'CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES',
  27. 'CRYPTO_AUTH_BYTES',
  28. 'CRYPTO_AUTH_KEYBYTES',
  29. 'CRYPTO_BOX_SEALBYTES',
  30. 'CRYPTO_BOX_SECRETKEYBYTES',
  31. 'CRYPTO_BOX_PUBLICKEYBYTES',
  32. 'CRYPTO_BOX_KEYPAIRBYTES',
  33. 'CRYPTO_BOX_MACBYTES',
  34. 'CRYPTO_BOX_NONCEBYTES',
  35. 'CRYPTO_BOX_SEEDBYTES',
  36. 'CRYPTO_KDF_BYTES_MIN',
  37. 'CRYPTO_KDF_BYTES_MAX',
  38. 'CRYPTO_KDF_CONTEXTBYTES',
  39. 'CRYPTO_KDF_KEYBYTES',
  40. 'CRYPTO_KX_BYTES',
  41. 'CRYPTO_KX_KEYPAIRBYTES',
  42. 'CRYPTO_KX_PRIMITIVE',
  43. 'CRYPTO_KX_SEEDBYTES',
  44. 'CRYPTO_KX_PUBLICKEYBYTES',
  45. 'CRYPTO_KX_SECRETKEYBYTES',
  46. 'CRYPTO_KX_SESSIONKEYBYTES',
  47. 'CRYPTO_GENERICHASH_BYTES',
  48. 'CRYPTO_GENERICHASH_BYTES_MIN',
  49. 'CRYPTO_GENERICHASH_BYTES_MAX',
  50. 'CRYPTO_GENERICHASH_KEYBYTES',
  51. 'CRYPTO_GENERICHASH_KEYBYTES_MIN',
  52. 'CRYPTO_GENERICHASH_KEYBYTES_MAX',
  53. 'CRYPTO_PWHASH_SALTBYTES',
  54. 'CRYPTO_PWHASH_STRPREFIX',
  55. 'CRYPTO_PWHASH_ALG_ARGON2I13',
  56. 'CRYPTO_PWHASH_ALG_ARGON2ID13',
  57. 'CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE',
  58. 'CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE',
  59. 'CRYPTO_PWHASH_MEMLIMIT_MODERATE',
  60. 'CRYPTO_PWHASH_OPSLIMIT_MODERATE',
  61. 'CRYPTO_PWHASH_MEMLIMIT_SENSITIVE',
  62. 'CRYPTO_PWHASH_OPSLIMIT_SENSITIVE',
  63. 'CRYPTO_SCALARMULT_BYTES',
  64. 'CRYPTO_SCALARMULT_SCALARBYTES',
  65. 'CRYPTO_SHORTHASH_BYTES',
  66. 'CRYPTO_SHORTHASH_KEYBYTES',
  67. 'CRYPTO_SECRETBOX_KEYBYTES',
  68. 'CRYPTO_SECRETBOX_MACBYTES',
  69. 'CRYPTO_SECRETBOX_NONCEBYTES',
  70. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES',
  71. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES',
  72. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES',
  73. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PUSH',
  74. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_PULL',
  75. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY',
  76. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL',
  77. 'CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX',
  78. 'CRYPTO_SIGN_BYTES',
  79. 'CRYPTO_SIGN_SEEDBYTES',
  80. 'CRYPTO_SIGN_PUBLICKEYBYTES',
  81. 'CRYPTO_SIGN_SECRETKEYBYTES',
  82. 'CRYPTO_SIGN_KEYPAIRBYTES',
  83. 'CRYPTO_STREAM_KEYBYTES',
  84. 'CRYPTO_STREAM_NONCEBYTES',
  85. 'LIBRARY_VERSION_MAJOR',
  86. 'LIBRARY_VERSION_MINOR',
  87. 'VERSION_STRING'
  88. ) as $constant
  89. ) {
  90. if (!defined("SODIUM_$constant") && defined("ParagonIE_Sodium_Compat::$constant")) {
  91. define("SODIUM_$constant", constant("ParagonIE_Sodium_Compat::$constant"));
  92. }
  93. }
  94. if (!is_callable('sodium_add')) {
  95. /**
  96. * @see ParagonIE_Sodium_Compat::add()
  97. * @param string $val
  98. * @param string $addv
  99. * @return void
  100. * @throws SodiumException
  101. */
  102. function sodium_add(&$val, $addv)
  103. {
  104. ParagonIE_Sodium_Compat::add($val, $addv);
  105. }
  106. }
  107. if (!is_callable('sodium_base642bin')) {
  108. /**
  109. * @see ParagonIE_Sodium_Compat::bin2base64()
  110. * @param string $string
  111. * @param int $variant
  112. * @param string $ignore
  113. * @return string
  114. * @throws SodiumException
  115. * @throws TypeError
  116. */
  117. function sodium_base642bin($string, $variant, $ignore ='')
  118. {
  119. return ParagonIE_Sodium_Compat::base642bin($string, $variant, $ignore);
  120. }
  121. }
  122. if (!is_callable('sodium_bin2base64')) {
  123. /**
  124. * @see ParagonIE_Sodium_Compat::bin2base64()
  125. * @param string $string
  126. * @param int $variant
  127. * @return string
  128. * @throws SodiumException
  129. * @throws TypeError
  130. */
  131. function sodium_bin2base64($string, $variant)
  132. {
  133. return ParagonIE_Sodium_Compat::bin2base64($string, $variant);
  134. }
  135. }
  136. if (!is_callable('sodium_bin2hex')) {
  137. /**
  138. * @see ParagonIE_Sodium_Compat::hex2bin()
  139. * @param string $string
  140. * @return string
  141. * @throws SodiumException
  142. * @throws TypeError
  143. */
  144. function sodium_bin2hex($string)
  145. {
  146. return ParagonIE_Sodium_Compat::bin2hex($string);
  147. }
  148. }
  149. if (!is_callable('sodium_compare')) {
  150. /**
  151. * @see ParagonIE_Sodium_Compat::compare()
  152. * @param string $a
  153. * @param string $b
  154. * @return int
  155. * @throws SodiumException
  156. * @throws TypeError
  157. */
  158. function sodium_compare($a, $b)
  159. {
  160. return ParagonIE_Sodium_Compat::compare($a, $b);
  161. }
  162. }
  163. if (!is_callable('sodium_crypto_aead_aes256gcm_decrypt')) {
  164. /**
  165. * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt()
  166. * @param string $message
  167. * @param string $assocData
  168. * @param string $nonce
  169. * @param string $key
  170. * @return string|bool
  171. */
  172. function sodium_crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key)
  173. {
  174. try {
  175. return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_decrypt($message, $assocData, $nonce, $key);
  176. } catch (Error $ex) {
  177. return false;
  178. } catch (Exception $ex) {
  179. return false;
  180. }
  181. }
  182. }
  183. if (!is_callable('sodium_crypto_aead_aes256gcm_encrypt')) {
  184. /**
  185. * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt()
  186. * @param string $message
  187. * @param string $assocData
  188. * @param string $nonce
  189. * @param string $key
  190. * @return string
  191. * @throws SodiumException
  192. * @throws TypeError
  193. */
  194. function sodium_crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key)
  195. {
  196. return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt($message, $assocData, $nonce, $key);
  197. }
  198. }
  199. if (!is_callable('sodium_crypto_aead_aes256gcm_is_available')) {
  200. /**
  201. * @see ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available()
  202. * @return bool
  203. */
  204. function sodium_crypto_aead_aes256gcm_is_available()
  205. {
  206. return ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_is_available();
  207. }
  208. }
  209. if (!is_callable('sodium_crypto_aead_chacha20poly1305_decrypt')) {
  210. /**
  211. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt()
  212. * @param string $message
  213. * @param string $assocData
  214. * @param string $nonce
  215. * @param string $key
  216. * @return string|bool
  217. */
  218. function sodium_crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key)
  219. {
  220. try {
  221. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_decrypt($message, $assocData, $nonce, $key);
  222. } catch (Error $ex) {
  223. return false;
  224. } catch (Exception $ex) {
  225. return false;
  226. }
  227. }
  228. }
  229. if (!is_callable('sodium_crypto_aead_chacha20poly1305_encrypt')) {
  230. /**
  231. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt()
  232. * @param string $message
  233. * @param string $assocData
  234. * @param string $nonce
  235. * @param string $key
  236. * @return string
  237. * @throws SodiumException
  238. * @throws TypeError
  239. */
  240. function sodium_crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key)
  241. {
  242. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt($message, $assocData, $nonce, $key);
  243. }
  244. }
  245. if (!is_callable('sodium_crypto_aead_chacha20poly1305_keygen')) {
  246. /**
  247. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen()
  248. * @return string
  249. * @throws Exception
  250. */
  251. function sodium_crypto_aead_chacha20poly1305_keygen()
  252. {
  253. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_keygen();
  254. }
  255. }
  256. if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_decrypt')) {
  257. /**
  258. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt()
  259. * @param string $message
  260. * @param string $assocData
  261. * @param string $nonce
  262. * @param string $key
  263. * @return string|bool
  264. */
  265. function sodium_crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key)
  266. {
  267. try {
  268. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key);
  269. } catch (Error $ex) {
  270. return false;
  271. } catch (Exception $ex) {
  272. return false;
  273. }
  274. }
  275. }
  276. if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_encrypt')) {
  277. /**
  278. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt()
  279. * @param string $message
  280. * @param string $assocData
  281. * @param string $nonce
  282. * @param string $key
  283. * @return string
  284. * @throws SodiumException
  285. * @throws TypeError
  286. */
  287. function sodium_crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key)
  288. {
  289. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key);
  290. }
  291. }
  292. if (!is_callable('sodium_crypto_aead_chacha20poly1305_ietf_keygen')) {
  293. /**
  294. * @see ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen()
  295. * @return string
  296. * @throws Exception
  297. */
  298. function sodium_crypto_aead_chacha20poly1305_ietf_keygen()
  299. {
  300. return ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_ietf_keygen();
  301. }
  302. }
  303. if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) {
  304. /**
  305. * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt()
  306. * @param string $message
  307. * @param string $assocData
  308. * @param string $nonce
  309. * @param string $key
  310. * @return string|bool
  311. */
  312. function sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key)
  313. {
  314. try {
  315. return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt($message, $assocData, $nonce, $key, true);
  316. } catch (Error $ex) {
  317. return false;
  318. } catch (Exception $ex) {
  319. return false;
  320. }
  321. }
  322. }
  323. if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) {
  324. /**
  325. * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt()
  326. * @param string $message
  327. * @param string $assocData
  328. * @param string $nonce
  329. * @param string $key
  330. * @return string
  331. * @throws SodiumException
  332. * @throws TypeError
  333. */
  334. function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key)
  335. {
  336. return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt($message, $assocData, $nonce, $key, true);
  337. }
  338. }
  339. if (!is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_keygen')) {
  340. /**
  341. * @see ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen()
  342. * @return string
  343. * @throws Exception
  344. */
  345. function sodium_crypto_aead_xchacha20poly1305_ietf_keygen()
  346. {
  347. return ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_keygen();
  348. }
  349. }
  350. if (!is_callable('sodium_crypto_auth')) {
  351. /**
  352. * @see ParagonIE_Sodium_Compat::crypto_auth()
  353. * @param string $message
  354. * @param string $key
  355. * @return string
  356. * @throws SodiumException
  357. * @throws TypeError
  358. */
  359. function sodium_crypto_auth($message, $key)
  360. {
  361. return ParagonIE_Sodium_Compat::crypto_auth($message, $key);
  362. }
  363. }
  364. if (!is_callable('sodium_crypto_auth_keygen')) {
  365. /**
  366. * @see ParagonIE_Sodium_Compat::crypto_auth_keygen()
  367. * @return string
  368. * @throws Exception
  369. */
  370. function sodium_crypto_auth_keygen()
  371. {
  372. return ParagonIE_Sodium_Compat::crypto_auth_keygen();
  373. }
  374. }
  375. if (!is_callable('sodium_crypto_auth_verify')) {
  376. /**
  377. * @see ParagonIE_Sodium_Compat::crypto_auth_verify()
  378. * @param string $mac
  379. * @param string $message
  380. * @param string $key
  381. * @return bool
  382. * @throws SodiumException
  383. * @throws TypeError
  384. */
  385. function sodium_crypto_auth_verify($mac, $message, $key)
  386. {
  387. return ParagonIE_Sodium_Compat::crypto_auth_verify($mac, $message, $key);
  388. }
  389. }
  390. if (!is_callable('sodium_crypto_box')) {
  391. /**
  392. * @see ParagonIE_Sodium_Compat::crypto_box()
  393. * @param string $message
  394. * @param string $nonce
  395. * @param string $kp
  396. * @return string
  397. * @throws SodiumException
  398. * @throws TypeError
  399. */
  400. function sodium_crypto_box($message, $nonce, $kp)
  401. {
  402. return ParagonIE_Sodium_Compat::crypto_box($message, $nonce, $kp);
  403. }
  404. }
  405. if (!is_callable('sodium_crypto_box_keypair')) {
  406. /**
  407. * @see ParagonIE_Sodium_Compat::crypto_box_keypair()
  408. * @return string
  409. * @throws SodiumException
  410. * @throws TypeError
  411. */
  412. function sodium_crypto_box_keypair()
  413. {
  414. return ParagonIE_Sodium_Compat::crypto_box_keypair();
  415. }
  416. }
  417. if (!is_callable('sodium_crypto_box_keypair_from_secretkey_and_publickey')) {
  418. /**
  419. * @see ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey()
  420. * @param string $sk
  421. * @param string $pk
  422. * @return string
  423. * @throws SodiumException
  424. * @throws TypeError
  425. */
  426. function sodium_crypto_box_keypair_from_secretkey_and_publickey($sk, $pk)
  427. {
  428. return ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey($sk, $pk);
  429. }
  430. }
  431. if (!is_callable('sodium_crypto_box_open')) {
  432. /**
  433. * @see ParagonIE_Sodium_Compat::crypto_box_open()
  434. * @param string $message
  435. * @param string $nonce
  436. * @param string $kp
  437. * @return string|bool
  438. */
  439. function sodium_crypto_box_open($message, $nonce, $kp)
  440. {
  441. try {
  442. return ParagonIE_Sodium_Compat::crypto_box_open($message, $nonce, $kp);
  443. } catch (Error $ex) {
  444. return false;
  445. } catch (Exception $ex) {
  446. return false;
  447. }
  448. }
  449. }
  450. if (!is_callable('sodium_crypto_box_publickey')) {
  451. /**
  452. * @see ParagonIE_Sodium_Compat::crypto_box_publickey()
  453. * @param string $keypair
  454. * @return string
  455. * @throws SodiumException
  456. * @throws TypeError
  457. */
  458. function sodium_crypto_box_publickey($keypair)
  459. {
  460. return ParagonIE_Sodium_Compat::crypto_box_publickey($keypair);
  461. }
  462. }
  463. if (!is_callable('sodium_crypto_box_publickey_from_secretkey')) {
  464. /**
  465. * @see ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey()
  466. * @param string $sk
  467. * @return string
  468. * @throws SodiumException
  469. * @throws TypeError
  470. */
  471. function sodium_crypto_box_publickey_from_secretkey($sk)
  472. {
  473. return ParagonIE_Sodium_Compat::crypto_box_publickey_from_secretkey($sk);
  474. }
  475. }
  476. if (!is_callable('sodium_crypto_box_seal')) {
  477. /**
  478. * @see ParagonIE_Sodium_Compat::crypto_box_seal()
  479. * @param string $message
  480. * @param string $publicKey
  481. * @return string
  482. * @throws SodiumException
  483. * @throws TypeError
  484. */
  485. function sodium_crypto_box_seal($message, $publicKey)
  486. {
  487. return ParagonIE_Sodium_Compat::crypto_box_seal($message, $publicKey);
  488. }
  489. }
  490. if (!is_callable('sodium_crypto_box_seal_open')) {
  491. /**
  492. * @see ParagonIE_Sodium_Compat::crypto_box_seal_open()
  493. * @param string $message
  494. * @param string $kp
  495. * @return string|bool
  496. * @throws SodiumException
  497. */
  498. function sodium_crypto_box_seal_open($message, $kp)
  499. {
  500. try {
  501. return ParagonIE_Sodium_Compat::crypto_box_seal_open($message, $kp);
  502. } catch (SodiumException $ex) {
  503. if ($ex->getMessage() === 'Argument 2 must be CRYPTO_BOX_KEYPAIRBYTES long.') {
  504. throw $ex;
  505. }
  506. return false;
  507. }
  508. }
  509. }
  510. if (!is_callable('sodium_crypto_box_secretkey')) {
  511. /**
  512. * @see ParagonIE_Sodium_Compat::crypto_box_secretkey()
  513. * @param string $keypair
  514. * @return string
  515. * @throws SodiumException
  516. * @throws TypeError
  517. */
  518. function sodium_crypto_box_secretkey($keypair)
  519. {
  520. return ParagonIE_Sodium_Compat::crypto_box_secretkey($keypair);
  521. }
  522. }
  523. if (!is_callable('sodium_crypto_box_seed_keypair')) {
  524. /**
  525. * @see ParagonIE_Sodium_Compat::crypto_box_seed_keypair()
  526. * @param string $seed
  527. * @return string
  528. * @throws SodiumException
  529. * @throws TypeError
  530. */
  531. function sodium_crypto_box_seed_keypair($seed)
  532. {
  533. return ParagonIE_Sodium_Compat::crypto_box_seed_keypair($seed);
  534. }
  535. }
  536. if (!is_callable('sodium_crypto_generichash')) {
  537. /**
  538. * @see ParagonIE_Sodium_Compat::crypto_generichash()
  539. * @param string $message
  540. * @param string|null $key
  541. * @param int $outLen
  542. * @return string
  543. * @throws SodiumException
  544. * @throws TypeError
  545. */
  546. function sodium_crypto_generichash($message, $key = null, $outLen = 32)
  547. {
  548. return ParagonIE_Sodium_Compat::crypto_generichash($message, $key, $outLen);
  549. }
  550. }
  551. if (!is_callable('sodium_crypto_generichash_final')) {
  552. /**
  553. * @see ParagonIE_Sodium_Compat::crypto_generichash_final()
  554. * @param string|null $ctx
  555. * @param int $outputLength
  556. * @return string
  557. * @throws SodiumException
  558. * @throws TypeError
  559. */
  560. function sodium_crypto_generichash_final(&$ctx, $outputLength = 32)
  561. {
  562. return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx, $outputLength);
  563. }
  564. }
  565. if (!is_callable('sodium_crypto_generichash_init')) {
  566. /**
  567. * @see ParagonIE_Sodium_Compat::crypto_generichash_init()
  568. * @param string|null $key
  569. * @param int $outLen
  570. * @return string
  571. * @throws SodiumException
  572. * @throws TypeError
  573. */
  574. function sodium_crypto_generichash_init($key = null, $outLen = 32)
  575. {
  576. return ParagonIE_Sodium_Compat::crypto_generichash_init($key, $outLen);
  577. }
  578. }
  579. if (!is_callable('sodium_crypto_generichash_keygen')) {
  580. /**
  581. * @see ParagonIE_Sodium_Compat::crypto_generichash_keygen()
  582. * @return string
  583. * @throws Exception
  584. */
  585. function sodium_crypto_generichash_keygen()
  586. {
  587. return ParagonIE_Sodium_Compat::crypto_generichash_keygen();
  588. }
  589. }
  590. if (!is_callable('sodium_crypto_generichash_update')) {
  591. /**
  592. * @see ParagonIE_Sodium_Compat::crypto_generichash_update()
  593. * @param string|null $ctx
  594. * @param string $message
  595. * @return void
  596. * @throws SodiumException
  597. * @throws TypeError
  598. */
  599. function sodium_crypto_generichash_update(&$ctx, $message = '')
  600. {
  601. ParagonIE_Sodium_Compat::crypto_generichash_update($ctx, $message);
  602. }
  603. }
  604. if (!is_callable('sodium_crypto_kdf_keygen')) {
  605. /**
  606. * @see ParagonIE_Sodium_Compat::crypto_kdf_keygen()
  607. * @return string
  608. * @throws Exception
  609. */
  610. function sodium_crypto_kdf_keygen()
  611. {
  612. return ParagonIE_Sodium_Compat::crypto_kdf_keygen();
  613. }
  614. }
  615. if (!is_callable('sodium_crypto_kdf_derive_from_key')) {
  616. /**
  617. * @see ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key()
  618. * @param int $subkey_len
  619. * @param int $subkey_id
  620. * @param string $context
  621. * @param string $key
  622. * @return string
  623. * @throws Exception
  624. */
  625. function sodium_crypto_kdf_derive_from_key($subkey_len, $subkey_id, $context, $key)
  626. {
  627. return ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key(
  628. $subkey_len,
  629. $subkey_id,
  630. $context,
  631. $key
  632. );
  633. }
  634. }
  635. if (!is_callable('sodium_crypto_kx')) {
  636. /**
  637. * @see ParagonIE_Sodium_Compat::crypto_kx()
  638. * @param string $my_secret
  639. * @param string $their_public
  640. * @param string $client_public
  641. * @param string $server_public
  642. * @return string
  643. * @throws SodiumException
  644. * @throws TypeError
  645. */
  646. function sodium_crypto_kx($my_secret, $their_public, $client_public, $server_public)
  647. {
  648. return ParagonIE_Sodium_Compat::crypto_kx(
  649. $my_secret,
  650. $their_public,
  651. $client_public,
  652. $server_public
  653. );
  654. }
  655. }
  656. if (!is_callable('sodium_crypto_kx_seed_keypair')) {
  657. /**
  658. * @param string $seed
  659. * @return string
  660. * @throws Exception
  661. */
  662. function sodium_crypto_kx_seed_keypair($seed)
  663. {
  664. return ParagonIE_Sodium_Compat::crypto_kx_seed_keypair($seed);
  665. }
  666. }
  667. if (!is_callable('sodium_crypto_kx_keypair')) {
  668. /**
  669. * @return string
  670. * @throws Exception
  671. */
  672. function sodium_crypto_kx_keypair()
  673. {
  674. return ParagonIE_Sodium_Compat::crypto_kx_keypair();
  675. }
  676. }
  677. if (!is_callable('sodium_crypto_kx_client_session_keys')) {
  678. /**
  679. * @param string $keypair
  680. * @param string $serverPublicKey
  681. * @return array{0: string, 1: string}
  682. * @throws SodiumException
  683. */
  684. function sodium_crypto_kx_client_session_keys($keypair, $serverPublicKey)
  685. {
  686. return ParagonIE_Sodium_Compat::crypto_kx_client_session_keys($keypair, $serverPublicKey);
  687. }
  688. }
  689. if (!is_callable('sodium_crypto_kx_server_session_keys')) {
  690. /**
  691. * @param string $keypair
  692. * @param string $clientPublicKey
  693. * @return array{0: string, 1: string}
  694. * @throws SodiumException
  695. */
  696. function sodium_crypto_kx_server_session_keys($keypair, $clientPublicKey)
  697. {
  698. return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($keypair, $clientPublicKey);
  699. }
  700. }
  701. if (!is_callable('sodium_crypto_kx_secretkey')) {
  702. /**
  703. * @param string $keypair
  704. * @return string
  705. * @throws Exception
  706. */
  707. function sodium_crypto_kx_secretkey($keypair)
  708. {
  709. return ParagonIE_Sodium_Compat::crypto_kx_secretkey($keypair);
  710. }
  711. }
  712. if (!is_callable('sodium_crypto_kx_publickey')) {
  713. /**
  714. * @param string $keypair
  715. * @return string
  716. * @throws Exception
  717. */
  718. function sodium_crypto_kx_publickey($keypair)
  719. {
  720. return ParagonIE_Sodium_Compat::crypto_kx_publickey($keypair);
  721. }
  722. }
  723. if (!is_callable('sodium_crypto_pwhash')) {
  724. /**
  725. * @see ParagonIE_Sodium_Compat::crypto_pwhash()
  726. * @param int $outlen
  727. * @param string $passwd
  728. * @param string $salt
  729. * @param int $opslimit
  730. * @param int $memlimit
  731. * @param int|null $algo
  732. * @return string
  733. * @throws SodiumException
  734. * @throws TypeError
  735. */
  736. function sodium_crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo = null)
  737. {
  738. return ParagonIE_Sodium_Compat::crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $algo);
  739. }
  740. }
  741. if (!is_callable('sodium_crypto_pwhash_str')) {
  742. /**
  743. * @see ParagonIE_Sodium_Compat::crypto_pwhash_str()
  744. * @param string $passwd
  745. * @param int $opslimit
  746. * @param int $memlimit
  747. * @return string
  748. * @throws SodiumException
  749. * @throws TypeError
  750. */
  751. function sodium_crypto_pwhash_str($passwd, $opslimit, $memlimit)
  752. {
  753. return ParagonIE_Sodium_Compat::crypto_pwhash_str($passwd, $opslimit, $memlimit);
  754. }
  755. }
  756. if (!is_callable('sodium_crypto_pwhash_str_needs_rehash')) {
  757. /**
  758. * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash()
  759. * @param string $hash
  760. * @param int $opslimit
  761. * @param int $memlimit
  762. * @return bool
  763. *
  764. * @throws SodiumException
  765. */
  766. function sodium_crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit)
  767. {
  768. return ParagonIE_Sodium_Compat::crypto_pwhash_str_needs_rehash($hash, $opslimit, $memlimit);
  769. }
  770. }
  771. if (!is_callable('sodium_crypto_pwhash_str_verify')) {
  772. /**
  773. * @see ParagonIE_Sodium_Compat::crypto_pwhash_str_verify()
  774. * @param string $passwd
  775. * @param string $hash
  776. * @return bool
  777. * @throws SodiumException
  778. * @throws TypeError
  779. */
  780. function sodium_crypto_pwhash_str_verify($passwd, $hash)
  781. {
  782. return ParagonIE_Sodium_Compat::crypto_pwhash_str_verify($passwd, $hash);
  783. }
  784. }
  785. if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256')) {
  786. /**
  787. * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256()
  788. * @param int $outlen
  789. * @param string $passwd
  790. * @param string $salt
  791. * @param int $opslimit
  792. * @param int $memlimit
  793. * @return string
  794. * @throws SodiumException
  795. * @throws TypeError
  796. */
  797. function sodium_crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit)
  798. {
  799. return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit);
  800. }
  801. }
  802. if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str')) {
  803. /**
  804. * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str()
  805. * @param string $passwd
  806. * @param int $opslimit
  807. * @param int $memlimit
  808. * @return string
  809. * @throws SodiumException
  810. * @throws TypeError
  811. */
  812. function sodium_crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit)
  813. {
  814. return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit);
  815. }
  816. }
  817. if (!is_callable('sodium_crypto_pwhash_scryptsalsa208sha256_str_verify')) {
  818. /**
  819. * @see ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify()
  820. * @param string $passwd
  821. * @param string $hash
  822. * @return bool
  823. * @throws SodiumException
  824. * @throws TypeError
  825. */
  826. function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash)
  827. {
  828. return ParagonIE_Sodium_Compat::crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash);
  829. }
  830. }
  831. if (!is_callable('sodium_crypto_scalarmult')) {
  832. /**
  833. * @see ParagonIE_Sodium_Compat::crypto_scalarmult()
  834. * @param string $n
  835. * @param string $p
  836. * @return string
  837. * @throws SodiumException
  838. * @throws TypeError
  839. */
  840. function sodium_crypto_scalarmult($n, $p)
  841. {
  842. return ParagonIE_Sodium_Compat::crypto_scalarmult($n, $p);
  843. }
  844. }
  845. if (!is_callable('sodium_crypto_scalarmult_base')) {
  846. /**
  847. * @see ParagonIE_Sodium_Compat::crypto_scalarmult_base()
  848. * @param string $n
  849. * @return string
  850. * @throws SodiumException
  851. * @throws TypeError
  852. */
  853. function sodium_crypto_scalarmult_base($n)
  854. {
  855. return ParagonIE_Sodium_Compat::crypto_scalarmult_base($n);
  856. }
  857. }
  858. if (!is_callable('sodium_crypto_secretbox')) {
  859. /**
  860. * @see ParagonIE_Sodium_Compat::crypto_secretbox()
  861. * @param string $message
  862. * @param string $nonce
  863. * @param string $key
  864. * @return string
  865. * @throws SodiumException
  866. * @throws TypeError
  867. */
  868. function sodium_crypto_secretbox($message, $nonce, $key)
  869. {
  870. return ParagonIE_Sodium_Compat::crypto_secretbox($message, $nonce, $key);
  871. }
  872. }
  873. if (!is_callable('sodium_crypto_secretbox_keygen')) {
  874. /**
  875. * @see ParagonIE_Sodium_Compat::crypto_secretbox_keygen()
  876. * @return string
  877. * @throws Exception
  878. */
  879. function sodium_crypto_secretbox_keygen()
  880. {
  881. return ParagonIE_Sodium_Compat::crypto_secretbox_keygen();
  882. }
  883. }
  884. if (!is_callable('sodium_crypto_secretbox_open')) {
  885. /**
  886. * @see ParagonIE_Sodium_Compat::crypto_secretbox_open()
  887. * @param string $message
  888. * @param string $nonce
  889. * @param string $key
  890. * @return string|bool
  891. */
  892. function sodium_crypto_secretbox_open($message, $nonce, $key)
  893. {
  894. try {
  895. return ParagonIE_Sodium_Compat::crypto_secretbox_open($message, $nonce, $key);
  896. } catch (Error $ex) {
  897. return false;
  898. } catch (Exception $ex) {
  899. return false;
  900. }
  901. }
  902. }
  903. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_push')) {
  904. /**
  905. * @param string $key
  906. * @return array<int, string>
  907. * @throws SodiumException
  908. */
  909. function sodium_crypto_secretstream_xchacha20poly1305_init_push($key)
  910. {
  911. return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_push($key);
  912. }
  913. }
  914. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_push')) {
  915. /**
  916. * @param string $state
  917. * @param string $msg
  918. * @param string $aad
  919. * @param int $tag
  920. * @return string
  921. * @throws SodiumException
  922. */
  923. function sodium_crypto_secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0)
  924. {
  925. return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_push($state, $msg, $aad, $tag);
  926. }
  927. }
  928. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_init_pull')) {
  929. /**
  930. * @param string $header
  931. * @param string $key
  932. * @return string
  933. * @throws Exception
  934. */
  935. function sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $key)
  936. {
  937. return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_init_pull($header, $key);
  938. }
  939. }
  940. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_pull')) {
  941. /**
  942. * @param string $state
  943. * @param string $cipher
  944. * @param string $aad
  945. * @return bool|array{0: string, 1: int}
  946. * @throws SodiumException
  947. */
  948. function sodium_crypto_secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '')
  949. {
  950. return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_pull($state, $cipher, $aad);
  951. }
  952. }
  953. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_rekey')) {
  954. /**
  955. * @param string $state
  956. * @return void
  957. * @throws SodiumException
  958. */
  959. function sodium_crypto_secretstream_xchacha20poly1305_rekey(&$state)
  960. {
  961. ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_rekey($state);
  962. }
  963. }
  964. if (!is_callable('sodium_crypto_secretstream_xchacha20poly1305_keygen')) {
  965. /**
  966. * @return string
  967. * @throws Exception
  968. */
  969. function sodium_crypto_secretstream_xchacha20poly1305_keygen()
  970. {
  971. return ParagonIE_Sodium_Compat::crypto_secretstream_xchacha20poly1305_keygen();
  972. }
  973. }
  974. if (!is_callable('sodium_crypto_shorthash')) {
  975. /**
  976. * @see ParagonIE_Sodium_Compat::crypto_shorthash()
  977. * @param string $message
  978. * @param string $key
  979. * @return string
  980. * @throws SodiumException
  981. * @throws TypeError
  982. */
  983. function sodium_crypto_shorthash($message, $key = '')
  984. {
  985. return ParagonIE_Sodium_Compat::crypto_shorthash($message, $key);
  986. }
  987. }
  988. if (!is_callable('sodium_crypto_shorthash_keygen')) {
  989. /**
  990. * @see ParagonIE_Sodium_Compat::crypto_shorthash_keygen()
  991. * @return string
  992. * @throws Exception
  993. */
  994. function sodium_crypto_shorthash_keygen()
  995. {
  996. return ParagonIE_Sodium_Compat::crypto_shorthash_keygen();
  997. }
  998. }
  999. if (!is_callable('sodium_crypto_sign')) {
  1000. /**
  1001. * @see ParagonIE_Sodium_Compat::crypto_sign()
  1002. * @param string $message
  1003. * @param string $sk
  1004. * @return string
  1005. * @throws SodiumException
  1006. * @throws TypeError
  1007. */
  1008. function sodium_crypto_sign($message, $sk)
  1009. {
  1010. return ParagonIE_Sodium_Compat::crypto_sign($message, $sk);
  1011. }
  1012. }
  1013. if (!is_callable('sodium_crypto_sign_detached')) {
  1014. /**
  1015. * @see ParagonIE_Sodium_Compat::crypto_sign_detached()
  1016. * @param string $message
  1017. * @param string $sk
  1018. * @return string
  1019. * @throws SodiumException
  1020. * @throws TypeError
  1021. */
  1022. function sodium_crypto_sign_detached($message, $sk)
  1023. {
  1024. return ParagonIE_Sodium_Compat::crypto_sign_detached($message, $sk);
  1025. }
  1026. }
  1027. if (!is_callable('sodium_crypto_sign_keypair_from_secretkey_and_publickey')) {
  1028. /**
  1029. * @see ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey()
  1030. * @param string $sk
  1031. * @param string $pk
  1032. * @return string
  1033. * @throws SodiumException
  1034. * @throws TypeError
  1035. */
  1036. function sodium_crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk)
  1037. {
  1038. return ParagonIE_Sodium_Compat::crypto_sign_keypair_from_secretkey_and_publickey($sk, $pk);
  1039. }
  1040. }
  1041. if (!is_callable('sodium_crypto_sign_keypair')) {
  1042. /**
  1043. * @see ParagonIE_Sodium_Compat::crypto_sign_keypair()
  1044. * @return string
  1045. * @throws SodiumException
  1046. * @throws TypeError
  1047. */
  1048. function sodium_crypto_sign_keypair()
  1049. {
  1050. return ParagonIE_Sodium_Compat::crypto_sign_keypair();
  1051. }
  1052. }
  1053. if (!is_callable('sodium_crypto_sign_open')) {
  1054. /**
  1055. * @see ParagonIE_Sodium_Compat::crypto_sign_open()
  1056. * @param string $signedMessage
  1057. * @param string $pk
  1058. * @return string|bool
  1059. */
  1060. function sodium_crypto_sign_open($signedMessage, $pk)
  1061. {
  1062. try {
  1063. return ParagonIE_Sodium_Compat::crypto_sign_open($signedMessage, $pk);
  1064. } catch (Error $ex) {
  1065. return false;
  1066. } catch (Exception $ex) {
  1067. return false;
  1068. }
  1069. }
  1070. }
  1071. if (!is_callable('sodium_crypto_sign_publickey')) {
  1072. /**
  1073. * @see ParagonIE_Sodium_Compat::crypto_sign_publickey()
  1074. * @param string $keypair
  1075. * @return string
  1076. * @throws SodiumException
  1077. * @throws TypeError
  1078. */
  1079. function sodium_crypto_sign_publickey($keypair)
  1080. {
  1081. return ParagonIE_Sodium_Compat::crypto_sign_publickey($keypair);
  1082. }
  1083. }
  1084. if (!is_callable('sodium_crypto_sign_publickey_from_secretkey')) {
  1085. /**
  1086. * @see ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey()
  1087. * @param string $sk
  1088. * @return string
  1089. * @throws SodiumException
  1090. * @throws TypeError
  1091. */
  1092. function sodium_crypto_sign_publickey_from_secretkey($sk)
  1093. {
  1094. return ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($sk);
  1095. }
  1096. }
  1097. if (!is_callable('sodium_crypto_sign_secretkey')) {
  1098. /**
  1099. * @see ParagonIE_Sodium_Compat::crypto_sign_secretkey()
  1100. * @param string $keypair
  1101. * @return string
  1102. * @throws SodiumException
  1103. * @throws TypeError
  1104. */
  1105. function sodium_crypto_sign_secretkey($keypair)
  1106. {
  1107. return ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair);
  1108. }
  1109. }
  1110. if (!is_callable('sodium_crypto_sign_seed_keypair')) {
  1111. /**
  1112. * @see ParagonIE_Sodium_Compat::crypto_sign_seed_keypair()
  1113. * @param string $seed
  1114. * @return string
  1115. * @throws SodiumException
  1116. * @throws TypeError
  1117. */
  1118. function sodium_crypto_sign_seed_keypair($seed)
  1119. {
  1120. return ParagonIE_Sodium_Compat::crypto_sign_seed_keypair($seed);
  1121. }
  1122. }
  1123. if (!is_callable('sodium_crypto_sign_verify_detached')) {
  1124. /**
  1125. * @see ParagonIE_Sodium_Compat::crypto_sign_verify_detached()
  1126. * @param string $signature
  1127. * @param string $message
  1128. * @param string $pk
  1129. * @return bool
  1130. * @throws SodiumException
  1131. * @throws TypeError
  1132. */
  1133. function sodium_crypto_sign_verify_detached($signature, $message, $pk)
  1134. {
  1135. return ParagonIE_Sodium_Compat::crypto_sign_verify_detached($signature, $message, $pk);
  1136. }
  1137. }
  1138. if (!is_callable('sodium_crypto_sign_ed25519_pk_to_curve25519')) {
  1139. /**
  1140. * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519()
  1141. * @param string $pk
  1142. * @return string
  1143. * @throws SodiumException
  1144. * @throws TypeError
  1145. */
  1146. function sodium_crypto_sign_ed25519_pk_to_curve25519($pk)
  1147. {
  1148. return ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($pk);
  1149. }
  1150. }
  1151. if (!is_callable('sodium_crypto_sign_ed25519_sk_to_curve25519')) {
  1152. /**
  1153. * @see ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519()
  1154. * @param string $sk
  1155. * @return string
  1156. * @throws SodiumException
  1157. * @throws TypeError
  1158. */
  1159. function sodium_crypto_sign_ed25519_sk_to_curve25519($sk)
  1160. {
  1161. return ParagonIE_Sodium_Compat::crypto_sign_ed25519_sk_to_curve25519($sk);
  1162. }
  1163. }
  1164. if (!is_callable('sodium_crypto_stream')) {
  1165. /**
  1166. * @see ParagonIE_Sodium_Compat::crypto_stream()
  1167. * @param int $len
  1168. * @param string $nonce
  1169. * @param string $key
  1170. * @return string
  1171. * @throws SodiumException
  1172. * @throws TypeError
  1173. */
  1174. function sodium_crypto_stream($len, $nonce, $key)
  1175. {
  1176. return ParagonIE_Sodium_Compat::crypto_stream($len, $nonce, $key);
  1177. }
  1178. }
  1179. if (!is_callable('sodium_crypto_stream_keygen')) {
  1180. /**
  1181. * @see ParagonIE_Sodium_Compat::crypto_stream_keygen()
  1182. * @return string
  1183. * @throws Exception
  1184. */
  1185. function sodium_crypto_stream_keygen()
  1186. {
  1187. return ParagonIE_Sodium_Compat::crypto_stream_keygen();
  1188. }
  1189. }
  1190. if (!is_callable('sodium_crypto_stream_xor')) {
  1191. /**
  1192. * @see ParagonIE_Sodium_Compat::crypto_stream_xor()
  1193. * @param string $message
  1194. * @param string $nonce
  1195. * @param string $key
  1196. * @return string
  1197. * @throws SodiumException
  1198. * @throws TypeError
  1199. */
  1200. function sodium_crypto_stream_xor($message, $nonce, $key)
  1201. {
  1202. return ParagonIE_Sodium_Compat::crypto_stream_xor($message, $nonce, $key);
  1203. }
  1204. }
  1205. if (!is_callable('sodium_hex2bin')) {
  1206. /**
  1207. * @see ParagonIE_Sodium_Compat::hex2bin()
  1208. * @param string $string
  1209. * @return string
  1210. * @throws SodiumException
  1211. * @throws TypeError
  1212. */
  1213. function sodium_hex2bin($string)
  1214. {
  1215. return ParagonIE_Sodium_Compat::hex2bin($string);
  1216. }
  1217. }
  1218. if (!is_callable('sodium_increment')) {
  1219. /**
  1220. * @see ParagonIE_Sodium_Compat::increment()
  1221. * @param string $string
  1222. * @return void
  1223. * @throws SodiumException
  1224. * @throws TypeError
  1225. */
  1226. function sodium_increment(&$string)
  1227. {
  1228. ParagonIE_Sodium_Compat::increment($string);
  1229. }
  1230. }
  1231. if (!is_callable('sodium_library_version_major')) {
  1232. /**
  1233. * @see ParagonIE_Sodium_Compat::library_version_major()
  1234. * @return int
  1235. */
  1236. function sodium_library_version_major()
  1237. {
  1238. return ParagonIE_Sodium_Compat::library_version_major();
  1239. }
  1240. }
  1241. if (!is_callable('sodium_library_version_minor')) {
  1242. /**
  1243. * @see ParagonIE_Sodium_Compat::library_version_minor()
  1244. * @return int
  1245. */
  1246. function sodium_library_version_minor()
  1247. {
  1248. return ParagonIE_Sodium_Compat::library_version_minor();
  1249. }
  1250. }
  1251. if (!is_callable('sodium_version_string')) {
  1252. /**
  1253. * @see ParagonIE_Sodium_Compat::version_string()
  1254. * @return string
  1255. */
  1256. function sodium_version_string()
  1257. {
  1258. return ParagonIE_Sodium_Compat::version_string();
  1259. }
  1260. }
  1261. if (!is_callable('sodium_memcmp')) {
  1262. /**
  1263. * @see ParagonIE_Sodium_Compat::memcmp()
  1264. * @param string $a
  1265. * @param string $b
  1266. * @return int
  1267. * @throws SodiumException
  1268. * @throws TypeError
  1269. */
  1270. function sodium_memcmp($a, $b)
  1271. {
  1272. return ParagonIE_Sodium_Compat::memcmp($a, $b);
  1273. }
  1274. }
  1275. if (!is_callable('sodium_memzero')) {
  1276. /**
  1277. * @see ParagonIE_Sodium_Compat::memzero()
  1278. * @param string $str
  1279. * @return void
  1280. * @throws SodiumException
  1281. * @throws TypeError
  1282. */
  1283. function sodium_memzero(&$str)
  1284. {
  1285. ParagonIE_Sodium_Compat::memzero($str);
  1286. }
  1287. }
  1288. if (!is_callable('sodium_pad')) {
  1289. /**
  1290. * @see ParagonIE_Sodium_Compat::pad()
  1291. * @param string $unpadded
  1292. * @param int $blockSize
  1293. * @return int
  1294. * @throws SodiumException
  1295. * @throws TypeError
  1296. */
  1297. function sodium_pad($unpadded, $blockSize)
  1298. {
  1299. return ParagonIE_Sodium_Compat::pad($unpadded, $blockSize, true);
  1300. }
  1301. }
  1302. if (!is_callable('sodium_unpad')) {
  1303. /**
  1304. * @see ParagonIE_Sodium_Compat::pad()
  1305. * @param string $padded
  1306. * @param int $blockSize
  1307. * @return int
  1308. * @throws SodiumException
  1309. * @throws TypeError
  1310. */
  1311. function sodium_unpad($padded, $blockSize)
  1312. {
  1313. return ParagonIE_Sodium_Compat::unpad($padded, $blockSize, true);
  1314. }
  1315. }
  1316. if (!is_callable('sodium_randombytes_buf')) {
  1317. /**
  1318. * @see ParagonIE_Sodium_Compat::randombytes_buf()
  1319. * @param int $amount
  1320. * @return string
  1321. * @throws Exception
  1322. */
  1323. function sodium_randombytes_buf($amount)
  1324. {
  1325. return ParagonIE_Sodium_Compat::randombytes_buf($amount);
  1326. }
  1327. }
  1328. if (!is_callable('sodium_randombytes_uniform')) {
  1329. /**
  1330. * @see ParagonIE_Sodium_Compat::randombytes_uniform()
  1331. * @param int $upperLimit
  1332. * @return int
  1333. * @throws Exception
  1334. */
  1335. function sodium_randombytes_uniform($upperLimit)
  1336. {
  1337. return ParagonIE_Sodium_Compat::randombytes_uniform($upperLimit);
  1338. }
  1339. }
  1340. if (!is_callable('sodium_randombytes_random16')) {
  1341. /**
  1342. * @see ParagonIE_Sodium_Compat::randombytes_random16()
  1343. * @return int
  1344. * @throws Exception
  1345. */
  1346. function sodium_randombytes_random16()
  1347. {
  1348. return ParagonIE_Sodium_Compat::randombytes_random16();
  1349. }
  1350. }