Brak opisu

php72compat.php 41KB

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