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

Tests for automatic search for the best XOR differential trail in block cipher Speck . More...

#include "common.hh"
#include "xdp-add.hh"
#include "max-xdp-add.hh"
#include "speck.hh"
#include "speck-xor-threshold-search.hh"

Macros

#define MIN(X, Y)   (((X) < (Y)) ? (X) : (Y))
 
#define UPDATE_BOUND   false
 
#define EPS   (1.0 / (double)(1ULL << 2))
 

Functions

void speck_best_diff_search_full (differential_3d_t T_best[NROUNDS], double *p_best)
 
void speck_add_diff_to_trail (differential_3d_t T[NROUNDS], const uint32_t i, const differential_3d_t new_diff)
 
void speck_remove_diff_from_trail (differential_3d_t T[NROUNDS], const uint32_t i)
 
void speck_init_diff_trail (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail (differential_3d_t T[NROUNDS])
 
void speck_print_differential (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail_log2 (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail_cstyle (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail_cstyle_log2 (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail_latex (differential_3d_t T[NROUNDS])
 
void speck_print_diff_trail_latex_log2 (differential_3d_t T[NROUNDS])
 
void speck_copy_diff_trail (const differential_3d_t from_T[NROUNDS], differential_3d_t to_T[NROUNDS])
 
void speck_best_diff_search_i (const uint32_t iround, const uint32_t ibit, const WORD_T alpha_in, const WORD_T beta_in, const WORD_T gamma_in)
 
void speck_best_diff_search ()
 
void speck_best_diff_search_log2_i (const uint32_t iround, const uint32_t ibit, const WORD_T alpha_in, const WORD_T beta_in, const WORD_T gamma_in)
 
void speck_best_diff_search_log2 ()
 
void speck_convert_diff_trail_to_differentials (const uint32_t nrounds, const differential_3d_t trail[SPECK_TRAIL_LEN], differential_t diff_arr[SPECK_TRAIL_LEN], WORD_T *delta_L, WORD_T *delta_R)
 
void speck_compute_next_alpha_beta (const WORD_T beta_in, const WORD_T gamma_in, WORD_T *alpha_next, WORD_T *beta_next)
 
void speck_compute_prev_gamma_beta (const WORD_T alpha_in, const WORD_T beta_in, WORD_T *gamma_prev, WORD_T *beta_prev)
 
void test_speck_best_diff_search_full ()
 
void test_xdp_add_lm ()
 
void test_xdp_add_monotonous_decrease ()
 
void test_mask ()
 
int main ()
 

Variables

double g_Bn = g_best_B[NROUNDS - 1] * EPS
 
differential_3d_t g_T [NROUNDS] = {{0, 0, 0, 0.0, LOG0}}
 
differential_3d_t g_best_T [NROUNDS] = {{0, 0, 0, 0.0, LOG0}}
 
const uint32_t g_r1 = SPECK_RIGHT_ROT_CONST_16BITS % WORD_SIZE
 
const uint32_t g_r2 = SPECK_LEFT_ROT_CONST_16BITS % WORD_SIZE
 
int g_Bn_log2 = g_best_B_log2[NROUNDS - 1]
 

Detailed Description

Tests for automatic search for the best XOR differential trail 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-2015

Macro Definition Documentation

#define UPDATE_BOUND   false

If UPDATE_BOUND is false then the algorithm will find ALL trails with probability (g_Bn * EPS) or higher.

Function Documentation

int main ( )

Main function.

void speck_add_diff_to_trail ( differential_3d_t  T[NROUNDS],
const uint32_t  i,
const differential_3d_t  new_diff 
)

Add new element at position i in the trail T

void speck_best_diff_search_full ( differential_3d_t  T_best[NROUNDS],
double *  p_best 
)

Full search for the best differential trail of block cipher SPECK (non-recursive).

Note
Feasible for up to 4 bit words and up to 5 rounds.
The complexity is 2^{(n+2) w}, where n is the total number of rounds and w is the word size. Therefore this function is exponential in the word size and in the number of rounds.
See Also
speck_xor_threshold_search_simple
void speck_best_diff_search_i ( const uint32_t  iround,
const uint32_t  ibit,
const WORD_T  alpha_in,
const WORD_T  beta_in,
const WORD_T  gamma_in 
)

Search for the best differential trail of block cipher SPECK.

Parameters
iroundcurrent round: $ 0 \ge r < NROUNDS$
ibitcurrent bit position
alphafirst input difference to the addition of round iround
betasecond input difference to the addition of round iround
gammaoutput difference from the addition of round iround
See Also
speck_xor_threshold_search_simple

If UPDATE_BOUND is false then the algorithm will find ALL trails with probability (g_Bn * EPS) or higher.

void speck_best_diff_search_log2_i ( const uint32_t  iround,
const uint32_t  ibit,
const WORD_T  alpha_in,
const WORD_T  beta_in,
const WORD_T  gamma_in 
)

Search for the best differential trail of block cipher SPECK using log base 2 probabilities.

Note
Same as speck_best_trail_search_i, but uses log base 2 probabilities. Therefore no multiplication is used and so this variant is more efficient.
Parameters
iroundcurrent round: $ 0 \ge r < NROUNDS$
ibitcurrent bit position
alphafirst input difference to the addition of round iround
betasecond input difference to the addition of round iround
gammaoutput difference from the addition of round iround

Credits: Yann Le Corre

See Also
speck_best_trail_search_i
void speck_convert_diff_trail_to_differentials ( const uint32_t  nrounds,
const differential_3d_t  trail[SPECK_TRAIL_LEN],
differential_t  diff_arr[SPECK_TRAIL_LEN],
WORD_T *  delta_L,
WORD_T *  delta_R 
)

Convert a trail as returned from speck_best_diff_search_i (= sequence of input and output differences from the modular addition) to a sequence of one round differentials (= sequences of one round input and output differences).

void speck_copy_diff_trail ( const differential_3d_t  from_T[NROUNDS],
differential_3d_t  to_T[NROUNDS] 
)

Copy trail from_T to to_T

void speck_init_diff_trail ( differential_3d_t  T[NROUNDS])

Print the trail T

void speck_print_diff_trail ( differential_3d_t  T[NROUNDS])

Print the trail T

void speck_print_diff_trail_cstyle ( differential_3d_t  T[NROUNDS])

Print the trail in C-style

See Also
speck_print_diff_trail
void speck_print_diff_trail_cstyle_log2 ( differential_3d_t  T[NROUNDS])

Print the trail in C-style with log2 probabilities

See Also
speck_print_diff_trail_cstyle
void speck_print_diff_trail_latex ( differential_3d_t  T[NROUNDS])

Print the trail in Latex-style

See Also
speck_print_diff_trail
void speck_print_diff_trail_latex_log2 ( differential_3d_t  T[NROUNDS])

Print the trail in Latex-style with log2 probabilities

See Also
speck_print_diff_trail_latex
void speck_print_diff_trail_log2 ( differential_3d_t  T[NROUNDS])

Print the trail T with log2 probabilities

void speck_print_differential ( differential_3d_t  T[NROUNDS])

Print the only the input and output diferences of trail T (i.e. the differential corresponding to T)

void speck_remove_diff_from_trail ( differential_3d_t  T[NROUNDS],
const uint32_t  i 
)

Remove element from position i in the trail T (sets differences and prob. to zero)

void test_xdp_add_monotonous_decrease ( )

Check that xdp is monotonously decreasing in the word size.