prrng.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. ** prrng.h -- NSPR Random Number Generator
  7. **
  8. **
  9. ** lth. 29-Oct-1999.
  10. */
  11. #ifndef prrng_h___
  12. #define prrng_h___
  13. #include "prtypes.h"
  14. PR_BEGIN_EXTERN_C
  15. /*
  16. ** PR_GetRandomNoise() -- Get random noise from the host platform
  17. **
  18. ** Description:
  19. ** PR_GetRandomNoise() provides, depending on platform, a random value.
  20. ** The length of the random value is dependent on platform and the
  21. ** platform's ability to provide a random value at that moment.
  22. **
  23. ** The intent of PR_GetRandomNoise() is to provide a "seed" value for a
  24. ** another random number generator that may be suitable for
  25. ** cryptographic operations. This implies that the random value
  26. ** provided may not be, by itself, cryptographically secure. The value
  27. ** generated by PR_GetRandomNoise() is at best, extremely difficult to
  28. ** predict and is as non-deterministic as the underlying platfrom can
  29. ** provide.
  30. **
  31. ** Inputs:
  32. ** buf -- pointer to a caller supplied buffer to contain the
  33. ** generated random number. buf must be at least as large as
  34. ** is specified in the 'size' argument.
  35. **
  36. ** size -- the requested size of the generated random number
  37. **
  38. ** Outputs:
  39. ** a random number provided in 'buf'.
  40. **
  41. ** Returns:
  42. ** PRSize value equal to the size of the random number actually
  43. ** generated, or zero. The generated size may be less than the size
  44. ** requested. A return value of zero means that PR_GetRandomNoise() is
  45. ** not implemented on this platform, or there is no available noise
  46. ** available to be returned at the time of the call.
  47. **
  48. ** Restrictions:
  49. ** Calls to PR_GetRandomNoise() may use a lot of CPU on some platforms.
  50. ** Some platforms may block for up to a few seconds while they
  51. ** accumulate some noise. Busy machines generate lots of noise, but
  52. ** care is advised when using PR_GetRandomNoise() frequently in your
  53. ** application.
  54. **
  55. ** History:
  56. ** Parts of the model dependent implementation for PR_GetRandomNoise()
  57. ** were taken in whole or part from code previously in Netscape's NSS
  58. ** component.
  59. **
  60. */
  61. NSPR_API(PRSize) PR_GetRandomNoise(
  62. void *buf,
  63. PRSize size
  64. );
  65. PR_END_EXTERN_C
  66. #endif /* prrng_h___ */
  67. /* end prrng.h */