Generic PRNG framework:

* A new, unified interface for generating random numbers and
  filling buffers supporting any engine that fits the
  UniformRandomNumberGenerator concept;
* Automatically seeded replacement for rand using the fast
  xorshift+ PRNG engine;
* A CSPRNG engine that can be used with the new framework
  when needing to to generate cryptographically secure
  randomness.
* Unit test cleanups to work with new engine.
This commit is contained in:
Nik Bougalis
2016-01-09 02:27:32 -08:00
parent 1c9577a1ac
commit 40363f96a9
28 changed files with 647 additions and 334 deletions

View File

@@ -23,8 +23,9 @@
#include <ripple/protocol/impl/secp256k1.h>
#include <ripple/basics/contract.h>
#include <ripple/crypto/GenerateDeterministicKey.h>
#include <ripple/crypto/RandomNumbers.h>
#include <ripple/crypto/csprng.h>
#include <beast/crypto/secure_erase.h>
#include <beast/random/rngfill.h>
#include <ed25519-donna/ed25519.h>
#include <cstring>
@@ -150,7 +151,10 @@ Seed
randomSeed()
{
std::uint8_t buf[16];
random_fill(buf, sizeof(buf));
beast::rngfill(
buf,
sizeof(buf),
crypto_prng());
Seed seed(Slice{ buf, sizeof(buf) });
beast::secure_erase(buf, sizeof(buf));
return seed;
@@ -170,7 +174,10 @@ SecretKey
randomSecretKey()
{
std::uint8_t buf[32];
random_fill(buf, sizeof(buf));
beast::rngfill(
buf,
sizeof(buf),
crypto_prng());
SecretKey sk(Slice{ buf, sizeof(buf) });
beast::secure_erase(buf, sizeof(buf));
return sk;