YAARX: Yet Another ARX Toolkit  0.1
 All Data Structures Files Functions Variables Macros Pages
salsa.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 Luxembourg University,
3  * Laboratory of Algorithmics, Cryptology and Security (LACS).
4  *
5  * This file is part of the YAARX toolkit. YAARX stands for
6  * Yet Another ARX toolkit for analysis of ARX cryptographic algorithms.
7  *
8  * YAARX is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * YAARX is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with YAARX. If not, see <http://www.gnu.org/licenses/>.
20  */
27 #ifndef SALSA_H
28 #define SALSA_H
29 
30 #define MAX_NROUNDS 20
31 
35 #define SALSA_FEED_FORWARD 0
36 
40 #define SALSA_RAND_ROT_CONST 0
41 
45 #define SALSA_STATE 16
46 
47 extern uint32_t E[SALSA_STATE + SALSA_STATE][5];
48 
49 void salsa20(const uint32_t e[SALSA_STATE + SALSA_STATE][5],
50  const uint32_t r_start, const uint32_t r_end,
51  const uint32_t X_in[SALSA_STATE], uint32_t Y_in[SALSA_STATE]);
52 
53 void salsa_gen_rand_input_state(uint32_t X[SALSA_STATE]);
54 
55 void salsa_print_state_uint32(const uint32_t X[SALSA_STATE]);
56 
57 void salsa_print_state_uint8(const uint8_t X[4 * SALSA_STATE]);
58 
59 void salsa_uint8_to_uint32(const uint8_t X[4], uint32_t* Y);
60 
61 void salsa_uint32_to_uint8(uint8_t X[4], const uint32_t Y);
62 
63 void salsa_state_uint8_to_uint32(const uint8_t X[4 * SALSA_STATE], uint32_t Y[SALSA_STATE]);
64 
65 void salsa_state_uint32_to_uint8(uint8_t X[4 * SALSA_STATE], const uint32_t Y[SALSA_STATE]);
66 
67 void salsa_print_trail(uint32_t nrounds, diff_set_t DT[MAX_NROUNDS][SALSA_STATE], double P[MAX_NROUNDS][SALSA_STATE]);
68 
69 void salsa_print_prob(double P[SALSA_STATE]);
70 
71 void salsa_print_prob_vs_rand(double P[SALSA_STATE], double P_rand[SALSA_STATE]);
72 
73 double xdp_add_dset_salsa20(const uint32_t e[SALSA_STATE + SALSA_STATE][5],
74  const uint32_t r_start, const uint32_t r_end, gsl_matrix* A[3][3][3],
75  const diff_set_t DX_in[SALSA_STATE], diff_set_t DY_in[SALSA_STATE],
76  diff_set_t DT[MAX_NROUNDS][SALSA_STATE], double P[MAX_NROUNDS][SALSA_STATE]);
77 
78 double xdp_add_dset_salsa20_exper(const uint32_t e[SALSA_STATE + SALSA_STATE][5],
79  const uint32_t r_start, const uint32_t r_end, uint32_t npairs,
80  const diff_set_t DX_set[SALSA_STATE], diff_set_t DY_set[SALSA_STATE],
81  double PW[SALSA_STATE]);
82 
84 
85 void salsa_gen_word_deps(const uint32_t nrounds,
86  const uint32_t e[SALSA_STATE + SALSA_STATE][5],
87  uint32_t dep[MAX_NROUNDS][SALSA_STATE]);
88 
89 void salsa_word_probs(const uint32_t nrounds,
90  const uint32_t e[SALSA_STATE + SALSA_STATE][5],
91  double PT[MAX_NROUNDS][SALSA_STATE],
92  uint32_t D[MAX_NROUNDS][SALSA_STATE],
93  double P[SALSA_STATE]);
94 
95 void salsa_word_probs_v2(const uint32_t r_start, const uint32_t r_end,
96  const uint32_t e[SALSA_STATE + SALSA_STATE][5],
97  double PT[MAX_NROUNDS][SALSA_STATE],
98  double P[SALSA_STATE]);
99 
100 void salsa_compute_prob_rand(const diff_set_t Y[SALSA_STATE], double P[SALSA_STATE]);
101 
102 double xdp_add_dset_salsa_arx(gsl_matrix* A[3][3][3],
103  diff_set_t dx,
104  diff_set_t dy,
105  diff_set_t dz,
106  diff_set_t* dt,
107  uint32_t k,
108  bool b_single_diff);
109 
110 #endif // #ifndef SALSA_H
void salsa_word_probs(const uint32_t nrounds, const uint32_t e[SALSA_STATE+SALSA_STATE][5], double PT[MAX_NROUNDS][SALSA_STATE], uint32_t D[MAX_NROUNDS][SALSA_STATE], double P[SALSA_STATE])
Definition: salsa.cc:614
void salsa_gen_rand_shift_const(uint32_t E[SALSA_STATE+SALSA_STATE][5])
Definition: salsa.cc:507
void salsa_gen_rand_input_state(uint32_t X[SALSA_STATE])
Definition: salsa.cc:322
void salsa_print_state_uint32(const uint32_t X[SALSA_STATE])
Definition: salsa.cc:381
uint32_t E[SALSA_STATE+SALSA_STATE][5]
Definition: salsa.cc:50
void salsa_gen_word_deps(const uint32_t nrounds, const uint32_t e[SALSA_STATE+SALSA_STATE][5], uint32_t dep[MAX_NROUNDS][SALSA_STATE])
Definition: salsa.cc:573
void salsa_compute_prob_rand(const diff_set_t Y[SALSA_STATE], double P[SALSA_STATE])
Definition: salsa.cc:465
void salsa_print_state_uint8(const uint8_t X[4 *SALSA_STATE])
Definition: salsa.cc:395
#define SALSA_STATE
Definition: salsa.hh:45
Definition: xdp-add-diff-set.hh:68