.386

; void __stdcall aes_128_key_schedule(unsigned char key[176])
; void __stdcall aes_192_key_schedule(unsigned char key[208])
; void __stdcall aes_256_key_schedule(unsigned char key[240])
; void __stdcall aes_128_key_inverse(unsigned char key[176])
; void __stdcall aes_192_key_inverse(unsigned char key[208])
; void __stdcall aes_256_key_inverse(unsigned char key[240])
; void __stdcall aes_128_encrypt(unsigned char buffer[16], const unsigned char key[176])
; void __stdcall aes_192_encrypt(unsigned char buffer[16], const unsigned char key[208])
; void __stdcall aes_256_encrypt(unsigned char buffer[16], const unsigned char key[240])
; void __stdcall aes_128_decrypt(unsigned char buffer[16], const unsigned char key[176])
; void __stdcall aes_192_decrypt(unsigned char buffer[16], const unsigned char key[208])
; void __stdcall aes_256_decrypt(unsigned char buffer[16], const unsigned char key[240])

PUBLIC _aes_128_key_schedule@4, _aes_128_key_inverse@4, _aes_128_encrypt@8, _aes_128_decrypt@8
PUBLIC _aes_192_key_schedule@4, _aes_192_key_inverse@4, _aes_192_encrypt@8, _aes_192_decrypt@8
PUBLIC _aes_256_key_schedule@4, _aes_256_key_inverse@4, _aes_256_encrypt@8, _aes_256_decrypt@8

_TEXT SEGMENT DWORD EXECUTE READ FLAT ALIAS('.text') 'CODE'
ASSUME CS:FLAT, DS:FLAT, ES:FLAT, SS:FLAT

invmatrix1 dd          0,  185403662,  370807324,  488053522,  741614648,  658058550,  976107044,  824393514, 1483229296, 1399144830, 1316117100, 1165972322, 1952214088, 2136040774, 1648787028, 1766553434
           dd 2966458592, 3151862254, 2798289660, 2915535858, 2632234200, 2548678102, 2331944644, 2180231114, 3904428176, 3820343710, 4272081548, 4121936770, 3297574056, 3481400742, 3533106868, 3650873274
           dd 2075868123, 1890988757, 1839278535, 1722556617, 1468997603, 1552029421, 1100287487, 1251476721,  601060267,  685669029,  902390199, 1053059257,  266819475,   82468509,  436028815,  317738113
           dd 3412831035, 3227951669, 3715217703, 3598495785, 3881799427, 3964831245, 4047871263, 4199060497, 2466505547, 2551114309, 2233069911, 2383738969, 3208103795, 3023752829, 2838353263, 2720062561
           dd 4134368941, 4250959779, 3765920945, 3950669247, 3663286933, 3511966619, 3426959497, 3343796615, 2919579357, 2768779219, 3089050817, 3004310991, 2184256229, 2302415851, 2485848313, 2670068215
           dd 1186850381, 1303441219, 1353184337, 1537932639, 1787413109, 1636092795, 2090061929, 2006899047,  517320253,  366520115,  147831841,   63092015,  853641733,  971801355,  620468249,  804688151
           dd 2379631990, 2262516856, 2613862250, 2428589668, 2715969870, 2867814464, 3086515026, 3170202204, 3586000134, 3736275976, 3282310938, 3366526484, 4186579262, 4068943920, 4019204898, 3835509292
           dd 1023860118,  906744984,  723308426,  538035844,  288553390,  440397984,  120122290,  203809468, 1701746150, 1852021992, 1937016826, 2021232372, 1230680542, 1113045200, 1598071746, 1414376140
           dd 4158319681, 4242007375, 3787521629, 3939366739, 3689859193, 3504587127, 3455375973, 3338261355, 2947720241, 2764025151, 3114841645, 2997206819, 2206629897, 2290845959, 2510066197, 2660342555
           dd 1191869601, 1275557295, 1360031421, 1511876531, 1799248025, 1613975959, 2099530373, 1982415755,  526529745,  342834655,  158869197,   41234371,  861278441,  945494503,  625738485,  776014843
           dd 2355222426, 2272059028, 2591802758, 2440481928, 2689987490, 2874735276, 3058688446, 3175278768, 3557400554, 3741619940, 3256061430, 3374220536, 4164795346, 4080055004, 3995576782, 3844776128
           dd 1018251130,  935087732,  715871590,  564550760,  277177154,  461924940,  111112542,  227702864, 1691946762, 1876166148, 1925389590, 2043548696, 1223502642, 1138762300, 1593260334, 1442459680
           dd   28809964,  179999714,  397248752,  480281086,  763608788,  646887386,  999926984,  815048134, 1507840668, 1389550482, 1338359936, 1154009486, 1978398372, 2129067946, 1676797112, 1761406390
           dd 2976320012, 3127509762, 2809993232, 2893025566, 2639474228, 2522752826, 2336832552, 2151953702, 3910091388, 3791801202, 4279586912, 4095236462, 3309004356, 3459673930, 3542185048, 3626794326
           dd 2047648055, 1895934009, 1813426987, 1729870373, 1446544655, 1563790337, 1076008723, 1261411869,  577038663,  694804553,  880737115, 1064563285,  240176511,   90031217,  407560035,  323475053
           dd 3403428311, 3251714265, 3703972811, 3620416197, 3873969647, 3991215329, 4042393587, 4227796733, 2461301159, 2579067049, 2226023355, 2409849525, 3196083615, 3045938321, 2828685187, 2744600205
invmatrix2 dd          0,  218697227,  437394454,  387650077,  874788908,  959264295,  775300154,  591342129, 1749577816, 1698790995, 1918528590, 2136171077, 1550600308, 1365591679, 1182684258, 1266113129
           dd 3499155632, 3717852859, 3397581990, 3347837613, 3837057180, 3921532567, 4272342154, 4088384129, 3101200616, 3050413795, 2731183358, 2948825845, 2365368516, 2180359887, 2532226258, 2615655129
           dd 3141262203, 3056784752, 2703869805, 2887829862, 2401231703, 2182540636, 2500722497, 2550460746, 3547573027, 3732579624, 3378624309, 3295197502, 3881276175, 3932069124, 4249194265, 4031545618
           dd 1806384075, 1721906624, 1907959773, 2091919830, 1603208167, 1384517100, 1167925233, 1217663482,   65227667,  250234264,  435246981,  351820174,  935818175,  986611124,  768962473,  551313826
           dd 1836494326, 1618977789, 2003087840, 2054012907, 1498584538, 1415289809, 1128303052, 1313441735,   88006062,  137876389,  523026872,  304467891,  823846274, 1007938441,  722008468,  637663135
           dd 3185986886, 2968470349, 2817806672, 2868731739, 2311222634, 2227927905, 2479909244, 2665047927, 3584965918, 3634836245, 3485212936, 3266653955, 3783918898, 3968011065, 4221049124, 4136703791
           dd 3595400845, 3678697606, 3428805275, 3243664528, 3798552225, 4016062634, 4168831671, 4117912764, 3188000469, 3003910366, 2752977603, 2837320904, 2317434617, 2267558130, 2419270383, 2637835492
           dd  115185213,  198481974,  483363371,  298222624,  855223825, 1072734234,  686535175,  635616268, 1855317605, 1671227502, 1955068531, 2039411832, 1521606217, 1471729730, 1084473951, 1303039060
           dd 3672916471, 3622129660, 3237895649, 3455538154, 4006115803, 3821107152, 4107953613, 4191382470, 2997105071, 3215802276, 2830511545, 2780767154, 2256537987, 2341013384, 2626819477, 2442861470
           dd  175939911,  125153100,  275692881,  493335386, 1045993835,  860985184,  608863613,  692292470, 1647628575, 1866325780, 2015808777, 1966064386, 1443948851, 1528424248, 1275262245, 1091304238
           dd 1641519756, 1826526343, 2076542618, 1993115793, 1442030240, 1492823211, 1340194486, 1122545853,  161475284,   76997855,  328070850,  512030921, 1035719416,  817028339,  665439982,  715178213
           dd 2974251580, 3159258167, 2874500650, 2791073825, 2237874704, 2288667675, 2675006982, 2457358349, 3641641572, 3557164143, 3273463410, 3457423481, 3979031112, 3760340035, 4147719774, 4197458005
           dd 3080383489, 3130253834, 2911432727, 2692873756, 2210321453, 2394413606, 2578237499, 2493892144, 3755121753, 3537605202, 3317727311, 3368652356, 3958809717, 3875515006, 4058298467, 4243437160
           dd 1728711857, 1778582202, 2098729127, 1880170156, 1395537053, 1579629206, 1228679307, 1144333952,  256015593,   38499042,  357589247,  408514292,  996558021,  913263310,  561273043,  746411736
           dd  211892090,   27801969,  380840812,  465184103,  948244310,  898367837,  580326208,  798891339, 1693009698, 1776306473, 2130402100, 1945261375, 1355644686, 1573155077, 1256153880, 1205234963
           dd 3694254026, 3510163905, 3324234716, 3408578007, 3893751782, 3843875309, 4060607472, 4279172603, 3027871634, 3111168409, 2926295940, 2741155215, 2153619390, 2371129781, 2588902312, 2537983395
