diff options
author | Matthias St. Pierre <matthias.st.pierre@ncp-e.com> | 2023-10-16 01:35:48 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-10-24 11:14:11 +0100 |
commit | 7998e7dc07d8f1f516af32887f2490c03cd8c594 (patch) | |
tree | 47fb9ebc7a356181874d8423dda1c4643d6c78ce /include | |
parent | 0a8faac3c7cc2e88f46a8bdce5bd039dc22abdec (diff) |
rand: fix seeding from a weak entropy source
The 'rand_generate' method is not well suited for being used with
weak entropy sources in the 'get_entropy' callback, because the
caller needs to provide a preallocated buffer without knowing
how much bytes are actually needed to collect the required entropy.
Instead we use the 'rand_get_seed' and 'rand_clear_seed' methods
which were exactly designed for this purpose: it's the callee who
allocates and fills the buffer, and finally cleans it up again.
The 'rand_get_seed' and 'rand_clear_seed' methods are currently
optional for a provided random generator. We could fall back to
using 'rand_generate' if those methods are not implemented.
However, imo it would be better to simply make them an officially
documented requirement for seed sources.
Fixes #22332
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22394)
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/evp.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/crypto/evp.h b/include/crypto/evp.h index 473b95514a..34cea2f9f4 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -953,6 +953,14 @@ int evp_keymgmt_get_number(const EVP_KEYMGMT *keymgmt); int evp_mac_get_number(const EVP_MAC *mac); int evp_md_get_number(const EVP_MD *md); int evp_rand_get_number(const EVP_RAND *rand); +int evp_rand_can_seed(EVP_RAND_CTX *ctx); +size_t evp_rand_get_seed(EVP_RAND_CTX *ctx, + unsigned char **buffer, + int entropy, size_t min_len, size_t max_len, + int prediction_resistance, + const unsigned char *adin, size_t adin_len); +void evp_rand_clear_seed(EVP_RAND_CTX *ctx, + unsigned char *buffer, size_t b_len); int evp_signature_get_number(const EVP_SIGNATURE *signature); int evp_pkey_decrypt_alloc(EVP_PKEY_CTX *ctx, unsigned char **outp, |