libsodium.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * This does nothing if the libsodium extension is loaded, so it's harmless.
  4. *
  5. * This file alone is released under CC0 and WTFPL dual licensing.
  6. */
  7. namespace Sodium {
  8. if (!extension_loaded('libsodium')) {
  9. /**
  10. * Generate a string of random bytes
  11. * /dev/urandom
  12. *
  13. * @param int $length
  14. * @return string
  15. */
  16. function randombytes_buf(
  17. $length
  18. )
  19. {
  20. return '';
  21. }
  22. /**
  23. * Generate a 16-bit integer
  24. * /dev/urandom
  25. *
  26. * @return int
  27. */
  28. function randombytes_random16()
  29. {
  30. return '';
  31. }
  32. /**
  33. * Generate an unbiased random integer between 0 and a specified value
  34. * /dev/urandom
  35. *
  36. * @param int $upperBoundNonInclusive
  37. * @return int
  38. */
  39. function randombytes_uniform(
  40. $upperBoundNonInclusive
  41. )
  42. {
  43. return 0;
  44. }
  45. }
  46. }
  47. namespace {
  48. class Sodium
  49. {
  50. /**
  51. * Generate a string of random bytes
  52. * /dev/urandom
  53. *
  54. * @param int $length
  55. * @return string
  56. */
  57. public static function randombytes_buf($length)
  58. {
  59. return '';
  60. }
  61. /**
  62. * Generate a 16-bit integer
  63. * /dev/urandom
  64. *
  65. * @return int
  66. */
  67. public static function randombytes_random16()
  68. {
  69. return '';
  70. }
  71. /**
  72. * Generate an unbiased random integer between 0 and a specified value
  73. * /dev/urandom
  74. *
  75. * @param int $upperBoundNonInclusive
  76. * @return int
  77. */
  78. public static function randombytes_uniform($upperBoundNonInclusive = 0)
  79. {
  80. return 0;
  81. }
  82. }
  83. }