invmatrix3 dd          0,  151915277,  303830554,  454171927,  607661108,  758523705,  908343854, 1059729699, 1215322216, 1098797925, 1517047410, 1398949247, 1816687708, 1699118929, 2119459398, 2002413899
           dd 2430644432, 2582559709, 2197595850, 2347937223, 3034094820, 3184957417, 2797898494, 2949284339, 3633375416, 3516851125, 3398237858, 3280139695, 4238918796, 4121350017, 4004827798, 3887782299
           dd 1004239803,  852848822,  700935585,  550069932,  534992783,  384654466,  234832277,   82922136, 1940595667, 2057644254, 1639396809, 1756970692, 1469255655, 1587348714, 1167006205, 1283527408
           dd 2872822635, 2721431654, 3106397553, 2955531900, 2399397727, 2249059410, 2636116293, 2484206152, 3813380867, 3930429454, 4049044761, 4166618644, 3346251575, 3464344634, 3580864813, 3697386016
           dd 1991112301, 2141453664, 1689378935, 1841294202, 1385552473, 1536938324, 1082772547, 1233635150, 1054715397,  936617224,  750893087,  634368786,  451248689,  334203196,  150574123,   33005350
           dd 3863824061, 4014165424, 4098969767, 4250885034, 3262474889, 3413860740, 3496574099, 3647436702, 2923241173, 2805143000, 3156281551, 3039757250, 2315596513, 2198551020, 2551784699, 2434215926
           dd 1299615190, 1148749531, 1600822220, 1449431233, 1766760930, 1614850799, 2069018616, 1918680309,   84334014,  201907891,  387629988,  504678569,  557775242,  674296455,  857927568,  976020637
           dd 3717610758, 3566745099, 3481938716, 3330547729, 4188934450, 4037024319, 3954313000, 3803974693, 2514904430, 2632478307, 2281337716, 2398386297, 2984135002, 3100656215, 2747424576, 2865517645
           dd 3963746266, 3847224535, 4267565504, 4149471949, 3363429358, 3245854947, 3664104948, 3547055865, 2754719666, 2906629311, 3056449960, 3206787749, 2148107142, 2298972299, 2450888092, 2602278545
           dd 2090944266, 1974422535, 1857900816, 1739807261, 1486449470, 1368875059, 1250262308, 1133213225,  886120290, 1038029935,  650971512,  801309301,  283718486,  434583643,   49620300,  201010753
           dd 3617229921, 3734275948, 3313932923, 3431502198, 4087521365, 4205620056, 3787372111, 3903896898, 2682967049, 2531581700, 2381758995, 2230896926, 3151165501, 3000824624, 2848910887, 2696996138
           dd 1199193265, 1316239292, 1432758955, 1550328230, 1665273989, 1783372680, 1901987487, 2018512274,  252339417,  100954068,  488010435,  337148366,  724715757,  574374880,  959340279,  807425530
           dd 2599158199, 2481064634, 2297436077, 2180914336, 3201576323, 3084527246, 2898803609, 2781229204, 3533461983, 3683799762, 3229634501, 3381544136, 4137973227, 4289363686, 3837289457, 3988154620
           dd  168604007,   50510442,  403744637,  287222896,  775200083,  658151006, 1009290057,  891715652, 1115482383, 1265820162, 1348534037, 1500443672, 1715782971, 1867173430, 1951978273, 2102843436
           dd 2704767500, 2822336769, 3005967382, 3123013403, 2232374840, 2348899637, 2534621218, 2652719919, 3913753188, 3762891113, 4217058430, 4065673075, 3447656016, 3295741277, 3747813450, 3597472583
           dd  836225756,  953795025,  600562886,  717608907,  368043752,  484568549,  133427442,  251526143, 2041025204, 1890163129, 1807451310, 1656065955, 1570750080, 1418835341, 1334028442, 1183687575
invmatrix4 dd          0,  235605257,  471210514,  303896347,  942421028,  908540205,  607792694,  707863359, 1884842056, 2119394625, 1817080410, 1648721747, 1215585388, 1182749029, 1415726718, 1516850039
           dd 3769684112, 4005289369, 4238789250, 4071475083, 3634160820, 3600279997, 3297443494, 3397514159, 2431170776, 2665723345, 2365498058, 2197139395, 2831453436, 2798617077, 3033700078, 3134823399
           dd 3682319163, 3580933682, 3345850665, 3378949152, 3814166303, 3982262806, 4282488077, 4048197636, 2871251827, 2770919034, 3073755489, 3107898472, 2467293015, 2634345054, 2400845125, 2165502028
           dd 1003187115,  901801634,  668823993,  701922480,   65494927,  233591430,  535905693,  301615252, 1267925987, 1167593194, 1468340721, 1502483704, 1941911495, 2108963534, 1873358293, 1638015196
           dd 2918608246, 2751291519, 2984277860, 3219880557, 2514114898, 2614187099, 2311865152, 2277985865, 3719169342, 3550808119, 3250069292, 3484619301, 3850514714, 3951639571, 4187237128, 4154402305
           dd 1296481766, 1129165039, 1364240372, 1599843069, 1969916354, 2069988555, 1769771984, 1735892697, 1025430958,  857069735,  554225596,  788775605,   87220618,  188345475,  421854104,  389019281
           dd 1989006925, 2022103876, 1788595295, 1687208278, 1319232105, 1084944224, 1387788411, 1555887474,  114671109,  148812556,  449029143,  348694814, 1056541217,  821200680,  586125363,  753179962
           dd 2520581853, 2553678804, 2318081231, 2216694214, 2920362745, 2686074864, 2986813675, 3154912738, 3865407125, 3899548572, 4201870471, 4101536142, 3729349297, 3494008760, 3261022371, 3428076970
           dd 1106762476, 1341970405, 1575076094, 1407897079, 2044456648, 2010178497, 1707996378, 1808202195,  833598116, 1067761581,  767142070,  598910399,  159614592,  126389129,  362126482,  463376795
           dd 2705787516, 2940995445, 3176206446, 3009027431, 2573942360, 2539664209, 2239571018, 2339776835, 3508494900, 3742658365, 3439949862, 3271718191, 3912455696, 3879230233, 4112862210, 4214112523
           dd 2592891351, 2491903198, 2258271173, 2291234508, 2728416755, 2896910586, 3199619041, 2965193448, 3939764639, 3839820950, 4139914125, 4173930116, 3539484091, 3706925234, 3471714217, 3236244128
           dd 2050797895, 1949809742, 1714072405, 1747035740, 1108378979, 1276872810, 1577492337, 1343066744,  174381327,   74437638,  376619805,  410635796,  843640107, 1011081250,  777975609,  542505520
           dd 3959535514, 3792353939, 4028083592, 4263288961, 3559752638, 3659959991, 3359349164, 3325072549, 2623135698, 2454901467, 2152711616, 2386872521, 2759191542, 2860443391, 3093557732, 3060333805
           dd  212952842,   45771267,  279411992,  514617361,  882725678,  982933031,  680216892,  645940277, 2095648578, 1927414347, 1627329872, 1861490777, 1153776486, 1255028335, 1490231668, 1457007741
           dd  930745505,  963707304,  728503987,  627514298,  257308805,   22885772,  322970263,  491466654, 1193436393, 1227450848, 1530167035, 1430221810, 2131644621, 1896177092, 1662536415, 1829980118
           dd 3620396081, 3653357880, 3420243491, 3319253802, 4024887317, 3790464284, 4092654087, 4261150478, 2811409529, 2845423984, 3146034795, 3046089570, 2680062045, 2444594516, 2208864847, 2376308550
