/****************************************************************************/ /***************************** SelectParams *********************************/ /****************************************************************************/ // Using the hash out binary byte string, set the parameters to be used in the // HELP algorithm. void SelectParams(int hash_out_len_bytes, unsigned char hash_out_bin_str[hash_out_len_bytes], unsigned int *LFSR_seed_ptr, float *mean_scaler_ptr, float *range_scaler_ptr, unsigned short *modulus_ptr, unsigned short *margin_ptr) { float mean_upper = 00.0; float mean_lower = -50.0; float range_upper = 170.0; float range_lower = 120.0; unsigned short modulus_vals[8] = {46, 48, 50, 52, 54, 56, 58, 60}; // Setting this to a constant for now *margin_ptr = 10; // Get 11-bits for 11-bit LFSR *LFSR_seed_ptr = (0x000007FF & ((hash_out_bin_str[1] << 8) + hash_out_bin_str[0])); //printf("\tLFSR seed choosen from 3-bits of byte1 '%u' and byte0 '%u' of hash => %u\n", (0x07 & hash_out_bin_str[1]), hash_out_bin_str[0], *LFSR_seed_ptr); // Use random 8-bit number to scale range of means from AES SBOX experiments *mean_scaler_ptr = (mean_upper - mean_lower) * hash_out_bin_str[2]/256 + mean_lower; //printf("\tMean scaler choosen from byte 2 (for 256 values) of hash %u to generate scaler between %f and %f => %f\n", // hash_out_bin_str[2], mean_upper, mean_lower, *mean_scaler_ptr); // Use random 8-bit number to scale range of ranges from AES SBOX experiments *range_scaler_ptr = (range_upper - range_lower) * hash_out_bin_str[3]/256 + range_lower; //printf("\tRange scaler choosen from byte 3 (for 256 values) of hash %u to generate scaler between %f and %f => %f\n", // hash_out_bin_str[3], range_upper, range_lower, *range_scaler_ptr); // Look up table for modulus -- use low order 3 or 4 bits of byte 4 *modulus_ptr = modulus_vals[0x07 & hash_out_bin_str[4]]; //printf("\tModulus choosen from low oder 4-bits of byte 4 %u as index %u into modulus vals => %u\n", hash_out_bin_str[4], (0x07 & hash_out_bin_str[4]), *modulus_ptr); // DEBUG printf("\tLFSR seed %u\tMean scaler %f\tRange scaler %f\tModulus %u\n", *LFSR_seed_ptr, *mean_scaler_ptr, *range_scaler_ptr, *modulus_ptr); return; } /****************************************************************************/ /**************************** LFSR_11_A_bits ********************************/ /****************************************************************************/ /* See /home/research/research/FPGAs/HELP/VHDL_HELP/contrib/lfsr_randgen/trunk/lfsr_pkg.vhd */ /* Other possibilities from stdint: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t */ uint16_t LFSR_11_A_bits(int load_seed, uint16_t seed) { static uint16_t lfsr; uint16_t bit, nor_bit; /* Load the seed on the first iteration */ if ( load_seed == 1 ) lfsr = seed; else { /* Allow all zero state. See my BIST class notes in VLSI Testing. Note, we use low order bits here because bit is shifted onto the low side, not high side as in my lecture slides. */ if ( !( (((lfsr >> 9) & 1) == 1) || (((lfsr >> 8) & 1) == 1) || (((lfsr >> 7) & 1) == 1) || (((lfsr >> 6) & 1) == 1) || (((lfsr >> 5) & 1) == 1) || (((lfsr >> 4) & 1) == 1) || (((lfsr >> 3) & 1) == 1) || (((lfsr >> 2) & 1) == 1) || (((lfsr >> 1) & 1) == 1) || (((lfsr >> 0) & 1) == 1) ) ) nor_bit = 1; else nor_bit = 0; /* xor_out := rand(10) xor rand(8); */ bit = ((lfsr >> 10) & 1) ^ ((lfsr >> 8) & 1) ^ nor_bit; /* printf("LFSR value %d\tNOR bit value %d\tlow order bit %d\n", lfsr, nor_bit, bit); */ /* Change the shift of the bit to match the width of the data type. */ lfsr = ((lfsr << 1) | bit) & 2047; } return lfsr; }