選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

rand.h 3.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (c) 2014, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_RAND_H
  15. #define OPENSSL_HEADER_RAND_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. /* Random number generation. */
  21. /* RAND_bytes writes |len| bytes of random data to |buf| and returns one. */
  22. OPENSSL_EXPORT int RAND_bytes(uint8_t *buf, size_t len);
  23. /* RAND_cleanup frees any resources used by the RNG. This is not safe if other
  24. * threads might still be calling |RAND_bytes|. */
  25. OPENSSL_EXPORT void RAND_cleanup(void);
  26. /* Obscure functions. */
  27. #if !defined(OPENSSL_WINDOWS)
  28. /* RAND_set_urandom_fd causes the module to use a copy of |fd| for system
  29. * randomness rather opening /dev/urandom internally. The caller retains
  30. * ownership of |fd| and is at liberty to close it at any time. This is useful
  31. * if, due to a sandbox, /dev/urandom isn't available. If used, it must be
  32. * called before |RAND_bytes| is called in the current address space.
  33. *
  34. * |RAND_set_urandom_fd| does not buffer any entropy, so it is safe to call
  35. * |fork| between |RAND_set_urandom_fd| and the first call to |RAND_bytes|. */
  36. OPENSSL_EXPORT void RAND_set_urandom_fd(int fd);
  37. #endif
  38. /* Deprecated functions */
  39. /* RAND_pseudo_bytes is a wrapper around |RAND_bytes|. */
  40. OPENSSL_EXPORT int RAND_pseudo_bytes(uint8_t *buf, size_t len);
  41. /* RAND_seed does nothing. */
  42. OPENSSL_EXPORT void RAND_seed(const void *buf, int num);
  43. /* RAND_load_file returns a nonnegative number. */
  44. OPENSSL_EXPORT int RAND_load_file(const char *path, long num);
  45. /* RAND_add does nothing. */
  46. OPENSSL_EXPORT void RAND_add(const void *buf, int num, double entropy);
  47. /* RAND_egd returns 255. */
  48. OPENSSL_EXPORT int RAND_egd(const char *);
  49. /* RAND_poll returns one. */
  50. OPENSSL_EXPORT int RAND_poll(void);
  51. /* RAND_status returns one. */
  52. OPENSSL_EXPORT int RAND_status(void);
  53. /* rand_meth_st is typedefed to |RAND_METHOD| in base.h. It isn't used; it
  54. * exists only to be the return type of |RAND_SSLeay|. It's
  55. * external so that variables of this type can be initialized. */
  56. struct rand_meth_st {
  57. void (*seed) (const void *buf, int num);
  58. int (*bytes) (unsigned char *buf, int num);
  59. void (*cleanup) (void);
  60. void (*add) (const void *buf, int num, double entropy);
  61. int (*pseudorand) (unsigned char *buf, int num);
  62. int (*status) (void);
  63. };
  64. /* RAND_SSLeay returns a pointer to a dummy |RAND_METHOD|. */
  65. OPENSSL_EXPORT RAND_METHOD *RAND_SSLeay(void);
  66. /* RAND_set_rand_method does nothing. */
  67. OPENSSL_EXPORT void RAND_set_rand_method(const RAND_METHOD *);
  68. #if defined(__cplusplus)
  69. } /* extern C */
  70. #endif
  71. #endif /* OPENSSL_HEADER_RAND_H */