bool SpikingOutput::allocateValues(){ module::allocateValues(); // Use the allocateValues() method of the base class // Set parameters of distributions for random number generation normal_distribution<double>::param_type init_norm_dist_params(Min_period/1000.0, Min_period_std_dev/1000.0); // (mean=Min_period/1000.0, sigma=Min_period_std_dev/1000.0 seconds) norm_dist.param(init_norm_dist_params); // Set initial params of normal distribution gamma_distribution<double>::param_type init_gam_dist_params(Spike_dist_shape, 1.0/Spike_dist_shape); // Parameters of gamma distribution for spike: gam_k (alpha), gam_theta (beta) gam_dist.param(init_gam_dist_params); // Set params of uniform distribution // Resize initial image buffers inputImage->assign(sizeY, sizeX, 1, 1, 0.0); next_spk_time->assign(sizeY, sizeX, 1, 1, First_spk_delay); last_spk_time->assign(sizeY, sizeX, 1, 1, -numeric_limits<double>::infinity()); curr_ref_period->assign(sizeY, sizeX, 1, 1, Min_period/1000.0); initialize_state(); // Set ref. period and unwarped first spike time if(Random_init != 0.0) // If parameter Random_init is differnt from 0, init the state of outputs randomly randomize_state(); return(true); }
void test_inv_tbox() { tbox_mixing_bijections_t tbox_mixing_bijections, inv_tbox_mixing_bijections; tbox_t tbox; uint32_t expanded_key[(NR + 1) * 4]; uint8_t state[4][4]; uint8_t state2[4][4]; int round, row, col, i; make_tbox_mixing_bijections(tbox_mixing_bijections, inv_tbox_mixing_bijections); for (i = 0; i < (NR + 1) * 4; ++i) expanded_key[i] = (uint8_t) rand(); /* identity key expansion */ make_inv_tbox(tbox, ISBox, expanded_key, tbox_mixing_bijections); for (round = NR - 1; round != 1; --round) { printf("round: %d \n", round); randomize_state(state); memcpy(&state2[0][0], &state[0][0], 16); /* for validation */ dump_state("State before ", state); inv_shift_rows(state); for (row = 0; row < 4; ++row) { for (col = 0; col < 4; ++col) { state[row][col] = tbox[round][row][col][(state[row][col])]; } } dump_state("State after TBox ", state); /* validation */ /* The above should be equal to: */ /* 0. mix */ /* 1. addroundkey */ /* 2. subbytes */ /* 3. shiftrows */ for (row = 0; row < 4; ++row) { for (col = 0; col < 4; ++col) { mul_byte_by_matrix(&state2[row][col], tbox_mixing_bijections[round][row][col], state2[row][col]); } } add_round_key(state2, expanded_key, round+1); inv_sub_bytes(state2, ISBox); inv_shift_rows(state2); dump_state("Validation State ", state2); ASSERT(comp_states(state, state2)); } /* validation for the last round is different */ round = 0; { printf("rounds 9 and 10\n"); randomize_state(state); memcpy(&state2[0][0], &state[0][0], 16); /* for validation */ dump_state("State before ", state); inv_shift_rows(state); for (row = 0; row < 4; ++row) { for (col = 0; col < 4; ++col) { state[row][col] = tbox[round][row][col][(state[row][col])]; } } dump_state("State after TBox ", state); /* validation */ /* The above should be equal to: */ /* 0. mix */ /* 1. addroundkey */ /* 2. subbytes */ /* 3. shiftrows */ /* 4. addroundkey */ for (row = 0; row < 4; ++row) { for (col = 0; col < 4; ++col) { mul_byte_by_matrix(&state2[row][col], tbox_mixing_bijections[round][row][col], state2[row][col]); } } add_round_key(state2, expanded_key, 1); inv_sub_bytes(state2, ISBox); inv_shift_rows(state2); add_round_key(state2, expanded_key, 0); /* the last key */ dump_state("Validation State ", state2); ASSERT(comp_states(state, state2)); } free_tbox_mixing_bijections(tbox_mixing_bijections); free_tbox_mixing_bijections(inv_tbox_mixing_bijections); }