YAARX: Yet Another ARX Toolkit  0.1
 All Data Structures Files Functions Variables Macros Pages
speck-xor-threshold-search.cc File Reference

Tests for automatic search for XOR differentials in block cipher Speck . More...

#include "common.hh"
#include "xdp-add.hh"
#include "max-xdp-add.hh"
#include "speck.hh"
#include "xdp-add-pddt.hh"
#include "xdp-add-diff-set.hh"

Macros

#define CLEAR_CROADS   1
 
#define CLEAR_CROADS   1
 
#define PRINT_TRAIL   0
 
#define PRINT_TRAIL_FILE   0
 

Functions

void speck_print_round_diffs_latex (FILE *fp, uint32_t nrounds, uint32_t keys[4], differential_t trail[NROUNDS+1])
 
uint32_t speck_verify_xor_differential (uint32_t nrounds, uint32_t npairs, WORD_T key_in[SPECK_MAX_NROUNDS], differential_t trail[NROUNDS], const WORD_T dx_init, const WORD_T dy_init, uint32_t right_rot_const, uint32_t left_rot_const)
 
uint32_t speck_verify_xor_differential_decrypt (uint32_t nrounds, uint32_t npairs, WORD_T key_in[SPECK_MAX_NROUNDS], differential_t trail[NROUNDS], const WORD_T dx_init, const WORD_T dy_init, uint32_t right_rot_const, uint32_t left_rot_const)
 
uint32_t speck_verify_xor_trail (uint32_t nrounds, uint32_t npairs, WORD_T key_in[SPECK_MAX_NROUNDS], differential_t trail[NROUNDS], const WORD_T dx_init, const WORD_T dy_init, uint32_t right_rot_const, uint32_t left_rot_const)
 
uint32_t speck_verify_xor_trail_decrypt (uint32_t nrounds, uint32_t npairs, WORD_T key_in[SPECK_MAX_NROUNDS], differential_t trail[NROUNDS], const WORD_T dx_init, const WORD_T dy_init, uint32_t right_rot_const, uint32_t left_rot_const)
 
bool speck_xdp_add_is_dz_in_set_dx_dy_dz (uint32_t dx, uint32_t dy, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > diff_set_dx_dy_dz)
 
void speck_xdp_add_pddt_dx_dy_max_dz_i (const uint32_t k, const uint32_t n, const uint32_t hw_thres, const double p_thres, WORD_T *da, WORD_T *db, differential_3d_t full_diff_set[SPECK_MAX_DIFF_CNT], const uint64_t max_len, uint64_t *len)
 
void speck_xdp_add_pddt_dx_dy_max_dz (uint32_t n, const double p_thres, uint32_t hw_thres, differential_3d_t *full_diff_set, uint64_t *full_diff_set_len)
 
void speck_xdp_add_pddt_i (const uint32_t k, const uint32_t n, const double p_thres, const uint32_t hw_thres, gsl_matrix *A[2][2][2], gsl_vector *C, WORD_T *da, WORD_T *db, WORD_T *dc, double *p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, uint64_t max_size)
 
void speck_xdp_add_pddt (uint32_t n, double p_thres, uint32_t hw_thres, const uint64_t max_size, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p)
 
void speck_xdp_add_dx_dy_pddt_i (const WORD_T k, const WORD_T n, gsl_matrix *A[2][2][2], gsl_vector *C, const WORD_T da, const WORD_T db, WORD_T *dc, double *p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *hways_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *hways_diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, uint32_t right_rot_const, uint32_t left_rot_const, const double p_thres, uint32_t max_size, bool b_speck_cluster_trails)
 
WORD_T speck_xdp_add_dx_dy_pddt (WORD_T da, WORD_T db, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *hways_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *hways_diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, uint32_t right_rot_const, uint32_t left_rot_const, double p_thres, WORD_T max_size, bool b_speck_cluster_trails)
 
void speck_xdp_add_dx_dy_pddt_simple_i (const uint32_t k, const uint32_t n, gsl_matrix *A[2][2][2], gsl_vector *C, const WORD_T da, const WORD_T db, WORD_T *dc, double *p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, const double p_thres, const uint32_t dc_max_hw, uint32_t max_size)
 
