33 #if defined( INC_ALL )
41 #if defined(__cplusplus)
46 #define si(y,x,k,c) (s(y,c) = word_in(x, c) ^ (k)[c])
47 #define so(y,x,c) word_out(y, c, s(x,c))
50 #define locals(y,x) x[4],y[4]
52 #define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3
55 #define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \
56 s(y,2) = s(x,2); s(y,3) = s(x,3);
57 #define state_in(y,x,k) si(y,x,k,0); si(y,x,k,1); si(y,x,k,2); si(y,x,k,3)
58 #define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)
59 #define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3)
61 #if ( FUNCS_IN_C & ENCRYPTION_IN_C )
68 #if defined( _MSC_VER ) && !defined( _WIN64 )
69 #pragma optimize( "s", on )
83 #define fwd_var(x,r,c)\
84 ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
85 : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\
86 : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
87 : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))
91 #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c))
92 #elif defined(FT1_SET)
94 #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(f,n),fwd_var,rf1,c))
96 #define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_use(s,box),fwd_var,rf1,c)))
100 #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,l),fwd_var,rf1,c))
101 #elif defined(FL1_SET)
102 #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(f,l),fwd_var,rf1,c))
104 #define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(s,box),fwd_var,rf1,c))
108 { uint_32t
locals(b0, b1);
110 #if defined( dec_fmvars )
114 #if defined( AES_ERR_CHK )
115 if( cx->
inf.
b[0] != 10 * 16 && cx->
inf.
b[0] != 12 * 16 && cx->
inf.
b[0] != 14 * 16 )
122 #if (ENC_UNROLL == FULL)
149 #if (ENC_UNROLL == PARTIAL)
151 for(rnd = 0; rnd < (cx->
inf.
b[0] >> 5) - 1; ++rnd)
154 round(fwd_rnd, b1, b0, kp);
156 round(fwd_rnd, b0, b1, kp);
159 round(fwd_rnd, b1, b0, kp);
162 for(rnd = 0; rnd < (cx->
inf.
b[0] >> 4) - 1; ++rnd)
165 round(fwd_rnd, b1, b0, kp);
170 round(fwd_lrnd, b0, b1, kp);
176 #if defined( AES_ERR_CHK )
183 #if ( FUNCS_IN_C & DECRYPTION_IN_C)
190 #if defined( _MSC_VER ) && !defined( _WIN64 )
191 #pragma optimize( "t", on )
205 #define inv_var(x,r,c)\
206 ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
207 : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\
208 : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
209 : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0)))
213 #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,n),inv_var,rf1,c))
214 #elif defined(IT1_SET)
216 #define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_use(i,n),inv_var,rf1,c))
218 #define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c)))
222 #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(i,l),inv_var,rf1,c))
223 #elif defined(IL1_SET)
224 #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_use(i,l),inv_var,rf1,c))
226 #define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_use(i,box),inv_var,rf1,c))
238 #define rnd_key(n) (kp + n * N_COLS)
241 #define rnd_key(n) (kp - n * N_COLS)
245 { uint_32t
locals(b0, b1);
246 #if defined( dec_imvars )
251 #if defined( AES_ERR_CHK )
252 if( cx->
inf.
b[0] != 10 * 16 && cx->
inf.
b[0] != 12 * 16 && cx->
inf.
b[0] != 14 * 16 )
256 kp = cx->
ks + (key_ofs ? (cx->
inf.
b[0] >> 2) : 0);
259 #if (DEC_UNROLL == FULL)
261 kp = cx->
ks + (key_ofs ? 0 : (cx->
inf.
b[0] >> 2));
265 round(inv_rnd, b1, b0, rnd_key(-13));
266 round(inv_rnd, b0, b1, rnd_key(-12));
268 round(inv_rnd, b1, b0, rnd_key(-11));
269 round(inv_rnd, b0, b1, rnd_key(-10));
271 round(inv_rnd, b1, b0, rnd_key(-9));
272 round(inv_rnd, b0, b1, rnd_key(-8));
273 round(inv_rnd, b1, b0, rnd_key(-7));
274 round(inv_rnd, b0, b1, rnd_key(-6));
275 round(inv_rnd, b1, b0, rnd_key(-5));
276 round(inv_rnd, b0, b1, rnd_key(-4));
277 round(inv_rnd, b1, b0, rnd_key(-3));
278 round(inv_rnd, b0, b1, rnd_key(-2));
279 round(inv_rnd, b1, b0, rnd_key(-1));
280 round(inv_lrnd, b0, b1, rnd_key( 0));
285 #if (DEC_UNROLL == PARTIAL)
287 for(rnd = 0; rnd < (cx->
inf.
b[0] >> 5) - 1; ++rnd)
290 round(inv_rnd, b1, b0, kp);
292 round(inv_rnd, b0, b1, kp);
295 round(inv_rnd, b1, b0, kp);
298 for(rnd = 0; rnd < (cx->
inf.
b[0] >> 4) - 1; ++rnd)
301 round(inv_rnd, b1, b0, kp);
306 round(inv_lrnd, b0, b1, kp);
312 #if defined( AES_ERR_CHK )
319 #if defined(__cplusplus)