tbox1      dd 2774754246, 2222750968, 2574743534, 2373680118,  234025727, 3177933782, 2976870366, 1422247313, 1345335392,   50397442, 2842126286, 2099981142,  436141799, 1658312629, 3870010189, 2591454956
           dd 1170918031, 2642575903, 1086966153, 2273148410,  368769775, 3948501426, 3376891790,  200339707, 3970805057, 1742001331, 4255294047, 3937382213, 3214711843, 4154762323, 2524082916, 1539358875
           dd 3266819957,  486407649, 2928907069, 1780885068, 1513502316, 1094664062,   49805301, 1338821763, 1546925160, 4104496465,  887481809,  150073849, 2473685474, 1943591083, 1395732834, 1058346282
           dd  201589768, 1388824469, 1696801606, 1589887901,  672667696, 2711000631,  251987210, 3046808111,  151455502,  907153956, 2608889883, 1038279391,  652995533, 1764173646, 3451040383, 2675275242
           dd  453576978, 2659418909, 1949051992,  773462580,  756751158, 2993581788, 3998898868, 4221608027, 4132590244, 1295727478, 1641469623, 3467883389, 2066295122, 1055122397, 1898917726, 2542044179
           dd 4115878822, 1758581177,          0,  753790401, 1612718144,  536673507, 3367088505, 3982187446, 3194645204, 1187761037, 3653156455, 1262041458, 3729410708, 3561770136, 3898103984, 1255133061
           dd 1808847035,  720367557, 3853167183,  385612781, 3309519750, 3612167578, 1429418854, 2491778321, 3477423498,  284817897,  100794884, 2172616702, 4031795360, 1144798328, 3131023141, 3819481163
           dd 4082192802, 4272137053, 3225436288, 2324664069, 2912064063, 3164445985, 1211644016,   83228145, 3753688163, 3249976951, 1977277103, 1663115586,  806359072,  452984805,  250868733, 1842533055
           dd 1288555905,  336333848,  890442534,  804056259, 3781124030, 2727843637, 3427026056,  957814574, 1472513171, 4071073621, 2189328124, 1195195770, 2892260552, 3881655738,  723065138, 2507371494
           dd 2690670784, 2558624025, 3511635870, 2145180835, 1713513028, 2116692564, 2878378043, 2206763019, 3393603212,  703524551, 3552098411, 1007948840, 2044649127, 3797835452,  487262998, 1994120109
           dd 1004593371, 1446130276, 1312438900,  503974420, 3679013266,  168166924, 1814307912, 3831258296, 1573044895, 1859376061, 4021070915, 2791465668, 2828112185, 2761266481,  937747667, 2339994098
           dd  854058965, 1137232011, 1496790894, 3077402074, 2358086913, 1691735473, 3528347292, 3769215305, 3027004632, 4199962284,  133494003,  636152527, 2942657994, 2390391540, 3920539207,  403179536
           dd 3585784431, 2289596656, 1864705354, 1915629148,  605822008, 4054230615, 3350508659, 1371981463,  602466507, 2094914977, 2624877800,  555687742, 3712699286, 3703422305, 2257292045, 2240449039
           dd 2423288032, 1111375484, 3300242801, 2858837708, 3628615824,   84083462,   32962295,  302911004, 2741068226, 1597322602, 4183250862, 3501832553, 2441512471, 1489093017,  656219450, 3114180135
           dd  954327513,  335083755, 3013122091,  856756514, 3144247762, 1893325225, 2307821063, 2811532339, 3063651117,  572399164, 2458355477,  552200649, 1238290055, 4283782570, 2015897680, 2061492133
           dd 2408352771, 4171342169, 2156497161,  386731290, 3669999461,  837215959, 3326231172, 3093850320, 3275833730, 2962856233, 1999449434,  286199582, 3417354363, 4233385128, 3602627437,  974525996
tbox2      dd 1667483301, 2088564868, 2004348569, 2071721613, 4076011277, 1802229437, 1869602481, 3318059348,  808476752,   16843267, 1734856361,  724260477, 4278118169, 3621238114, 2880130534, 1987505306
           dd 3402272581, 2189565853, 3385428288, 2105408135, 4210749205, 1499050731, 1195871945, 4042324747, 2913812972, 3570709351, 2728550397, 2947499498, 2627478463, 2762232823, 1920132246, 3233848155
           dd 3082253762, 4261273884, 2475900334,  640044138,  909536346, 1061125697, 4160222466, 3435955023,  875849820, 2779075060, 3857043764, 4059166984, 1903288979, 3638078323,  825320019,  353708607
           dd   67373068, 3351745874,  589514341, 3284376926,  404238376, 2526427041,   84216335, 2593796021,  117902857,  303178806, 2155879323, 3806519101, 3958099238,  656887401, 2998042573, 1970662047
           dd  151589403, 2206408094,  741103732,  437924910,  454768173, 1852759218, 1515893998, 2694863867, 1381147894,  993752653, 3604395873, 3014884814,  690573947, 3823361342,  791633521, 2223248279
           dd 1397991157, 3520182632,          0, 3991781676,  538984544, 4244431647, 2981198280, 1532737261, 1785386174, 3419114822, 3200149465,  960066123, 1246401758, 1280088276, 1482207464, 3486483786
           dd 3503340395, 4025468202, 2863288293, 4227591446, 1128498885, 1296931543,  859006549, 2240090516, 1162185423, 4193904912,   33686534, 2139094657, 1347461360, 1010595908, 2678007226, 2829601763
           dd 1364304627, 2745392638, 1077969088, 2408514954, 2459058093, 2644320700,  943222856, 4126535940, 3166462943, 3065411521, 3671764853,  555827811,  269492272, 4294960410, 4092853518, 3537026925
           dd 3452797260,  202119188,  320022069, 3974939439, 1600110305, 2543269282, 1145342156,  387395129, 3301217111, 2812761586, 2122251394, 1027439175, 1684326572, 1566423783,  421081643, 1936975509
           dd 1616953504, 2172721560, 1330618065, 3705447295,  572671078,  707417214, 2425371563, 2290617219, 1179028682, 4008625961, 3099093971,  336865340, 3739133817, 1583267042,  185275933, 3688607094
           dd 3772832571,  842163286,  976909390,  168432670, 1229558491,  101059594,  606357612, 1549580516, 3267534685, 3553869166, 2896970735, 1650640038, 2442213800, 2509582756, 3840201527, 2038035083
           dd 3890730290, 3368586051,  926379609, 1835915959, 2374828428, 3587551588, 1313774802, 2846444000, 1819072692, 1448520954, 4109693703, 3941256997, 1701169839, 2054878350, 2930657257,  134746136
           dd 3132780501, 2021191816,  623200879,  774790258,  471611428, 2795919345, 3031724999, 3334903633, 3907570467, 3722289532, 1953818780,  522141217, 1263245021, 3183305180, 2341145990, 2324303749
           dd 1886445712, 1044282434, 3048567236, 1718013098, 1212715224,   50529797, 4143380225,  235805714, 1633796771,  892693087, 1465364217, 3115936208, 2256934801, 3250690392,  488454695, 2661164985
           dd 3789674808, 4177062675, 2560109491,  286335539, 1768542907, 3654920560, 2391672713, 2492740519, 2610638262,  505297954, 2273777042, 3924412704, 3469641545, 1431677695,  673730680, 3755976058
           dd 2357986191, 2711706104, 2307459456,  218962455, 3216991706, 3873888049, 1111655622, 1751699640, 1094812355, 2576951728,  757946999,  252648977, 2964356043, 1414834428, 3149622742,  370551866