WORD_T speck_xdp_add_dx_dy_pddt_simple (WORD_T da, WORD_T db, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, double p_thres, uint32_t hw_thres, uint32_t max_size)
 
void speck_xdp_add_pddt_rand (WORD_T n, const double p_thres, const uint32_t hw_thres, const uint64_t max_size, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p)
 
void speck_xor_threshold_search_decrypt (const int n, const int nrounds, gsl_matrix *A[2][2][2], double B[NROUNDS], double *Bn, const differential_t diff_in[NROUNDS], const WORD_T dx_init_in, const WORD_T dy_init_in, differential_t trail[NROUNDS], WORD_T *dx_init, WORD_T *dy_init, uint32_t right_rot_const, uint32_t left_rot_const, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, double p_thres, bool b_speck_cluster_trails)
 
void speck_xor_threshold_search_encrypt (const int n, const int nrounds, gsl_matrix *A[2][2][2], double B[NROUNDS], double *Bn, const differential_t diff_in[NROUNDS], const WORD_T dx_init_in, const WORD_T dy_init_in, differential_t trail[NROUNDS], WORD_T *dx_init, WORD_T *dy_init, uint32_t right_rot_const, uint32_t left_rot_const, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, double p_thres, bool b_speck_cluster_trails)
 
void speck_xor_threshold_search_simple (const int n, const int nrounds, gsl_matrix *A[2][2][2], double B[NROUNDS], double *Bn, const differential_t diff_in[NROUNDS], WORD_T dx_init_in, WORD_T dy_init_in, differential_t trail[NROUNDS], WORD_T *dx_init, WORD_T *dy_init, uint32_t right_rot_const, uint32_t left_rot_const, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, double p_thres, bool b_speck_cluster_trails)
 
void speck_xor_threshold_search_48 (const int n, const int nrounds, gsl_matrix *A[2][2][2], double B[NROUNDS], double *Bn, const differential_t diff_in[NROUNDS], WORD_T dx_init_in, WORD_T dy_init_in, differential_t trail[NROUNDS], WORD_T *dx_init, WORD_T *dy_init, uint32_t right_rot_const, uint32_t left_rot_const, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, differential_3d_t *full_diff_set, const uint64_t full_diff_set_len, double p_thres, bool b_speck_cluster_trails)
 
void speck_boost_print_hash_table (boost::unordered_map< std::array< differential_t, NROUNDS >, uint32_t, speck_trail_hash, speck_trail_equal_to > trails_hash_map, uint32_t trail_len, uint32_t dx_input, uint32_t dy_input)
 
void speck_xor_cluster_trails_boost (const int n, const int nrounds, gsl_matrix *A[2][2][2], double B[NROUNDS], const differential_t diff_in[NROUNDS], differential_t trail[NROUNDS], boost::unordered_map< std::array< differential_t, NROUNDS >, uint32_t, speck_trail_hash, speck_trail_equal_to > *trails_hash_map, const differential_t input_diff, const differential_t output_diff, uint32_t right_rot_const, uint32_t left_rot_const, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *croads_diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *croads_diff_set_dx_dy_dz, double eps)
 
void speck_trail_cluster_search_boost (boost::unordered_map< std::array< differential_t, NROUNDS >, uint32_t, speck_trail_hash, speck_trail_equal_to > *trails_hash_map, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, uint32_t dx_input, uint32_t dy_input, double B[NROUNDS], differential_t trail_in[NROUNDS], uint32_t trail_len)
 
void speck_array_differential_3d_alloc (differential_3d_t **T, const uint64_t len)
 
void speck_array_differential_3d_free (differential_3d_t *T, const uint64_t len)
 
uint32_t speck_xor_trail_search (uint32_t key[SPECK_MAX_NROUNDS], double B[NROUNDS], WORD_T *dx_input, WORD_T *dy_input, differential_t best_trail[NROUNDS], uint32_t num_rounds)
 
uint32_t speck_xor_trail_search_encrypt (uint32_t key[SPECK_MAX_NROUNDS], double B[NROUNDS], const WORD_T dx_input, const WORD_T dy_input, differential_t best_trail[NROUNDS], const uint32_t num_rounds, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, gsl_matrix *A[2][2][2])
 
