159 #if defined( __CRYPTLIB__ ) && !defined( INC_ALL ) && !defined( INC_CHILD ) 160 #include "crypt/aes.h" 165 #if defined(__GNUC__) || defined(__GNU_LIBRARY__) 167 # include <byteswap.h> 168 #elif defined(__CRYPTLIB__) 169 # if defined( INC_ALL ) 171 # elif defined( INC_CHILD ) 172 # include "../crypt.h" 176 # if defined(DATA_LITTLEENDIAN) 177 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 179 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 181 #elif defined(_MSC_VER) 183 #elif !defined(WIN32) 185 # if !defined (_ENDIAN_H) 186 # include <sys/param.h> 201 #define AES_LITTLE_ENDIAN 1234 202 #define AES_BIG_ENDIAN 4321 204 #if !defined(PLATFORM_BYTE_ORDER) 205 #if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN) 206 # if defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) 207 # if defined(BYTE_ORDER) 208 # if (BYTE_ORDER == LITTLE_ENDIAN) 209 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 210 # elif (BYTE_ORDER == BIG_ENDIAN) 211 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 214 # elif defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN) 215 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 216 # elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) 217 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 219 #elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN) 220 # if defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) 221 # if defined(_BYTE_ORDER) 222 # if (_BYTE_ORDER == _LITTLE_ENDIAN) 223 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 224 # elif (_BYTE_ORDER == _BIG_ENDIAN) 225 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 228 # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) 229 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 230 # elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN) 231 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 234 #define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 236 #define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 237 #elif (('1234' >> 24) == '1') 238 # define PLATFORM_BYTE_ORDER AES_LITTLE_ENDIAN 239 #elif (('4321' >> 24) == '1') 240 # define PLATFORM_BYTE_ORDER AES_BIG_ENDIAN 244 #if !defined(PLATFORM_BYTE_ORDER) 245 # error Please set undetermined byte order (lines 233 or 235 of aesopt.h). 254 #define ENCRYPTION_KEY_SCHEDULE 255 #define DECRYPTION_KEY_SCHEDULE 267 #define ENCRYPTION_KEY_SCHEDULE 271 #define DECRYPTION_KEY_SCHEDULE 312 #define INTERNAL_BYTE_ORDER PLATFORM_BYTE_ORDER 313 #elif defined(AES_LITTLE_ENDIAN) 314 #define INTERNAL_BYTE_ORDER AES_LITTLE_ENDIAN 315 #elif defined(AES_BIG_ENDIAN) 316 #define INTERNAL_BYTE_ORDER AES_BIG_ENDIAN 351 #define ENC_UNROLL FULL 353 #define ENC_UNROLL PARTIAL 355 #define ENC_UNROLL NONE 359 #define DEC_UNROLL FULL 361 #define DEC_UNROLL PARTIAL 363 #define DEC_UNROLL NONE 420 #define FAST_VARIABLE 444 #define ENC_ROUND FOUR_TABLES 446 #define ENC_ROUND ONE_TABLE 448 #define ENC_ROUND NO_TABLES 452 #define LAST_ENC_ROUND FOUR_TABLES 454 #define LAST_ENC_ROUND ONE_TABLE 456 #define LAST_ENC_ROUND NO_TABLES 460 #define DEC_ROUND FOUR_TABLES 462 #define DEC_ROUND ONE_TABLE 464 #define DEC_ROUND NO_TABLES 468 #define LAST_DEC_ROUND FOUR_TABLES 470 #define LAST_DEC_ROUND ONE_TABLE 472 #define LAST_DEC_ROUND NO_TABLES 480 #define KEY_SCHED FOUR_TABLES 482 #define KEY_SCHED ONE_TABLE 484 #define KEY_SCHED NO_TABLES 491 #define FOUR_TABLES 4 496 #if defined(AES_BLOCK_SIZE) && ((AES_BLOCK_SIZE & 3) || AES_BLOCK_SIZE < 16 || AES_BLOCK_SIZE > 32) 497 #error An illegal block size has been specified. 500 #if !defined(AES_BLOCK_SIZE) 503 #define RC_LENGTH 5 * AES_BLOCK_SIZE / 4 - (AES_BLOCK_SIZE == 16 ? 10 : 11) 508 #if ENC_ROUND == NO_TABLES && LAST_ENC_ROUND != NO_TABLES 509 #undef LAST_ENC_ROUND 510 #define LAST_ENC_ROUND NO_TABLES 511 #elif ENC_ROUND == ONE_TABLE && LAST_ENC_ROUND == FOUR_TABLES 512 #undef LAST_ENC_ROUND 513 #define LAST_ENC_ROUND ONE_TABLE 516 #if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE 518 #define ENC_UNROLL NONE 521 #if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES 522 #undef LAST_DEC_ROUND 523 #define LAST_DEC_ROUND NO_TABLES 524 #elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES 525 #undef LAST_DEC_ROUND 526 #define LAST_DEC_ROUND ONE_TABLE 529 #if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE 531 #define DEC_UNROLL NONE 545 #if (INTERNAL_BYTE_ORDER == AES_LITTLE_ENDIAN) 546 #if defined(_MSC_VER) 547 #define upr(x,n) _lrotl((aes_32t)(x), 8 * (n)) 549 #define upr(x,n) ((aes_32t)(x) << 8 * (n) | (aes_32t)(x) >> 32 - 8 * (n)) 551 #define ups(x,n) ((aes_32t)(x) << 8 * (n)) 552 #define bval(x,n) ((aes_08t)((x) >> 8 * (n))) 553 #define bytes2word(b0, b1, b2, b3) \ 554 (((aes_32t)(b3) << 24) | ((aes_32t)(b2) << 16) | ((aes_32t)(b1) << 8) | (b0)) 557 #if (INTERNAL_BYTE_ORDER == AES_BIG_ENDIAN) 558 #define upr(x,n) ((aes_32t)(x) >> 8 * (n) | (aes_32t)(x) << 32 - 8 * (n)) 559 #define ups(x,n) ((aes_32t)(x) >> 8 * (n))) 560 #define bval(x,n) ((aes_08t)((x) >> 24 - 8 * (n))) 561 #define bytes2word(b0, b1, b2, b3) \ 562 (((aes_32t)(b0) << 24) | ((aes_32t)(b1) << 16) | ((aes_32t)(b2) << 8) | (b3)) 567 #define word_in(x) bytes2word((x)[0], (x)[1], (x)[2], (x)[3]) 568 #define word_out(x,v) { (x)[0] = bval(v,0); (x)[1] = bval(v,1); \ 569 (x)[2] = bval(v,2); (x)[3] = bval(v,3); } 571 #elif (INTERNAL_BYTE_ORDER == PLATFORM_BYTE_ORDER) 573 #define word_in(x) *(aes_32t*)(x) 574 #define word_out(x,v) *(aes_32t*)(x) = (v) 578 #if !defined(bswap_32) 579 #if !defined(_MSC_VER) 580 #define _lrotl(x,n) ((aes_32t)(x) << n | (aes_32t)(x) >> 32 - n) 582 #define bswap_32(x) ((_lrotl((x),8) & 0x00ff00ff) | (_lrotl((x),24) & 0xff00ff00)) 585 #define word_in(x) bswap_32(*(aes_32t*)(x)) 586 #define word_out(x,v) *(aes_32t*)(x) = bswap_32(v) 597 #define m1 0x80808080 598 #define m2 0x7f7f7f7f 599 #define FFmulX(x) ((((x) & m2) << 1) ^ ((((x) & m1) >> 7) * BPOLY)) 616 #define ENC_ROUND FOUR_TABLES 617 #ifdef LAST_ENC_ROUND 618 #undef LAST_ENC_ROUND 620 #define LAST_ENC_ROUND FOUR_TABLES 624 #define DEC_ROUND FOUR_TABLES 625 #ifdef LAST_DEC_ROUND 626 #undef LAST_DEC_ROUND 628 #define LAST_DEC_ROUND FOUR_TABLES 631 #define KEY_SCHED FOUR_TABLES 635 #if defined(ENCRYPTION) || defined(AES_ASM) 636 #if ENC_ROUND == ONE_TABLE 638 #elif ENC_ROUND == FOUR_TABLES 643 #if LAST_ENC_ROUND == ONE_TABLE 645 #elif LAST_ENC_ROUND == FOUR_TABLES 647 #elif !defined(SBX_SET) 652 #if defined(DECRYPTION) || defined(AES_ASM) 653 #if DEC_ROUND == ONE_TABLE 655 #elif DEC_ROUND == FOUR_TABLES 660 #if LAST_DEC_ROUND == ONE_TABLE 662 #elif LAST_DEC_ROUND == FOUR_TABLES 664 #elif !defined(ISB_SET) 669 #if defined(ENCRYPTION_KEY_SCHEDULE) || defined(DECRYPTION_KEY_SCHEDULE) 670 #if KEY_SCHED == ONE_TABLE 673 #elif KEY_SCHED == FOUR_TABLES 676 #elif !defined(SBX_SET) 682 #define prefx extern const 685 extern aes_08t tab_init;
692 prefx aes_08t s_box[256];
696 prefx aes_08t inv_s_box[256];
735 prefx aes_32t ls_tab[256];
743 prefx aes_32t ls_tab[4][256];
760 #if defined(AES_BLOCK_SIZE) 761 #define nc (AES_BLOCK_SIZE >> 2) 763 #define nc (cx->n_blk >> 2) 768 #define no_table(x,box,vf,rf,c) bytes2word( \ 769 box[bval(vf(x,0,c),rf(0,c))], \ 770 box[bval(vf(x,1,c),rf(1,c))], \ 771 box[bval(vf(x,2,c),rf(2,c))], \ 772 box[bval(vf(x,3,c),rf(3,c))]) 774 #define one_table(x,op,tab,vf,rf,c) \ 775 ( tab[bval(vf(x,0,c),rf(0,c))] \ 776 ^ op(tab[bval(vf(x,1,c),rf(1,c))],1) \ 777 ^ op(tab[bval(vf(x,2,c),rf(2,c))],2) \ 778 ^ op(tab[bval(vf(x,3,c),rf(3,c))],3)) 780 #define four_tables(x,tab,vf,rf,c) \ 781 ( tab[0][bval(vf(x,0,c),rf(0,c))] \ 782 ^ tab[1][bval(vf(x,1,c),rf(1,c))] \ 783 ^ tab[2][bval(vf(x,2,c),rf(2,c))] \ 784 ^ tab[3][bval(vf(x,3,c),rf(3,c))]) 786 #define vf1(x,r,c) (x) 788 #define rf2(r,c) ((r-c)&3) 795 #define fwd_mcol(x) four_tables(x,fm_tab,vf1,rf1,0) 796 #elif defined(FM1_SET) 797 #define fwd_mcol(x) one_table(x,upr,fm_tab,vf1,rf1,0) 800 #define dec_fmvars aes_32t f1, f2; 801 #define fwd_mcol(x) (f1 = (x), f2 = FFmulX(f1), f2 ^ upr(f1 ^ f2, 3) ^ upr(f1, 2) ^ upr(f1, 1)) 806 #define inv_mcol(x) four_tables(x,im_tab,vf1,rf1,0) 807 #elif defined(IM1_SET) 808 #define inv_mcol(x) one_table(x,upr,im_tab,vf1,rf1,0) 811 #define dec_imvars aes_32t f2, f4, f8, f9; 812 #define inv_mcol(x) \ 813 (f9 = (x), f2 = FFmulX(f9), f4 = FFmulX(f2), f8 = FFmulX(f4), f9 ^= f8, \ 814 f2 ^= f4 ^ f8 ^ upr(f2 ^ f9,3) ^ upr(f4 ^ f9,2) ^ upr(f9,1)) 818 #define ls_box(x,c) four_tables(x,fl_tab,vf1,rf2,c) 819 #elif defined(LS4_SET) 820 #define ls_box(x,c) four_tables(x,ls_tab,vf1,rf2,c) 821 #elif defined(FL1_SET) 822 #define ls_box(x,c) one_table(x,upr,fl_tab,vf1,rf2,c) 823 #elif defined(LS1_SET) 824 #define ls_box(x,c) one_table(x,upr,ls_tab,vf1,rf2,c) 826 #define ls_box(x,c) no_table(x,s_box,vf1,rf2,c) prefx aes_32t il_tab[4][256]
Definition: aesopt.h:728
prefx aes_32t ft_tab[4][256]
Definition: aesopt.h:704
prefx aes_32t it_tab[4][256]
Definition: aesopt.h:720
prefx aes_32t im_tab[4][256]
Definition: aesopt.h:752
#define prefx
Definition: aesopt.h:682
prefx aes_32t fl_tab[4][256]
Definition: aesopt.h:712
prefx aes_32t rcon_tab[29]
Definition: aesopt.h:689