tbox3      dd 1673962851, 2096661628, 2012125559, 2079755643, 4076801522, 1809235307, 1876865391, 3314635973,  811618352,   16909057, 1741597031,  727088427, 4276558334, 3618988759, 2874009259, 1995217526
           dd 3398387146, 2183110018, 3381215433, 2113570685, 4209972730, 1504897881, 1200539975, 4042984432, 2906778797, 3568527316, 2724199842, 2940594863, 2619588508, 2756966308, 1927583346, 3231407040
           dd 3077948087, 4259388669, 2470293139,  642542118,  913070646, 1065238847, 4160029431, 3431157708,  879254580, 2773611685, 3855693029, 4059629809, 1910674289, 3635114968,  828527409,  355090197
           dd   67636228, 3348452039,  591815971, 3281870531,  405809176, 2520228246,   84545285, 2586817946,  118360327,  304363026, 2149292928, 3806281186, 3956090603,  659450151, 2994720178, 1978310517
           dd  152181513, 2199756419,  743994412,  439627290,  456535323, 1859957358, 1521806938, 2690382752, 1386542674,  997608763, 3602342358, 3011366579,  693271337, 3822927587,  794718511, 2215876484
           dd 1403450707, 3518589137,          0, 3988860141,  541089824, 4242743292, 2977548465, 1538714971, 1792327274, 3415033547, 3194476990,  963791673, 1251270218, 1285084236, 1487988824, 3481619151
           dd 3501943760, 4022676207, 2857362858, 4226619131, 1132905795, 1301993293,  862344499, 2232521861, 1166724933, 4192801017,   33818114, 2147385727, 1352724560, 1014514748, 2670049951, 2823545768
           dd 1369633617, 2740846243, 1082179648, 2399505039, 2453646738, 2636233885,  946882616, 4126213365, 3160661948, 3061301686, 3668932058,  557998881,  270544912, 4293204735, 4093447923, 3535760850
           dd 3447803085,  202904588,  321271059, 3972214764, 1606345055, 2536874647, 1149815876,  388905239, 3297990596, 2807427751, 2130477694, 1031423805, 1690872932, 1572530013,  422718233, 1944491379
           dd 1623236704, 2165938305, 1335808335, 3701702620,  574907938,  710180394, 2419829648, 2282455944, 1183631942, 4006029806, 3094074296,  338181140, 3735517662, 1589437022,  185998603, 3685578459
           dd 3772464096,  845436466,  980700730,  169090570, 1234361161,  101452294,  608726052, 1555620956, 3265224130, 3552407251, 2890133420, 1657054818, 2436475025, 2503058581, 3839047652, 2045938553
           dd 3889509095, 3364570056,  929978679, 1843050349, 2365688973, 3585172693, 1318900302, 2840191145, 1826141292, 1454176854, 4109567988, 3939444202, 1707781989, 2062847610, 2923948462,  135272456
           dd 3127891386, 2029029496,  625635109,  777810478,  473441308, 2790781350, 3027486644, 3331805638, 3905627112, 3718347997, 1961401460,  524165407, 1268178251, 3177307325, 2332919435, 2316273034
           dd 1893765232, 1048330814, 3044132021, 1724688998, 1217452104,   50726147, 4143383030,  236720654, 1640145761,  896163637, 1471084887, 3110719673, 2249691526, 3248052417,  490350365, 2653403550
           dd 3789109473, 4176155640, 2553000856,  287453969, 1775418217, 3651760345, 2382858638, 2486413204, 2603464347,  507257374, 2266337927, 3922272489, 3464972750, 1437269845,  676362280, 3752164063
           dd 2349043596, 2707028129, 2299101321,  219813645, 3211123391, 3872862694, 1115997762, 1758509160, 1099088705, 2569646233,  760903469,  253628687, 2960903088, 1420360788, 3144537787,  371997206
tbox4      dd 3332727651, 4169432188, 4003034999, 4136467323, 4279104242, 3602738027, 3736170351, 2438251973, 1615867952,   33751297, 3467208551, 1451043627, 3877240574, 3043153879, 1306962859, 3969545846
           dd 2403715786,  530416258, 2302724553, 4203183485, 4011195130, 3001768281, 2395555655, 4211863792, 1106029997, 3009926356, 1610457762, 1173008303,  599760028, 1408738468, 3835064946, 2606481600
           dd 1975695287, 3776773629, 1034851219, 1282024998, 1817851446, 2118205247, 4110612471, 2203045068, 1750873140, 1374987685, 3509904869, 4178113009, 3801313649, 2876496088, 1649619249,  708777237
           dd  135005188, 2505230279, 1181033251, 2640233411,  807933976,  933336726,  168756485,  800430746,  235472647,  607523346,  463175808, 3745374946, 3441880043, 1315514151, 2144187058, 3936318837
           dd  303761673,  496927619, 1484008492,  875436570,  908925723, 3702681198, 3035519578, 1543217312, 2767606354, 1984772923, 3076642518, 2110698419, 1383803177, 3711886307, 1584475951,  328696964
           dd 2801095507, 3110654417,          0, 3240947181, 1080041504, 3810524412, 2043195825, 3069008731, 3569248874, 2370227147, 1742323390, 1917532473, 2497595978, 2564049996, 2968016984, 2236272591
           dd 3144405200, 3307925487, 1340451498, 3977706491, 2261074755, 2597801293, 1716859699,  294946181, 2328839493, 3910203897,   67502594, 4269899647, 2700103760, 2017737788,  632987551, 1273211048
           dd 2733855057, 1576969123, 2160083008,   92966799, 1068339858,  566009245, 1883781176, 4043634165, 1675607228, 2009183926, 2943736538, 1113792801,  540020752, 3843751935, 4245615603, 3211645650
           dd 2169294285,  403966988,  641012499, 3274697964, 3202441055,  899848087, 2295088196,  775493399, 2472002756, 1441965991, 4236410494, 2051489085, 3366741092, 3135724893,  841685273, 3868554099
           dd 3231735904,  429425025, 2664517455, 2743065820, 1147544098, 1417554474, 1001099408,  193169544, 2362066502, 3341414126, 1809037496,  675025940, 2809781982, 3168951902,  371002123, 2910247899
           dd 3678134496, 1683370546, 1951283770,  337512970, 2463844681,  201983494, 1215046692, 3101973596, 2673722050, 3178157011, 1139780780, 3299238498,  967348625,  832869781, 3543655652, 4069226873
           dd 3576883175, 2336475336, 1851340599, 3669454189,   25988493, 2976175573, 2631028302, 1239460265, 3635702892, 2902087254, 4077384948, 3475368682, 3400492389, 4102978170, 1206496942,  270010376
           dd 1876277946, 4035475576, 1248797989, 1550986798,  941890588, 1475454630, 1942467764, 2538718918, 3408128232, 2709315037, 3902567540, 1042358047, 2531085131, 1641856445,  226921355,  260409994
           dd 3767562352, 2084716094, 1908716981, 3433719398, 2430093384,  100991747, 4144101110,  470945294, 3265487201, 1784624437, 2935576407, 1775286713,  395413126, 2572730817,  975641885,  666476190
           dd 3644383713, 3943954680,  733190296,  573772049, 3535497577, 2842745305,  126455438,  866620564,  766942107, 1008868894,  361924487, 3374377449, 2269761230, 2868860245, 1350051880, 2776293343
           dd   59739276, 1509466529,  159418761,  437718285, 1708834751, 3610371814, 2227585602, 3501746280, 2193834305,  699439513, 1517759789,  504434447, 2076946608, 2835108948, 1842789307,  742004246
