ossl_rand_get_entropy.pod 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. =pod
  2. =head1 NAME
  3. ossl_rand_get_entropy, ossl_rand_get_user_entropy, ossl_rand_cleanup_entropy,
  4. ossl_rand_get_nonce, ossl_rand_get_user_nonce, ossl_rand_cleanup_nonce
  5. - get seed material from the operating system
  6. =head1 SYNOPSIS
  7. #include "crypto/rand.h"
  8. size_t ossl_rand_get_entropy(OSSL_CORE_HANDLE *handle,
  9. unsigned char **pout, int entropy,
  10. size_t min_len, size_t max_len);
  11. size_t ossl_rand_get_user_entropy(OSSL_CORE_HANDLE *handle,
  12. unsigned char **pout, int entropy,
  13. size_t min_len, size_t max_len);
  14. void ossl_rand_cleanup_entropy(OSSL_CORE_HANDLE *handle,
  15. unsigned char *buf, size_t len);
  16. size_t ossl_rand_get_nonce(OSSL_CORE_HANDLE *handle,
  17. unsigned char **pout, size_t min_len,
  18. size_t max_len, const void *salt, size_t salt_len);
  19. size_t ossl_rand_get_user_nonce(OSSL_CORE_HANDLE *handle, unsigned char **pout,
  20. size_t min_len, size_t max_len,
  21. const void *salt, size_t salt_len);
  22. void ossl_rand_cleanup_nonce(OSSL_CORE_HANDLE *handle,
  23. unsigned char *buf, size_t len);
  24. =head1 DESCRIPTION
  25. ossl_rand_get_entropy() retrieves seeding material from the operating system.
  26. The seeding material will have at least I<entropy> bytes of randomness and is
  27. stored in a buffer which contains at least I<min_len> and at most I<max_len>
  28. bytes. The buffer address is stored in I<*pout> and the buffer length is
  29. returned to the caller.
  30. ossl_rand_get_user_entropy() is the same as ossl_rand_get_entropy()
  31. except that it retrieves the seeding material from the library context's
  32. DRBG seed source. By default this is the operating system but it can
  33. be changed by calling L<RAND_set_seed_source_type(3)>.
  34. ossl_rand_cleanup_entropy() cleanses and frees any storage allocated by
  35. ossl_rand_get_entropy() or ossl_rand_get_user_entropy(). The entropy
  36. buffer is pointed to by I<buf> and is of length I<len> bytes.
  37. ossl_rand_get_nonce() retrieves a nonce using the passed I<salt> parameter
  38. of length I<salt_len> and operating system specific information.
  39. The I<salt> should contain uniquely identifying information and this is
  40. included, in an unspecified manner, as part of the output.
  41. The output is stored in a buffer which contains at least I<min_len> and at
  42. most I<max_len> bytes. The buffer address is stored in I<*pout> and the
  43. buffer length returned to the caller.
  44. ossl_rand_get_user_nonce() is the same as ossl_rand_get_nonce() except
  45. that it retrieves the seeding material from the library context's DRBG
  46. seed source. By default this is the operating system but it can be
  47. changed by calling L<RAND_set_seed_source_type(3)>.
  48. ossl_rand_cleanup_nonce() cleanses and frees any storage allocated by
  49. ossl_rand_get_nonce() or ossl_rand_get_user_nonce(). The nonce buffer
  50. is pointed to by I<buf> and is of length I<len> bytes.
  51. =head1 NOTES
  52. FIPS providers 3.0.0, 3.0.8 and 3.0.9 incorrectly pass a provider
  53. internal pointer to ossl_rand_get_entropy(), ossl_rand_cleanup_entropy(),
  54. ossl_rand_get_nonce() and ossl_rand_cleanup_nonce(). This pointer cannot
  55. be safely dereferenced.
  56. =head1 RETURN VALUES
  57. ossl_rand_get_entropy(), ossl_rand_get_user_entropy(),
  58. ossl_rand_get_nonce() and ossl_rand_get_user_nonce() return the number
  59. of bytes in I<*pout> or 0 on error.
  60. =head1 HISTORY
  61. The functions ossl_rand_get_user_entropy() and ossl_rand_get_user_nonce()
  62. were added in OpenSSL 3.0.12, 3.1.4 and 3.2.0.
  63. The remaining functions described here were all added in OpenSSL 3.0.
  64. =head1 COPYRIGHT
  65. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  66. Licensed under the Apache License 2.0 (the "License"). You may not use
  67. this file except in compliance with the License. You can obtain a copy
  68. in the file LICENSE in the source distribution or at
  69. L<https://www.openssl.org/source/license.html>.
  70. =cut