RAND_bytes.pod 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. =pod
  2. =head1 NAME
  3. RAND_bytes, RAND_priv_bytes, RAND_pseudo_bytes - generate random data
  4. =head1 SYNOPSIS
  5. #include <openssl/rand.h>
  6. int RAND_bytes(unsigned char *buf, int num);
  7. int RAND_priv_bytes(unsigned char *buf, int num);
  8. Deprecated:
  9. #if OPENSSL_API_COMPAT < 0x10100000L
  10. int RAND_pseudo_bytes(unsigned char *buf, int num);
  11. #endif
  12. =head1 DESCRIPTION
  13. RAND_bytes() generates B<num> random bytes using a cryptographically
  14. secure pseudo random generator (CSPRNG) and stores them in B<buf>.
  15. RAND_priv_bytes() has the same semantics as RAND_bytes(). It is intended to
  16. be used for generating values that should remain private. If using the
  17. default RAND_METHOD, this function uses a separate "private" PRNG
  18. instance so that a compromise of the "public" PRNG instance will not
  19. affect the secrecy of these private values, as described in L<RAND(7)>
  20. and L<RAND_DRBG(7)>.
  21. =head1 NOTES
  22. By default, the OpenSSL CSPRNG supports a security level of 256 bits, provided it
  23. was able to seed itself from a trusted entropy source.
  24. On all major platforms supported by OpenSSL (including the Unix-like platforms
  25. and Windows), OpenSSL is configured to automatically seed the CSPRNG on first use
  26. using the operating systems's random generator.
  27. If the entropy source fails or is not available, the CSPRNG will enter an
  28. error state and refuse to generate random bytes. For that reason, it is important
  29. to always check the error return value of RAND_bytes() and RAND_priv_bytes() and
  30. not take randomness for granted.
  31. On other platforms, there might not be a trusted entropy source available
  32. or OpenSSL might have been explicitly configured to use different entropy sources.
  33. If you are in doubt about the quality of the entropy source, don't hesitate to ask
  34. your operating system vendor or post a question on GitHub or the openssl-users
  35. mailing list.
  36. =head1 RETURN VALUES
  37. RAND_bytes() and RAND_priv_bytes()
  38. return 1 on success, -1 if not supported by the current
  39. RAND method, or 0 on other failure. The error code can be
  40. obtained by L<ERR_get_error(3)>.
  41. =head1 SEE ALSO
  42. L<RAND_add(3)>,
  43. L<RAND_bytes(3)>,
  44. L<RAND_priv_bytes(3)>,
  45. L<ERR_get_error(3)>,
  46. L<RAND(7)>,
  47. L<RAND_DRBG(7)>
  48. =head1 HISTORY
  49. =over 2
  50. =item *
  51. RAND_pseudo_bytes() was deprecated in OpenSSL 1.1.0; use RAND_bytes() instead.
  52. =item *
  53. The RAND_priv_bytes() function was added in OpenSSL 1.1.1.
  54. =back
  55. =head1 COPYRIGHT
  56. Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
  57. Licensed under the OpenSSL license (the "License"). You may not use
  58. this file except in compliance with the License. You can obtain a copy
  59. in the file LICENSE in the source distribution or at
  60. L<https://www.openssl.org/source/license.html>.
  61. =cut