invtbox1   dd 1353184337, 1399144830, 3282310938, 2522752826, 3412831035, 4047871263, 2874735276, 2466505547, 1442459680, 4134368941, 2440481928,  625738485, 4242007375, 3620416197, 2151953702, 2409849525
           dd 1230680542, 1729870373, 2551114309, 3787521629,   41234371,  317738113, 2744600205, 3338261355, 3881799427, 2510066197, 3950669247, 3663286933,  763608788, 3542185048,  694804553, 1154009486
           dd 1787413109, 2021232372, 1799248025, 3715217703, 3058688446,  397248752, 1722556617, 3023752829,  407560035, 2184256229, 1613975959, 1165972322, 3765920945, 2226023355,  480281086, 2485848313
           dd 1483229296,  436028815, 2272059028, 3086515026,  601060267, 3791801202, 1468997603,  715871590,  120122290,   63092015, 2591802758, 2768779219, 4068943920, 2997206819, 3127509762, 1552029421
           dd  723308426, 2461301159, 4042393587, 2715969870, 3455375973, 3586000134,  526529745, 2331944644, 2639474228, 2689987490,  853641733, 1978398372,  971801355, 2867814464,  111112542, 1360031421
           dd 4186579262, 1023860118, 2919579357, 1186850381, 3045938321,   90031217, 1876166148, 4279586912,  620468249, 2548678102, 3426959497, 2006899047, 3175278768, 2290845959,  945494503, 3689859193
           dd 1191869601, 3910091388, 3374220536,          0, 2206629897, 1223502642, 2893025566, 1316117100, 4227796733, 1446544655,  517320253,  658058550, 1691946762,  564550760, 3511966619,  976107044
           dd 2976320012,  266819475, 3533106868, 2660342555, 1338359936, 2720062561, 1766553434,  370807324,  179999714, 3844776128, 1138762300,  488053522,  185403662, 2915535858, 3114841645, 3366526484
           dd 2233069911, 1275557295, 3151862254, 4250959779, 2670068215, 3170202204, 3309004356,  880737115, 1982415755, 3703972811, 1761406390, 1676797112, 3403428311,  277177154, 1076008723,  538035844
           dd 2099530373, 4164795346,  288553390, 1839278535, 1261411869, 4080055004, 3964831245, 3504587127, 1813426987, 2579067049, 4199060497,  577038663, 3297574056,  440397984, 3626794326, 4019204898
           dd 3343796615, 3251714265, 4272081548,  906744984, 3481400742,  685669029,  646887386, 2764025151, 3835509292,  227702864, 2613862250, 1648787028, 3256061430, 3904428176, 1593260334, 4121936770
           dd 3196083615, 2090061929, 2838353263, 3004310991,  999926984, 2809993232, 1852021992, 2075868123,  158869197, 4095236462,   28809964, 2828685187, 1701746150, 2129067946,  147831841, 3873969647
           dd 3650873274, 3459673930, 3557400554, 3598495785, 2947720241,  824393514,  815048134, 3227951669,  935087732, 2798289660, 2966458592,  366520115, 1251476721, 4158319681,  240176511,  804688151
           dd 2379631990, 1303441219, 1414376140, 3741619940, 3820343710,  461924940, 3089050817, 2136040774,   82468509, 1563790337, 1937016826,  776014843, 1511876531, 1389550482,  861278441,  323475053
           dd 2355222426, 2047648055, 2383738969, 2302415851, 3995576782,  902390199, 3991215329, 1018251130, 1507840668, 1064563285, 2043548696, 3208103795, 3939366739, 1537932639,  342834655, 2262516856
           dd 2180231114, 1053059257,  741614648, 1598071746, 1925389590,  203809468, 2336832552, 1100287487, 1895934009, 3736275976, 2632234200, 2428589668, 1636092795, 1890988757, 1952214088, 1113045200
invtbox2   dd 2817806672, 1698790995, 2752977603, 1579629206, 1806384075, 1167925233, 1492823211,   65227667, 4197458005, 1836494326, 1993115793, 1275262245, 3622129660, 3408578007, 1144333952, 2741155215
           dd 1521606217,  465184103,  250234264, 3237895649, 1966064386, 4031545618, 2537983395, 4191382470, 1603208167, 2626819477, 2054012907, 1498584538, 2210321453,  561273043, 1776306473, 3368652356
           dd 2311222634, 2039411832, 1045993835, 1907959773, 1340194486, 2911432727, 2887829862,  986611124, 1256153880,  823846274,  860985184, 2136171077, 2003087840, 2926295940, 2692873756,  722008468
           dd 1749577816, 4249194265, 1826526343, 4168831671, 3547573027,   38499042, 2401231703, 2874500650,  686535175, 3266653955, 2076542618,  137876389, 2267558130, 2780767154, 1778582202, 2182540636
           dd  483363371, 3027871634, 4060607472, 3798552225, 4107953613, 3188000469, 1647628575, 4272342154, 1395537053, 1442030240, 3783918898, 3958809717, 3968011065, 4016062634, 2675006982,  275692881
           dd 2317434617,  115185213,   88006062, 3185986886, 2371129781, 1573155077, 3557164143,  357589247, 4221049124, 3921532567, 1128303052, 2665047927, 1122545853, 2341013384, 1528424248, 4006115803
           dd  175939911,  256015593,  512030921,          0, 2256537987, 3979031112, 1880170156, 1918528590, 4279172603,  948244310, 3584965918,  959264295, 3641641572, 2791073825, 1415289809,  775300154
           dd 1728711857, 3881276175, 2532226258, 2442861470, 3317727311,  551313826, 1266113129,  437394454, 3130253834,  715178213, 3760340035,  387650077,  218697227, 3347837613, 2830511545, 2837320904
           dd  435246981,  125153100, 3717852859, 1618977789,  637663135, 4117912764,  996558021, 2130402100,  692292470, 3324234716, 4243437160, 4058298467, 3694254026, 2237874704,  580326208,  298222624
           dd  608863613, 1035719416,  855223825, 2703869805,  798891339,  817028339, 1384517100, 3821107152,  380840812, 3111168409, 1217663482, 1693009698, 2365368516, 1072734234,  746411736, 2419270383
           dd 1313441735, 3510163905, 2731183358,  198481974, 2180359887, 3732579624, 2394413606, 3215802276, 2637835492, 2457358349, 3428805275, 1182684258,  328070850, 3101200616, 4147719774, 2948825845
           dd 2153619390, 2479909244,  768962473,  304467891, 2578237499, 2098729127, 1671227502, 3141262203, 2015808777,  408514292, 3080383489, 2588902312, 1855317605, 3875515006, 3485212936, 3893751782
           dd 2615655129,  913263310,  161475284, 2091919830, 2997105071,  591342129, 2493892144, 1721906624, 3159258167, 3397581990, 3499155632, 3634836245, 2550460746, 3672916471, 1355644686, 4136703791
           dd 3595400845, 2968470349, 1303039060,   76997855, 3050413795, 2288667675,  523026872, 1365591679, 3932069124,  898367837, 1955068531, 1091304238,  493335386, 3537605202, 1443948851, 1205234963
           dd 1641519756,  211892090,  351820174, 1007938441,  665439982, 3378624309, 3843875309, 2974251580, 3755121753, 1945261375, 3457423481,  935818175, 3455538154, 2868731739, 1866325780, 3678697606
           dd 4088384129, 3295197502,  874788908, 1084473951, 3273463410,  635616268, 1228679307, 2500722497,   27801969, 3003910366, 3837057180, 3243664528, 2227927905, 3056784752, 1550600308, 1471729730
