Merge pull request #10676 from poettering/rdrand-everywhere
prefer RDRAND over getrandom() and /dev/urandom when we don't need the very best randomness
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
#include "log.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_acquire_random_bytes(bool high_quality_required) {
|
||||
static void test_genuine_random_bytes(RandomFlags flags) {
|
||||
uint8_t buf[16] = {};
|
||||
unsigned i;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (i = 1; i < sizeof buf; i++) {
|
||||
assert_se(acquire_random_bytes(buf, i, high_quality_required) == 0);
|
||||
assert_se(genuine_random_bytes(buf, i, flags) == 0);
|
||||
if (i + 1 < sizeof buf)
|
||||
assert_se(buf[i] == 0);
|
||||
|
||||
@@ -20,14 +20,14 @@ static void test_acquire_random_bytes(bool high_quality_required) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_pseudorandom_bytes(void) {
|
||||
static void test_pseudo_random_bytes(void) {
|
||||
uint8_t buf[16] = {};
|
||||
unsigned i;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (i = 1; i < sizeof buf; i++) {
|
||||
pseudorandom_bytes(buf, i);
|
||||
pseudo_random_bytes(buf, i);
|
||||
if (i + 1 < sizeof buf)
|
||||
assert_se(buf[i] == 0);
|
||||
|
||||
@@ -54,10 +54,12 @@ static void test_rdrand64(void) {
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_acquire_random_bytes(false);
|
||||
test_acquire_random_bytes(true);
|
||||
test_genuine_random_bytes(RANDOM_EXTEND_WITH_PSEUDO);
|
||||
test_genuine_random_bytes(0);
|
||||
test_genuine_random_bytes(RANDOM_BLOCK);
|
||||
test_genuine_random_bytes(RANDOM_ALLOW_RDRAND);
|
||||
|
||||
test_pseudorandom_bytes();
|
||||
test_pseudo_random_bytes();
|
||||
|
||||
test_rdrand64();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user