27 #ifndef SIMON_XOR_THRESHOLD_SEARCH_H
28 #define SIMON_XOR_THRESHOLD_SEARCH_H
34 #define SIMON_TRAIL_LEN 15
35 #elif(WORD_SIZE == 24)
36 #define SIMON_TRAIL_LEN 15
37 #elif(WORD_SIZE == 32)
38 #define SIMON_TRAIL_LEN 21
41 #define SIMON32_TRAIL_LEN 15
42 #define SIMON48_TRAIL_LEN 20
43 #define SIMON64_TRAIL_LEN 21
46 extern double g_B[SIMON_TRAIL_LEN];
48 #elif(WORD_SIZE == 24)
49 extern double g_B[SIMON_TRAIL_LEN];
51 #elif(WORD_SIZE == 32)
52 extern double g_B[SIMON_TRAIL_LEN];
57 : std::binary_function<std::array<differential_t, SIMON_NDIFFS>, std::array<differential_t, SIMON_NDIFFS>, bool>
59 bool operator()(std::array<differential_t, SIMON_NDIFFS>
const& a,
60 std::array<differential_t, SIMON_NDIFFS>
const& b)
const
62 assert(a.size() == SIMON_NDIFFS);
63 assert(b.size() == SIMON_NDIFFS);
67 if(a.size() == b.size()) {
68 while((i != a.size()) && (i != b.size()) && (b_equal ==
true)) {
69 b_equal = ((a[i].dx == b[i].dx) && (a[i].dy == b[i].dy));
77 assert(i == a.size());
78 assert(i == b.size());
87 : std::unary_function<std::array<differential_t, SIMON_NDIFFS>, std::size_t>
89 std::size_t operator()(std::array<differential_t, SIMON_NDIFFS>
const& a)
const
91 assert(a.size() == SIMON_NDIFFS);
94 for(uint32_t i = 0; i < a.size(); i++) {
95 boost::hash_combine(seed, a[i].dx);
96 boost::hash_combine(seed, a[i].dy);
103 : std::binary_function<std::array<differential_t, NROUNDS>, std::array<differential_t, NROUNDS>, bool>
105 bool operator()(std::array<differential_t, NROUNDS>
const& a,
106 std::array<differential_t, NROUNDS>
const& b)
const
113 if(a.size() == b.size()) {
114 while((i != a.size()) && (i != b.size()) && (b_equal ==
true)) {
115 b_equal = ((a[i].dx == b[i].dx) && (a[i].dy == b[i].dy));
123 assert(i == a.size());
124 assert(i == b.size());
133 : std::unary_function<std::array<differential_t, NROUNDS>, std::size_t>
135 std::size_t operator()(std::array<differential_t, NROUNDS>
const& a)
const
138 std::size_t seed = 0;
140 for(uint32_t i = 0; i < a.size(); i++) {
141 boost::hash_combine(seed, a[i].dx);
142 boost::hash_combine(seed, a[i].dy);
149 : std::binary_function<simon_diff_graph_node_t, simon_diff_graph_node_t, bool>
155 if(a.level != b.level) {
156 b_less = (a.level < b.level);
158 if(a.node[1] != b.node[1]) {
159 b_less = (a.node[1] < b.node[1]);
161 if(a.node[0] != b.node[0]) {
162 b_less = (a.node[0] < b.node[0]);
167 printf(
"(%d %d) (%X %X) (%X %X) | %d\n", a.level, b.level, a.node[1], b.node[1], a.node[0], b.node[0], b_less);
174 : std::unary_function<simon_diff_graph_node_t, simon_diff_graph_node_t>
181 node_key.level = a.level;
182 node_key.node[0] = a.node[0];
183 node_key.node[1] = a.node[1];
189 void simon_diff_graph_check_edge(std::vector<simon_diff_graph_edge_t>*
E,
191 void simon_print_diff_array(std::array<differential_t, SIMON_NDIFFS> diff_array);
193 void simon_print_trail_array(std::array<differential_t, NROUNDS> trail_array);
197 uint32_t key_in[SIMON_MAX_NROUNDS],
199 uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u);
200 double simon_verify_differential(
const uint32_t key_in[SIMON_MAX_NROUNDS],
203 const uint32_t nrounds,
204 const uint64_t npairs,
205 std::vector<simon_diff_graph_edge_t>*
E);
206 double simon_verify_differential_approx(
const uint32_t key_in[SIMON_MAX_NROUNDS],
209 const uint32_t nrounds,
210 const uint64_t npairs,
211 std::vector<simon_diff_graph_edge_t>*
E);
212 void simon_graphviz_write_file(
char* datfile,
char* datfile_con,
213 std::vector< simon_diff_graph_edge_t>
E);
215 uint32_t nrounds, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u);
217 uint32_t key_in[SIMON_MAX_NROUNDS],
219 uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u);
220 void simon_encrypt_pairs(uint32_t key[SIMON_MAX_NROUNDS], uint32_t nrounds,
221 uint32_t* x_in, uint32_t* y_in,
222 uint32_t* xx_in, uint32_t* yy_in);
226 const uint32_t dyy_init,
227 uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u,
228 std::multiset<differential_t, struct_comp_diff_p>* diff_mset_p,
230 std::set<differential_t, struct_comp_diff_dx_dy>* diff_set_dx_dy,
231 std::multiset<differential_t, struct_comp_diff_p>* hways_diff_mset_p,
232 std::set<differential_t, struct_comp_diff_dx_dy>* hways_diff_set_dx_dy,
233 std::multiset<differential_t, struct_comp_diff_p>* croads_diff_mset_p,
234 std::set<differential_t, struct_comp_diff_dx_dy>* croads_diff_set_dx_dy,
241 void simon_print_round_diffs_latex(FILE* fp, uint32_t nrounds, uint32_t keys[4],
differential_t trail[
NROUNDS + 1]);
244 std::string trail_to_string(
differential_t* trail, uint32_t trail_len);
250 std::unordered_map<std::string, differential_t**>* trails_hash_map,
253 uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u,
254 std::multiset<differential_t, struct_comp_diff_p>* diff_mset_p,
255 std::set<differential_t, struct_comp_diff_dx_dy>* diff_set_dx_dy,
256 std::multiset<differential_t, struct_comp_diff_p>* croads_diff_mset_p,
257 std::set<differential_t, struct_comp_diff_dx_dy>* croads_diff_set_dx_dy,
263 void simon_print_hash_table(std::unordered_map<std::string, differential_t**> trails_hash_map, uint32_t trail_len);
264 void simon_boost_print_hash_table(boost::unordered_map<std::array<differential_t, NROUNDS>, uint32_t,
simon_trail_hash,
simon_trail_equal_to> trails_hash_map, uint32_t trail_len);
265 void simon_cluster_trails_datfile_read(std::vector<simon_diff_graph_edge_t>*
E);
266 void simon_diff_graph_extract_nodes(std::vector<simon_diff_graph_edge_t>
E,
270 void simon_diff_graph_print_nodes(std::map<simon_diff_graph_node_t, simon_diff_graph_node_t, simon_diff_graph_node_comp> V);
271 bool simon_diff_vec_comp(std::pair<simon_diff_graph_node_t, simon_diff_graph_node_t> a,
272 std::pair<simon_diff_graph_node_t, simon_diff_graph_node_t> b);
273 #endif // #ifndef SIMON_XOR_THRESHOLD_SEARCH_H
#define NROUNDS
Definition: common.hh:122
void simon_xor_threshold_search(const int n, const int nrounds, double B[NROUNDS], double *Bn, const differential_t diff_in[NROUNDS], differential_t trail[NROUNDS], const uint32_t dyy_init, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u, std::multiset< differential_t, struct_comp_diff_p > *diff_mset_p, std::set< differential_t, struct_comp_diff_dx_dy > *diff_set_dx_dy, std::multiset< differential_t, struct_comp_diff_p > *hways_diff_mset_p, std::set< differential_t, struct_comp_diff_dx_dy > *hways_diff_set_dx_dy, std::multiset< differential_t, struct_comp_diff_p > *croads_diff_mset_p, std::set< differential_t, struct_comp_diff_dx_dy > *croads_diff_set_dx_dy, boost::unordered_map< std::array< differential_t, SIMON_NDIFFS >, uint32_t, simon_diff_hash, simon_diff_equal_to > *diffs_hash_map, boost::unordered_map< std::array< differential_t, NROUNDS >, uint32_t, simon_trail_hash, simon_trail_equal_to > *trails_hash_map, differential_t **diff_max, bool b_hash_map, double p_eps, double p_thres)
Definition: simon-xor-threshold-search.cc:1890
Definition: simon-xor-threshold-search.hh:173
Definition: common.hh:272
void simon_trail_to_round_diffs(differential_t trail_in[NROUNDS], differential_t round_diffs[NROUNDS+1], uint32_t nrounds, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u)
Definition: simon-xor-threshold-search.cc:526
Definition: simon-xor-threshold-search.hh:86
Definition: simon-xor-threshold-search.hh:56
uint32_t simon_xor_trail_search(uint32_t key[SIMON_MAX_NROUNDS], double B[NROUNDS], differential_t best_trail[NROUNDS], uint32_t *best_trail_len)
Definition: simon-xor-threshold-search.cc:2304
uint32_t simon_verify_xor_differential(uint32_t nrounds, uint32_t npairs, uint32_t key_in[SIMON_MAX_NROUNDS], differential_t trail_in[NROUNDS], uint32_t dy_init, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u)
Definition: simon-xor-threshold-search.cc:571
uint32_t E[SALSA_STATE+SALSA_STATE][5]
Definition: salsa.cc:50
void simon_trail_cluster_search(std::unordered_map< std::string, differential_t ** > *trails_hash_map, double B[NROUNDS], const differential_t trail_in[NROUNDS], uint32_t trail_len, uint32_t *dyy_init)
Definition: simon-xor-threshold-search.cc:2961
uint32_t simon_verify_xor_trail(uint32_t nrounds, uint32_t npairs, uint32_t key_in[SIMON_MAX_NROUNDS], differential_t trail[NROUNDS], uint32_t dy_init, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u)
Definition: simon-xor-threshold-search.cc:447
Definition: simon-xor-threshold-search.hh:102
Definition: simon-xor-threshold-search.hh:132
uint32_t simon_xor_threshold_count_lp(differential_t trail[NROUNDS], uint32_t trail_len, double p_thres)
Definition: simon-xor-threshold-search.cc:427
void simon_xor_cluster_trails(const int n, const int nrounds, const double B[NROUNDS], const differential_t diff_in[NROUNDS], const differential_t best_trail[NROUNDS], std::unordered_map< std::string, differential_t ** > *trails_hash_map, const differential_t input_diff, const differential_t output_diff, uint32_t lrot_const_s, uint32_t lrot_const_t, uint32_t lrot_const_u, std::multiset< differential_t, struct_comp_diff_p > *diff_mset_p, std::set< differential_t, struct_comp_diff_dx_dy > *diff_set_dx_dy, std::multiset< differential_t, struct_comp_diff_p > *croads_diff_mset_p, std::set< differential_t, struct_comp_diff_dx_dy > *croads_diff_set_dx_dy, double eps)
Definition: simon-xor-threshold-search.cc:2733
Definition: simon-xor-threshold-search.hh:148