invtbox3   dd 4098969767, 1098797925,  387629988,  658151006, 2872822635, 2636116293, 4205620056, 3813380867,  807425530, 1991112301, 3431502198,   49620300, 3847224535,  717608907,  891715652, 1656065955
           dd 2984135002, 3123013403, 3930429454, 4267565504,  801309301, 1283527408, 1183687575, 3547055865, 2399397727, 2450888092, 1841294202, 1385552473, 3201576323, 1951978273, 3762891113, 3381544136
           dd 3262474889, 2398386297, 1486449470, 3106397553, 3787372111, 2297436077,  550069932, 3464344634, 3747813450,  451248689, 1368875059, 1398949247, 1689378935, 1807451310, 2180914336,  150574123
           dd 1215322216, 1167006205, 3734275948, 2069018616, 1940595667, 1265820162,  534992783, 1432758955, 3954313000, 3039757250, 3313932923,  936617224,  674296455, 3206787749,   50510442,  384654466
           dd 3481938716, 2041025204,  133427442, 1766760930, 3664104948,   84334014,  886120290, 2797898494,  775200083, 4087521365, 2315596513, 4137973227, 2198551020, 1614850799, 1901987487, 1857900816
           dd  557775242, 3717610758, 1054715397, 3863824061, 1418835341, 3295741277,  100954068, 1348534037, 2551784699, 3184957417, 1082772547, 3647436702, 3903896898, 2298972299,  434583643, 3363429358
           dd 2090944266, 1115482383, 2230896926,          0, 2148107142,  724715757,  287222896, 1517047410,  251526143, 2232374840, 2923241173,  758523705,  252339417, 1550328230, 1536938324,  908343854
           dd  168604007, 1469255655, 4004827798, 2602278545, 3229634501, 3697386016, 2002413899,  303830554, 2481064634, 2696996138,  574374880,  454171927,  151915277, 2347937223, 3056449960,  504678569
           dd 4049044761, 1974422535, 2582559709, 2141453664,   33005350, 1918680309, 1715782971, 4217058430, 1133213225,  600562886, 3988154620, 3837289457,  836225756, 1665273989, 2534621218, 3330547729
           dd 1250262308, 3151165501, 4188934450,  700935585, 2652719919, 3000824624, 2249059410, 3245854947, 3005967382, 1890163129, 2484206152, 3913753188, 4238918796, 4037024319, 2102843436,  857927568
           dd 1233635150,  953795025, 3398237858, 3566745099, 4121350017, 2057644254, 3084527246, 2906629311,  976020637, 2018512274, 1600822220, 2119459398, 2381758995, 3633375416,  959340279, 3280139695
           dd 1570750080, 3496574099, 3580864813,  634368786, 2898803609,  403744637, 2632478307, 1004239803,  650971512, 1500443672, 2599158199, 1334028442, 2514904430, 4289363686, 3156281551,  368043752
           dd 3887782299, 1867173430, 2682967049, 2955531900, 2754719666, 1059729699, 2781229204, 2721431654, 1316239292, 2197595850, 2430644432, 2805143000,   82922136, 3963746266, 3447656016, 2434215926
           dd 1299615190, 4014165424, 2865517645, 2531581700, 3516851125, 1783372680,  750893087, 1699118929, 1587348714, 2348899637, 2281337716,  201010753, 1739807261, 3683799762,  283718486, 3597472583
           dd 3617229921, 2704767500, 4166618644,  334203196, 2848910887, 1639396809,  484568549, 1199193265, 3533461983, 4065673075,  337148366, 3346251575, 4149471949, 4250885034, 1038029935, 1148749531
           dd 2949284339, 1756970692,  607661108, 2747424576,  488010435, 3803974693, 1009290057,  234832277, 2822336769,  201907891, 3034094820, 1449431233, 3413860740,  852848822, 1816687708, 3100656215
invtbox4   dd 1364240372, 2119394625,  449029143,  982933031, 1003187115,  535905693, 2896910586, 1267925987,  542505520, 2918608246, 2291234508, 4112862210, 1341970405, 3319253802,  645940277, 3046089570
           dd 3729349297,  627514298, 1167593194, 1575076094, 3271718191, 2165502028, 2376308550, 1808202195,   65494927,  362126482, 3219880557, 2514114898, 3559752638, 1490231668, 1227450848, 2386872521
           dd 1969916354, 4101536142, 2573942360,  668823993, 3199619041, 4028083592, 3378949152, 2108963534, 1662536415, 3850514714, 2539664209, 1648721747, 2984277860, 3146034795, 4263288961, 4187237128
           dd 1884842056, 2400845125, 2491903198, 1387788411, 2871251827, 1927414347, 3814166303, 1714072405, 2986813675,  788775605, 2258271173, 3550808119,  821200680,  598910399,   45771267, 3982262806
           dd 2318081231, 2811409529, 4092654087, 1319232105, 1707996378,  114671109, 3508494900, 3297443494,  882725678, 2728416755,   87220618, 2759191542,  188345475, 1084944224, 1577492337, 3176206446
           dd 1056541217, 2520581853, 3719169342, 1296481766, 2444594516, 1896177092,   74437638, 1627329872,  421854104, 3600279997, 2311865152, 1735892697, 2965193448,  126389129, 3879230233, 2044456648
           dd 2705787516, 2095648578, 4173930116,          0,  159614592,  843640107,  514617361, 1817080410, 4261150478,  257308805, 1025430958,  908540205,  174381327, 1747035740, 2614187099,  607792694
           dd  212952842, 2467293015, 3033700078,  463376795, 2152711616, 1638015196, 1516850039,  471210514, 3792353939, 3236244128, 1011081250,  303896347,  235605257, 4071475083,  767142070,  348694814
           dd 1468340721, 2940995445, 4005289369, 2751291519, 4154402305, 1555887474, 1153776486, 1530167035, 2339776835, 3420243491, 3060333805, 3093557732, 3620396081, 1108378979,  322970263, 2216694214
           dd 2239571018, 3539484091, 2920362745, 3345850665,  491466654, 3706925234,  233591430, 2010178497,  728503987, 2845423984,  301615252, 1193436393, 2831453436, 2686074864, 1457007741,  586125363
           dd 2277985865, 3653357880, 2365498058, 2553678804, 2798617077, 2770919034, 3659959991, 1067761581,  753179962, 1343066744, 1788595295, 1415726718, 4139914125, 2431170776,  777975609, 2197139395
           dd 2680062045, 1769771984, 1873358293, 3484619301, 3359349164,  279411992, 3899548572, 3682319163, 3439949862, 1861490777, 3959535514, 2208864847, 3865407125, 2860443391,  554225596, 4024887317
           dd 3134823399, 1255028335, 3939764639,  701922480,  833598116,  707863359, 3325072549,  901801634, 1949809742, 4238789250, 3769684112,  857069735, 4048197636, 1106762476, 2131644621,  389019281
           dd 1989006925, 1129165039, 3428076970, 3839820950, 2665723345, 1276872810, 3250069292, 1182749029, 2634345054,   22885772, 4201870471, 4214112523, 3009027431, 2454901467, 3912455696, 1829980118
           dd 2592891351,  930745505, 1502483704, 3951639571, 3471714217, 3073755489, 3790464284, 2050797895, 2623135698, 1430221810,  410635796, 1941911495, 1407897079, 1599843069, 3742658365, 2022103876
           dd 3397514159, 3107898472,  942421028, 3261022371,  376619805, 3154912738,  680216892, 4282488077,  963707304,  148812556, 3634160820, 1687208278, 2069988555, 3580933682, 1215585388, 3494008760
