Merge branch 'bug/349/exclude_rand_from_fc_library' into 'latest-fc'
Exclude random from fc library See merge request PBSA/tools-libs/peerplays-fc!27
This commit is contained in:
commit
a409f944d0
4 changed files with 0 additions and 81 deletions
|
|
@ -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
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#include <openssl/rand.h>
|
||||
#include <fc/crypto/openssl.hpp>
|
||||
#include <fc/exception/exception.hpp>
|
||||
#include <fc/fwd_impl.hpp>
|
||||
|
||||
|
||||
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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fc/crypto/rand.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
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()
|
||||
Loading…
Reference in a new issue