openssl: Use separate DRBG for RNG_STRONG and RNG_TRUE with OpenSSL 1.1.1
OpenSSL 1.1.1 introduces DRGBs and provides two sources (same security profile etc. but separate internal state), which allows us to use one for RNG_WEAK (e.g. for nonces that are directly publicly visible) and the other for stronger random data like keys.
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2012-2018 Tobias Brunner
|
||||||
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
* Copyright (C) 2012 Aleksandr Grinberg
|
* Copyright (C) 2012 Aleksandr Grinberg
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
@@ -24,7 +27,6 @@
|
|||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
#include <openssl/err.h>
|
|
||||||
|
|
||||||
#include "openssl_rng.h"
|
#include "openssl_rng.h"
|
||||||
|
|
||||||
@@ -49,6 +51,13 @@ struct private_openssl_rng_t {
|
|||||||
METHOD(rng_t, get_bytes, bool,
|
METHOD(rng_t, get_bytes, bool,
|
||||||
private_openssl_rng_t *this, size_t bytes, uint8_t *buffer)
|
private_openssl_rng_t *this, size_t bytes, uint8_t *buffer)
|
||||||
{
|
{
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x1010100fL
|
||||||
|
if (this->quality > RNG_WEAK)
|
||||||
|
{ /* use a separate DRBG for data we wan't to keep private, compared
|
||||||
|
* to e.g. nonces */
|
||||||
|
return RAND_priv_bytes((char*)buffer, bytes) == 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return RAND_bytes((char*)buffer, bytes) == 1;
|
return RAND_bytes((char*)buffer, bytes) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user