提交 a27cb956 编写于 作者: D Dr. Matthias St. Pierre

Fix: uninstantiation breaks the RAND_DRBG callback mechanism

The RAND_DRBG callbacks are wrappers around the EVP_RAND callbacks.
During uninstantiation, the EVP_RAND callbacks got lost while the
RAND_DRBG callbacks remained, because RAND_DRBG_uninstantiate()
calls RAND_DRBG_set(), which recreates the EVP_RAND object.
This was causing drbgtest failures.

This commit fixes the problem by adding code to RAND_DRBG_set() for
saving and restoring the EVP_RAND callbacks.
Reviewed-by: NPaul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/11195)
上级 d1768e82
...@@ -296,6 +296,11 @@ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags) ...@@ -296,6 +296,11 @@ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags)
EVP_RAND_CTX *pctx; EVP_RAND_CTX *pctx;
int use_df; int use_df;
RAND_DRBG_get_entropy_fn get_entropy = drbg->get_entropy;
RAND_DRBG_cleanup_entropy_fn cleanup_entropy = drbg->cleanup_entropy;
RAND_DRBG_get_nonce_fn get_nonce = drbg->get_nonce;
RAND_DRBG_cleanup_nonce_fn cleanup_nonce = drbg->cleanup_nonce;
if (type == 0 && flags == 0) { if (type == 0 && flags == 0) {
type = rand_drbg_type[RAND_DRBG_TYPE_PRIMARY]; type = rand_drbg_type[RAND_DRBG_TYPE_PRIMARY];
flags = rand_drbg_flags[RAND_DRBG_TYPE_PRIMARY]; flags = rand_drbg_flags[RAND_DRBG_TYPE_PRIMARY];
...@@ -344,6 +349,14 @@ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags) ...@@ -344,6 +349,14 @@ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags)
RANDerr(0, RAND_R_ERROR_INITIALISING_DRBG); RANDerr(0, RAND_R_ERROR_INITIALISING_DRBG);
goto err; goto err;
} }
if (!RAND_DRBG_set_callbacks(drbg,
get_entropy, cleanup_entropy,
get_nonce, cleanup_nonce)) {
RANDerr(0, RAND_R_ERROR_INITIALISING_DRBG);
goto err;
}
return 1; return 1;
err: err:
EVP_RAND_CTX_free(drbg->rand); EVP_RAND_CTX_free(drbg->rand);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册