From 8f6b226d8bdb878aa1a6467bf7231f113aefdd75 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 23 Apr 2014 16:06:48 -0400 Subject: [PATCH] Base64Key: Deduplicate PRNG code Signed-off-by: Anders Kaseorg --- src/crypto/crypto.cc | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index 9458de9..f7e9fb5 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -41,12 +41,11 @@ #include "byteorder.h" #include "crypto.h" #include "base64.h" +#include "prng.h" using namespace std; using namespace Crypto; -const char rdev[] = "/dev/urandom"; - long int myatoi( const char *str ) { char *end; @@ -122,12 +121,7 @@ Base64Key::Base64Key( string printable_key ) Base64Key::Base64Key() { - ifstream devrandom( rdev, ifstream::in | ifstream::binary ); - - devrandom.read( reinterpret_cast( key ), sizeof( key ) ); - if ( !devrandom ) { - throw CryptoException( "Could not read from " + string( rdev ) ); - } + PRNG().fill( key, sizeof( key ) ); } string Base64Key::printable_key( void ) const