sbox       db  99, 124, 119, 123, 242, 107, 111, 197,  48,   1, 103,  43, 254, 215, 171, 118
           db 202, 130, 201, 125, 250,  89,  71, 240, 173, 212, 162, 175, 156, 164, 114, 192
           db 183, 253, 147,  38,  54,  63, 247, 204,  52, 165, 229, 241, 113, 216,  49,  21
           db   4, 199,  35, 195,  24, 150,   5, 154,   7,  18, 128, 226, 235,  39, 178, 117
           db   9, 131,  44,  26,  27, 110,  90, 160,  82,  59, 214, 179,  41, 227,  47, 132
           db  83, 209,   0, 237,  32, 252, 177,  91, 106, 203, 190,  57,  74,  76,  88, 207
           db 208, 239, 170, 251,  67,  77,  51, 133,  69, 249,   2, 127,  80,  60, 159, 168
           db  81, 163,  64, 143, 146, 157,  56, 245, 188, 182, 218,  33,  16, 255, 243, 210
           db 205,  12,  19, 236,  95, 151,  68,  23, 196, 167, 126,  61, 100,  93,  25, 115
           db  96, 129,  79, 220,  34,  42, 144, 136,  70, 238, 184,  20, 222,  94,  11, 219
           db 224,  50,  58,  10,  73,   6,  36,  92, 194, 211, 172,  98, 145, 149, 228, 121
           db 231, 200,  55, 109, 141, 213,  78, 169, 108,  86, 244, 234, 101, 122, 174,   8
           db 186, 120,  37,  46,  28, 166, 180, 198, 232, 221, 116,  31,  75, 189, 139, 138
           db 112,  62, 181, 102,  72,   3, 246,  14,  97,  53,  87, 185, 134, 193,  29, 158
           db 225, 248, 152,  17, 105, 217, 142, 148, 155,  30, 135, 233, 206,  85,  40, 223
           db 140, 161, 137,  13, 191, 230,  66, 104,  65, 153,  45,  15, 176,  84, 187,  22
invsbox    db  82,   9, 106, 213,  48,  54, 165,  56, 191,  64, 163, 158, 129, 243, 215, 251
           db 124, 227,  57, 130, 155,  47, 255, 135,  52, 142,  67,  68, 196, 222, 233, 203
           db  84, 123, 148,  50, 166, 194,  35,  61, 238,  76, 149,  11,  66, 250, 195,  78
           db   8,  46, 161, 102,  40, 217,  36, 178, 118,  91, 162,  73, 109, 139, 209,  37
           db 114, 248, 246, 100, 134, 104, 152,  22, 212, 164,  92, 204,  93, 101, 182, 146
           db 108, 112,  72,  80, 253, 237, 185, 218,  94,  21,  70,  87, 167, 141, 157, 132
           db 144, 216, 171,   0, 140, 188, 211,  10, 247, 228,  88,   5, 184, 179,  69,   6
           db 208,  44,  30, 143, 202,  63,  15,   2, 193, 175, 189,   3,   1,  19, 138, 107
           db  58, 145,  17,  65,  79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115
           db 150, 172, 116,  34, 231, 173,  53, 133, 226, 249,  55, 232,  28, 117, 223, 110
           db  71, 241,  26, 113,  29,  41, 197, 137, 111, 183,  98,  14, 170,  24, 190,  27
           db 252,  86,  62,  75, 198, 210, 121,  32, 154, 219, 192, 254, 120, 205,  90, 244
           db  31, 221, 168,  51, 136,   7, 199,  49, 177,  18,  16,  89,  39, 128, 236,  95
           db  96,  81, 127, 169,  25, 181,  74,  13,  45, 229, 122, 159, 147, 201, 156, 239
           db 160, 224,  59,  77, 174,  42, 245, 176, 200, 235, 187,  60, 131,  83, 153,  97
           db  23,  43,   4, 126, 186, 119, 214,  38, 225, 105,  20,  99,  85,  33,  12, 125

get_eip:
    mov     ebx, DWORD PTR [esp]
    ret

dd 2385037

_aes_128_key_schedule@4:
    push    ebx                         ; save ebx
    push    edi                         ; save edi
    call    get_eip
    mov     edi, DWORD PTR [esp+12]     ; pointer to key
    mov     dl, 1                       ; first rcon
    add     edi, 16                     ; next round key
    sub     ebx, 527                    ; pointer to sbox
    mov     eax, [edi-4]                ; last four bytes of key
aes_128_key_schedule_round:
    xlatb                               ; 1st subbyte
    rol     eax, 8
    xlatb                               ; 2nd subbyte
    rol     eax, 8
    xlatb                               ; 3rd subbyte
    rol     eax, 8
    xlatb                               ; 4th subbyte
    xor     al, dl
    xor     eax, DWORD PTR [edi-16]
    stosd                               ; 1st column
    xor     eax, DWORD PTR [edi-16]
    stosd                               ; 2nd column
    xor     eax, DWORD PTR [edi-16]
    stosd                               ; 3rd column
    xor     eax, DWORD PTR [edi-16]
    stosd                               ; 4th column
    shl     dl, 1                       ; next rcon
    sbb     dh, dh
    and     dh, 27
    or      dl, dh
    cmp     dl, 108
    jne     aes_128_key_schedule_round
    pop     edi                         ; restore edi
    pop     ebx                         ; restore ebx
    ret     4

db 144

_aes_192_key_schedule@4:
    push    ebx                         ; save ebx
    push    edi                         ; save edi
    call    get_eip
    mov     edi, DWORD PTR [esp+12]     ; pointer to key
    mov     dl, 1                       ; first rcon
    add     edi, 24                     ; next round key
    sub     ebx, 603                    ; pointer to sbox
    mov     eax, [edi-4]                ; last four bytes of key
    jmp     aes_192_key_schedule_start
aes_192_key_schedule_round:
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 5th column
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 6th column
aes_192_key_schedule_start:
    xlatb                               ; 1st subbyte
    rol     eax, 8
    xlatb                               ; 2nd subbyte
    rol     eax, 8
    xlatb                               ; 3rd subbyte
    rol     eax, 8
    xlatb                               ; 4th subbyte
    xor     al, dl
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 1st column
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 2nd column
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 3rd column
    xor     eax, DWORD PTR [edi-24]
    stosd                               ; 4th column
    shl     dl, 1                       ; next rcon
    jne     aes_192_key_schedule_round
    pop     edi                         ; restore edi
    pop     ebx                         ; restore ebx
    ret     4

db 144

_aes_256_key_schedule@4:
    push    ebx                         ; save ebx
    push    edi                         ; save edi
    call    get_eip
    mov     edi, DWORD PTR [esp+12]     ; pointer to key
    mov     dl, 1                       ; first rcon
    add     edi, 32                     ; next round key
    sub     ebx, 679                    ; pointer to sbox
    mov     eax, [edi-4]                ; last four bytes of key
    jmp     aes_256_key_schedule_start
