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

Use RAND_DRBG_bytes() for RAND_bytes() and RAND_priv_bytes()

The functions RAND_bytes() and RAND_priv_bytes() are now both based
on a common implementation using RAND_DRBG_bytes() (if the default
OpenSSL rand method is active). This not only simplifies the code
but also has the advantage that additional input from a high precision
timer is added on every generate call if the timer is available.
Reviewed-by: NKurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/5251)
上级 1648338b
......@@ -776,26 +776,16 @@ void rand_drbg_cleanup_int(void)
/* Implements the default OpenSSL RAND_bytes() method */
static int drbg_bytes(unsigned char *out, int count)
{
int ret = 0;
size_t chunk;
int ret;
RAND_DRBG *drbg = RAND_DRBG_get0_public();
if (drbg == NULL)
return 0;
CRYPTO_THREAD_write_lock(drbg->lock);
for ( ; count > 0; count -= chunk, out += chunk) {
chunk = count;
if (chunk > drbg->max_request)
chunk = drbg->max_request;
ret = RAND_DRBG_generate(drbg, out, chunk, 0, NULL, 0);
if (!ret)
goto err;
}
ret = 1;
err:
ret = RAND_DRBG_bytes(drbg, out, count);
CRYPTO_THREAD_unlock(drbg->lock);
return ret;
}
......
/*
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
......@@ -719,7 +719,7 @@ int RAND_priv_bytes(unsigned char *buf, int num)
/* We have to lock the DRBG before generating bits from it. */
CRYPTO_THREAD_write_lock(drbg->lock);
ret = RAND_DRBG_generate(drbg, buf, num, 0, NULL, 0);
ret = RAND_DRBG_bytes(drbg, buf, num);
CRYPTO_THREAD_unlock(drbg->lock);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册