1 | /* |
2 | The Keccak sponge function, designed by Guido Bertoni, Joan Daemen, |
3 | Michaƫl Peeters and Gilles Van Assche. For more information, feedback or |
4 | questions, please refer to our website: http://keccak.noekeon.org/ |
5 | |
6 | Implementation by the designers, |
7 | hereby denoted as "the implementer". |
8 | |
9 | To the extent possible under law, the implementer has waived all copyright |
10 | and related or neighboring rights to the source code in this file. |
11 | http://creativecommons.org/publicdomain/zero/1.0/ |
12 | */ |
13 | |
14 | #if (Unrolling == 24) |
15 | #define rounds \ |
16 | prepareTheta \ |
17 | thetaRhoPiChiIotaPrepareTheta( 0, A, E) \ |
18 | thetaRhoPiChiIotaPrepareTheta( 1, E, A) \ |
19 | thetaRhoPiChiIotaPrepareTheta( 2, A, E) \ |
20 | thetaRhoPiChiIotaPrepareTheta( 3, E, A) \ |
21 | thetaRhoPiChiIotaPrepareTheta( 4, A, E) \ |
22 | thetaRhoPiChiIotaPrepareTheta( 5, E, A) \ |
23 | thetaRhoPiChiIotaPrepareTheta( 6, A, E) \ |
24 | thetaRhoPiChiIotaPrepareTheta( 7, E, A) \ |
25 | thetaRhoPiChiIotaPrepareTheta( 8, A, E) \ |
26 | thetaRhoPiChiIotaPrepareTheta( 9, E, A) \ |
27 | thetaRhoPiChiIotaPrepareTheta(10, A, E) \ |
28 | thetaRhoPiChiIotaPrepareTheta(11, E, A) \ |
29 | thetaRhoPiChiIotaPrepareTheta(12, A, E) \ |
30 | thetaRhoPiChiIotaPrepareTheta(13, E, A) \ |
31 | thetaRhoPiChiIotaPrepareTheta(14, A, E) \ |
32 | thetaRhoPiChiIotaPrepareTheta(15, E, A) \ |
33 | thetaRhoPiChiIotaPrepareTheta(16, A, E) \ |
34 | thetaRhoPiChiIotaPrepareTheta(17, E, A) \ |
35 | thetaRhoPiChiIotaPrepareTheta(18, A, E) \ |
36 | thetaRhoPiChiIotaPrepareTheta(19, E, A) \ |
37 | thetaRhoPiChiIotaPrepareTheta(20, A, E) \ |
38 | thetaRhoPiChiIotaPrepareTheta(21, E, A) \ |
39 | thetaRhoPiChiIotaPrepareTheta(22, A, E) \ |
40 | thetaRhoPiChiIota(23, E, A) \ |
41 | copyToState(state, A) |
42 | #elif (Unrolling == 12) |
43 | #define rounds \ |
44 | prepareTheta \ |
45 | for(i=0; i<24; i+=12) { \ |
46 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
47 | thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \ |
48 | thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \ |
49 | thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \ |
50 | thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \ |
51 | thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \ |
52 | thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \ |
53 | thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \ |
54 | thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \ |
55 | thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \ |
56 | thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \ |
57 | thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \ |
58 | } \ |
59 | copyToState(state, A) |
60 | #elif (Unrolling == 8) |
61 | #define rounds \ |
62 | prepareTheta \ |
63 | for(i=0; i<24; i+=8) { \ |
64 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
65 | thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ |
66 | thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ |
67 | thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ |
68 | thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ |
69 | thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ |
70 | thetaRhoPiChiIotaPrepareTheta(i+6, A, E) \ |
71 | thetaRhoPiChiIotaPrepareTheta(i+7, E, A) \ |
72 | } \ |
73 | copyToState(state, A) |
74 | #elif (Unrolling == 6) |
75 | #define rounds \ |
76 | prepareTheta \ |
77 | for(i=0; i<24; i+=6) { \ |
78 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
79 | thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ |
80 | thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ |
81 | thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ |
82 | thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \ |
83 | thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \ |
84 | } \ |
85 | copyToState(state, A) |
86 | #elif (Unrolling == 4) |
87 | #define rounds \ |
88 | prepareTheta \ |
89 | for(i=0; i<24; i+=4) { \ |
90 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
91 | thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ |
92 | thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ |
93 | thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \ |
94 | } \ |
95 | copyToState(state, A) |
96 | #elif (Unrolling == 3) |
97 | #define rounds \ |
98 | prepareTheta \ |
99 | for(i=0; i<24; i+=3) { \ |
100 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
101 | thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ |
102 | thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \ |
103 | copyStateVariables(A, E) \ |
104 | } \ |
105 | copyToState(state, A) |
106 | #elif (Unrolling == 2) |
107 | #define rounds \ |
108 | prepareTheta \ |
109 | for(i=0; i<24; i+=2) { \ |
110 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
111 | thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \ |
112 | } \ |
113 | copyToState(state, A) |
114 | #elif (Unrolling == 1) |
115 | #define rounds \ |
116 | prepareTheta \ |
117 | for(i=0; i<24; i++) { \ |
118 | thetaRhoPiChiIotaPrepareTheta(i , A, E) \ |
119 | copyStateVariables(A, E) \ |
120 | } \ |
121 | copyToState(state, A) |
122 | #else |
123 | #error "Unrolling is not correctly specified!" |
124 | #endif |
125 | |