aes_256_key_schedule_round:
    xlatb                               ; 1st subbyte
    rol     eax, 8
    xlatb                               ; 2nd subbyte
    rol     eax, 8
    xlatb                               ; 3rd subbyte
    rol     eax, 8
    xlatb                               ; 4th subbyte
    rol     eax, 8
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 5th column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 6th column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 7th column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 8th column
aes_256_key_schedule_start:
    xlatb                               ; 1st subbyte
    rol     eax, 8
    xlatb                               ; 2nd subbyte
    rol     eax, 8
    xlatb                               ; 3rd subbyte
    rol     eax, 8
    xlatb                               ; 4th subbyte
    xor     al, dl
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 1st column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 2nd column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 3rd column
    xor     eax, DWORD PTR [edi-32]
    stosd                               ; 4th column
    shl     dl, 1                       ; next rcon
    jns     aes_256_key_schedule_round
    pop     edi                         ; restore edi
    pop     ebx                         ; restore ebx
    ret     4

db 144

_aes_128_key_inverse@4:
    mov     cl,  9                      ; number of main rounds
    jmp     aes_key_inverse

_aes_192_key_inverse@4:
    mov     cl, 11                      ; number of main rounds
    jmp     aes_key_inverse

_aes_256_key_inverse@4:
    mov     cl, 13                      ; number of main rounds
    jmp     aes_key_inverse

aes_key_inverse:
    push    ebx                         ; save ebx
    push    esi                         ; save esi
    push    edi                         ; save edi
    push    ebp                         ; save ebp
    call    get_eip
    mov     esi, DWORD PTR [esp+20]     ; pointer to key
    and     ecx, 15                     ; number of main rounds
    sub     edx, edx                    ; zero edx
    add     esi, 16                     ; pointer to 1st main round key
    xor     ebp, ebp                    ; zero ebp
    mov     edi, esi                    ; pointer to 1st main round key
    sub     ebx, 13081                  ; pointer to invmatrix1
    shl     cl, 2                       ; number of columns
aes_key_inverse_round:
    lodsd                               ; load column
    mov     dl, al
    xor     ebp, DWORD PTR [ebx+edx*4     ]
    shr     eax, 8
    mov     dl, al
    xor     ebp, DWORD PTR [ebx+edx*4+1024]
    shr     eax, 8
    mov     dl, al
    xor     ebp, DWORD PTR [ebx+edx*4+2048]
    shr     eax, 8
    mov     dl, al
    xor     ebp, DWORD PTR [ebx+edx*4+3072]
    shr     eax, 8
    xchg    eax, ebp
    stosd                               ; replace column
    loop    aes_key_inverse_round
    pop     ebp                         ; restore ebp
    pop     edi                         ; restore edi
    pop     esi                         ; restore esi
    pop     ebx                         ; restore ebx
    ret     4

dw 65419

_aes_128_encrypt@8:
    mov     cl,  9                      ; number of main rounds
    jmp     aes_encrypt

_aes_192_encrypt@8:
    mov     cl, 11                      ; number of main rounds
    jmp     aes_encrypt

_aes_256_encrypt@8:
    mov     cl, 13                      ; number of main rounds
    jmp     aes_encrypt

aes_encrypt:
    push    ebx                         ; save ebx
    push    esi                         ; save esi
    push    edi                         ; save edi
    push    ebp                         ; save ebp
    and     ecx, 15                     ; number of main rounds
    mov     esi, DWORD PTR [esp+24]     ; pointer to expanded key
    call    get_eip
    mov     ebp, DWORD PTR [esp+20]     ; pointer to data block
    xor     edx, edx                    ; zero edx
    sub     esp, 16                     ; allocate temporary block
    sub     ebx, 9096                   ; pointer to tbox1
    mov     edi, esp                    ; pointer to temporary block
    lodsd
    xor     DWORD PTR [ebp   ], eax
    lodsd
    xor     DWORD PTR [ebp+ 4], eax
    lodsd
    xor     DWORD PTR [ebp+ 8], eax
    lodsd
    xor     DWORD PTR [ebp+12], eax
aes_encrypt_round:
    lodsd
    mov     dl, BYTE PTR [ebp   ]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 5]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+10]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+15]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 4]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 9]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+14]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+ 3]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 8]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+13]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+ 2]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+ 7]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+12]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 1]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+ 6]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+11]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    sub     edi, 16                     ; rewind to beginning of block
    dec     cl                          ; loop control variable
    xchg    ebp, edi                    ; exchange temporary block and data block pointers
    jne     aes_encrypt_round
    add     ebx, 8192                   ; pointer to sbox
    lodsd
    mov     dl, BYTE PTR [ebp   ]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 5]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+10]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+15]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 4]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 9]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+14]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 3]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 8]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+13]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 2]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 7]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+12]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 1]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 6]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+11]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    add     esp, 16                     ; deallocate temporary block
    pop     ebp                         ; restore ebp
    pop     edi                         ; restore edi
    pop     esi                         ; restore esi
    pop     ebx                         ; restore ebx
    ret     8

dw 65419

_aes_128_decrypt@8:
    mov     cl,  9                      ; number of main rounds
    jmp     aes_decrypt

_aes_192_decrypt@8:
    mov     cl, 11                      ; number of main rounds
    jmp     aes_decrypt

_aes_256_decrypt@8:
    mov     cl, 13                      ; number of main rounds
    jmp     aes_decrypt

aes_decrypt:
    push    ebx                         ; save ebx
    push    esi                         ; save esi
    push    edi                         ; save edi
    push    ebp                         ; save ebp
    and     ecx, 15                     ; number of main rounds
    std
    mov     ebx, ecx
    mov     esi, DWORD PTR [esp+24]     ; pointer to expanded key
    shl     ebx, 4
    lea     esi, [ebx+esi+28]
    call    get_eip
    mov     ebp, DWORD PTR [esp+20]     ; pointer to data block
    xor     edx, edx                    ; zero edx
    sub     esp, 16                     ; allocate temporary block
    sub     ebx, 5406                   ; pointer to invtbox1
    lea     edi, [esp+12]               ; pointer to temporary block
    lodsd
    xor     DWORD PTR [ebp+12], eax
    lodsd
    xor     DWORD PTR [ebp+ 8], eax
    lodsd
    xor     DWORD PTR [ebp+ 4], eax
    lodsd
    xor     DWORD PTR [ebp   ], eax
aes_decrypt_round:
    lodsd
    mov     dl, BYTE PTR [ebp+12]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 9]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+ 6]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+ 3]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 8]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 5]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+ 2]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+15]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 4]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+ 1]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+14]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+11]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp   ]
    xor     eax, DWORD PTR [ebx+edx*4     ]
    mov     dl, BYTE PTR [ebp+13]
    xor     eax, DWORD PTR [ebx+edx*4+1024]
    mov     dl, BYTE PTR [ebp+10]
    xor     eax, DWORD PTR [ebx+edx*4+2048]
    mov     dl, BYTE PTR [ebp+ 7]
    xor     eax, DWORD PTR [ebx+edx*4+3072]
    stosd
    add     ebp, 12
    add     edi, 4                      ; rewind to beginning of block
    dec     cl                          ; loop control variable
    xchg    ebp, edi                    ; exchange temporary block and data block pointers
    jne     aes_decrypt_round
    add     ebx, 4352                   ; pointer to invsbox
    lodsd
    mov     dl, BYTE PTR [ebp+12]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 9]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 6]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 3]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 8]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 5]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 2]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+15]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp+ 4]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 1]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+14]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+11]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    lodsd
    mov     dl, BYTE PTR [ebp   ]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+13]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+10]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    mov     dl, BYTE PTR [ebp+ 7]
    xor     al, BYTE PTR [ebx+edx]
    ror     eax, 8
    stosd
    add     esp, 16                     ; deallocate temporary block
    cld
    pop     ebp                         ; restore ebp
    pop     edi                         ; restore edi
    pop     esi                         ; restore esi
    pop     ebx                         ; restore ebx
    ret     8

dw 65419

_TEXT ENDS

END