ossl_rand_get_entropy.pod 4.5 KB

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