diff --git a/include/fc/crypto/rand.hpp b/include/fc/crypto/rand.hpp deleted file mode 100755 index 8979ba7..0000000 --- a/include/fc/crypto/rand.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace fc { - - /* provides access to the OpenSSL random number generator */ - void rand_bytes(char* buf, int count); - //void rand_pseudo_bytes(char* buf, int count); -} // namespace fc diff --git a/src/crypto/rand.cpp b/src/crypto/rand.cpp deleted file mode 100755 index ac0b9db..0000000 --- a/src/crypto/rand.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - - -namespace fc { - -void rand_bytes(char* buf, int count) -{ - static int init = init_openssl(); - (void)init; - - int result = RAND_bytes((unsigned char*)buf, count); - if (result != 1) - FC_THROW("Error calling OpenSSL's RAND_bytes(): ${code}", ("code", (uint32_t)ERR_get_error())); -} - -//void rand_pseudo_bytes(char* buf, int count) -//{ -// static int init = init_openssl(); -// (void)init; -// -// int result = RAND_pseudo_bytes((unsigned char*)buf, count); -// if (result == -1) -// FC_THROW("Error calling OpenSSL's RAND_pseudo_bytes(): ${code}", ("code", (uint32_t)ERR_get_error())); -//} - -} // namespace fc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ec052b9..5c10623 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,7 +44,6 @@ add_executable( all_tests all_tests.cpp crypto/blind.cpp crypto/blowfish_test.cpp crypto/dh_test.cpp - crypto/rand_test.cpp crypto/sha_tests.cpp io/json_tests.cpp io/stream_tests.cpp diff --git a/tests/crypto/rand_test.cpp b/tests/crypto/rand_test.cpp deleted file mode 100755 index bc068d3..0000000 --- a/tests/crypto/rand_test.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#include - -#include - -static void check_randomness( const char* buffer, size_t len ) { - if (len == 0) { return; } - // count bit runs and 0's / 1's - unsigned int zc = 0, oc = 0, rc = 0, last = 2; - for (size_t k = len; k; k--) { - char c = *buffer++; - for (int i = 0; i < 8; i++) { - unsigned int bit = c & 1; - c >>= 1; - if (bit) { oc++; } else { zc++; } - if (bit != last) { rc++; last = bit; } - } - } - BOOST_CHECK_EQUAL( 8*len, zc + oc ); - double E = 1 + (zc + oc) / 2.0; - double variance = (E - 1) * (E - 2) / (oc + zc - 1); - double sigma = sqrt(variance); - BOOST_CHECK( rc < 2*(E + sigma) ); -} - -BOOST_AUTO_TEST_SUITE(fc_crypto) - -BOOST_AUTO_TEST_CASE(rand_test) -{ - char buffer[128]; - fc::rand_bytes( buffer, sizeof(buffer) ); - check_randomness( buffer, sizeof(buffer) ); -} - -//BOOST_AUTO_TEST_CASE(pseudo_rand_test) -//{ -// char buffer[10013]; -// fc::rand_pseudo_bytes( buffer, sizeof(buffer) ); -// check_randomness( buffer, sizeof(buffer) ); -//} - -BOOST_AUTO_TEST_SUITE_END()