Go to the documentation of this file.
33 #if defined( INC_ALL )
36 #ifdef USE_VIA_ACE_IF_PRESENT
42 #ifdef USE_VIA_ACE_IF_PRESENT
47 #if defined(__cplusplus)
70 #if (FUNCS_IN_C & ENC_KEYING_IN_C)
72 #if defined(AES_128) || defined(AES_VAR)
75 { k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; \
76 k[4*(i)+5] = ss[1] ^= ss[0]; \
77 k[4*(i)+6] = ss[2] ^= ss[1]; \
78 k[4*(i)+7] = ss[3] ^= ss[2]; \
89 #if ENC_UNROLL == NONE
91 for(i = 0; i < 9; ++i)
97 ke4(cx->
ks, 2); ke4(cx->
ks, 3);
98 ke4(cx->
ks, 4); ke4(cx->
ks, 5);
99 ke4(cx->
ks, 6); ke4(cx->
ks, 7);
104 cx->
inf.
b[0] = 10 * 16;
106 #ifdef USE_VIA_ACE_IF_PRESENT
111 #if defined( AES_ERR_CHK )
118 #if defined(AES_192) || defined(AES_VAR)
121 { k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; \
122 k[6*(i)+ 7] = ss[1] ^= ss[0]; \
123 k[6*(i)+ 8] = ss[2] ^= ss[1]; \
124 k[6*(i)+ 9] = ss[3] ^= ss[2]; \
129 k[6*(i)+10] = ss[4] ^= ss[3]; \
130 k[6*(i)+11] = ss[5] ^= ss[4]; \
143 #if ENC_UNROLL == NONE
145 for(i = 0; i < 7; ++i)
149 ke6(cx->
ks, 0); ke6(cx->
ks, 1);
150 ke6(cx->
ks, 2); ke6(cx->
ks, 3);
151 ke6(cx->
ks, 4); ke6(cx->
ks, 5);
156 cx->
inf.
b[0] = 12 * 16;
158 #ifdef USE_VIA_ACE_IF_PRESENT
163 #if defined( AES_ERR_CHK )
170 #if defined(AES_256) || defined(AES_VAR)
173 { k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; \
174 k[8*(i)+ 9] = ss[1] ^= ss[0]; \
175 k[8*(i)+10] = ss[2] ^= ss[1]; \
176 k[8*(i)+11] = ss[3] ^= ss[2]; \
181 k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); \
182 k[8*(i)+13] = ss[5] ^= ss[4]; \
183 k[8*(i)+14] = ss[6] ^= ss[5]; \
184 k[8*(i)+15] = ss[7] ^= ss[6]; \
199 #if ENC_UNROLL == NONE
201 for(i = 0; i < 6; ++i)
205 ke8(cx->
ks, 0); ke8(cx->
ks, 1);
206 ke8(cx->
ks, 2); ke8(cx->
ks, 3);
207 ke8(cx->
ks, 4); ke8(cx->
ks, 5);
211 cx->
inf.
b[0] = 14 * 16;
213 #ifdef USE_VIA_ACE_IF_PRESENT
218 #if defined( AES_ERR_CHK )
231 #if defined( AES_ERR_CHK )
248 #if (FUNCS_IN_C & DEC_KEYING_IN_C)
254 #define v(n,i) ((n) - (i) + 2 * ((i) & 3))
259 #if DEC_ROUND == NO_TABLES
262 #define ff(x) inv_mcol(x)
263 #if defined( dec_imvars )
264 #define d_vars dec_imvars
268 #if defined(AES_128) || defined(AES_VAR)
271 { k[v(40,(4*(i))+4)] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; \
272 k[v(40,(4*(i))+5)] = ss[1] ^= ss[0]; \
273 k[v(40,(4*(i))+6)] = ss[2] ^= ss[1]; \
274 k[v(40,(4*(i))+7)] = ss[3] ^= ss[2]; \
280 { ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; \
281 ss[1] = ss[1] ^ ss[3]; \
282 ss[2] = ss[2] ^ ss[3]; \
283 ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; \
284 ss[i % 4] ^= ss[4]; \
285 ss[4] ^= k[v(40,(4*(i)))]; k[v(40,(4*(i))+4)] = ff(ss[4]); \
286 ss[4] ^= k[v(40,(4*(i))+1)]; k[v(40,(4*(i))+5)] = ff(ss[4]); \
287 ss[4] ^= k[v(40,(4*(i))+2)]; k[v(40,(4*(i))+6)] = ff(ss[4]); \
288 ss[4] ^= k[v(40,(4*(i))+3)]; k[v(40,(4*(i))+7)] = ff(ss[4]); \
292 { ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; \
293 ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \
294 k[v(40,(4*(i))+4)] = ss[4] ^= k[v(40,(4*(i)))]; \
295 k[v(40,(4*(i))+5)] = ss[4] ^= k[v(40,(4*(i))+1)]; \
296 k[v(40,(4*(i))+6)] = ss[4] ^= k[v(40,(4*(i))+2)]; \
297 k[v(40,(4*(i))+7)] = ss[4] ^= k[v(40,(4*(i))+3)]; \
301 { ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \
302 k[v(40,(4*(i))+4)] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; \
303 k[v(40,(4*(i))+5)] = ss[1] ^ ss[3]; \
304 k[v(40,(4*(i))+6)] = ss[0]; \
305 k[v(40,(4*(i))+7)] = ss[1]; \
311 { ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[v(40,(4*(i))+ 4)] = ff(ss[0]); \
312 ss[1] ^= ss[0]; k[v(40,(4*(i))+ 5)] = ff(ss[1]); \
313 ss[2] ^= ss[1]; k[v(40,(4*(i))+ 6)] = ff(ss[2]); \
314 ss[3] ^= ss[2]; k[v(40,(4*(i))+ 7)] = ff(ss[3]); \
318 { ss[4] = ls_box(ss[3],3) ^ t_use(r,c)[i]; \
319 ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[v(40,(4*(i))+ 4)] = ss[4] ^= k[v(40,(4*(i)))]; \
320 ss[1] ^= ss[0]; k[v(40,(4*(i))+ 5)] = ss[4] ^= k[v(40,(4*(i))+ 1)]; \
321 ss[2] ^= ss[1]; k[v(40,(4*(i))+ 6)] = ss[4] ^= k[v(40,(4*(i))+ 2)]; \
322 ss[3] ^= ss[2]; k[v(40,(4*(i))+ 7)] = ss[4] ^= k[v(40,(4*(i))+ 3)]; \
326 { ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[v(40,(4*(i))+ 4)] = ss[0]; \
327 ss[1] ^= ss[0]; k[v(40,(4*(i))+ 5)] = ss[1]; \
328 ss[2] ^= ss[1]; k[v(40,(4*(i))+ 6)] = ss[2]; \
329 ss[3] ^= ss[2]; k[v(40,(4*(i))+ 7)] = ss[3]; \
336 #if defined( d_vars )
339 cx->
ks[v(40,(0))] = ss[0] =
word_in(key, 0);
340 cx->
ks[v(40,(1))] = ss[1] =
word_in(key, 1);
341 cx->
ks[v(40,(2))] = ss[2] =
word_in(key, 2);
342 cx->
ks[v(40,(3))] = ss[3] =
word_in(key, 3);
344 #if DEC_UNROLL == NONE
346 for(i = 0; i < 10; ++i)
348 #if !(DEC_ROUND == NO_TABLES)
356 kd4(cx->
ks, 2); kd4(cx->
ks, 3);
357 kd4(cx->
ks, 4); kd4(cx->
ks, 5);
358 kd4(cx->
ks, 6); kd4(cx->
ks, 7);
359 kd4(cx->
ks, 8); kdl4(cx->
ks, 9);
362 cx->
inf.
b[0] = 10 * 16;
364 #ifdef USE_VIA_ACE_IF_PRESENT
369 #if defined( AES_ERR_CHK )
376 #if defined(AES_192) || defined(AES_VAR)
379 { k[v(48,(6*(i))+ 6)] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; \
380 k[v(48,(6*(i))+ 7)] = ss[1] ^= ss[0]; \
381 k[v(48,(6*(i))+ 8)] = ss[2] ^= ss[1]; \
382 k[v(48,(6*(i))+ 9)] = ss[3] ^= ss[2]; \
387 k[v(48,(6*(i))+10)] = ss[4] ^= ss[3]; \
388 k[v(48,(6*(i))+11)] = ss[5] ^= ss[4]; \
392 { ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[v(48,(6*(i))+ 6)] = ff(ss[0]); \
393 ss[1] ^= ss[0]; k[v(48,(6*(i))+ 7)] = ff(ss[1]); \
394 ss[2] ^= ss[1]; k[v(48,(6*(i))+ 8)] = ff(ss[2]); \
395 ss[3] ^= ss[2]; k[v(48,(6*(i))+ 9)] = ff(ss[3]); \
396 ss[4] ^= ss[3]; k[v(48,(6*(i))+10)] = ff(ss[4]); \
397 ss[5] ^= ss[4]; k[v(48,(6*(i))+11)] = ff(ss[5]); \
401 { ss[6] = ls_box(ss[5],3) ^ t_use(r,c)[i]; \
402 ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[v(48,(6*(i))+ 6)] = ss[6] ^= k[v(48,(6*(i)))]; \
403 ss[1] ^= ss[0]; k[v(48,(6*(i))+ 7)] = ss[6] ^= k[v(48,(6*(i))+ 1)]; \
404 ss[2] ^= ss[1]; k[v(48,(6*(i))+ 8)] = ss[6] ^= k[v(48,(6*(i))+ 2)]; \
405 ss[3] ^= ss[2]; k[v(48,(6*(i))+ 9)] = ss[6] ^= k[v(48,(6*(i))+ 3)]; \
406 ss[4] ^= ss[3]; k[v(48,(6*(i))+10)] = ss[6] ^= k[v(48,(6*(i))+ 4)]; \
407 ss[5] ^= ss[4]; k[v(48,(6*(i))+11)] = ss[6] ^= k[v(48,(6*(i))+ 5)]; \
411 { ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[v(48,(6*(i))+ 6)] = ss[0]; \
412 ss[1] ^= ss[0]; k[v(48,(6*(i))+ 7)] = ss[1]; \
413 ss[2] ^= ss[1]; k[v(48,(6*(i))+ 8)] = ss[2]; \
414 ss[3] ^= ss[2]; k[v(48,(6*(i))+ 9)] = ss[3]; \
419 #if defined( d_vars )
422 cx->
ks[v(48,(0))] = ss[0] =
word_in(key, 0);
423 cx->
ks[v(48,(1))] = ss[1] =
word_in(key, 1);
424 cx->
ks[v(48,(2))] = ss[2] =
word_in(key, 2);
425 cx->
ks[v(48,(3))] = ss[3] =
word_in(key, 3);
427 #if DEC_UNROLL == NONE
428 cx->
ks[v(48,(4))] = ss[4] =
word_in(key, 4);
429 cx->
ks[v(48,(5))] = ss[5] =
word_in(key, 5);
432 for(i = 0; i < 7; ++i)
435 #if !(DEC_ROUND == NO_TABLES)
436 for(i = N_COLS; i < 12 *
N_COLS; ++i)
441 cx->
ks[v(48,(4))] = ff(ss[4] =
word_in(key, 4));
442 cx->
ks[v(48,(5))] = ff(ss[5] =
word_in(key, 5));
443 kdf6(cx->
ks, 0); kd6(cx->
ks, 1);
444 kd6(cx->
ks, 2); kd6(cx->
ks, 3);
445 kd6(cx->
ks, 4); kd6(cx->
ks, 5);
446 kd6(cx->
ks, 6); kdl6(cx->
ks, 7);
449 cx->
inf.
b[0] = 12 * 16;
451 #ifdef USE_VIA_ACE_IF_PRESENT
456 #if defined( AES_ERR_CHK )
463 #if defined(AES_256) || defined(AES_VAR)
466 { k[v(56,(8*(i))+ 8)] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; \
467 k[v(56,(8*(i))+ 9)] = ss[1] ^= ss[0]; \
468 k[v(56,(8*(i))+10)] = ss[2] ^= ss[1]; \
469 k[v(56,(8*(i))+11)] = ss[3] ^= ss[2]; \
474 k[v(56,(8*(i))+12)] = ss[4] ^= ls_box(ss[3],0); \
475 k[v(56,(8*(i))+13)] = ss[5] ^= ss[4]; \
476 k[v(56,(8*(i))+14)] = ss[6] ^= ss[5]; \
477 k[v(56,(8*(i))+15)] = ss[7] ^= ss[6]; \
481 { ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[v(56,(8*(i))+ 8)] = ff(ss[0]); \
482 ss[1] ^= ss[0]; k[v(56,(8*(i))+ 9)] = ff(ss[1]); \
483 ss[2] ^= ss[1]; k[v(56,(8*(i))+10)] = ff(ss[2]); \
484 ss[3] ^= ss[2]; k[v(56,(8*(i))+11)] = ff(ss[3]); \
485 ss[4] ^= ls_box(ss[3],0); k[v(56,(8*(i))+12)] = ff(ss[4]); \
486 ss[5] ^= ss[4]; k[v(56,(8*(i))+13)] = ff(ss[5]); \
487 ss[6] ^= ss[5]; k[v(56,(8*(i))+14)] = ff(ss[6]); \
488 ss[7] ^= ss[6]; k[v(56,(8*(i))+15)] = ff(ss[7]); \
492 { ss[8] = ls_box(ss[7],3) ^ t_use(r,c)[i]; \
493 ss[0] ^= ss[8]; ss[8] = ff(ss[8]); k[v(56,(8*(i))+ 8)] = ss[8] ^= k[v(56,(8*(i)))]; \
494 ss[1] ^= ss[0]; k[v(56,(8*(i))+ 9)] = ss[8] ^= k[v(56,(8*(i))+ 1)]; \
495 ss[2] ^= ss[1]; k[v(56,(8*(i))+10)] = ss[8] ^= k[v(56,(8*(i))+ 2)]; \
496 ss[3] ^= ss[2]; k[v(56,(8*(i))+11)] = ss[8] ^= k[v(56,(8*(i))+ 3)]; \
497 ss[8] = ls_box(ss[3],0); \
498 ss[4] ^= ss[8]; ss[8] = ff(ss[8]); k[v(56,(8*(i))+12)] = ss[8] ^= k[v(56,(8*(i))+ 4)]; \
499 ss[5] ^= ss[4]; k[v(56,(8*(i))+13)] = ss[8] ^= k[v(56,(8*(i))+ 5)]; \
500 ss[6] ^= ss[5]; k[v(56,(8*(i))+14)] = ss[8] ^= k[v(56,(8*(i))+ 6)]; \
501 ss[7] ^= ss[6]; k[v(56,(8*(i))+15)] = ss[8] ^= k[v(56,(8*(i))+ 7)]; \
505 { ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[v(56,(8*(i))+ 8)] = ss[0]; \
506 ss[1] ^= ss[0]; k[v(56,(8*(i))+ 9)] = ss[1]; \
507 ss[2] ^= ss[1]; k[v(56,(8*(i))+10)] = ss[2]; \
508 ss[3] ^= ss[2]; k[v(56,(8*(i))+11)] = ss[3]; \
513 #if defined( d_vars )
516 cx->
ks[v(56,(0))] = ss[0] =
word_in(key, 0);
517 cx->
ks[v(56,(1))] = ss[1] =
word_in(key, 1);
518 cx->
ks[v(56,(2))] = ss[2] =
word_in(key, 2);
519 cx->
ks[v(56,(3))] = ss[3] =
word_in(key, 3);
521 #if DEC_UNROLL == NONE
522 cx->
ks[v(56,(4))] = ss[4] =
word_in(key, 4);
523 cx->
ks[v(56,(5))] = ss[5] =
word_in(key, 5);
524 cx->
ks[v(56,(6))] = ss[6] =
word_in(key, 6);
525 cx->
ks[v(56,(7))] = ss[7] =
word_in(key, 7);
528 for(i = 0; i < 6; ++i)
531 #if !(DEC_ROUND == NO_TABLES)
532 for(i = N_COLS; i < 14 *
N_COLS; ++i)
538 cx->
ks[v(56,(4))] = ff(ss[4] =
word_in(key, 4));
539 cx->
ks[v(56,(5))] = ff(ss[5] =
word_in(key, 5));
540 cx->
ks[v(56,(6))] = ff(ss[6] =
word_in(key, 6));
541 cx->
ks[v(56,(7))] = ff(ss[7] =
word_in(key, 7));
542 kdf8(cx->
ks, 0); kd8(cx->
ks, 1);
543 kd8(cx->
ks, 2); kd8(cx->
ks, 3);
544 kd8(cx->
ks, 4); kd8(cx->
ks, 5);
548 cx->
inf.
b[0] = 14 * 16;
550 #ifdef USE_VIA_ACE_IF_PRESENT
555 #if defined( AES_ERR_CHK )
568 #if defined( AES_ERR_CHK )
585 #if defined(__cplusplus)