RAND_DRBG_set_callbacks.pod 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. =pod
  2. =head1 NAME
  3. RAND_DRBG_set_callbacks,
  4. RAND_DRBG_get_entropy_fn,
  5. RAND_DRBG_cleanup_entropy_fn,
  6. RAND_DRBG_get_nonce_fn,
  7. RAND_DRBG_cleanup_nonce_fn
  8. - set callbacks for reseeding
  9. =head1 SYNOPSIS
  10. #include <openssl/rand_drbg.h>
  11. int RAND_DRBG_set_callbacks(RAND_DRBG *drbg,
  12. RAND_DRBG_get_entropy_fn get_entropy,
  13. RAND_DRBG_cleanup_entropy_fn cleanup_entropy,
  14. RAND_DRBG_get_nonce_fn get_nonce,
  15. RAND_DRBG_cleanup_nonce_fn cleanup_nonce);
  16. =head2 Callback Functions
  17. typedef size_t (*RAND_DRBG_get_entropy_fn)(
  18. RAND_DRBG *drbg,
  19. unsigned char **pout,
  20. int entropy,
  21. size_t min_len, size_t max_len,
  22. int prediction_resistance);
  23. typedef void (*RAND_DRBG_cleanup_entropy_fn)(
  24. RAND_DRBG *drbg,
  25. unsigned char *out, size_t outlen);
  26. typedef size_t (*RAND_DRBG_get_nonce_fn)(
  27. RAND_DRBG *drbg,
  28. unsigned char **pout,
  29. int entropy,
  30. size_t min_len, size_t max_len);
  31. typedef void (*RAND_DRBG_cleanup_nonce_fn)(
  32. RAND_DRBG *drbg,
  33. unsigned char *out, size_t outlen);
  34. =head1 DESCRIPTION
  35. RAND_DRBG_set_callbacks() sets the callbacks for obtaining fresh entropy and
  36. the nonce when reseeding the given B<drbg>.
  37. The callback functions are implemented and provided by the caller.
  38. Their parameter lists need to match the function prototypes above.
  39. Setting the callbacks is allowed only if the DRBG has not been initialized yet.
  40. Otherwise, the operation will fail.
  41. To change the settings for one of the three shared DRBGs it is necessary to call
  42. RAND_DRBG_uninstantiate() first.
  43. The B<get_entropy>() callback is called by the B<drbg> when it requests fresh
  44. random input.
  45. It is expected that the callback allocates and fills a random buffer of size
  46. B<min_len> <= size <= B<max_len> (in bytes) which contains at least B<entropy>
  47. bits of randomness.
  48. The B<prediction_resistance> flag indicates whether the reseeding was
  49. triggered by a prediction resistance request.
  50. The buffer's address is to be returned in *B<pout> and the number of collected
  51. randomness bytes as return value.
  52. If the callback fails to acquire at least B<entropy> bits of randomness,
  53. it must indicate an error by returning a buffer length of 0.
  54. If B<prediction_resistance> was requested and the random source of the DRBG
  55. does not satisfy the conditions requested by [NIST SP 800-90C], then
  56. it must also indicate an error by returning a buffer length of 0.
  57. See NOTES section for more details.
  58. The B<cleanup_entropy>() callback is called from the B<drbg> to to clear and
  59. free the buffer allocated previously by get_entropy().
  60. The values B<out> and B<outlen> are the random buffer's address and length,
  61. as returned by the get_entropy() callback.
  62. The B<get_nonce>() and B<cleanup_nonce>() callbacks are used to obtain a nonce
  63. and free it again. A nonce is only required for instantiation (not for reseeding)
  64. and only in the case where the DRBG uses a derivation function.
  65. The callbacks are analogous to get_entropy() and cleanup_entropy(),
  66. except for the missing prediction_resistance flag.
  67. If the derivation function is disabled, then no nonce is used for instantiation,
  68. and the B<get_nonce>() and B<cleanup_nonce>() callbacks can be omitted by
  69. setting them to NULL.
  70. =head1 RETURN VALUES
  71. RAND_DRBG_set_callbacks() return 1 on success, and 0 on failure
  72. =head1 NOTES
  73. It is important that B<cleanup_entropy>() and B<cleanup_nonce>() clear the buffer
  74. contents safely before freeing it, in order not to leave sensitive information
  75. about the DRBG's state in memory.
  76. A request for prediction resistance can only be satisfied by pulling fresh
  77. entropy from one of the approved entropy sources listed in section 5.5.2 of
  78. [NIST SP 800-90C].
  79. Since the default implementation of the get_entropy callback does not have access
  80. to such an approved entropy source, a request for prediction resistance will
  81. always fail.
  82. In other words, prediction resistance is currently not supported yet by the DRBG.
  83. The derivation function is disabled during initialization by calling the
  84. RAND_DRBG_set() function with the RAND_DRBG_FLAG_CTR_NO_DF flag.
  85. For more information on the derivation function and when it can be omitted,
  86. see [NIST SP 800-90A Rev. 1]. Roughly speeking it can be omitted if the random
  87. source has "full entropy", i.e., contains 8 bits of entropy per byte.
  88. Even if a nonce is required, the B<get_nonce>() and B<cleanup_nonce>()
  89. callbacks can be omitted by setting them to NULL.
  90. In this case the DRBG will automatically request an extra amount of entropy
  91. (using the B<get_entropy>() and B<cleanup_entropy>() callbacks) which it will
  92. utilize for the nonce, following the recommendations of [NIST SP 800-90A Rev. 1],
  93. section 8.6.7.
  94. =head1 HISTORY
  95. The RAND_DRBG functions were added in OpenSSL 1.1.1.
  96. =head1 SEE ALSO
  97. L<RAND_DRBG_new(3)>,
  98. L<RAND_DRBG_reseed(3)>,
  99. L<RAND_DRBG(7)>
  100. =head1 COPYRIGHT
  101. Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
  102. Licensed under the OpenSSL license (the "License"). You may not use
  103. this file except in compliance with the License. You can obtain a copy
  104. in the file LICENSE in the source distribution or at
  105. L<https://www.openssl.org/source/license.html>.
  106. =cut