45 #include <sys/time.h> // gettimeofday
51 #ifndef UNORDERED_MAP_H
52 #define UNORDERED_MAP_H
53 #include <unordered_map>
55 #ifndef BOOST_FUNCTIONAL_HASH_H
56 #define BOOST_FUNCTIONAL_HASH_H
57 #include <boost/functional/hash.hpp>
59 #ifndef BOOST_ALGORITHM_STRING_PREDICATE_H
60 #define BOOST_ALGORITHM_STRING_PREDICATE_H
61 #include <boost/algorithm/string/predicate.hpp>
63 #ifndef BOOST_UNORDERED_MAP_H
64 #define BOOST_UNORDERED_MAP_H
65 #include <boost/unordered_map.hpp>
77 #include <iomanip> // setfill setw
81 #include <gsl/gsl_blas.h>
83 #ifndef STL_ALGORITHM_H
84 #define STL_ALGORITHM_H
117 #define NROUNDS_MAX 10
125 #define ALL_WORDS (1ULL << WORD_SIZE)
129 #define MASK (0xffffffffUL >> (32 - WORD_SIZE))
130 #define MASK_NO_MSB (0xffffffffUL >> (32 - (WORD_SIZE - 1)))
131 #else // #if(WORD_SIZE > 32)
132 #define MASK (0xffffffffffffffffULL >> (64 - WORD_SIZE))
133 #define MASK_NO_MSB (0xffffffffffffffffULL >> (64 - (WORD_SIZE - 1)))
134 #endif // #if(WORD_SIZE <= 32)
137 #define MOD (1ULL << WORD_SIZE)
139 #ifndef TEA_LSH_CONST
140 #define TEA_LSH_CONST 4//9//4
142 #ifndef TEA_RSH_CONST
143 #define TEA_RSH_CONST 5//14//5
146 #define DELTA_INIT 0x9e3779b9
149 #define NPAIRS (1ULL << 15)
152 #define NDELTA (NROUNDS / 2)
155 #ifndef WORD_T // abstract word type
156 #if (WORD_SIZE <= 32)
157 #define WORD_T uint32_t
159 #define WORD_T uint64_t
160 #endif // #if (WORD_SIZE <= 32)
161 #endif // #ifndef WORD
162 #ifndef WORD_MAX_T // max word type on the target system
163 #define WORD_MAX_T long long unsigned int // = uint64_t
164 #endif // #ifdef WORD_MAX_T
169 #define XOR(x,y) ((x ^ y) & MASK)
172 #define ADD(x,y) ((x + y) & MASK)
176 #define SUB(x,y) ((WORD_T)(x - y + MOD) & MASK)
177 #else // #if(WORD_SIZE == 64)
178 #define SUB(x,y) ((WORD_T)(x - y))
179 #endif // #if(WORD_SIZE < 64)
180 #endif // #ifndef SUB
185 #define LSH(x,r) ((x << r) & MASK)
188 #define RSH(x,r) ((x >> r) & MASK)
191 #define LROT(x,r) (((x << r) | (x >> (WORD_SIZE - r))) & MASK)
194 #define RROT(x,r) (((x >> r) | (x << (WORD_SIZE - r))) & MASK)
197 #define MUL(x,y) ((x * y) & MASK) // mod 2^n
206 #define ARX(r,x,y,z) XOR(z,LROT(ADD(x,y),r))
212 #define DEBUG_XDP_ADD_TESTS 1
213 #define DEBUG_MAX_XDP_ADD_TESTS 0
214 #define DEBUG_ADP_XOR_TESTS 1
215 #define DEBUG_ADP_XOR3_TESTS 0
216 #define DEBUG_MAX_ADP_XOR_TESTS 1//0
217 #define DEBUG_ADP_XOR_FI_TESTS 0
218 #define DEBUG_MAX_ADP_XOR_FI_TESTS 0
219 #define DEBUG_MAX_ADP_XOR3_TESTS 0
220 #define DEBUG_MAX_ADP_XOR3_SET_TESTS 0
221 #define DEBUG_ADP_RSH_XOR_TESTS 0
222 #define DEBUG_ADP_SHIFT_TESTS 0
223 #define DEBUG_EADP_TEA_F_TESTS 0
224 #define DEBUG_ADP_TEA_F_FK_TESTS 0
225 #define DEBUG_XDP_TEA_F_FK_TESTS 0
226 #define DEBUG_XDP_XTEA_F_FK_TESTS 0
227 #define DEBUG_ADP_XTEA_F_FK_TESTS 0
232 #define DEBUG_ADP_RSH_XOR 0
233 #define DEBUG_ADP_TEA_F_FK 0
234 #define DEBUG_XDP_TEA_F_FK 0
242 static inline int builtin_hamming_weight(
const WORD_T w)
244 return __builtin_popcountll(w);
297 bool b_more = (a.
p > b.
p);
317 b_less = (a.
dx < b.
dx);
320 b_less = (a.
dy < b.
dy);
322 b_less = (a.
dz < b.
dz);
336 bool b_more = (a.
p > b.
p);
350 bool b_more = (hw_a < hw_b);
368 b_less = (a.
dx < b.
dx);
370 b_less = (a.
dy < b.
dy);
376 typedef unsigned long long timestamp_t;
384 uint32_t
hw8(
const uint32_t x);
385 WORD_T
parity(
const WORD_T x);
391 void print_binary(
const uint64_t n,
const uint32_t word_size);
395 void print_set(
const std::set<differential_t, struct_comp_diff_dx_dy> diff_set_dx_dy);
396 void print_mset(
const std::multiset<differential_t, struct_comp_diff_p> diff_mset_p);
398 void yaarx_alloc_matrices_3d(WORD_T**** A, uint32_t A_len);
399 void yaarx_free_matrices_3d(WORD_T*** A, uint32_t A_len);
400 void yaarx_alloc_matrices_3d(gsl_matrix* A[2][2][2], uint32_t A_len);
401 void yaarx_free_matrices_3d(gsl_matrix* A[2][2][2], uint32_t A_len);
402 void yaarx_alloc_matrices_2d(WORD_T*** A, uint32_t A_rows, uint32_t A_cols);
403 void yaarx_free_matrices_2d(WORD_T** A, uint32_t A_rows, uint32_t A_cols);
404 void yaarx_alloc_matrices_4d(WORD_T***** A, uint32_t A_dim);
405 void yaarx_free_matrices_4d(WORD_T**** A, uint32_t A_dim);
407 #endif // #ifndef COMMON_H
WORD_T dx
Definition: common.hh:251
void print_mset(const std::multiset< differential_t, struct_comp_diff_p > diff_mset_p)
Definition: common.cc:297
Definition: common.hh:344
int log2p
Definition: common.hh:266
bool sort_comp_diff_3d_p(differential_3d_t a, differential_3d_t b)
Definition: common.cc:312
WORD_T xrandom()
Definition: common.cc:61
Definition: common.hh:284
void print_binary(const uint64_t n)
Definition: common.cc:218
Definition: common.hh:272
bool operator<(differential_t x, differential_t y)
Definition: common.cc:247
WORD_T fixed
Definition: common.hh:287
Definition: common.hh:293
uint32_t hamming_weight(const WORD_T w)
Definition: common.cc:128
double p
Definition: common.hh:276
timestamp_t get_timestamp()
Definition: common.cc:35
WORD_T dx
Definition: common.hh:262
Definition: common.hh:332
bool is_even(uint32_t i)
Definition: common.cc:189
Definition: common.hh:310
Definition: common.hh:250
WORD_T npairs
Definition: common.hh:275
WORD_T dy
Definition: common.hh:263
WORD_T parity(const WORD_T x)
Definition: common.cc:176
uint32_t hw8(const uint32_t x)
Definition: common.cc:75
double p
Definition: common.hh:265
void print_set(const std::set< differential_t, struct_comp_diff_dx_dy > diff_set_dx_dy)
Definition: common.cc:281
Definition: common.hh:261
WORD_T gen_sparse(uint32_t hw, uint32_t n)
Definition: common.cc:200
WORD_T dx
Definition: common.hh:273
WORD_T dz
Definition: common.hh:264
bool operator==(differential_t a, differential_t b)
Definition: common.cc:268
double p
Definition: common.hh:252
Definition: common.hh:362
WORD_T dy
Definition: common.hh:274