uint32_t speck_xor_trail_search_decrypt (uint32_t key[SPECK_MAX_NROUNDS], double B[NROUNDS], const WORD_T dx_input, const WORD_T dy_input, differential_t best_trail[NROUNDS], const uint32_t num_rounds, std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *diff_set_dx_dy_dz, std::multiset< differential_3d_t, struct_comp_diff_3d_p > *diff_mset_p, gsl_matrix *A[2][2][2])
 

Detailed Description

Tests for automatic search for XOR differentials in block cipher Speck .

Author
V.Velichkov, vesse.nosp@m.lin..nosp@m.velic.nosp@m.hkov.nosp@m.@uni..nosp@m.lu
Date
2012-2013

Function Documentation

uint32_t speck_verify_xor_differential ( uint32_t  nrounds,
uint32_t  npairs,
WORD_T  key_in[SPECK_MAX_NROUNDS],
differential_t  trail[NROUNDS],
const WORD_T  dx_init,
const WORD_T  dy_init,
uint32_t  right_rot_const,
uint32_t  left_rot_const 
)

Given an XOR trail for $N$ rounds, experimentally verify the probabilities of the corresponding $N$ differentials:

  - Differential for 1 round: round 0. 
  - Differential for 2 rounds: rounds \form#316. 
  - Differential for 3 rounds: rounds \form#317. 
  -  \form#318
  - Differential for \form#315 rounds: rounds \form#319. 
uint32_t speck_verify_xor_trail ( uint32_t  nrounds,
uint32_t  npairs,
WORD_T  key_in[SPECK_MAX_NROUNDS],
differential_t  trail[NROUNDS],
const WORD_T  dx_init,
const WORD_T  dy_init,
uint32_t  right_rot_const,
uint32_t  left_rot_const 
)

Experimentally verify the probability of all 1-round differentials from which an N round trail is composed.

uint32_t speck_verify_xor_trail_decrypt ( uint32_t  nrounds,
uint32_t  npairs,
WORD_T  key_in[SPECK_MAX_NROUNDS],
differential_t  trail[NROUNDS],
const WORD_T  dx_init,
const WORD_T  dy_init,
uint32_t  right_rot_const,
uint32_t  left_rot_const 
)

Experimentally verify the probability of all 1-round differentials from which an N round trail is composed in DECRYPT mode.

WORD_T speck_xdp_add_dx_dy_pddt ( WORD_T  da,
WORD_T  db,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  hways_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  hways_diff_mset_p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  croads_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  croads_diff_mset_p,
uint32_t  right_rot_const,
uint32_t  left_rot_const,
double  p_thres,
WORD_T  max_size,
bool  b_speck_cluster_trails 
)

For given input XOR differences da,db to ADD compute a pDDT of differentials (da,db->dc) with probability above a fixed threshold p_thres. Wrapper for speck_xdp_add_dx_dy_pddt_i .

right_rot_const and left_rot_const are the rotation constants of block cipher Speck speck.cc .

See Also
xdp_add_dx_dy_pddt
void speck_xdp_add_dx_dy_pddt_i ( const WORD_T  k,
const WORD_T  n,
gsl_matrix *  A[2][2][2],
gsl_vector *  C,
const WORD_T  da,
const WORD_T  db,
WORD_T *  dc,
double *  p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  hways_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  hways_diff_mset_p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  croads_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  croads_diff_mset_p,
uint32_t  right_rot_const,
uint32_t  left_rot_const,
const double  p_thres,
uint32_t  max_size,
bool  b_speck_cluster_trails 
)

For given input XOR differences da,db to ADD compute a pDDT of differentials (da,db->dc) with probability above a fixed threshold p_thres.

See Also
speck_xdp_add_dx_dy_pddt
WORD_T speck_xdp_add_dx_dy_pddt_simple ( WORD_T  da,
WORD_T  db,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  croads_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  croads_diff_mset_p,
double  p_thres,
uint32_t  hw_thres,
uint32_t  max_size 
)

Simplified version of xdp_add_dx_dy_pddt : for given input XOR differences da,db to ADD compute a pDDT of differentials (da,db->dc) with probability above a fixed threshold p_thres. Wrapper for speck_xdp_add_dx_dy_pddt_simple_i .

right_rot_const and left_rot_const are the rotation constants of block cipher Speck speck.cc .

