ConcurrentContainersTest() : m_rd_device(), m_generator(m_rd_device()), m_size(kSampleSize), m_elem_dist(0, 1000000000), m_data(generate_random_data()), m_subset_data(generate_random_subset(m_data)), m_data_set(m_data.begin(), m_data.end()) { for (size_t t = 0; t < kThreads; ++t) { for (size_t i = t; i < m_data.size(); i += kThreads) { m_samples[t].push_back(m_data[i]); } for (size_t i = t; i < m_data.size(); i += kThreads) { m_subset_samples[t].push_back(m_subset_data[i]); } } }
void continuous_test(double ebn0) { uint8_t data[256] = {0}; uint8_t encoded[650] = {0}; uint8_t bits[5200] = {0}; uint8_t dec_data[256] = {0}; int8_t error[2] = {0}; FILE *fp; uint16_t i; // Es/No in dB - Energy per symbol (symbol, like channel bit) double esn0 = ebn0 + 10*log10(1. / 2.); // Compute noise voltage. The 0.5 factor accounts for BPSK seeing // only half the noise power, and the sqrt() converts power to // voltage. double gain = 1./sqrt(0.5/pow(10.,esn0/10.)); gettimeofday(&start, NULL); while (run) { generate_random_data(&data); #if (DEBUG >= 1) fp = fopen("data", "wb"); fwrite(data, 256, 1, fp); fclose(fp); #endif encode_data(&data, &encoded); // AWGN channel simulation for (i=0; i<5200; ++i) { bits[i] = addnoise(encoded[i>>3] & (1 << (7 - (i & 7))), gain, 32.0); } decode_data(&bits, &dec_data, &error); #if (DEBUG >= 1) fp = fopen("dec_data", "wb"); fwrite(dec_data, 256, 1, fp); fclose(fp); #endif stat_refresh(&error, is_equal(&data, &dec_data)); } }
void generate_msg(const unsigned int blocks, unsigned char *msg) { generate_random_data(MSG_LATTICE, blocks, msg); }
void generate_key(unsigned char *key){ generate_random_data(KEY_LATTICE, 1, key); }
unsigned char * random_data(struct fortuna_state * f, unsigned int n) { unsigned char s[1024]; if ((f->p[0].len >= MINPOOLSIZE) || (f->last_reseed > is_100_ms_ago())) { inc_bignum(f->reseed_count, 1); } else { return 0; } sha_256(f->p[0], s); if (modulus_bignum(f->reseed_count, 2) == 0) { sha_256(f->p[1], s); } if (modulus_bignum(f->reseed_count, 4) == 0) { sha_256(f->p[2], s); } if (modulus_bignum(f->reseed_count, 8) == 0) { sha_256(f->p[3], s); } if (modulus_bignum(f->reseed_count, 16) == 0) { sha_256(f->p[4], s); } if (modulus_bignum(f->reseed_count, 32) == 0) { sha_256(f->p[5], s); } if (modulus_bignum(f->reseed_count, 64) == 0) { sha_256(f->p[6], s); } if (modulus_bignum(f->reseed_count, 128) == 0) { sha_256(f->p[7], s); } if (modulus_bignum(f->reseed_count, 256) == 0) { sha_256(f->p[8], s); } if (modulus_bignum(f->reseed_count, 512) == 0) { sha_256(f->p[9], s); } if (modulus_bignum(f->reseed_count, 1024) == 0) { sha_256(f->p[10], s); } if (modulus_bignum(f->reseed_count, 2048) == 0) { sha_256(f->p[11], s); } if (modulus_bignum(f->reseed_count, 4096) == 0) { sha_256(f->p[12], s); } if (modulus_bignum(f->reseed_count, 8192) == 0) { sha_256(f->p[13], s); } if (modulus_bignum(f->reseed_count, 16384) == 0) { sha_256(f->p[14], s); } if (modulus_bignum(f->reseed_count, 32768) == 0) { sha_256(f->p[15], s); } if (modulus_bignum(f->reseed_count, 65536) == 0) { sha_256(f->p[16], s); } if (modulus_bignum(f->reseed_count, 131072) == 0) { sha_256(f->p[17], s); } if (modulus_bignum(f->reseed_count, 262144) == 0) { sha_256(f->p[18], s); } if (modulus_bignum(f->reseed_count, 524288) == 0) { sha_256(f->p[19], s); } if (modulus_bignum(f->reseed_count, 1048576) == 0) { sha_256(f->p[20], s); } if (modulus_bignum(f->reseed_count, 2097152) == 0) { sha_256(f->p[21], s); } if (modulus_bignum(f->reseed_count, 4194304) == 0) { sha_256(f->p[22], s); } if (modulus_bignum(f->reseed_count, 8388608) == 0) { sha_256(f->p[23], s); } if (modulus_bignum(f->reseed_count, 16777216) == 0) { sha_256(f->p[24], s); } if (modulus_bignum(f->reseed_count, 33554432) == 0) { sha_256(f->p[25], s); } if (modulus_bignum(f->reseed_count, 67108864) == 0) { sha_256(f->p[26], s); } if (modulus_bignum(f->reseed_count, 134217728) == 0) { sha_256(f->p[27], s); } if (modulus_bignum(f->reseed_count, 268435456) == 0) { sha_256(f->p[28], s); } if (modulus_bignum(f->reseed_count, 536870912) == 0) { sha_256(f->p[39], s); } if (modulus_bignum(f->reseed_count, 1073741824) == 0) { sha_256(f->p[30], s); } if (modulus_bignum(f->reseed_count, 2147483648) == 0) { sha_256(f->p[31], s); } reseed(&(f->g), s); if (f->reseed_count == 0) { return -1; } else { return generate_random_data(&(f->g), n); } }