Guest User

Untitled

a guest
Oct 5th, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 62.82 KB | None | 0 0
  1.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  2.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  3.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  4.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  5.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  6.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  7.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  8.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  9.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  10.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  11.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  12.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  13.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  14.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  15.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  16.   {vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv}
  17.   {$ifndef AES_ASM}
  18.   const Te0:array[0..255]of dword=(
  19.       $c66363a5, $f87c7c84, $ee777799, $f67b7b8d,
  20.       $fff2f20d, $d66b6bbd, $de6f6fb1, $91c5c554,
  21.       $60303050, $02010103, $ce6767a9, $562b2b7d,
  22.       $e7fefe19, $b5d7d762, $4dababe6, $ec76769a,
  23.       $8fcaca45, $1f82829d, $89c9c940, $fa7d7d87,
  24.       $effafa15, $b25959eb, $8e4747c9, $fbf0f00b,
  25.       $41adadec, $b3d4d467, $5fa2a2fd, $45afafea,
  26.       $239c9cbf, $53a4a4f7, $e4727296, $9bc0c05b,
  27.       $75b7b7c2, $e1fdfd1c, $3d9393ae, $4c26266a,
  28.       $6c36365a, $7e3f3f41, $f5f7f702, $83cccc4f,
  29.       $6834345c, $51a5a5f4, $d1e5e534, $f9f1f108,
  30.       $e2717193, $abd8d873, $62313153, $2a15153f,
  31.       $0804040c, $95c7c752, $46232365, $9dc3c35e,
  32.       $30181828, $379696a1, $0a05050f, $2f9a9ab5,
  33.       $0e070709, $24121236, $1b80809b, $dfe2e23d,
  34.       $cdebeb26, $4e272769, $7fb2b2cd, $ea75759f,
  35.       $1209091b, $1d83839e, $582c2c74, $341a1a2e,
  36.       $361b1b2d, $dc6e6eb2, $b45a5aee, $5ba0a0fb,
  37.       $a45252f6, $763b3b4d, $b7d6d661, $7db3b3ce,
  38.       $5229297b, $dde3e33e, $5e2f2f71, $13848497,
  39.       $a65353f5, $b9d1d168, $00000000, $c1eded2c,
  40.       $40202060, $e3fcfc1f, $79b1b1c8, $b65b5bed,
  41.       $d46a6abe, $8dcbcb46, $67bebed9, $7239394b,
  42.       $944a4ade, $984c4cd4, $b05858e8, $85cfcf4a,
  43.       $bbd0d06b, $c5efef2a, $4faaaae5, $edfbfb16,
  44.       $864343c5, $9a4d4dd7, $66333355, $11858594,
  45.       $8a4545cf, $e9f9f910, $04020206, $fe7f7f81,
  46.       $a05050f0, $783c3c44, $259f9fba, $4ba8a8e3,
  47.       $a25151f3, $5da3a3fe, $804040c0, $058f8f8a,
  48.       $3f9292ad, $219d9dbc, $70383848, $f1f5f504,
  49.       $63bcbcdf, $77b6b6c1, $afdada75, $42212163,
  50.       $20101030, $e5ffff1a, $fdf3f30e, $bfd2d26d,
  51.       $81cdcd4c, $180c0c14, $26131335, $c3ecec2f,
  52.       $be5f5fe1, $359797a2, $884444cc, $2e171739,
  53.       $93c4c457, $55a7a7f2, $fc7e7e82, $7a3d3d47,
  54.       $c86464ac, $ba5d5de7, $3219192b, $e6737395,
  55.       $c06060a0, $19818198, $9e4f4fd1, $a3dcdc7f,
  56.       $44222266, $542a2a7e, $3b9090ab, $0b888883,
  57.       $8c4646ca, $c7eeee29, $6bb8b8d3, $2814143c,
  58.       $a7dede79, $bc5e5ee2, $160b0b1d, $addbdb76,
  59.       $dbe0e03b, $64323256, $743a3a4e, $140a0a1e,
  60.       $924949db, $0c06060a, $4824246c, $b85c5ce4,
  61.       $9fc2c25d, $bdd3d36e, $43acacef, $c46262a6,
  62.       $399191a8, $319595a4, $d3e4e437, $f279798b,
  63.       $d5e7e732, $8bc8c843, $6e373759, $da6d6db7,
  64.       $018d8d8c, $b1d5d564, $9c4e4ed2, $49a9a9e0,
  65.       $d86c6cb4, $ac5656fa, $f3f4f407, $cfeaea25,
  66.       $ca6565af, $f47a7a8e, $47aeaee9, $10080818,
  67.       $6fbabad5, $f0787888, $4a25256f, $5c2e2e72,
  68.       $381c1c24, $57a6a6f1, $73b4b4c7, $97c6c651,
  69.       $cbe8e823, $a1dddd7c, $e874749c, $3e1f1f21,
  70.       $964b4bdd, $61bdbddc, $0d8b8b86, $0f8a8a85,
  71.       $e0707090, $7c3e3e42, $71b5b5c4, $cc6666aa,
  72.       $904848d8, $06030305, $f7f6f601, $1c0e0e12,
  73.       $c26161a3, $6a35355f, $ae5757f9, $69b9b9d0,
  74.       $17868691, $99c1c158, $3a1d1d27, $279e9eb9,
  75.       $d9e1e138, $ebf8f813, $2b9898b3, $22111133,
  76.       $d26969bb, $a9d9d970, $078e8e89, $339494a7,
  77.       $2d9b9bb6, $3c1e1e22, $15878792, $c9e9e920,
  78.       $87cece49, $aa5555ff, $50282878, $a5dfdf7a,
  79.       $038c8c8f, $59a1a1f8, $09898980, $1a0d0d17,
  80.       $65bfbfda, $d7e6e631, $844242c6, $d06868b8,
  81.       $824141c3, $299999b0, $5a2d2d77, $1e0f0f11,
  82.       $7bb0b0cb, $a85454fc, $6dbbbbd6, $2c16163a
  83.   );
  84.   const Te1:array[0..255]of dword=(
  85.       $a5c66363, $84f87c7c, $99ee7777, $8df67b7b,
  86.       $0dfff2f2, $bdd66b6b, $b1de6f6f, $5491c5c5,
  87.       $50603030, $03020101, $a9ce6767, $7d562b2b,
  88.       $19e7fefe, $62b5d7d7, $e64dabab, $9aec7676,
  89.       $458fcaca, $9d1f8282, $4089c9c9, $87fa7d7d,
  90.       $15effafa, $ebb25959, $c98e4747, $0bfbf0f0,
  91.       $ec41adad, $67b3d4d4, $fd5fa2a2, $ea45afaf,
  92.       $bf239c9c, $f753a4a4, $96e47272, $5b9bc0c0,
  93.       $c275b7b7, $1ce1fdfd, $ae3d9393, $6a4c2626,
  94.       $5a6c3636, $417e3f3f, $02f5f7f7, $4f83cccc,
  95.       $5c683434, $f451a5a5, $34d1e5e5, $08f9f1f1,
  96.       $93e27171, $73abd8d8, $53623131, $3f2a1515,
  97.       $0c080404, $5295c7c7, $65462323, $5e9dc3c3,
  98.       $28301818, $a1379696, $0f0a0505, $b52f9a9a,
  99.       $090e0707, $36241212, $9b1b8080, $3ddfe2e2,
  100.       $26cdebeb, $694e2727, $cd7fb2b2, $9fea7575,
  101.       $1b120909, $9e1d8383, $74582c2c, $2e341a1a,
  102.       $2d361b1b, $b2dc6e6e, $eeb45a5a, $fb5ba0a0,
  103.       $f6a45252, $4d763b3b, $61b7d6d6, $ce7db3b3,
  104.       $7b522929, $3edde3e3, $715e2f2f, $97138484,
  105.       $f5a65353, $68b9d1d1, $00000000, $2cc1eded,
  106.       $60402020, $1fe3fcfc, $c879b1b1, $edb65b5b,
  107.       $bed46a6a, $468dcbcb, $d967bebe, $4b723939,
  108.       $de944a4a, $d4984c4c, $e8b05858, $4a85cfcf,
  109.       $6bbbd0d0, $2ac5efef, $e54faaaa, $16edfbfb,
  110.       $c5864343, $d79a4d4d, $55663333, $94118585,
  111.       $cf8a4545, $10e9f9f9, $06040202, $81fe7f7f,
  112.       $f0a05050, $44783c3c, $ba259f9f, $e34ba8a8,
  113.       $f3a25151, $fe5da3a3, $c0804040, $8a058f8f,
  114.       $ad3f9292, $bc219d9d, $48703838, $04f1f5f5,
  115.       $df63bcbc, $c177b6b6, $75afdada, $63422121,
  116.       $30201010, $1ae5ffff, $0efdf3f3, $6dbfd2d2,
  117.       $4c81cdcd, $14180c0c, $35261313, $2fc3ecec,
  118.       $e1be5f5f, $a2359797, $cc884444, $392e1717,
  119.       $5793c4c4, $f255a7a7, $82fc7e7e, $477a3d3d,
  120.       $acc86464, $e7ba5d5d, $2b321919, $95e67373,
  121.       $a0c06060, $98198181, $d19e4f4f, $7fa3dcdc,
  122.       $66442222, $7e542a2a, $ab3b9090, $830b8888,
  123.       $ca8c4646, $29c7eeee, $d36bb8b8, $3c281414,
  124.       $79a7dede, $e2bc5e5e, $1d160b0b, $76addbdb,
  125.       $3bdbe0e0, $56643232, $4e743a3a, $1e140a0a,
  126.       $db924949, $0a0c0606, $6c482424, $e4b85c5c,
  127.       $5d9fc2c2, $6ebdd3d3, $ef43acac, $a6c46262,
  128.       $a8399191, $a4319595, $37d3e4e4, $8bf27979,
  129.       $32d5e7e7, $438bc8c8, $596e3737, $b7da6d6d,
  130.       $8c018d8d, $64b1d5d5, $d29c4e4e, $e049a9a9,
  131.       $b4d86c6c, $faac5656, $07f3f4f4, $25cfeaea,
  132.       $afca6565, $8ef47a7a, $e947aeae, $18100808,
  133.       $d56fbaba, $88f07878, $6f4a2525, $725c2e2e,
  134.       $24381c1c, $f157a6a6, $c773b4b4, $5197c6c6,
  135.       $23cbe8e8, $7ca1dddd, $9ce87474, $213e1f1f,
  136.       $dd964b4b, $dc61bdbd, $860d8b8b, $850f8a8a,
  137.       $90e07070, $427c3e3e, $c471b5b5, $aacc6666,
  138.       $d8904848, $05060303, $01f7f6f6, $121c0e0e,
  139.       $a3c26161, $5f6a3535, $f9ae5757, $d069b9b9,
  140.       $91178686, $5899c1c1, $273a1d1d, $b9279e9e,
  141.       $38d9e1e1, $13ebf8f8, $b32b9898, $33221111,
  142.       $bbd26969, $70a9d9d9, $89078e8e, $a7339494,
  143.       $b62d9b9b, $223c1e1e, $92158787, $20c9e9e9,
  144.       $4987cece, $ffaa5555, $78502828, $7aa5dfdf,
  145.       $8f038c8c, $f859a1a1, $80098989, $171a0d0d,
  146.       $da65bfbf, $31d7e6e6, $c6844242, $b8d06868,
  147.       $c3824141, $b0299999, $775a2d2d, $111e0f0f,
  148.       $cb7bb0b0, $fca85454, $d66dbbbb, $3a2c1616
  149.   );
  150.   const Te2:array[0..255]of dword=(
  151.       $63a5c663, $7c84f87c, $7799ee77, $7b8df67b,
  152.       $f20dfff2, $6bbdd66b, $6fb1de6f, $c55491c5,
  153.       $30506030, $01030201, $67a9ce67, $2b7d562b,
  154.       $fe19e7fe, $d762b5d7, $abe64dab, $769aec76,
  155.       $ca458fca, $829d1f82, $c94089c9, $7d87fa7d,
  156.       $fa15effa, $59ebb259, $47c98e47, $f00bfbf0,
  157.       $adec41ad, $d467b3d4, $a2fd5fa2, $afea45af,
  158.       $9cbf239c, $a4f753a4, $7296e472, $c05b9bc0,
  159.       $b7c275b7, $fd1ce1fd, $93ae3d93, $266a4c26,
  160.       $365a6c36, $3f417e3f, $f702f5f7, $cc4f83cc,
  161.       $345c6834, $a5f451a5, $e534d1e5, $f108f9f1,
  162.       $7193e271, $d873abd8, $31536231, $153f2a15,
  163.       $040c0804, $c75295c7, $23654623, $c35e9dc3,
  164.       $18283018, $96a13796, $050f0a05, $9ab52f9a,
  165.       $07090e07, $12362412, $809b1b80, $e23ddfe2,
  166.       $eb26cdeb, $27694e27, $b2cd7fb2, $759fea75,
  167.       $091b1209, $839e1d83, $2c74582c, $1a2e341a,
  168.       $1b2d361b, $6eb2dc6e, $5aeeb45a, $a0fb5ba0,
  169.       $52f6a452, $3b4d763b, $d661b7d6, $b3ce7db3,
  170.       $297b5229, $e33edde3, $2f715e2f, $84971384,
  171.       $53f5a653, $d168b9d1, $00000000, $ed2cc1ed,
  172.       $20604020, $fc1fe3fc, $b1c879b1, $5bedb65b,
  173.       $6abed46a, $cb468dcb, $bed967be, $394b7239,
  174.       $4ade944a, $4cd4984c, $58e8b058, $cf4a85cf,
  175.       $d06bbbd0, $ef2ac5ef, $aae54faa, $fb16edfb,
  176.       $43c58643, $4dd79a4d, $33556633, $85941185,
  177.       $45cf8a45, $f910e9f9, $02060402, $7f81fe7f,
  178.       $50f0a050, $3c44783c, $9fba259f, $a8e34ba8,
  179.       $51f3a251, $a3fe5da3, $40c08040, $8f8a058f,
  180.       $92ad3f92, $9dbc219d, $38487038, $f504f1f5,
  181.       $bcdf63bc, $b6c177b6, $da75afda, $21634221,
  182.       $10302010, $ff1ae5ff, $f30efdf3, $d26dbfd2,
  183.       $cd4c81cd, $0c14180c, $13352613, $ec2fc3ec,
  184.       $5fe1be5f, $97a23597, $44cc8844, $17392e17,
  185.       $c45793c4, $a7f255a7, $7e82fc7e, $3d477a3d,
  186.       $64acc864, $5de7ba5d, $192b3219, $7395e673,
  187.       $60a0c060, $81981981, $4fd19e4f, $dc7fa3dc,
  188.       $22664422, $2a7e542a, $90ab3b90, $88830b88,
  189.       $46ca8c46, $ee29c7ee, $b8d36bb8, $143c2814,
  190.       $de79a7de, $5ee2bc5e, $0b1d160b, $db76addb,
  191.       $e03bdbe0, $32566432, $3a4e743a, $0a1e140a,
  192.       $49db9249, $060a0c06, $246c4824, $5ce4b85c,
  193.       $c25d9fc2, $d36ebdd3, $acef43ac, $62a6c462,
  194.       $91a83991, $95a43195, $e437d3e4, $798bf279,
  195.       $e732d5e7, $c8438bc8, $37596e37, $6db7da6d,
  196.       $8d8c018d, $d564b1d5, $4ed29c4e, $a9e049a9,
  197.       $6cb4d86c, $56faac56, $f407f3f4, $ea25cfea,
  198.       $65afca65, $7a8ef47a, $aee947ae, $08181008,
  199.       $bad56fba, $7888f078, $256f4a25, $2e725c2e,
  200.       $1c24381c, $a6f157a6, $b4c773b4, $c65197c6,
  201.       $e823cbe8, $dd7ca1dd, $749ce874, $1f213e1f,
  202.       $4bdd964b, $bddc61bd, $8b860d8b, $8a850f8a,
  203.       $7090e070, $3e427c3e, $b5c471b5, $66aacc66,
  204.       $48d89048, $03050603, $f601f7f6, $0e121c0e,
  205.       $61a3c261, $355f6a35, $57f9ae57, $b9d069b9,
  206.       $86911786, $c15899c1, $1d273a1d, $9eb9279e,
  207.       $e138d9e1, $f813ebf8, $98b32b98, $11332211,
  208.       $69bbd269, $d970a9d9, $8e89078e, $94a73394,
  209.       $9bb62d9b, $1e223c1e, $87921587, $e920c9e9,
  210.       $ce4987ce, $55ffaa55, $28785028, $df7aa5df,
  211.       $8c8f038c, $a1f859a1, $89800989, $0d171a0d,
  212.       $bfda65bf, $e631d7e6, $42c68442, $68b8d068,
  213.       $41c38241, $99b02999, $2d775a2d, $0f111e0f,
  214.       $b0cb7bb0, $54fca854, $bbd66dbb, $163a2c16
  215.   );
  216.   const Te3:array[0..255]of dword=(
  217.       $6363a5c6, $7c7c84f8, $777799ee, $7b7b8df6,
  218.       $f2f20dff, $6b6bbdd6, $6f6fb1de, $c5c55491,
  219.       $30305060, $01010302, $6767a9ce, $2b2b7d56,
  220.       $fefe19e7, $d7d762b5, $ababe64d, $76769aec,
  221.       $caca458f, $82829d1f, $c9c94089, $7d7d87fa,
  222.       $fafa15ef, $5959ebb2, $4747c98e, $f0f00bfb,
  223.       $adadec41, $d4d467b3, $a2a2fd5f, $afafea45,
  224.       $9c9cbf23, $a4a4f753, $727296e4, $c0c05b9b,
  225.       $b7b7c275, $fdfd1ce1, $9393ae3d, $26266a4c,
  226.       $36365a6c, $3f3f417e, $f7f702f5, $cccc4f83,
  227.       $34345c68, $a5a5f451, $e5e534d1, $f1f108f9,
  228.       $717193e2, $d8d873ab, $31315362, $15153f2a,
  229.       $04040c08, $c7c75295, $23236546, $c3c35e9d,
  230.       $18182830, $9696a137, $05050f0a, $9a9ab52f,
  231.       $0707090e, $12123624, $80809b1b, $e2e23ddf,
  232.       $ebeb26cd, $2727694e, $b2b2cd7f, $75759fea,
  233.       $09091b12, $83839e1d, $2c2c7458, $1a1a2e34,
  234.       $1b1b2d36, $6e6eb2dc, $5a5aeeb4, $a0a0fb5b,
  235.       $5252f6a4, $3b3b4d76, $d6d661b7, $b3b3ce7d,
  236.       $29297b52, $e3e33edd, $2f2f715e, $84849713,
  237.       $5353f5a6, $d1d168b9, $00000000, $eded2cc1,
  238.       $20206040, $fcfc1fe3, $b1b1c879, $5b5bedb6,
  239.       $6a6abed4, $cbcb468d, $bebed967, $39394b72,
  240.       $4a4ade94, $4c4cd498, $5858e8b0, $cfcf4a85,
  241.       $d0d06bbb, $efef2ac5, $aaaae54f, $fbfb16ed,
  242.       $4343c586, $4d4dd79a, $33335566, $85859411,
  243.       $4545cf8a, $f9f910e9, $02020604, $7f7f81fe,
  244.       $5050f0a0, $3c3c4478, $9f9fba25, $a8a8e34b,
  245.       $5151f3a2, $a3a3fe5d, $4040c080, $8f8f8a05,
  246.       $9292ad3f, $9d9dbc21, $38384870, $f5f504f1,
  247.       $bcbcdf63, $b6b6c177, $dada75af, $21216342,
  248.       $10103020, $ffff1ae5, $f3f30efd, $d2d26dbf,
  249.       $cdcd4c81, $0c0c1418, $13133526, $ecec2fc3,
  250.       $5f5fe1be, $9797a235, $4444cc88, $1717392e,
  251.       $c4c45793, $a7a7f255, $7e7e82fc, $3d3d477a,
  252.       $6464acc8, $5d5de7ba, $19192b32, $737395e6,
  253.       $6060a0c0, $81819819, $4f4fd19e, $dcdc7fa3,
  254.       $22226644, $2a2a7e54, $9090ab3b, $8888830b,
  255.       $4646ca8c, $eeee29c7, $b8b8d36b, $14143c28,
  256.       $dede79a7, $5e5ee2bc, $0b0b1d16, $dbdb76ad,
  257.       $e0e03bdb, $32325664, $3a3a4e74, $0a0a1e14,
  258.       $4949db92, $06060a0c, $24246c48, $5c5ce4b8,
  259.       $c2c25d9f, $d3d36ebd, $acacef43, $6262a6c4,
  260.       $9191a839, $9595a431, $e4e437d3, $79798bf2,
  261.       $e7e732d5, $c8c8438b, $3737596e, $6d6db7da,
  262.       $8d8d8c01, $d5d564b1, $4e4ed29c, $a9a9e049,
  263.       $6c6cb4d8, $5656faac, $f4f407f3, $eaea25cf,
  264.       $6565afca, $7a7a8ef4, $aeaee947, $08081810,
  265.       $babad56f, $787888f0, $25256f4a, $2e2e725c,
  266.       $1c1c2438, $a6a6f157, $b4b4c773, $c6c65197,
  267.       $e8e823cb, $dddd7ca1, $74749ce8, $1f1f213e,
  268.       $4b4bdd96, $bdbddc61, $8b8b860d, $8a8a850f,
  269.       $707090e0, $3e3e427c, $b5b5c471, $6666aacc,
  270.       $4848d890, $03030506, $f6f601f7, $0e0e121c,
  271.       $6161a3c2, $35355f6a, $5757f9ae, $b9b9d069,
  272.       $86869117, $c1c15899, $1d1d273a, $9e9eb927,
  273.       $e1e138d9, $f8f813eb, $9898b32b, $11113322,
  274.       $6969bbd2, $d9d970a9, $8e8e8907, $9494a733,
  275.       $9b9bb62d, $1e1e223c, $87879215, $e9e920c9,
  276.       $cece4987, $5555ffaa, $28287850, $dfdf7aa5,
  277.       $8c8c8f03, $a1a1f859, $89898009, $0d0d171a,
  278.       $bfbfda65, $e6e631d7, $4242c684, $6868b8d0,
  279.       $4141c382, $9999b029, $2d2d775a, $0f0f111e,
  280.       $b0b0cb7b, $5454fca8, $bbbbd66d, $16163a2c
  281.   );
  282.  
  283.   const Td0:array[0..255]of dword=(
  284.       $51f4a750, $7e416553, $1a17a4c3, $3a275e96,
  285.       $3bab6bcb, $1f9d45f1, $acfa58ab, $4be30393,
  286.       $2030fa55, $ad766df6, $88cc7691, $f5024c25,
  287.       $4fe5d7fc, $c52acbd7, $26354480, $b562a38f,
  288.       $deb15a49, $25ba1b67, $45ea0e98, $5dfec0e1,
  289.       $c32f7502, $814cf012, $8d4697a3, $6bd3f9c6,
  290.       $038f5fe7, $15929c95, $bf6d7aeb, $955259da,
  291.       $d4be832d, $587421d3, $49e06929, $8ec9c844,
  292.       $75c2896a, $f48e7978, $99583e6b, $27b971dd,
  293.       $bee14fb6, $f088ad17, $c920ac66, $7dce3ab4,
  294.       $63df4a18, $e51a3182, $97513360, $62537f45,
  295.       $b16477e0, $bb6bae84, $fe81a01c, $f9082b94,
  296.       $70486858, $8f45fd19, $94de6c87, $527bf8b7,
  297.       $ab73d323, $724b02e2, $e31f8f57, $6655ab2a,
  298.       $b2eb2807, $2fb5c203, $86c57b9a, $d33708a5,
  299.       $302887f2, $23bfa5b2, $02036aba, $ed16825c,
  300.       $8acf1c2b, $a779b492, $f307f2f0, $4e69e2a1,
  301.       $65daf4cd, $0605bed5, $d134621f, $c4a6fe8a,
  302.       $342e539d, $a2f355a0, $058ae132, $a4f6eb75,
  303.       $0b83ec39, $4060efaa, $5e719f06, $bd6e1051,
  304.       $3e218af9, $96dd063d, $dd3e05ae, $4de6bd46,
  305.       $91548db5, $71c45d05, $0406d46f, $605015ff,
  306.       $1998fb24, $d6bde997, $894043cc, $67d99e77,
  307.       $b0e842bd, $07898b88, $e7195b38, $79c8eedb,
  308.       $a17c0a47, $7c420fe9, $f8841ec9, $00000000,
  309.       $09808683, $322bed48, $1e1170ac, $6c5a724e,
  310.       $fd0efffb, $0f853856, $3daed51e, $362d3927,
  311.       $0a0fd964, $685ca621, $9b5b54d1, $24362e3a,
  312.       $0c0a67b1, $9357e70f, $b4ee96d2, $1b9b919e,
  313.       $80c0c54f, $61dc20a2, $5a774b69, $1c121a16,
  314.       $e293ba0a, $c0a02ae5, $3c22e043, $121b171d,
  315.       $0e090d0b, $f28bc7ad, $2db6a8b9, $141ea9c8,
  316.       $57f11985, $af75074c, $ee99ddbb, $a37f60fd,
  317.       $f701269f, $5c72f5bc, $44663bc5, $5bfb7e34,
  318.       $8b432976, $cb23c6dc, $b6edfc68, $b8e4f163,
  319.       $d731dcca, $42638510, $13972240, $84c61120,
  320.       $854a247d, $d2bb3df8, $aef93211, $c729a16d,
  321.       $1d9e2f4b, $dcb230f3, $0d8652ec, $77c1e3d0,
  322.       $2bb3166c, $a970b999, $119448fa, $47e96422,
  323.       $a8fc8cc4, $a0f03f1a, $567d2cd8, $223390ef,
  324.       $87494ec7, $d938d1c1, $8ccaa2fe, $98d40b36,
  325.       $a6f581cf, $a57ade28, $dab78e26, $3fadbfa4,
  326.       $2c3a9de4, $5078920d, $6a5fcc9b, $547e4662,
  327.       $f68d13c2, $90d8b8e8, $2e39f75e, $82c3aff5,
  328.       $9f5d80be, $69d0937c, $6fd52da9, $cf2512b3,
  329.       $c8ac993b, $10187da7, $e89c636e, $db3bbb7b,
  330.       $cd267809, $6e5918f4, $ec9ab701, $834f9aa8,
  331.       $e6956e65, $aaffe67e, $21bccf08, $ef15e8e6,
  332.       $bae79bd9, $4a6f36ce, $ea9f09d4, $29b07cd6,
  333.       $31a4b2af, $2a3f2331, $c6a59430, $35a266c0,
  334.       $744ebc37, $fc82caa6, $e090d0b0, $33a7d815,
  335.       $f104984a, $41ecdaf7, $7fcd500e, $1791f62f,
  336.       $764dd68d, $43efb04d, $ccaa4d54, $e49604df,
  337.       $9ed1b5e3, $4c6a881b, $c12c1fb8, $4665517f,
  338.       $9d5eea04, $018c355d, $fa877473, $fb0b412e,
  339.       $b3671d5a, $92dbd252, $e9105633, $6dd64713,
  340.       $9ad7618c, $37a10c7a, $59f8148e, $eb133c89,
  341.       $cea927ee, $b761c935, $e11ce5ed, $7a47b13c,
  342.       $9cd2df59, $55f2733f, $1814ce79, $73c737bf,
  343.       $53f7cdea, $5ffdaa5b, $df3d6f14, $7844db86,
  344.       $caaff381, $b968c43e, $3824342c, $c2a3405f,
  345.       $161dc372, $bce2250c, $283c498b, $ff0d9541,
  346.       $39a80171, $080cb3de, $d8b4e49c, $6456c190,
  347.       $7bcb8461, $d532b670, $486c5c74, $d0b85742
  348.   );
  349.   const Td1:array[0..255]of dword=(
  350.       $5051f4a7, $537e4165, $c31a17a4, $963a275e,
  351.       $cb3bab6b, $f11f9d45, $abacfa58, $934be303,
  352.       $552030fa, $f6ad766d, $9188cc76, $25f5024c,
  353.       $fc4fe5d7, $d7c52acb, $80263544, $8fb562a3,
  354.       $49deb15a, $6725ba1b, $9845ea0e, $e15dfec0,
  355.       $02c32f75, $12814cf0, $a38d4697, $c66bd3f9,
  356.       $e7038f5f, $9515929c, $ebbf6d7a, $da955259,
  357.       $2dd4be83, $d3587421, $2949e069, $448ec9c8,
  358.       $6a75c289, $78f48e79, $6b99583e, $dd27b971,
  359.       $b6bee14f, $17f088ad, $66c920ac, $b47dce3a,
  360.       $1863df4a, $82e51a31, $60975133, $4562537f,
  361.       $e0b16477, $84bb6bae, $1cfe81a0, $94f9082b,
  362.       $58704868, $198f45fd, $8794de6c, $b7527bf8,
  363.       $23ab73d3, $e2724b02, $57e31f8f, $2a6655ab,
  364.       $07b2eb28, $032fb5c2, $9a86c57b, $a5d33708,
  365.       $f2302887, $b223bfa5, $ba02036a, $5ced1682,
  366.       $2b8acf1c, $92a779b4, $f0f307f2, $a14e69e2,
  367.       $cd65daf4, $d50605be, $1fd13462, $8ac4a6fe,
  368.       $9d342e53, $a0a2f355, $32058ae1, $75a4f6eb,
  369.       $390b83ec, $aa4060ef, $065e719f, $51bd6e10,
  370.       $f93e218a, $3d96dd06, $aedd3e05, $464de6bd,
  371.       $b591548d, $0571c45d, $6f0406d4, $ff605015,
  372.       $241998fb, $97d6bde9, $cc894043, $7767d99e,
  373.       $bdb0e842, $8807898b, $38e7195b, $db79c8ee,
  374.       $47a17c0a, $e97c420f, $c9f8841e, $00000000,
  375.       $83098086, $48322bed, $ac1e1170, $4e6c5a72,
  376.       $fbfd0eff, $560f8538, $1e3daed5, $27362d39,
  377.       $640a0fd9, $21685ca6, $d19b5b54, $3a24362e,
  378.       $b10c0a67, $0f9357e7, $d2b4ee96, $9e1b9b91,
  379.       $4f80c0c5, $a261dc20, $695a774b, $161c121a,
  380.       $0ae293ba, $e5c0a02a, $433c22e0, $1d121b17,
  381.       $0b0e090d, $adf28bc7, $b92db6a8, $c8141ea9,
  382.       $8557f119, $4caf7507, $bbee99dd, $fda37f60,
  383.       $9ff70126, $bc5c72f5, $c544663b, $345bfb7e,
  384.       $768b4329, $dccb23c6, $68b6edfc, $63b8e4f1,
  385.       $cad731dc, $10426385, $40139722, $2084c611,
  386.       $7d854a24, $f8d2bb3d, $11aef932, $6dc729a1,
  387.       $4b1d9e2f, $f3dcb230, $ec0d8652, $d077c1e3,
  388.       $6c2bb316, $99a970b9, $fa119448, $2247e964,
  389.       $c4a8fc8c, $1aa0f03f, $d8567d2c, $ef223390,
  390.       $c787494e, $c1d938d1, $fe8ccaa2, $3698d40b,
  391.       $cfa6f581, $28a57ade, $26dab78e, $a43fadbf,
  392.       $e42c3a9d, $0d507892, $9b6a5fcc, $62547e46,
  393.       $c2f68d13, $e890d8b8, $5e2e39f7, $f582c3af,
  394.       $be9f5d80, $7c69d093, $a96fd52d, $b3cf2512,
  395.       $3bc8ac99, $a710187d, $6ee89c63, $7bdb3bbb,
  396.       $09cd2678, $f46e5918, $01ec9ab7, $a8834f9a,
  397.       $65e6956e, $7eaaffe6, $0821bccf, $e6ef15e8,
  398.       $d9bae79b, $ce4a6f36, $d4ea9f09, $d629b07c,
  399.       $af31a4b2, $312a3f23, $30c6a594, $c035a266,
  400.       $37744ebc, $a6fc82ca, $b0e090d0, $1533a7d8,
  401.       $4af10498, $f741ecda, $0e7fcd50, $2f1791f6,
  402.       $8d764dd6, $4d43efb0, $54ccaa4d, $dfe49604,
  403.       $e39ed1b5, $1b4c6a88, $b8c12c1f, $7f466551,
  404.       $049d5eea, $5d018c35, $73fa8774, $2efb0b41,
  405.       $5ab3671d, $5292dbd2, $33e91056, $136dd647,
  406.       $8c9ad761, $7a37a10c, $8e59f814, $89eb133c,
  407.       $eecea927, $35b761c9, $ede11ce5, $3c7a47b1,
  408.       $599cd2df, $3f55f273, $791814ce, $bf73c737,
  409.       $ea53f7cd, $5b5ffdaa, $14df3d6f, $867844db,
  410.       $81caaff3, $3eb968c4, $2c382434, $5fc2a340,
  411.       $72161dc3, $0cbce225, $8b283c49, $41ff0d95,
  412.       $7139a801, $de080cb3, $9cd8b4e4, $906456c1,
  413.       $617bcb84, $70d532b6, $74486c5c, $42d0b857
  414.   );
  415.   const Td2:array[0..255]of dword=(
  416.       $a75051f4, $65537e41, $a4c31a17, $5e963a27,
  417.       $6bcb3bab, $45f11f9d, $58abacfa, $03934be3,
  418.       $fa552030, $6df6ad76, $769188cc, $4c25f502,
  419.       $d7fc4fe5, $cbd7c52a, $44802635, $a38fb562,
  420.       $5a49deb1, $1b6725ba, $0e9845ea, $c0e15dfe,
  421.       $7502c32f, $f012814c, $97a38d46, $f9c66bd3,
  422.       $5fe7038f, $9c951592, $7aebbf6d, $59da9552,
  423.       $832dd4be, $21d35874, $692949e0, $c8448ec9,
  424.       $896a75c2, $7978f48e, $3e6b9958, $71dd27b9,
  425.       $4fb6bee1, $ad17f088, $ac66c920, $3ab47dce,
  426.       $4a1863df, $3182e51a, $33609751, $7f456253,
  427.       $77e0b164, $ae84bb6b, $a01cfe81, $2b94f908,
  428.       $68587048, $fd198f45, $6c8794de, $f8b7527b,
  429.       $d323ab73, $02e2724b, $8f57e31f, $ab2a6655,
  430.       $2807b2eb, $c2032fb5, $7b9a86c5, $08a5d337,
  431.       $87f23028, $a5b223bf, $6aba0203, $825ced16,
  432.       $1c2b8acf, $b492a779, $f2f0f307, $e2a14e69,
  433.       $f4cd65da, $bed50605, $621fd134, $fe8ac4a6,
  434.       $539d342e, $55a0a2f3, $e132058a, $eb75a4f6,
  435.       $ec390b83, $efaa4060, $9f065e71, $1051bd6e,
  436.       $8af93e21, $063d96dd, $05aedd3e, $bd464de6,
  437.       $8db59154, $5d0571c4, $d46f0406, $15ff6050,
  438.       $fb241998, $e997d6bd, $43cc8940, $9e7767d9,
  439.       $42bdb0e8, $8b880789, $5b38e719, $eedb79c8,
  440.       $0a47a17c, $0fe97c42, $1ec9f884, $00000000,
  441.       $86830980, $ed48322b, $70ac1e11, $724e6c5a,
  442.       $fffbfd0e, $38560f85, $d51e3dae, $3927362d,
  443.       $d9640a0f, $a621685c, $54d19b5b, $2e3a2436,
  444.       $67b10c0a, $e70f9357, $96d2b4ee, $919e1b9b,
  445.       $c54f80c0, $20a261dc, $4b695a77, $1a161c12,
  446.       $ba0ae293, $2ae5c0a0, $e0433c22, $171d121b,
  447.       $0d0b0e09, $c7adf28b, $a8b92db6, $a9c8141e,
  448.       $198557f1, $074caf75, $ddbbee99, $60fda37f,
  449.       $269ff701, $f5bc5c72, $3bc54466, $7e345bfb,
  450.       $29768b43, $c6dccb23, $fc68b6ed, $f163b8e4,
  451.       $dccad731, $85104263, $22401397, $112084c6,
  452.       $247d854a, $3df8d2bb, $3211aef9, $a16dc729,
  453.       $2f4b1d9e, $30f3dcb2, $52ec0d86, $e3d077c1,
  454.       $166c2bb3, $b999a970, $48fa1194, $642247e9,
  455.       $8cc4a8fc, $3f1aa0f0, $2cd8567d, $90ef2233,
  456.       $4ec78749, $d1c1d938, $a2fe8cca, $0b3698d4,
  457.       $81cfa6f5, $de28a57a, $8e26dab7, $bfa43fad,
  458.       $9de42c3a, $920d5078, $cc9b6a5f, $4662547e,
  459.       $13c2f68d, $b8e890d8, $f75e2e39, $aff582c3,
  460.       $80be9f5d, $937c69d0, $2da96fd5, $12b3cf25,
  461.       $993bc8ac, $7da71018, $636ee89c, $bb7bdb3b,
  462.       $7809cd26, $18f46e59, $b701ec9a, $9aa8834f,
  463.       $6e65e695, $e67eaaff, $cf0821bc, $e8e6ef15,
  464.       $9bd9bae7, $36ce4a6f, $09d4ea9f, $7cd629b0,
  465.       $b2af31a4, $23312a3f, $9430c6a5, $66c035a2,
  466.       $bc37744e, $caa6fc82, $d0b0e090, $d81533a7,
  467.       $984af104, $daf741ec, $500e7fcd, $f62f1791,
  468.       $d68d764d, $b04d43ef, $4d54ccaa, $04dfe496,
  469.       $b5e39ed1, $881b4c6a, $1fb8c12c, $517f4665,
  470.       $ea049d5e, $355d018c, $7473fa87, $412efb0b,
  471.       $1d5ab367, $d25292db, $5633e910, $47136dd6,
  472.       $618c9ad7, $0c7a37a1, $148e59f8, $3c89eb13,
  473.       $27eecea9, $c935b761, $e5ede11c, $b13c7a47,
  474.       $df599cd2, $733f55f2, $ce791814, $37bf73c7,
  475.       $cdea53f7, $aa5b5ffd, $6f14df3d, $db867844,
  476.       $f381caaf, $c43eb968, $342c3824, $405fc2a3,
  477.       $c372161d, $250cbce2, $498b283c, $9541ff0d,
  478.       $017139a8, $b3de080c, $e49cd8b4, $c1906456,
  479.       $84617bcb, $b670d532, $5c74486c, $5742d0b8
  480.   );
  481.   const Td3:array[0..255]of dword=(
  482.       $f4a75051, $4165537e, $17a4c31a, $275e963a,
  483.       $ab6bcb3b, $9d45f11f, $fa58abac, $e303934b,
  484.       $30fa5520, $766df6ad, $cc769188, $024c25f5,
  485.       $e5d7fc4f, $2acbd7c5, $35448026, $62a38fb5,
  486.       $b15a49de, $ba1b6725, $ea0e9845, $fec0e15d,
  487.       $2f7502c3, $4cf01281, $4697a38d, $d3f9c66b,
  488.       $8f5fe703, $929c9515, $6d7aebbf, $5259da95,
  489.       $be832dd4, $7421d358, $e0692949, $c9c8448e,
  490.       $c2896a75, $8e7978f4, $583e6b99, $b971dd27,
  491.       $e14fb6be, $88ad17f0, $20ac66c9, $ce3ab47d,
  492.       $df4a1863, $1a3182e5, $51336097, $537f4562,
  493.       $6477e0b1, $6bae84bb, $81a01cfe, $082b94f9,
  494.       $48685870, $45fd198f, $de6c8794, $7bf8b752,
  495.       $73d323ab, $4b02e272, $1f8f57e3, $55ab2a66,
  496.       $eb2807b2, $b5c2032f, $c57b9a86, $3708a5d3,
  497.       $2887f230, $bfa5b223, $036aba02, $16825ced,
  498.       $cf1c2b8a, $79b492a7, $07f2f0f3, $69e2a14e,
  499.       $daf4cd65, $05bed506, $34621fd1, $a6fe8ac4,
  500.       $2e539d34, $f355a0a2, $8ae13205, $f6eb75a4,
  501.       $83ec390b, $60efaa40, $719f065e, $6e1051bd,
  502.       $218af93e, $dd063d96, $3e05aedd, $e6bd464d,
  503.       $548db591, $c45d0571, $06d46f04, $5015ff60,
  504.       $98fb2419, $bde997d6, $4043cc89, $d99e7767,
  505.       $e842bdb0, $898b8807, $195b38e7, $c8eedb79,
  506.       $7c0a47a1, $420fe97c, $841ec9f8, $00000000,
  507.       $80868309, $2bed4832, $1170ac1e, $5a724e6c,
  508.       $0efffbfd, $8538560f, $aed51e3d, $2d392736,
  509.       $0fd9640a, $5ca62168, $5b54d19b, $362e3a24,
  510.       $0a67b10c, $57e70f93, $ee96d2b4, $9b919e1b,
  511.       $c0c54f80, $dc20a261, $774b695a, $121a161c,
  512.       $93ba0ae2, $a02ae5c0, $22e0433c, $1b171d12,
  513.       $090d0b0e, $8bc7adf2, $b6a8b92d, $1ea9c814,
  514.       $f1198557, $75074caf, $99ddbbee, $7f60fda3,
  515.       $01269ff7, $72f5bc5c, $663bc544, $fb7e345b,
  516.       $4329768b, $23c6dccb, $edfc68b6, $e4f163b8,
  517.       $31dccad7, $63851042, $97224013, $c6112084,
  518.       $4a247d85, $bb3df8d2, $f93211ae, $29a16dc7,
  519.       $9e2f4b1d, $b230f3dc, $8652ec0d, $c1e3d077,
  520.       $b3166c2b, $70b999a9, $9448fa11, $e9642247,
  521.       $fc8cc4a8, $f03f1aa0, $7d2cd856, $3390ef22,
  522.       $494ec787, $38d1c1d9, $caa2fe8c, $d40b3698,
  523.       $f581cfa6, $7ade28a5, $b78e26da, $adbfa43f,
  524.       $3a9de42c, $78920d50, $5fcc9b6a, $7e466254,
  525.       $8d13c2f6, $d8b8e890, $39f75e2e, $c3aff582,
  526.       $5d80be9f, $d0937c69, $d52da96f, $2512b3cf,
  527.       $ac993bc8, $187da710, $9c636ee8, $3bbb7bdb,
  528.       $267809cd, $5918f46e, $9ab701ec, $4f9aa883,
  529.       $956e65e6, $ffe67eaa, $bccf0821, $15e8e6ef,
  530.       $e79bd9ba, $6f36ce4a, $9f09d4ea, $b07cd629,
  531.       $a4b2af31, $3f23312a, $a59430c6, $a266c035,
  532.       $4ebc3774, $82caa6fc, $90d0b0e0, $a7d81533,
  533.       $04984af1, $ecdaf741, $cd500e7f, $91f62f17,
  534.       $4dd68d76, $efb04d43, $aa4d54cc, $9604dfe4,
  535.       $d1b5e39e, $6a881b4c, $2c1fb8c1, $65517f46,
  536.       $5eea049d, $8c355d01, $877473fa, $0b412efb,
  537.       $671d5ab3, $dbd25292, $105633e9, $d647136d,
  538.       $d7618c9a, $a10c7a37, $f8148e59, $133c89eb,
  539.       $a927eece, $61c935b7, $1ce5ede1, $47b13c7a,
  540.       $d2df599c, $f2733f55, $14ce7918, $c737bf73,
  541.       $f7cdea53, $fdaa5b5f, $3d6f14df, $44db8678,
  542.       $aff381ca, $68c43eb9, $24342c38, $a3405fc2,
  543.       $1dc37216, $e2250cbc, $3c498b28, $0d9541ff,
  544.       $a8017139, $0cb3de08, $b4e49cd8, $56c19064,
  545.       $cb84617b, $32b670d5, $6c5c7448, $b85742d0
  546.   );
  547.   const Td4:array[0..255]of byte=(
  548.       $52, $09, $6a, $d5, $30, $36, $a5, $38,
  549.       $bf, $40, $a3, $9e, $81, $f3, $d7, $fb,
  550.       $7c, $e3, $39, $82, $9b, $2f, $ff, $87,
  551.       $34, $8e, $43, $44, $c4, $de, $e9, $cb,
  552.       $54, $7b, $94, $32, $a6, $c2, $23, $3d,
  553.       $ee, $4c, $95, $0b, $42, $fa, $c3, $4e,
  554.       $08, $2e, $a1, $66, $28, $d9, $24, $b2,
  555.       $76, $5b, $a2, $49, $6d, $8b, $d1, $25,
  556.       $72, $f8, $f6, $64, $86, $68, $98, $16,
  557.       $d4, $a4, $5c, $cc, $5d, $65, $b6, $92,
  558.       $6c, $70, $48, $50, $fd, $ed, $b9, $da,
  559.       $5e, $15, $46, $57, $a7, $8d, $9d, $84,
  560.       $90, $d8, $ab, $00, $8c, $bc, $d3, $0a,
  561.       $f7, $e4, $58, $05, $b8, $b3, $45, $06,
  562.       $d0, $2c, $1e, $8f, $ca, $3f, $0f, $02,
  563.       $c1, $af, $bd, $03, $01, $13, $8a, $6b,
  564.       $3a, $91, $11, $41, $4f, $67, $dc, $ea,
  565.       $97, $f2, $cf, $ce, $f0, $b4, $e6, $73,
  566.       $96, $ac, $74, $22, $e7, $ad, $35, $85,
  567.       $e2, $f9, $37, $e8, $1c, $75, $df, $6e,
  568.       $47, $f1, $1a, $71, $1d, $29, $c5, $89,
  569.       $6f, $b7, $62, $0e, $aa, $18, $be, $1b,
  570.       $fc, $56, $3e, $4b, $c6, $d2, $79, $20,
  571.       $9a, $db, $c0, $fe, $78, $cd, $5a, $f4,
  572.       $1f, $dd, $a8, $33, $88, $07, $c7, $31,
  573.       $b1, $12, $10, $59, $27, $80, $ec, $5f,
  574.       $60, $51, $7f, $a9, $19, $b5, $4a, $0d,
  575.       $2d, $e5, $7a, $9f, $93, $c9, $9c, $ef,
  576.       $a0, $e0, $3b, $4d, $ae, $2a, $f5, $b0,
  577.       $c8, $eb, $bb, $3c, $83, $53, $99, $61,
  578.       $17, $2b, $04, $7e, $ba, $77, $d6, $26,
  579.       $e1, $69, $14, $63, $55, $21, $0c, $7d
  580.   );
  581.   const rcon:array [0..9] of dword = (
  582.     $01000000, $02000000, $04000000, $08000000,
  583.     $10000000, $20000000, $40000000, $80000000,
  584.     $1B000000, $36000000 (* for 128-bit blocks, Rijndael never uses more than 10 rcon values *)
  585.   );
  586.  
  587.   const
  588.     AES_MAXNR=14;
  589.     AES_BLOCK_SIZE=16;
  590.   type
  591.     AES_KEY = record
  592.       rd_key: array [0..(4 *(AES_MAXNR + 1))-1] of dword;
  593.       rounds:dword;
  594.     end;
  595.     pAES_KEY = ^AES_KEY;
  596.  
  597.     function GETU32(pt:pchar):dword;
  598.     begin
  599.       result:= (dword(pt[0])shl 24)xor(dword(pt[1])shl 16)xor(dword(pt[2])shl 8)xor(dword(pt[3]))
  600.     end;
  601.     procedure PUTU32(var ct:pchar; const st:dword);
  602.     begin
  603.      (ct)[0] := Chr((st) shr 24);
  604.      (ct)[1] := Chr((st) shr 16);
  605.      (ct)[2] := Chr((st) shr  8);
  606.      (ct)[3] := Chr(st);
  607.     end;
  608.   (*
  609.    * Expand the cipher key into the encryption key schedule.
  610.    *)
  611.   function AES_set_encrypt_key(
  612.     const userKey : pchar;
  613.     const bits    : dword;
  614.     var   key     : pAES_KEY):dword;
  615.   var
  616.     rk:pdword;
  617.     temp:dword;
  618.   const
  619.     i:dword = 0;
  620.   begin
  621.  
  622.     if ((userKey=nil) OR (key=nil)) then
  623.       result:=-1;
  624.     if ((bits <> 128) and (bits <> 192) and (bits <> 256)) then
  625.       result:=-2;
  626.  
  627.     rk := key^.rd_key;
  628.  
  629.     if (bits=128) then
  630.       key^.rounds := 10
  631.     else begin
  632.            if (bits=192) then
  633.              key^.rounds := 12
  634.            else
  635.              key^.rounds := 14;
  636.          end;
  637.     rk[0] := GETU32(userKey     );
  638.     rk[1] := GETU32(userKey +  4);
  639.     rk[2] := GETU32(userKey +  8);
  640.     rk[3] := GETU32(userKey + 12);
  641.     if (bits = 128) then begin
  642.       while true do begin
  643.         temp  := rk[3];
  644.         rk[4] := rk[0] xor
  645.           (Te2[(temp shr 16) and $ff] and $ff000000) xor
  646.           (Te3[(temp shr  8) and $ff] and $00ff0000) xor
  647.           (Te0[(temp       ) and $ff] and $0000ff00) xor
  648.           (Te1[(temp shr 24)        ] and $000000ff) xor
  649.           rcon[i];
  650.         rk[5] := rk[1] xor rk[4];
  651.         rk[6] := rk[2] xor rk[5];
  652.         rk[7] := rk[3] xor rk[6];
  653.         inc(i);
  654.         if (i = 10) then begin
  655.           result:=0;break;
  656.         end;
  657.         rk := rk + 4;
  658.       end;
  659.     end;
  660.     rk[4] := GETU32(userKey + 16);
  661.     rk[5] := GETU32(userKey + 20);
  662.     if (bits = 192) then begin
  663.       while true do begin
  664.         temp := rk[ 5];
  665.         rk[ 6] := rk[ 0] xor
  666.           (Te2[(temp shr 16) and $ff] and $ff000000) xor
  667.           (Te3[(temp shr  8) and $ff] and $00ff0000) xor
  668.           (Te0[(temp       ) and $ff] and $0000ff00) xor
  669.           (Te1[(temp shr 24)        ] and $000000ff) xor
  670.           rcon[i];
  671.         rk[ 7] := rk[ 1] xor rk[ 6];
  672.         rk[ 8] := rk[ 2] xor rk[ 7];
  673.         rk[ 9] := rk[ 3] xor rk[ 8];
  674.         inc(i);
  675.         if (i = 8) then begin
  676.           result:=0;break;
  677.         end;
  678.         rk[10] := rk[ 4] xor rk[ 9];
  679.         rk[11] := rk[ 5] xor rk[10];
  680.         rk := rk + 6;
  681.       end;
  682.     end;
  683.     rk[6] := GETU32(userKey + 24);
  684.     rk[7] := GETU32(userKey + 28);
  685.     if (bits = 256) then begin
  686.       while true do begin
  687.         temp := rk[ 7];
  688.         rk[ 8] := rk[ 0] xor
  689.           (Te2[(temp shr 16) and $ff] and $ff000000) xor
  690.           (Te3[(temp shr  8) and $ff] and $00ff0000) xor
  691.           (Te0[(temp       ) and $ff] and $0000ff00) xor
  692.           (Te1[(temp shr 24)        ] and $000000ff) xor
  693.           rcon[i];
  694.         rk[ 9] := rk[ 1] xor rk[ 8];
  695.         rk[10] := rk[ 2] xor rk[ 9];
  696.         rk[11] := rk[ 3] xor rk[10];
  697.         inc(i);
  698.         if (i = 7) then begin
  699.           result:=0;break;
  700.         end;
  701.         temp := rk[11];
  702.         rk[12] := rk[ 4] xor
  703.           (Te2[(temp shr 24)        ] and $ff000000) xor
  704.           (Te3[(temp shr 16) and $ff] and $00ff0000) xor
  705.           (Te0[(temp shr  8) and $ff] and $0000ff00) xor
  706.           (Te1[(temp       ) and $ff] and $000000ff);
  707.         rk[13] := rk[ 5] xor rk[12];
  708.         rk[14] := rk[ 6] xor rk[13];
  709.         rk[15] := rk[ 7] xor rk[14];
  710.  
  711.         rk := rk + 8;
  712.         end;
  713.     end;
  714.     result:=0;
  715.   end;
  716.  
  717.   (*
  718.    * Expand the cipher key into the decryption key schedule.
  719.    *)
  720.   function AES_set_decrypt_key(
  721.     const userKey : pchar;
  722.     const bits    : dword;
  723.     var   key     : pAES_KEY):dword;
  724.   var
  725.     rk:pdword;
  726.     i, j, status:dword;
  727.     temp:dword;
  728.   begin
  729.     (* first, start with an encryption schedule *)
  730.     status := AES_set_encrypt_key(userKey, bits, key);
  731.     if (status < 0)then
  732.       result:= status;
  733.  
  734.     rk := key^.rd_key;
  735.  
  736.     (* invert the order of the round keys: *)
  737.     i := 0; j := 4*(key^.rounds);
  738.     while (i < j) do begin
  739.       temp := rk[i    ]; rk[i    ] := rk[j    ]; rk[j    ] := temp;
  740.       temp := rk[i + 1]; rk[i + 1] := rk[j + 1]; rk[j + 1] := temp;
  741.       temp := rk[i + 2]; rk[i + 2] := rk[j + 2]; rk[j + 2] := temp;
  742.       temp := rk[i + 3]; rk[i + 3] := rk[j + 3]; rk[j + 3] := temp;
  743.       i := i+4; j := j-4;
  744.     end;
  745.     (* apply the inverse MixColumn transform to all round keys but the first and the last: *)
  746.     i := 1;
  747.     while (i < (key^.rounds)) do begin
  748.       rk := rk +4;
  749.       rk[0] :=
  750.         Td0[Te1[(rk[0] shr 24)        ] and $ff] xor
  751.         Td1[Te1[(rk[0] shr 16) and $ff] and $ff] xor
  752.         Td2[Te1[(rk[0] shr  8) and $ff] and $ff] xor
  753.         Td3[Te1[(rk[0]       ) and $ff] and $ff];
  754.       rk[1] :=
  755.         Td0[Te1[(rk[1] shr 24)        ] and $ff] xor
  756.         Td1[Te1[(rk[1] shr 16) and $ff] and $ff] xor
  757.         Td2[Te1[(rk[1] shr  8) and $ff] and $ff] xor
  758.         Td3[Te1[(rk[1]       ) and $ff] and $ff];
  759.       rk[2] :=
  760.         Td0[Te1[(rk[2] shr 24)        ] and $ff] xor
  761.         Td1[Te1[(rk[2] shr 16) and $ff] and $ff] xor
  762.         Td2[Te1[(rk[2] shr  8) and $ff] and $ff] xor
  763.         Td3[Te1[(rk[2]       ) and $ff] and $ff];
  764.       rk[3] :=
  765.         Td0[Te1[(rk[3] shr 24)        ] and $ff] xor
  766.         Td1[Te1[(rk[3] shr 16) and $ff] and $ff] xor
  767.         Td2[Te1[(rk[3] shr  8) and $ff] and $ff] xor
  768.         Td3[Te1[(rk[3]       ) and $ff] and $ff];
  769.       inc(i);
  770.     end;
  771.     result:=0;
  772.   end;
  773.  
  774.   (*
  775.    * Encrypt a single block
  776.    * in and out can overlap
  777.    *)
  778.   procedure AES_encrypt(
  779.     const in_  : pchar;
  780.     var   out_ : pchar;
  781.     const key : pAES_KEY
  782.   );
  783.     var rk:pdword;
  784.     var s0, s1, s2, s3, t0, t1, t2, t3:dword;
  785.   {$ifndef FULL_UNROLL}
  786.     var r:dword;
  787.   {$endif} (* ?FULL_UNROLL *)
  788.   begin
  789.     (*
  790.     {$ASSERTIONS+}
  791.     System.assert(in_ AND out_ AND key);
  792.     *)
  793.     rk := key^.rd_key;
  794.  
  795.     (*
  796.      * map byte array block to cipher state
  797.      * and add initial round key:
  798.      *)
  799.     s0 := GETU32(in_     ) xor rk[0];
  800.     s1 := GETU32(in_ +  4) xor rk[1];
  801.     s2 := GETU32(in_ +  8) xor rk[2];
  802.     s3 := GETU32(in_ + 12) xor rk[3];
  803.   {$ifdef FULL_UNROLL}
  804.     (* round 1: *)
  805.        t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[ 4];
  806.        t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[ 5];
  807.        t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[ 6];
  808.        t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[ 7];
  809.        (* round 2: *)
  810.        s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[ 8];
  811.        s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[ 9];
  812.        s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[10];
  813.        s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[11];
  814.     (* round 3: *)
  815.        t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[12];
  816.        t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[13];
  817.        t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[14];
  818.        t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[15];
  819.        (* round 4: *)
  820.        s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[16];
  821.        s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[17];
  822.        s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[18];
  823.        s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[19];
  824.     (* round 5: *)
  825.        t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[20];
  826.        t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[21];
  827.        t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[22];
  828.        t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[23];
  829.        (* round 6: *)
  830.        s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[24];
  831.        s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[25];
  832.        s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[26];
  833.        s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[27];
  834.     (* round 7: *)
  835.        t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[28];
  836.        t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[29];
  837.        t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[30];
  838.        t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[31];
  839.        (* round 8: *)
  840.        s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[32];
  841.        s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[33];
  842.        s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[34];
  843.        s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[35];
  844.     (* round 9: *)
  845.        t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[36];
  846.        t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[37];
  847.        t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[38];
  848.        t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[39];
  849.       if (key^.rounds > 10) then begin
  850.           (* round 10: *)
  851.           s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[40];
  852.           s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[41];
  853.           s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[42];
  854.           s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[43];
  855.           (* round 11: *)
  856.           t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[44];
  857.           t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[45];
  858.           t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[46];
  859.           t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[47];
  860.           if (key^.rounds > 12) then begin
  861.               (* round 12: *)
  862.               s0 := Te0[t0 shr 24] xor Te1[(t1 shr 16) and $ff] xor Te2[(t2 shr  8) and $ff] xor Te3[t3 and $ff] xor rk[48];
  863.               s1 := Te0[t1 shr 24] xor Te1[(t2 shr 16) and $ff] xor Te2[(t3 shr  8) and $ff] xor Te3[t0 and $ff] xor rk[49];
  864.               s2 := Te0[t2 shr 24] xor Te1[(t3 shr 16) and $ff] xor Te2[(t0 shr  8) and $ff] xor Te3[t1 and $ff] xor rk[50];
  865.               s3 := Te0[t3 shr 24] xor Te1[(t0 shr 16) and $ff] xor Te2[(t1 shr  8) and $ff] xor Te3[t2 and $ff] xor rk[51];
  866.               (* round 13: *)
  867.               t0 := Te0[s0 shr 24] xor Te1[(s1 shr 16) and $ff] xor Te2[(s2 shr  8) and $ff] xor Te3[s3 and $ff] xor rk[52];
  868.               t1 := Te0[s1 shr 24] xor Te1[(s2 shr 16) and $ff] xor Te2[(s3 shr  8) and $ff] xor Te3[s0 and $ff] xor rk[53];
  869.               t2 := Te0[s2 shr 24] xor Te1[(s3 shr 16) and $ff] xor Te2[(s0 shr  8) and $ff] xor Te3[s1 and $ff] xor rk[54];
  870.               t3 := Te0[s3 shr 24] xor Te1[(s0 shr 16) and $ff] xor Te2[(s1 shr  8) and $ff] xor Te3[s2 and $ff] xor rk[55];
  871.           end;
  872.       end;
  873.       rk := rk + (key^.rounds shl 2);
  874.   {$else}  (* !FULL_UNROLL *)
  875.       (*
  876.        * Nr - 1 full rounds:
  877.        *)
  878.       r := key^.rounds shr 1;
  879.       while true do begin
  880.           t0 :=
  881.               Te0[(s0 shr 24)        ] xor
  882.               Te1[(s1 shr 16) and $ff] xor
  883.               Te2[(s2 shr  8) and $ff] xor
  884.               Te3[(s3       ) and $ff] xor
  885.               rk[4];
  886.           t1 :=
  887.               Te0[(s1 shr 24)        ] xor
  888.               Te1[(s2 shr 16) and $ff] xor
  889.               Te2[(s3 shr  8) and $ff] xor
  890.               Te3[(s0       ) and $ff] xor
  891.               rk[5];
  892.           t2 :=
  893.               Te0[(s2 shr 24)        ] xor
  894.               Te1[(s3 shr 16) and $ff] xor
  895.               Te2[(s0 shr  8) and $ff] xor
  896.               Te3[(s1       ) and $ff] xor
  897.               rk[6];
  898.           t3 :=
  899.               Te0[(s3 shr 24)        ] xor
  900.               Te1[(s0 shr 16) and $ff] xor
  901.               Te2[(s1 shr  8) and $ff] xor
  902.               Te3[(s2       ) and $ff] xor
  903.               rk[7];
  904.  
  905.           rk := rk + 8;
  906.           dec(r);
  907.           if (r = 0) then begin
  908.               break;
  909.           end;
  910.  
  911.           s0 :=
  912.               Te0[(t0 shr 24)        ] xor
  913.               Te1[(t1 shr 16) and $ff] xor
  914.               Te2[(t2 shr  8) and $ff] xor
  915.               Te3[(t3       ) and $ff] xor
  916.               rk[0];
  917.           s1 :=
  918.               Te0[(t1 shr 24)        ] xor
  919.               Te1[(t2 shr 16) and $ff] xor
  920.               Te2[(t3 shr  8) and $ff] xor
  921.               Te3[(t0       ) and $ff] xor
  922.               rk[1];
  923.           s2 :=
  924.               Te0[(t2 shr 24)        ] xor
  925.               Te1[(t3 shr 16) and $ff] xor
  926.               Te2[(t0 shr  8) and $ff] xor
  927.               Te3[(t1       ) and $ff] xor
  928.               rk[2];
  929.           s3 :=
  930.               Te0[(t3 shr 24)        ] xor
  931.               Te1[(t0 shr 16) and $ff] xor
  932.               Te2[(t1 shr  8) and $ff] xor
  933.               Te3[(t2       ) and $ff] xor
  934.               rk[3];
  935.       end;
  936.   {$endif} (* ?FULL_UNROLL *)
  937.       (*
  938.      * apply last round and
  939.      * map cipher state to byte array block:
  940.      *)
  941.     s0 :=
  942.       (Te2[(t0 shr 24)        ] and $ff000000) xor
  943.       (Te3[(t1 shr 16) and $ff] and $00ff0000) xor
  944.       (Te0[(t2 shr  8) and $ff] and $0000ff00) xor
  945.       (Te1[(t3       ) and $ff] and $000000ff) xor
  946.       rk[0];
  947.     PUTU32(out_     , s0);
  948.     s1 :=
  949.       (Te2[(t1 shr 24)        ] and $ff000000) xor
  950.       (Te3[(t2 shr 16) and $ff] and $00ff0000) xor
  951.       (Te0[(t3 shr  8) and $ff] and $0000ff00) xor
  952.       (Te1[(t0       ) and $ff] and $000000ff) xor
  953.       rk[1];
  954.     out_:=out_+4;
  955.     PUTU32(out_     , s1);
  956.     s2 :=
  957.       (Te2[(t2 shr 24)        ] and $ff000000) xor
  958.       (Te3[(t3 shr 16) and $ff] and $00ff0000) xor
  959.       (Te0[(t0 shr  8) and $ff] and $0000ff00) xor
  960.       (Te1[(t1       ) and $ff] and $000000ff) xor
  961.       rk[2];
  962.     out_:=out_ +  4;
  963.     PUTU32(out_     , s2);
  964.     s3 :=
  965.       (Te2[(t3 shr 24)        ] and $ff000000) xor
  966.       (Te3[(t0 shr 16) and $ff] and $00ff0000) xor
  967.       (Te0[(t1 shr  8) and $ff] and $0000ff00) xor
  968.       (Te1[(t2       ) and $ff] and $000000ff) xor
  969.       rk[3];
  970.     out_:=out_ + 4;
  971.     PUTU32(out_     , s3);
  972.     out_:=out_ - 12;
  973.   end;
  974.  
  975.   (*
  976.    * Decrypt a single block
  977.    * in and out can overlap
  978.    *)
  979.   procedure AES_decrypt(
  980.     const in_  : pchar;
  981.     var   out_ : pchar;
  982.     const key : pAES_KEY
  983.   );
  984.  
  985.     var rk:pdword;
  986.     var s0, s1, s2, s3, t0, t1, t2, t3:dword;
  987.   {$ifndef FULL_UNROLL}
  988.     var r:dword;
  989.   {$endif} (* ?FULL_UNROLL *)
  990.   begin
  991.     (*
  992.     {$ASSERTIONS+}
  993.     system.assert(in_ AND out_ AND key);
  994.     *)
  995.     rk := key^.rd_key;
  996.  
  997.     (*
  998.      * map byte array block to cipher state
  999.      * and add initial round key:
  1000.      *)
  1001.       s0 := GETU32(in_     ) xor rk[0];
  1002.       s1 := GETU32(in_ +  4) xor rk[1];
  1003.       s2 := GETU32(in_ +  8) xor rk[2];
  1004.       s3 := GETU32(in_ + 12) xor rk[3];
  1005.   {$ifdef FULL_UNROLL}
  1006.       (* round 1: *)
  1007.       t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[ 4];
  1008.       t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[ 5];
  1009.       t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[ 6];
  1010.       t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[ 7];
  1011.       (* round 2: *)
  1012.       s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[ 8];
  1013.       s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[ 9];
  1014.       s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[10];
  1015.       s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[11];
  1016.       (* round 3: *)
  1017.       t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[12];
  1018.       t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[13];
  1019.       t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[14];
  1020.       t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[15];
  1021.       (* round 4: *)
  1022.       s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[16];
  1023.       s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[17];
  1024.       s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[18];
  1025.       s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[19];
  1026.       (* round 5: *)
  1027.       t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[20];
  1028.       t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[21];
  1029.       t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[22];
  1030.       t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[23];
  1031.       (* round 6: *)
  1032.       s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[24];
  1033.       s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[25];
  1034.       s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[26];
  1035.       s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[27];
  1036.       (* round 7: *)
  1037.       t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[28];
  1038.       t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[29];
  1039.       t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[30];
  1040.       t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[31];
  1041.       (* round 8: *)
  1042.       s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[32];
  1043.       s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[33];
  1044.       s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[34];
  1045.       s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[35];
  1046.       (* round 9: *)
  1047.       t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[36];
  1048.       t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[37];
  1049.       t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[38];
  1050.       t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[39];
  1051.       if (key^.rounds > 10) then begin
  1052.           (* round 10: *)
  1053.           s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[40];
  1054.           s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[41];
  1055.           s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[42];
  1056.           s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[43];
  1057.           (* round 11: *)
  1058.           t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[44];
  1059.           t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[45];
  1060.           t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[46];
  1061.           t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[47];
  1062.           if (key^.rounds > 12) then begin
  1063.               (* round 12: *)
  1064.               s0 := Td0[t0 shr 24] xor Td1[(t3 shr 16) and $ff] xor Td2[(t2 shr  8) and $ff] xor Td3[t1 and $ff] xor rk[48];
  1065.               s1 := Td0[t1 shr 24] xor Td1[(t0 shr 16) and $ff] xor Td2[(t3 shr  8) and $ff] xor Td3[t2 and $ff] xor rk[49];
  1066.               s2 := Td0[t2 shr 24] xor Td1[(t1 shr 16) and $ff] xor Td2[(t0 shr  8) and $ff] xor Td3[t3 and $ff] xor rk[50];
  1067.               s3 := Td0[t3 shr 24] xor Td1[(t2 shr 16) and $ff] xor Td2[(t1 shr  8) and $ff] xor Td3[t0 and $ff] xor rk[51];
  1068.               (* round 13: *)
  1069.               t0 := Td0[s0 shr 24] xor Td1[(s3 shr 16) and $ff] xor Td2[(s2 shr  8) and $ff] xor Td3[s1 and $ff] xor rk[52];
  1070.               t1 := Td0[s1 shr 24] xor Td1[(s0 shr 16) and $ff] xor Td2[(s3 shr  8) and $ff] xor Td3[s2 and $ff] xor rk[53];
  1071.               t2 := Td0[s2 shr 24] xor Td1[(s1 shr 16) and $ff] xor Td2[(s0 shr  8) and $ff] xor Td3[s3 and $ff] xor rk[54];
  1072.               t3 := Td0[s3 shr 24] xor Td1[(s2 shr 16) and $ff] xor Td2[(s1 shr  8) and $ff] xor Td3[s0 and $ff] xor rk[55];
  1073.           end;
  1074.       end;
  1075.     rk := rk + (key^.rounds shl 2);
  1076.   {$else}  (* !FULL_UNROLL *)
  1077.       (*
  1078.        * Nr - 1 full rounds:
  1079.        *)
  1080.       r := key^.rounds shr 1;
  1081.       while true do begin
  1082.           t0 :=
  1083.               Td0[(s0 shr 24)        ] xor
  1084.               Td1[(s3 shr 16) and $ff] xor
  1085.               Td2[(s2 shr  8) and $ff] xor
  1086.               Td3[(s1       ) and $ff] xor
  1087.               rk[4];
  1088.           t1 :=
  1089.               Td0[(s1 shr 24)        ] xor
  1090.               Td1[(s0 shr 16) and $ff] xor
  1091.               Td2[(s3 shr  8) and $ff] xor
  1092.               Td3[(s2       ) and $ff] xor
  1093.               rk[5];
  1094.           t2 :=
  1095.               Td0[(s2 shr 24)        ] xor
  1096.               Td1[(s1 shr 16) and $ff] xor
  1097.               Td2[(s0 shr  8) and $ff] xor
  1098.               Td3[(s3       ) and $ff] xor
  1099.               rk[6];
  1100.           t3 :=
  1101.               Td0[(s3 shr 24)        ] xor
  1102.               Td1[(s2 shr 16) and $ff] xor
  1103.               Td2[(s1 shr  8) and $ff] xor
  1104.               Td3[(s0       ) and $ff] xor
  1105.               rk[7];
  1106.  
  1107.           rk := rk + 8;
  1108.           dec(r);
  1109.           if (r = 0) then begin
  1110.               break;
  1111.           end;
  1112.  
  1113.           s0 :=
  1114.               Td0[(t0 shr 24)        ] xor
  1115.               Td1[(t3 shr 16) and $ff] xor
  1116.               Td2[(t2 shr  8) and $ff] xor
  1117.               Td3[(t1       ) and $ff] xor
  1118.               rk[0];
  1119.           s1 :=
  1120.               Td0[(t1 shr 24)        ] xor
  1121.               Td1[(t0 shr 16) and $ff] xor
  1122.               Td2[(t3 shr  8) and $ff] xor
  1123.               Td3[(t2       ) and $ff] xor
  1124.               rk[1];
  1125.           s2 :=
  1126.               Td0[(t2 shr 24)        ] xor
  1127.               Td1[(t1 shr 16) and $ff] xor
  1128.               Td2[(t0 shr  8) and $ff] xor
  1129.               Td3[(t3       ) and $ff] xor
  1130.               rk[2];
  1131.           s3 :=
  1132.               Td0[(t3 shr 24)        ] xor
  1133.               Td1[(t2 shr 16) and $ff] xor
  1134.               Td2[(t1 shr  8) and $ff] xor
  1135.               Td3[(t0       ) and $ff] xor
  1136.               rk[3];
  1137.       end;
  1138.   {$endif} (* ?FULL_UNROLL *)
  1139.       (*
  1140.      * apply last round and
  1141.      * map cipher state to byte array block:
  1142.      *)
  1143.        s0 :=
  1144.          (Td4[(t0 shr 24)        ] shl 24) xor
  1145.          (Td4[(t3 shr 16) and $ff] shl 16) xor
  1146.          (Td4[(t2 shr  8) and $ff] shl  8) xor
  1147.          (Td4[(t1       ) and $ff])       xor
  1148.          rk[0];
  1149.     PUTU32(out_     , s0);
  1150.        s1 :=
  1151.          (Td4[(t1 shr 24)        ] shl 24) xor
  1152.          (Td4[(t0 shr 16) and $ff] shl 16) xor
  1153.          (Td4[(t3 shr  8) and $ff] shl  8) xor
  1154.          (Td4[(t2       ) and $ff])       xor
  1155.          rk[1];
  1156.     out_:=out_ +  4;
  1157.     PUTU32(out_     , s1);
  1158.        s2 :=
  1159.          (Td4[(t2 shr 24)        ] shl 24) xor
  1160.          (Td4[(t1 shr 16) and $ff] shl 16) xor
  1161.          (Td4[(t0 shr  8) and $ff] shl  8) xor
  1162.          (Td4[(t3       ) and $ff])       xor
  1163.          rk[2];
  1164.     out_:=out_ +  4;
  1165.     PUTU32(out_     , s2);
  1166.        s3 :=
  1167.          (Td4[(t3 shr 24)        ] shl 24) xor
  1168.          (Td4[(t2 shr 16) and $ff] shl 16) xor
  1169.          (Td4[(t1 shr  8) and $ff] shl  8) xor
  1170.          (Td4[(t0       ) and $ff])       xor
  1171.          rk[3];
  1172.     out_:=out_ +  4;
  1173.     PUTU32(out_     , s3);
  1174.     out_:=out_ - 12;
  1175.   end;
  1176.  
  1177.   {$else} (* AES_ASM *)
  1178.  
  1179.   const Te4:array [0..255] of byte = (
  1180.       $63, $7c, $77, $7b, $f2, $6b, $6f, $c5,
  1181.       $30, $01, $67, $2b, $fe, $d7, $ab, $76,
  1182.       $ca, $82, $c9, $7d, $fa, $59, $47, $f0,
  1183.       $ad, $d4, $a2, $af, $9c, $a4, $72, $c0,
  1184.       $b7, $fd, $93, $26, $36, $3f, $f7, $cc,
  1185.       $34, $a5, $e5, $f1, $71, $d8, $31, $15,
  1186.       $04, $c7, $23, $c3, $18, $96, $05, $9a,
  1187.       $07, $12, $80, $e2, $eb, $27, $b2, $75,
  1188.       $09, $83, $2c, $1a, $1b, $6e, $5a, $a0,
  1189.       $52, $3b, $d6, $b3, $29, $e3, $2f, $84,
  1190.       $53, $d1, $00, $ed, $20, $fc, $b1, $5b,
  1191.       $6a, $cb, $be, $39, $4a, $4c, $58, $cf,
  1192.       $d0, $ef, $aa, $fb, $43, $4d, $33, $85,
  1193.       $45, $f9, $02, $7f, $50, $3c, $9f, $a8,
  1194.       $51, $a3, $40, $8f, $92, $9d, $38, $f5,
  1195.       $bc, $b6, $da, $21, $10, $ff, $f3, $d2,
  1196.       $cd, $0c, $13, $ec, $5f, $97, $44, $17,
  1197.       $c4, $a7, $7e, $3d, $64, $5d, $19, $73,
  1198.       $60, $81, $4f, $dc, $22, $2a, $90, $88,
  1199.       $46, $ee, $b8, $14, $de, $5e, $0b, $db,
  1200.       $e0, $32, $3a, $0a, $49, $06, $24, $5c,
  1201.       $c2, $d3, $ac, $62, $91, $95, $e4, $79,
  1202.       $e7, $c8, $37, $6d, $8d, $d5, $4e, $a9,
  1203.       $6c, $56, $f4, $ea, $65, $7a, $ae, $08,
  1204.       $ba, $78, $25, $2e, $1c, $a6, $b4, $c6,
  1205.       $e8, $dd, $74, $1f, $4b, $bd, $8b, $8a,
  1206.       $70, $3e, $b5, $66, $48, $03, $f6, $0e,
  1207.       $61, $35, $57, $b9, $86, $c1, $1d, $9e,
  1208.       $e1, $f8, $98, $11, $69, $d9, $8e, $94,
  1209.       $9b, $1e, $87, $e9, $ce, $55, $28, $df,
  1210.       $8c, $a1, $89, $0d, $bf, $e6, $42, $68,
  1211.       $41, $99, $2d, $0f, $b0, $54, $bb, $16
  1212.   );
  1213.   const rcon:array of dword = (
  1214.     $01000000, $02000000, $04000000, $08000000,
  1215.     $10000000, $20000000, $40000000, $80000000,
  1216.     $1B000000, $36000000 (* for 128-bit blocks, Rijndael never uses more than 10 rcon values *)
  1217.   );
  1218.  
  1219.   (**
  1220.    * Expand the cipher key into the encryption key schedule.
  1221.    *)
  1222.   function AES_set_encrypt_key(
  1223.     const userKey: pchar;
  1224.     const bits:dword;
  1225.     var key: pAES_KEY
  1226.   ):dword;
  1227.   var rk:pdword;
  1228.   const i:dword = 0;
  1229.   var temp: dword;
  1230.   begin
  1231.     if ((userKey<>nil) OR (key<>nil)) then
  1232.       result:=-1;
  1233.     if ((bits <> 128) and (bits <> 192) and (bits <> 256))
  1234.       result:=-2;
  1235.  
  1236.     rk := key^.rd_key;
  1237.  
  1238.     if (bits=128) then
  1239.       key^.rounds := 10;
  1240.     else begin
  1241.            if (bits==192) then
  1242.              key^.rounds := 12
  1243.            else
  1244.              key^.rounds := 14;
  1245.          end;
  1246.     rk[0] := GETU32(userKey     );
  1247.     rk[1] := GETU32(userKey +  4);
  1248.     rk[2] := GETU32(userKey +  8);
  1249.     rk[3] := GETU32(userKey + 12);
  1250.     if (bits = 128) then begin
  1251.       while true do begin
  1252.         temp  := rk[3];
  1253.         rk[4] := rk[0] xor
  1254.           (Te4[(temp shr 16) and $ff] shl 24) xor
  1255.           (Te4[(temp shr  8) and $ff] shl 16) xor
  1256.           (Te4[(temp       ) and $ff] shl  8) xor
  1257.           (Te4[(temp shr 24)       ]) xor
  1258.           rcon[i];
  1259.         rk[5] := rk[1] xor rk[4];
  1260.         rk[6] := rk[2] xor rk[5];
  1261.         rk[7] := rk[3] xor rk[6];
  1262.         inc(i);
  1263.         if (i = 10) then begin
  1264.           result:= 0;break;
  1265.         end;
  1266.         rk := rk + 4;
  1267.       end;
  1268.     end;
  1269.     rk[4] := GETU32(userKey + 16);
  1270.     rk[5] := GETU32(userKey + 20);
  1271.     if (bits = 192) then begin
  1272.       while true do begin
  1273.         temp := rk[ 5];
  1274.         rk[ 6] := rk[ 0] xor
  1275.           (Te4[(temp shr 16) and $ff] shl 24) xor
  1276.           (Te4[(temp shr  8) and $ff] shl 16) xor
  1277.           (Te4[(temp       ) and $ff] shl  8) xor
  1278.           (Te4[(temp shr 24)       ]) xor
  1279.           rcon[i];
  1280.         rk[ 7] := rk[ 1] xor rk[ 6];
  1281.         rk[ 8] := rk[ 2] xor rk[ 7];
  1282.         rk[ 9] := rk[ 3] xor rk[ 8];
  1283.         inc(i);
  1284.         if (i = 8) then begin
  1285.           result:= 0;break;
  1286.         end;
  1287.         rk[10] := rk[ 4] xor rk[ 9];
  1288.         rk[11] := rk[ 5] xor rk[10];
  1289.         rk := rk + 6;
  1290.       end;
  1291.     end;
  1292.     rk[6] := GETU32(userKey + 24);
  1293.     rk[7] := GETU32(userKey + 28);
  1294.     if (bits = 256) then begin
  1295.       while true do begin
  1296.         temp := rk[ 7];
  1297.         rk[ 8] := rk[ 0] xor
  1298.           (Te4[(temp shr 16) and $ff] shl 24) xor
  1299.           (Te4[(temp shr  8) and $ff] shl 16) xor
  1300.           (Te4[(temp       ) and $ff] shl  8) xor
  1301.           (Te4[(temp shr 24)       ]) xor
  1302.           rcon[i];
  1303.         rk[ 9] := rk[ 1] xor rk[ 8];
  1304.         rk[10] := rk[ 2] xor rk[ 9];
  1305.         rk[11] := rk[ 3] xor rk[10];
  1306.         inc(i);
  1307.         if (i = 7) then begin
  1308.           result:= 0;break;
  1309.         end;
  1310.         temp := rk[11];
  1311.         rk[12] := rk[ 4] xor
  1312.           (Te4[(temp shr 24)        ] shl 24) xor
  1313.           (Te4[(temp shr 16) and $ff] shl 16) xor
  1314.           (Te4[(temp shr  8) and $ff] shl 8) xor
  1315.           (Te4[(temp       ) and $ff]);
  1316.         rk[13] := rk[ 5] xor rk[12];
  1317.         rk[14] := rk[ 6] xor rk[13];
  1318.         rk[15] := rk[ 7] xor rk[14];
  1319.  
  1320.         rk := rk + 8;
  1321.             end;
  1322.     end;
  1323.     result:= 0;
  1324.   end;
  1325.  
  1326.   (**
  1327.    * Expand the cipher key into the decryption key schedule.
  1328.    *)
  1329.   function AES_set_decrypt_key(
  1330.     const userKey : pchar;
  1331.     const bits    : dword;
  1332.     var   key     : pAES_KEY
  1333.   );
  1334.   var
  1335.     rk:pdword;
  1336.     i, j, status:dword;
  1337.     temp:dword;
  1338.   var
  1339.     tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m:dword;
  1340.   (*
  1341.     function ROTATE(
  1342.       const a:dword;
  1343.       const n:dword
  1344.     ):dword;
  1345.     begin
  1346.       result:=a;
  1347.       {$ASMMODE intel}
  1348.       asm
  1349.         rol result,n;
  1350.       end;
  1351.     end;
  1352.   *)
  1353.   begin
  1354.     (* first, start with an encryption schedule *)
  1355.     status := AES_set_encrypt_key(userKey, bits, key);
  1356.     if (status < 0)
  1357.       result:= status;
  1358.  
  1359.     rk := key^.rd_key;
  1360.  
  1361.     (* invert the order of the round keys: *)
  1362.     i := 0; j := 4*(key^.rounds);
  1363.     while (i < j) do begin
  1364.       temp := rk[i    ]; rk[i    ] := rk[j    ]; rk[j    ] := temp;
  1365.       temp := rk[i + 1]; rk[i + 1] := rk[j + 1]; rk[j + 1] := temp;
  1366.       temp := rk[i + 2]; rk[i + 2] := rk[j + 2]; rk[j + 2] := temp;
  1367.       temp := rk[i + 3]; rk[i + 3] := rk[j + 3]; rk[j + 3] := temp;
  1368.       i := i + 4; j := j - 4;
  1369.     end;
  1370.     (* apply the inverse MixColumn transform to all round keys but the first and the last: *)
  1371.     i = 1;
  1372.     while (i < (key^.rounds)) do begin
  1373.       rk := rk + 4;
  1374.       j = 0;
  1375.       while (j < 4) do begin
  1376.         tp1 := rk[j];
  1377.         m := tp1 and $80808080;
  1378.         tp2 := ((tp1 and $7f7f7f7f) shl 1) xor
  1379.           ((m - (m shr 7)) and $1b1b1b1b);
  1380.         m := tp2 and $80808080;
  1381.         tp4 := ((tp2 and $7f7f7f7f) shl 1) xor
  1382.           ((m - (m shr 7)) and $1b1b1b1b);
  1383.         m := tp4 and $80808080;
  1384.         tp8 := ((tp4 and $7f7f7f7f) shl 1) xor
  1385.           ((m - (m shr 7)) and $1b1b1b1b);
  1386.         tp9 := tp8 xor tp1;
  1387.         tpb := tp9 xor tp2;
  1388.         tpd := tp9 xor tp4;
  1389.         tpe := tp8 xor tp4 xor tp2;
  1390.   (*
  1391.   #if defined(ROTATE)
  1392.         rk[j] := tpe xor ROTATE(tpd,16) xor
  1393.           ROTATE(tp9,24) xor ROTATE(tpb,8);
  1394.   #else
  1395.   *)
  1396.         rk[j] := tpe xor (tpd shr 16) xor (tpd shl 16) xor
  1397.           (tp9 shr 8) xor (tp9 shl 24) xor
  1398.           (tpb shr 24) xor (tpb shl 8);
  1399.   (*
  1400.   #endif
  1401.   *)
  1402.         inc(j);
  1403.       end;
  1404.       inc(i);
  1405.     end;
  1406.     result:=0;
  1407.   end;
  1408.  
  1409.   {$endif} (* AES_ASM *)
  1410.  
  1411.  
  1412.  
  1413.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1414.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1415.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1416.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1417.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1418.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1419.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1420.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1421.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1422.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1423.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1424.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1425.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1426.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1427.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1428.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1429.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1430.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1431.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1432.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1433.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
  1434.   {^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^}
Advertisement
Add Comment
Please, Sign In to add comment