No Description

php72compat.php 41KB

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