See Also
xdp_add_dx_dy_pddt
void speck_xdp_add_dx_dy_pddt_simple_i ( const uint32_t  k,
const uint32_t  n,
gsl_matrix *  A[2][2][2],
gsl_vector *  C,
const WORD_T  da,
const WORD_T  db,
WORD_T *  dc,
double *  p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  croads_diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  croads_diff_mset_p,
const double  p_thres,
const uint32_t  dc_max_hw,
uint32_t  max_size 
)

Simplified version of speck_xdp_add_dx_dy_pddt_i

See Also
xdp_add_dx_dy_pddt , speck_xdp_add_dx_dy_pddt_simple
bool speck_xdp_add_is_dz_in_set_dx_dy_dz ( uint32_t  dx,
uint32_t  dy,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz diff_set_dx_dy_dz 
)

SPECK: For given input differences dx,dy, check if in the list of differentials set_dx_dy_dz exists an entry (dx,dy->dz)

See Also
xdp_add_is_dz_in_set_dx_dy_dz
void speck_xdp_add_pddt ( uint32_t  n,
double  p_thres,
uint32_t  hw_thres,
const uint64_t  max_size,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p 
)

For Speck: compute a partial DDT for $\mathrm{xdp}^{+}$: wrapper function of xdp_add_pddt_i.

See Also
xdp_add_pddt speck_xdp_add_pddt_i
void speck_xdp_add_pddt_i ( const uint32_t  k,
const uint32_t  n,
const double  p_thres,
const uint32_t  hw_thres,
gsl_matrix *  A[2][2][2],
gsl_vector *  C,
WORD_T *  da,
WORD_T *  db,
WORD_T *  dc,
double *  p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p,
uint64_t  max_size 
)

Compute a pDDT for SPECK.

See Also
xdp_add_pddt_i
void speck_xor_cluster_trails_boost ( const int  n,
const int  nrounds,
gsl_matrix *  A[2][2][2],
double  B[NROUNDS],
const differential_t  diff_in[NROUNDS],
differential_t  trail[NROUNDS],
boost::unordered_map< std::array< differential_t, NROUNDS >, uint32_t, speck_trail_hash, speck_trail_equal_to > *  trails_hash_map,
const differential_t  input_diff,
const differential_t  output_diff,
uint32_t  right_rot_const,
uint32_t  left_rot_const,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  croads_diff_mset_p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  croads_diff_set_dx_dy_dz,
double  eps 
)
See Also
simon_xor_cluster_trails_boost
void speck_xor_threshold_search_simple ( const int  n,
const int  nrounds,
gsl_matrix *  A[2][2][2],
double  B[NROUNDS],
double *  Bn,
const differential_t  diff_in[NROUNDS],
WORD_T  dx_init_in,
WORD_T  dy_init_in,
differential_t  trail[NROUNDS],
WORD_T *  dx_init,
WORD_T *  dy_init,
uint32_t  right_rot_const,
uint32_t  left_rot_const,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
double  p_thres,
bool  b_speck_cluster_trails 
)

Do not apply the back-to-the-highway heuristic. Limit only by Hamming weight.

uint32_t speck_xor_trail_search_decrypt ( uint32_t  key[SPECK_MAX_NROUNDS],
double  B[NROUNDS],
const WORD_T  dx_input,
const WORD_T  dy_input,
differential_t  best_trail[NROUNDS],
const uint32_t  num_rounds,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p,
gsl_matrix *  A[2][2][2] 
)

Apply threshold search starting from a fixed differences in the middle and proceeding in the decryption direction.

uint32_t speck_xor_trail_search_encrypt ( uint32_t  key[SPECK_MAX_NROUNDS],
double  B[NROUNDS],
const WORD_T  dx_input,
const WORD_T  dy_input,
differential_t  best_trail[NROUNDS],
const uint32_t  num_rounds,
std::set< differential_3d_t, struct_comp_diff_3d_dx_dy_dz > *  diff_set_dx_dy_dz,
std::multiset< differential_3d_t, struct_comp_diff_3d_p > *  diff_mset_p,
gsl_matrix *  A[2][2][2] 
)

Apply threshold search starting from a fixed differences in the middle end rpoceeding in the encryption direction.