日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

java delphi aes加密算法_Delphi AES,又一个加密算法例子

發(fā)布時(shí)間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java delphi aes加密算法_Delphi AES,又一个加密算法例子 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

///

//AES DEMO V1.0//

//作者:ksaiy//

//歡迎使用由ksaiy制作的AES加密算法演示程序,此算法為標(biāo)準(zhǔn)的AES算法,你可以根據(jù)的

//的自己需要進(jìn)行變形。具體怎么操作可以登錄我們的網(wǎng)站查詢(xún)?cè)敿?xì)的資料。我們專(zhuān)門(mén)為軟

//件開(kāi)發(fā)者提供軟件加密安全測(cè)試服務(wù)和軟件加密解決方案,具體的可以參看我們的網(wǎng)站上

//的資料。

//技術(shù)支持:ksaiy@sina.com 在線QQ:40188696 UC:934155

//End //

//注意:轉(zhuǎn)載請(qǐng)保留以上信息。//

///

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Edit1: TEdit;

Edit2: TEdit;

Button1: TButton;

Button2: TButton;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

type

EAESError = class(Exception);

PInteger? = ^Integer;

TAESBuffer = array [0..15] of byte;

TAESKey128 = array [0..15] of byte;

TAESKey192 = array [0..23] of byte;

TAESKey256 = array [0..31] of byte;

TAESExpandedKey128 = array [0..43] of longword;

TAESExpandedKey192 = array [0..53] of longword;

TAESExpandedKey256 = array [0..63] of longword;

PAESBuffer =^TAESBuffer;

PAESKey128 =^TAESKey128;

PAESKey192 =^TAESKey192;

PAESKey256 =^TAESKey256;

PAESExpandedKey128 =^TAESExpandedKey128;

PAESExpandedKey192 =^TAESExpandedKey192;

PAESExpandedKey256 =^TAESExpandedKey256;

procedure ExpandAESKeyForEncryption(const Key: TAESKey128;

var ExpandedKey: TAESExpandedKey128); overload;

procedure ExpandAESKeyForEncryption(const Key: TAESKey192;

var ExpandedKey: TAESExpandedKey192); overload;

procedure ExpandAESKeyForEncryption(const Key: TAESKey256;

var ExpandedKey: TAESExpandedKey256); overload;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer); overload;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;

var OutBuf: TAESBuffer); overload;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;

var OutBuf: TAESBuffer); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey192; Dest: TStream); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192; Dest: TStream); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey256; Dest: TStream); overload;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256; Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128;? const InitVector: TAESBuffer;

Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192;? const InitVector: TAESBuffer;

Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256;? const InitVector: TAESBuffer;

Dest: TStream); overload;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey128); overload;

procedure ExpandAESKeyForDecryption(const Key: TAESKey128;

var ExpandedKey: TAESExpandedKey128); overload;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey192); overload;

procedure ExpandAESKeyForDecryption(const Key: TAESKey192;

var ExpandedKey: TAESExpandedKey192); overload;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey256); overload;

procedure ExpandAESKeyForDecryption(const Key: TAESKey256;

var ExpandedKey: TAESExpandedKey256); overload;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer); overload;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;

var OutBuf: TAESBuffer); overload;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;

var OutBuf: TAESBuffer); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey192; Dest: TStream); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192; Dest: TStream); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey256; Dest: TStream); overload;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256; Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128;? const InitVector: TAESBuffer;

Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192;? const InitVector: TAESBuffer;

Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream); overload;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256;? const InitVector: TAESBuffer;

Dest: TStream); overload;

resourcestring

SInvalidInBufSize = 'Invalid buffer size for decryption';

SReadError = 'Stream read error';

SWriteError = 'Stream write error';

var

Form1: TForm1;

implementation

{$R *.dfm}

type

PLongWord = ^LongWord;

function Min(A, B: integer): integer;

begin

if A < B then

Result := A

else

Result := B;

end;

const

Rcon: array [1..30] of longword = (

$00000001, $00000002, $00000004, $00000008, $00000010, $00000020,

$00000040, $00000080, $0000001B, $00000036, $0000006C, $000000D8,

$000000AB, $0000004D, $0000009A, $0000002F, $0000005E, $000000BC,

$00000063, $000000C6, $00000097, $00000035, $0000006A, $000000D4,

$000000B3, $0000007D, $000000FA, $000000EF, $000000C5, $00000091

);

ForwardTable: array [0..255] of longword = (

$A56363C6, $847C7CF8, $997777EE, $8D7B7BF6, $0DF2F2FF, $BD6B6BD6, $B16F6FDE, $54C5C591,

$50303060, $03010102, $A96767CE, $7D2B2B56, $19FEFEE7, $62D7D7B5, $E6ABAB4D, $9A7676EC,

$45CACA8F, $9D82821F, $40C9C989, $877D7DFA, $15FAFAEF, $EB5959B2, $C947478E, $0BF0F0FB,

$ECADAD41, $67D4D4B3, $FDA2A25F, $EAAFAF45, $BF9C9C23, $F7A4A453, $967272E4, $5BC0C09B,

$C2B7B775, $1CFDFDE1, $AE93933D, $6A26264C, $5A36366C, $413F3F7E, $02F7F7F5, $4FCCCC83,

$5C343468, $F4A5A551, $34E5E5D1, $08F1F1F9, $937171E2, $73D8D8AB, $53313162, $3F15152A,

$0C040408, $52C7C795, $65232346, $5EC3C39D, $28181830, $A1969637, $0F05050A, $B59A9A2F,

$0907070E, $36121224, $9B80801B, $3DE2E2DF, $26EBEBCD, $6927274E, $CDB2B27F, $9F7575EA,

$1B090912, $9E83831D, $742C2C58, $2E1A1A34, $2D1B1B36, $B26E6EDC, $EE5A5AB4, $FBA0A05B,

$F65252A4, $4D3B3B76, $61D6D6B7, $CEB3B37D, $7B292952, $3EE3E3DD, $712F2F5E, $97848413,

$F55353A6, $68D1D1B9, $00000000, $2CEDEDC1, $60202040, $1FFCFCE3, $C8B1B179, $ED5B5BB6,

$BE6A6AD4, $46CBCB8D, $D9BEBE67, $4B393972, $DE4A4A94, $D44C4C98, $E85858B0, $4ACFCF85,

$6BD0D0BB, $2AEFEFC5, $E5AAAA4F, $16FBFBED, $C5434386, $D74D4D9A, $55333366, $94858511,

$CF45458A, $10F9F9E9, $06020204, $817F7FFE, $F05050A0, $443C3C78, $BA9F9F25, $E3A8A84B,

$F35151A2, $FEA3A35D, $C0404080, $8A8F8F05, $AD92923F, $BC9D9D21, $48383870, $04F5F5F1,

$DFBCBC63, $C1B6B677, $75DADAAF, $63212142, $30101020, $1AFFFFE5, $0EF3F3FD, $6DD2D2BF,

$4CCDCD81, $140C0C18, $35131326, $2FECECC3, $E15F5FBE, $A2979735, $CC444488, $3917172E,

$57C4C493, $F2A7A755, $827E7EFC, $473D3D7A, $AC6464C8, $E75D5DBA, $2B191932, $957373E6,

$A06060C0, $98818119, $D14F4F9E, $7FDCDCA3, $66222244, $7E2A2A54, $AB90903B, $8388880B,

$CA46468C, $29EEEEC7, $D3B8B86B, $3C141428, $79DEDEA7, $E25E5EBC, $1D0B0B16, $76DBDBAD,

$3BE0E0DB, $56323264, $4E3A3A74, $1E0A0A14, $DB494992, $0A06060C, $6C242448, $E45C5CB8,

$5DC2C29F, $6ED3D3BD, $EFACAC43, $A66262C4, $A8919139, $A4959531, $37E4E4D3, $8B7979F2,

$32E7E7D5, $43C8C88B, $5937376E, $B76D6DDA, $8C8D8D01, $64D5D5B1, $D24E4E9C, $E0A9A949,

$B46C6CD8, $FA5656AC, $07F4F4F3, $25EAEACF, $AF6565CA, $8E7A7AF4, $E9AEAE47, $18080810,

$D5BABA6F, $887878F0, $6F25254A, $722E2E5C, $241C1C38, $F1A6A657, $C7B4B473, $51C6C697,

$23E8E8CB, $7CDDDDA1, $9C7474E8, $211F1F3E, $DD4B4B96, $DCBDBD61, $868B8B0D, $858A8A0F,

$907070E0, $423E3E7C, $C4B5B571, $AA6666CC, $D8484890, $05030306, $01F6F6F7, $120E0E1C,

$A36161C2, $5F35356A, $F95757AE, $D0B9B969, $91868617, $58C1C199, $271D1D3A, $B99E9E27,

$38E1E1D9, $13F8F8EB, $B398982B, $33111122, $BB6969D2, $70D9D9A9, $898E8E07, $A7949433,

$B69B9B2D, $221E1E3C, $92878715, $20E9E9C9, $49CECE87, $FF5555AA, $78282850, $7ADFDFA5,

$8F8C8C03, $F8A1A159, $80898909, $170D0D1A, $DABFBF65, $31E6E6D7, $C6424284, $B86868D0,

$C3414182, $B0999929, $772D2D5A, $110F0F1E, $CBB0B07B, $FC5454A8, $D6BBBB6D, $3A16162C

);

LastForwardTable: array [0..255] of longword = (

$00000063, $0000007C, $00000077, $0000007B, $000000F2, $0000006B, $0000006F, $000000C5,

$00000030, $00000001, $00000067, $0000002B, $000000FE, $000000D7, $000000AB, $00000076,

$000000CA, $00000082, $000000C9, $0000007D, $000000FA, $00000059, $00000047, $000000F0,

$000000AD, $000000D4, $000000A2, $000000AF, $0000009C, $000000A4, $00000072, $000000C0,

$000000B7, $000000FD, $00000093, $00000026, $00000036, $0000003F, $000000F7, $000000CC,

$00000034, $000000A5, $000000E5, $000000F1, $00000071, $000000D8, $00000031, $00000015,

$00000004, $000000C7, $00000023, $000000C3, $00000018, $00000096, $00000005, $0000009A,

$00000007, $00000012, $00000080, $000000E2, $000000EB, $00000027, $000000B2, $00000075,

$00000009, $00000083, $0000002C, $0000001A, $0000001B, $0000006E, $0000005A, $000000A0,

$00000052, $0000003B, $000000D6, $000000B3, $00000029, $000000E3, $0000002F, $00000084,

$00000053, $000000D1, $00000000, $000000ED, $00000020, $000000FC, $000000B1, $0000005B,

$0000006A, $000000CB, $000000BE, $00000039, $0000004A, $0000004C, $00000058, $000000CF,

$000000D0, $000000EF, $000000AA, $000000FB, $00000043, $0000004D, $00000033, $00000085,

$00000045, $000000F9, $00000002, $0000007F, $00000050, $0000003C, $0000009F, $000000A8,

$00000051, $000000A3, $00000040, $0000008F, $00000092, $0000009D, $00000038, $000000F5,

$000000BC, $000000B6, $000000DA, $00000021, $00000010, $000000FF, $000000F3, $000000D2,

$000000CD, $0000000C, $00000013, $000000EC, $0000005F, $00000097, $00000044, $00000017,

$000000C4, $000000A7, $0000007E, $0000003D, $00000064, $0000005D, $00000019, $00000073,

$00000060, $00000081, $0000004F, $000000DC, $00000022, $0000002A, $00000090, $00000088,

$00000046, $000000EE, $000000B8, $00000014, $000000DE, $0000005E, $0000000B, $000000DB,

$000000E0, $00000032, $0000003A, $0000000A, $00000049, $00000006, $00000024, $0000005C,

$000000C2, $000000D3, $000000AC, $00000062, $00000091, $00000095, $000000E4, $00000079,

$000000E7, $000000C8, $00000037, $0000006D, $0000008D, $000000D5, $0000004E, $000000A9,

$0000006C, $00000056, $000000F4, $000000EA, $00000065, $0000007A, $000000AE, $00000008,

$000000BA, $00000078, $00000025, $0000002E, $0000001C, $000000A6, $000000B4, $000000C6,

$000000E8, $000000DD, $00000074, $0000001F, $0000004B, $000000BD, $0000008B, $0000008A,

$00000070, $0000003E, $000000B5, $00000066, $00000048, $00000003, $000000F6, $0000000E,

$00000061, $00000035, $00000057, $000000B9, $00000086, $000000C1, $0000001D, $0000009E,

$000000E1, $000000F8, $00000098, $00000011, $00000069, $000000D9, $0000008E, $00000094,

$0000009B, $0000001E, $00000087, $000000E9, $000000CE, $00000055, $00000028, $000000DF,

$0000008C, $000000A1, $00000089, $0000000D, $000000BF, $000000E6, $00000042, $00000068,

$00000041, $00000099, $0000002D, $0000000F, $000000B0, $00000054, $000000BB, $00000016

);

InverseTable: array [0..255] of longword = (

$50A7F451, $5365417E, $C3A4171A, $965E273A, $CB6BAB3B, $F1459D1F, $AB58FAAC, $9303E34B,

$55FA3020, $F66D76AD, $9176CC88, $254C02F5, $FCD7E54F, $D7CB2AC5, $80443526, $8FA362B5,

$495AB1DE, $671BBA25, $980EEA45, $E1C0FE5D, $02752FC3, $12F04C81, $A397468D, $C6F9D36B,

$E75F8F03, $959C9215, $EB7A6DBF, $DA595295, $2D83BED4, $D3217458, $2969E049, $44C8C98E,

$6A89C275, $78798EF4, $6B3E5899, $DD71B927, $B64FE1BE, $17AD88F0, $66AC20C9, $B43ACE7D,

$184ADF63, $82311AE5, $60335197, $457F5362, $E07764B1, $84AE6BBB, $1CA081FE, $942B08F9,

$58684870, $19FD458F, $876CDE94, $B7F87B52, $23D373AB, $E2024B72, $578F1FE3, $2AAB5566,

$0728EBB2, $03C2B52F, $9A7BC586, $A50837D3, $F2872830, $B2A5BF23, $BA6A0302, $5C8216ED,

$2B1CCF8A, $92B479A7, $F0F207F3, $A1E2694E, $CDF4DA65, $D5BE0506, $1F6234D1, $8AFEA6C4,

$9D532E34, $A055F3A2, $32E18A05, $75EBF6A4, $39EC830B, $AAEF6040, $069F715E, $51106EBD,

$F98A213E, $3D06DD96, $AE053EDD, $46BDE64D, $B58D5491, $055DC471, $6FD40604, $FF155060,

$24FB9819, $97E9BDD6, $CC434089, $779ED967, $BD42E8B0, $888B8907, $385B19E7, $DBEEC879,

$470A7CA1, $E90F427C, $C91E84F8, $00000000, $83868009, $48ED2B32, $AC70111E, $4E725A6C,

$FBFF0EFD, $5638850F, $1ED5AE3D, $27392D36, $64D90F0A, $21A65C68, $D1545B9B, $3A2E3624,

$B1670A0C, $0FE75793, $D296EEB4, $9E919B1B, $4FC5C080, $A220DC61, $694B775A, $161A121C,

$0ABA93E2, $E52AA0C0, $43E0223C, $1D171B12, $0B0D090E, $ADC78BF2, $B9A8B62D, $C8A91E14,

$8519F157, $4C0775AF, $BBDD99EE, $FD607FA3, $9F2601F7, $BCF5725C, $C53B6644, $347EFB5B,

$7629438B, $DCC623CB, $68FCEDB6, $63F1E4B8, $CADC31D7, $10856342, $40229713, $2011C684,

$7D244A85, $F83DBBD2, $1132F9AE, $6DA129C7, $4B2F9E1D, $F330B2DC, $EC52860D, $D0E3C177,

$6C16B32B, $99B970A9, $FA489411, $2264E947, $C48CFCA8, $1A3FF0A0, $D82C7D56, $EF903322,

$C74E4987, $C1D138D9, $FEA2CA8C, $360BD498, $CF81F5A6, $28DE7AA5, $268EB7DA, $A4BFAD3F,

$E49D3A2C, $0D927850, $9BCC5F6A, $62467E54, $C2138DF6, $E8B8D890, $5EF7392E, $F5AFC382,

$BE805D9F, $7C93D069, $A92DD56F, $B31225CF, $3B99ACC8, $A77D1810, $6E639CE8, $7BBB3BDB,

$097826CD, $F418596E, $01B79AEC, $A89A4F83, $656E95E6, $7EE6FFAA, $08CFBC21, $E6E815EF,

$D99BE7BA, $CE366F4A, $D4099FEA, $D67CB029, $AFB2A431, $31233F2A, $3094A5C6, $C066A235,

$37BC4E74, $A6CA82FC, $B0D090E0, $15D8A733, $4A9804F1, $F7DAEC41, $0E50CD7F, $2FF69117,

$8DD64D76, $4DB0EF43, $544DAACC, $DF0496E4, $E3B5D19E, $1B886A4C, $B81F2CC1, $7F516546,

$04EA5E9D, $5D358C01, $737487FA, $2E410BFB, $5A1D67B3, $52D2DB92, $335610E9, $1347D66D,

$8C61D79A, $7A0CA137, $8E14F859, $893C13EB, $EE27A9CE, $35C961B7, $EDE51CE1, $3CB1477A,

$59DFD29C, $3F73F255, $79CE1418, $BF37C773, $EACDF753, $5BAAFD5F, $146F3DDF, $86DB4478,

$81F3AFCA, $3EC468B9, $2C342438, $5F40A3C2, $72C31D16, $0C25E2BC, $8B493C28, $41950DFF,

$7101A839, $DEB30C08, $9CE4B4D8, $90C15664, $6184CB7B, $70B632D5, $745C6C48, $4257B8D0

);

LastInverseTable: array [0..255] of longword = (

$00000052, $00000009, $0000006A, $000000D5, $00000030, $00000036, $000000A5, $00000038,

$000000BF, $00000040, $000000A3, $0000009E, $00000081, $000000F3, $000000D7, $000000FB,

$0000007C, $000000E3, $00000039, $00000082, $0000009B, $0000002F, $000000FF, $00000087,

$00000034, $0000008E, $00000043, $00000044, $000000C4, $000000DE, $000000E9, $000000CB,

$00000054, $0000007B, $00000094, $00000032, $000000A6, $000000C2, $00000023, $0000003D,

$000000EE, $0000004C, $00000095, $0000000B, $00000042, $000000FA, $000000C3, $0000004E,

$00000008, $0000002E, $000000A1, $00000066, $00000028, $000000D9, $00000024, $000000B2,

$00000076, $0000005B, $000000A2, $00000049, $0000006D, $0000008B, $000000D1, $00000025,

$00000072, $000000F8, $000000F6, $00000064, $00000086, $00000068, $00000098, $00000016,

$000000D4, $000000A4, $0000005C, $000000CC, $0000005D, $00000065, $000000B6, $00000092,

$0000006C, $00000070, $00000048, $00000050, $000000FD, $000000ED, $000000B9, $000000DA,

$0000005E, $00000015, $00000046, $00000057, $000000A7, $0000008D, $0000009D, $00000084,

$00000090, $000000D8, $000000AB, $00000000, $0000008C, $000000BC, $000000D3, $0000000A,

$000000F7, $000000E4, $00000058, $00000005, $000000B8, $000000B3, $00000045, $00000006,

$000000D0, $0000002C, $0000001E, $0000008F, $000000CA, $0000003F, $0000000F, $00000002,

$000000C1, $000000AF, $000000BD, $00000003, $00000001, $00000013, $0000008A, $0000006B,

$0000003A, $00000091, $00000011, $00000041, $0000004F, $00000067, $000000DC, $000000EA,

$00000097, $000000F2, $000000CF, $000000CE, $000000F0, $000000B4, $000000E6, $00000073,

$00000096, $000000AC, $00000074, $00000022, $000000E7, $000000AD, $00000035, $00000085,

$000000E2, $000000F9, $00000037, $000000E8, $0000001C, $00000075, $000000DF, $0000006E,

$00000047, $000000F1, $0000001A, $00000071, $0000001D, $00000029, $000000C5, $00000089,

$0000006F, $000000B7, $00000062, $0000000E, $000000AA, $00000018, $000000BE, $0000001B,

$000000FC, $00000056, $0000003E, $0000004B, $000000C6, $000000D2, $00000079, $00000020,

$0000009A, $000000DB, $000000C0, $000000FE, $00000078, $000000CD, $0000005A, $000000F4,

$0000001F, $000000DD, $000000A8, $00000033, $00000088, $00000007, $000000C7, $00000031,

$000000B1, $00000012, $00000010, $00000059, $00000027, $00000080, $000000EC, $0000005F,

$00000060, $00000051, $0000007F, $000000A9, $00000019, $000000B5, $0000004A, $0000000D,

$0000002D, $000000E5, $0000007A, $0000009F, $00000093, $000000C9, $0000009C, $000000EF,

$000000A0, $000000E0, $0000003B, $0000004D, $000000AE, $0000002A, $000000F5, $000000B0,

$000000C8, $000000EB, $000000BB, $0000003C, $00000083, $00000053, $00000099, $00000061,

$00000017, $0000002B, $00000004, $0000007E, $000000BA, $00000077, $000000D6, $00000026,

$000000E1, $00000069, $00000014, $00000063, $00000055, $00000021, $0000000C, $0000007D

);

procedure ExpandAESKeyForEncryption(const Key: TAESKey128; var ExpandedKey: TAESExpandedKey128);

var

I, J: integer;

T: longword;

W0, W1, W2, W3: longword;

begin

ExpandedKey[0] := PLongWord(@Key[0])^;

ExpandedKey[1] := PLongWord(@Key[4])^;

ExpandedKey[2] := PLongWord(@Key[8])^;

ExpandedKey[3] := PLongWord(@Key[12])^;

I := 0; J := 1;

repeat

T := (ExpandedKey[I + 3] shl 24) or (ExpandedKey[I + 3] shr 8);

W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];

W2 := LastForwardTable[Byte(T shr 16)]; W3 := LastForwardTable[Byte(T shr 24)];

ExpandedKey[I + 4] := ExpandedKey[I] xor

(W0 xor ((W1 shl 8) or (W1 shr 24)) xor

((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];

Inc(J);

ExpandedKey[I + 5] := ExpandedKey[I + 1] xor ExpandedKey[I + 4];

ExpandedKey[I + 6] := ExpandedKey[I + 2] xor ExpandedKey[I + 5];

ExpandedKey[I + 7] := ExpandedKey[I + 3] xor ExpandedKey[I + 6];

Inc(I, 4);

until I >= 40;

end;

procedure ExpandAESKeyForEncryption(const Key: TAESKey192; var ExpandedKey: TAESExpandedKey192); overload;

var

I, J: integer;

T: longword;

W0, W1, W2, W3: longword;

begin

ExpandedKey[0] := PLongWord(@Key[0])^;

ExpandedKey[1] := PLongWord(@Key[4])^;

ExpandedKey[2] := PLongWord(@Key[8])^;

ExpandedKey[3] := PLongWord(@Key[12])^;

ExpandedKey[4] := PLongWord(@Key[16])^;

ExpandedKey[5] := PLongWord(@Key[20])^;

I := 0; J := 1;

repeat

T := (ExpandedKey[I + 5] shl 24) or (ExpandedKey[I + 5] shr 8);

W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];

W2 := LastForwardTable[Byte(T shr 16)]; W3 := LastForwardTable[Byte(T shr 24)];

ExpandedKey[I + 6] := ExpandedKey[I] xor

(W0 xor ((W1 shl 8) or (W1 shr 24)) xor

((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];

Inc(J);

ExpandedKey[I + 7] := ExpandedKey[I + 1] xor ExpandedKey[I + 6];

ExpandedKey[I + 8] := ExpandedKey[I + 2] xor ExpandedKey[I + 7];

ExpandedKey[I + 9] := ExpandedKey[I + 3] xor ExpandedKey[I + 8];

ExpandedKey[I + 10] := ExpandedKey[I + 4] xor ExpandedKey[I + 9];

ExpandedKey[I + 11] := ExpandedKey[I + 5] xor ExpandedKey[I + 10];

Inc(I, 6);

until I >= 46;

end;

procedure ExpandAESKeyForEncryption(const Key: TAESKey256; var ExpandedKey: TAESExpandedKey256); overload;

var

I, J: integer;

T: longword;

W0, W1, W2, W3: longword;

begin

ExpandedKey[0] := PLongWord(@Key[0])^;

ExpandedKey[1] := PLongWord(@Key[4])^;

ExpandedKey[2] := PLongWord(@Key[8])^;

ExpandedKey[3] := PLongWord(@Key[12])^;

ExpandedKey[4] := PLongWord(@Key[16])^;

ExpandedKey[5] := PLongWord(@Key[20])^;

ExpandedKey[6] := PLongWord(@Key[24])^;

ExpandedKey[7] := PLongWord(@Key[28])^;

I := 0; J := 1;

repeat

T := (ExpandedKey[I + 7] shl 24) or (ExpandedKey[I + 7] shr 8);

W0 := LastForwardTable[Byte(T)]; W1 := LastForwardTable[Byte(T shr 8)];

W2 := LastForwardTable[Byte(T shr 16)]; W3 := LastForwardTable[Byte(T shr 24)];

ExpandedKey[I + 8] := ExpandedKey[I] xor

(W0 xor ((W1 shl 8) or (W1 shr 24)) xor

((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8))) xor Rcon[J];

Inc(J);

ExpandedKey[I + 9] := ExpandedKey[I + 1] xor ExpandedKey[I + 8];

ExpandedKey[I + 10] := ExpandedKey[I + 2] xor ExpandedKey[I + 9];

ExpandedKey[I + 11] := ExpandedKey[I + 3] xor ExpandedKey[I + 10];

W0 := LastForwardTable[Byte(ExpandedKey[I + 11])];

W1 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 8)];

W2 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 16)];

W3 := LastForwardTable[Byte(ExpandedKey[I + 11] shr 24)];

ExpandedKey[I + 12] := ExpandedKey[I + 4] xor

(W0 xor ((W1 shl 8) or (W1 shr 24)) xor

((W2 shl 16) or (W2 shr 16)) xor ((W3 shl 24) or (W3 shr 8)));

ExpandedKey[I + 13] := ExpandedKey[I + 5] xor ExpandedKey[I + 12];

ExpandedKey[I + 14] := ExpandedKey[I + 6] xor ExpandedKey[I + 13];

ExpandedKey[I + 15] := ExpandedKey[I + 7] xor ExpandedKey[I + 14];

Inc(I, 8);

until I >= 52;

end;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[0];

T0[1] := PLongWord(@InBuf[4])^ xor Key[1];

T0[2] := PLongWord(@InBuf[8])^ xor Key[2];

T0[3] := PLongWord(@InBuf[12])^ xor Key[3];

// performing transformation 9 times

// round 1

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// round 2

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 3

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 4

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 5

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 6

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 7

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 8

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 9

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// last round of transformations

W0 := LastForwardTable[Byte(T1[0])]; W1 := LastForwardTable[Byte(T1[1] shr 8)];

W2 := LastForwardTable[Byte(T1[2] shr 16)]; W3 := LastForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[40];

W0 := LastForwardTable[Byte(T1[1])]; W1 := LastForwardTable[Byte(T1[2] shr 8)];

W2 := LastForwardTable[Byte(T1[3] shr 16)]; W3 := LastForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[41];

W0 := LastForwardTable[Byte(T1[2])]; W1 := LastForwardTable[Byte(T1[3] shr 8)];

W2 := LastForwardTable[Byte(T1[0] shr 16)]; W3 := LastForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[42];

W0 := LastForwardTable[Byte(T1[3])]; W1 := LastForwardTable[Byte(T1[0] shr 8)];

W2 := LastForwardTable[Byte(T1[1] shr 16)]; W3 := LastForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[43];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[0];

T0[1] := PLongWord(@InBuf[4])^ xor Key[1];

T0[2] := PLongWord(@InBuf[8])^ xor Key[2];

T0[3] := PLongWord(@InBuf[12])^ xor Key[3];

// performing transformation 11 times

// round 1

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// round 2

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 3

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 4

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 5

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 6

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 7

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 8

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 9

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// round 10

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[40];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[41];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[42];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[43];

// round 11

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[44];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[45];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[46];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[47];

// last round of transformations

W0 := LastForwardTable[Byte(T1[0])]; W1 := LastForwardTable[Byte(T1[1] shr 8)];

W2 := LastForwardTable[Byte(T1[2] shr 16)]; W3 := LastForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[48];

W0 := LastForwardTable[Byte(T1[1])]; W1 := LastForwardTable[Byte(T1[2] shr 8)];

W2 := LastForwardTable[Byte(T1[3] shr 16)]; W3 := LastForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[49];

W0 := LastForwardTable[Byte(T1[2])]; W1 := LastForwardTable[Byte(T1[3] shr 8)];

W2 := LastForwardTable[Byte(T1[0] shr 16)]; W3 := LastForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[50];

W0 := LastForwardTable[Byte(T1[3])]; W1 := LastForwardTable[Byte(T1[0] shr 8)];

W2 := LastForwardTable[Byte(T1[1] shr 16)]; W3 := LastForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[51];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

procedure EncryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[0];

T0[1] := PLongWord(@InBuf[4])^ xor Key[1];

T0[2] := PLongWord(@InBuf[8])^ xor Key[2];

T0[3] := PLongWord(@InBuf[12])^ xor Key[3];

// performing transformation 13 times

// round 1

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// round 2

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 3

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 4

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 5

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 6

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 7

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 8

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 9

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// round 10

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[40];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[41];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[42];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[43];

// round 11

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[44];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[45];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[46];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[47];

// round 12

W0 := ForwardTable[Byte(T1[0])]; W1 := ForwardTable[Byte(T1[1] shr 8)];

W2 := ForwardTable[Byte(T1[2] shr 16)]; W3 := ForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[48];

W0 := ForwardTable[Byte(T1[1])]; W1 := ForwardTable[Byte(T1[2] shr 8)];

W2 := ForwardTable[Byte(T1[3] shr 16)]; W3 := ForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[49];

W0 := ForwardTable[Byte(T1[2])]; W1 := ForwardTable[Byte(T1[3] shr 8)];

W2 := ForwardTable[Byte(T1[0] shr 16)]; W3 := ForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[50];

W0 := ForwardTable[Byte(T1[3])]; W1 := ForwardTable[Byte(T1[0] shr 8)];

W2 := ForwardTable[Byte(T1[1] shr 16)]; W3 := ForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[51];

// round 13

W0 := ForwardTable[Byte(T0[0])]; W1 := ForwardTable[Byte(T0[1] shr 8)];

W2 := ForwardTable[Byte(T0[2] shr 16)]; W3 := ForwardTable[Byte(T0[3] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[52];

W0 := ForwardTable[Byte(T0[1])]; W1 := ForwardTable[Byte(T0[2] shr 8)];

W2 := ForwardTable[Byte(T0[3] shr 16)]; W3 := ForwardTable[Byte(T0[0] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[53];

W0 := ForwardTable[Byte(T0[2])]; W1 := ForwardTable[Byte(T0[3] shr 8)];

W2 := ForwardTable[Byte(T0[0] shr 16)]; W3 := ForwardTable[Byte(T0[1] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[54];

W0 := ForwardTable[Byte(T0[3])]; W1 := ForwardTable[Byte(T0[0] shr 8)];

W2 := ForwardTable[Byte(T0[1] shr 16)]; W3 := ForwardTable[Byte(T0[2] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[55];

// last round of transformations

W0 := LastForwardTable[Byte(T1[0])]; W1 := LastForwardTable[Byte(T1[1] shr 8)];

W2 := LastForwardTable[Byte(T1[2] shr 16)]; W3 := LastForwardTable[Byte(T1[3] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[56];

W0 := LastForwardTable[Byte(T1[1])]; W1 := LastForwardTable[Byte(T1[2] shr 8)];

W2 := LastForwardTable[Byte(T1[3] shr 16)]; W3 := LastForwardTable[Byte(T1[0] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[57];

W0 := LastForwardTable[Byte(T1[2])]; W1 := LastForwardTable[Byte(T1[3] shr 8)];

W2 := LastForwardTable[Byte(T1[0] shr 16)]; W3 := LastForwardTable[Byte(T1[1] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[58];

W0 := LastForwardTable[Byte(T1[3])]; W1 := LastForwardTable[Byte(T1[0] shr 8)];

W2 := LastForwardTable[Byte(T1[1] shr 16)]; W3 := LastForwardTable[Byte(T1[2] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[59];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey128);

var

I: integer;

U, F2, F4, F8, F9: longword;

begin

for I := 1 to 9 do

begin

F9 := ExpandedKey[I * 4];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 1];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 1] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 2];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 2] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 3];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 3] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

end;

end;

procedure ExpandAESKeyForDecryption(const Key: TAESKey128; var ExpandedKey: TAESExpandedKey128);

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

ExpandAESKeyForDecryption(ExpandedKey);

end;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey192);

var

I: integer;

U, F2, F4, F8, F9: longword;

begin

for I := 1 to 11 do

begin

F9 := ExpandedKey[I * 4];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 1];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 1] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 2];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 2] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 3];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 3] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

end;

end;

procedure ExpandAESKeyForDecryption(const Key: TAESKey192; var ExpandedKey: TAESExpandedKey192);

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

ExpandAESKeyForDecryption(ExpandedKey);

end;

procedure ExpandAESKeyForDecryption(var ExpandedKey: TAESExpandedKey256);

var

I: integer;

U, F2, F4, F8, F9: longword;

begin

for I := 1 to 13 do

begin

F9 := ExpandedKey[I * 4];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 1];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 1] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 2];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 2] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

F9 := ExpandedKey[I * 4 + 3];

U := F9 and $80808080;

F2 := ((F9 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F2 and $80808080;

F4 := ((F2 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

U := F4 and $80808080;

F8 := ((F4 and $7F7F7F7F) shl 1) xor ((U - (U shr 7)) and $1B1B1B1B);

F9 := F9 xor F8;

ExpandedKey[I * 4 + 3] := F2 xor F4 xor F8 xor

(((F2 xor F9) shl 24) or ((F2 xor F9) shr 8)) xor

(((F4 xor F9) shl 16) or ((F4 xor F9) shr 16)) xor ((F9 shl 8) or (F9 shr 24));

end;

end;

procedure ExpandAESKeyForDecryption(const Key: TAESKey256; var ExpandedKey: TAESExpandedKey256);

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

ExpandAESKeyForDecryption(ExpandedKey);

end;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey128;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[40];

T0[1] := PLongWord(@InBuf[4])^ xor Key[41];

T0[2] := PLongWord(@InBuf[8])^ xor Key[42];

T0[3] := PLongWord(@InBuf[12])^ xor Key[43];

// performing transformations 9 times

// round 1

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// round 2

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 3

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 4

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 5

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 6

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 7

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 8

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 9

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// last round of transformations

W0 := LastInverseTable[Byte(T1[0])]; W1 := LastInverseTable[Byte(T1[3] shr 8)];

W2 := LastInverseTable[Byte(T1[2] shr 16)]; W3 := LastInverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[0];

W0 := LastInverseTable[Byte(T1[1])]; W1 := LastInverseTable[Byte(T1[0] shr 8)];

W2 := LastInverseTable[Byte(T1[3] shr 16)]; W3 := LastInverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[1];

W0 := LastInverseTable[Byte(T1[2])]; W1 := LastInverseTable[Byte(T1[1] shr 8)];

W2 := LastInverseTable[Byte(T1[0] shr 16)]; W3 := LastInverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[2];

W0 := LastInverseTable[Byte(T1[3])]; W1 := LastInverseTable[Byte(T1[2] shr 8)];

W2 := LastInverseTable[Byte(T1[1] shr 16)]; W3 := LastInverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[3];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey192;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[48];

T0[1] := PLongWord(@InBuf[4])^ xor Key[49];

T0[2] := PLongWord(@InBuf[8])^ xor Key[50];

T0[3] := PLongWord(@InBuf[12])^ xor Key[51];

// performing transformations 11 times

// round 1

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[44];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[45];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[46];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[47];

// round 2

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[40];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[41];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[42];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[43];

// round 3

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// round 4

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 5

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 6

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 7

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 8

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 9

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 10

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 11

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// last round of transformations

W0 := LastInverseTable[Byte(T1[0])]; W1 := LastInverseTable[Byte(T1[3] shr 8)];

W2 := LastInverseTable[Byte(T1[2] shr 16)]; W3 := LastInverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[0];

W0 := LastInverseTable[Byte(T1[1])]; W1 := LastInverseTable[Byte(T1[0] shr 8)];

W2 := LastInverseTable[Byte(T1[3] shr 16)]; W3 := LastInverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[1];

W0 := LastInverseTable[Byte(T1[2])]; W1 := LastInverseTable[Byte(T1[1] shr 8)];

W2 := LastInverseTable[Byte(T1[0] shr 16)]; W3 := LastInverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[2];

W0 := LastInverseTable[Byte(T1[3])]; W1 := LastInverseTable[Byte(T1[2] shr 8)];

W2 := LastInverseTable[Byte(T1[1] shr 16)]; W3 := LastInverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[3];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

procedure DecryptAES(const InBuf: TAESBuffer; const Key: TAESExpandedKey256;

var OutBuf: TAESBuffer);

var

T0, T1: array [0..3] of longword;

W0, W1, W2, W3: longword;

begin

// initializing

T0[0] := PLongWord(@InBuf[0])^ xor Key[56];

T0[1] := PLongWord(@InBuf[4])^ xor Key[57];

T0[2] := PLongWord(@InBuf[8])^ xor Key[58];

T0[3] := PLongWord(@InBuf[12])^ xor Key[59];

// performing transformations 13 times

// round 1

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[52];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[53];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[54];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[55];

// round 2

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[48];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[49];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[50];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[51];

// round 3

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[44];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[45];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[46];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[47];

// round 4

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[40];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[41];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[42];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[43];

// round 5

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[36];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[37];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[38];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[39];

// round 6

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[32];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[33];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[34];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[35];

// round 7

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[28];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[29];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[30];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[31];

// round 8

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[24];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[25];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[26];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[27];

// round 9

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[20];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[21];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[22];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[23];

// round 10

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[16];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[17];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[18];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[19];

// round 11

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[12];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[13];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[14];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[15];

// round 12

W0 := InverseTable[Byte(T1[0])]; W1 := InverseTable[Byte(T1[3] shr 8)];

W2 := InverseTable[Byte(T1[2] shr 16)]; W3 := InverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[8];

W0 := InverseTable[Byte(T1[1])]; W1 := InverseTable[Byte(T1[0] shr 8)];

W2 := InverseTable[Byte(T1[3] shr 16)]; W3 := InverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[9];

W0 := InverseTable[Byte(T1[2])]; W1 := InverseTable[Byte(T1[1] shr 8)];

W2 := InverseTable[Byte(T1[0] shr 16)]; W3 := InverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[10];

W0 := InverseTable[Byte(T1[3])]; W1 := InverseTable[Byte(T1[2] shr 8)];

W2 := InverseTable[Byte(T1[1] shr 16)]; W3 := InverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[11];

// round 13

W0 := InverseTable[Byte(T0[0])]; W1 := InverseTable[Byte(T0[3] shr 8)];

W2 := InverseTable[Byte(T0[2] shr 16)]; W3 := InverseTable[Byte(T0[1] shr 24)];

T1[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[4];

W0 := InverseTable[Byte(T0[1])]; W1 := InverseTable[Byte(T0[0] shr 8)];

W2 := InverseTable[Byte(T0[3] shr 16)]; W3 := InverseTable[Byte(T0[2] shr 24)];

T1[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[5];

W0 := InverseTable[Byte(T0[2])]; W1 := InverseTable[Byte(T0[1] shr 8)];

W2 := InverseTable[Byte(T0[0] shr 16)]; W3 := InverseTable[Byte(T0[3] shr 24)];

T1[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[6];

W0 := InverseTable[Byte(T0[3])]; W1 := InverseTable[Byte(T0[2] shr 8)];

W2 := InverseTable[Byte(T0[1] shr 16)]; W3 := InverseTable[Byte(T0[0] shr 24)];

T1[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[7];

// last round of transformations

W0 := LastInverseTable[Byte(T1[0])]; W1 := LastInverseTable[Byte(T1[3] shr 8)];

W2 := LastInverseTable[Byte(T1[2] shr 16)]; W3 := LastInverseTable[Byte(T1[1] shr 24)];

T0[0] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[0];

W0 := LastInverseTable[Byte(T1[1])]; W1 := LastInverseTable[Byte(T1[0] shr 8)];

W2 := LastInverseTable[Byte(T1[3] shr 16)]; W3 := LastInverseTable[Byte(T1[2] shr 24)];

T0[1] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[1];

W0 := LastInverseTable[Byte(T1[2])]; W1 := LastInverseTable[Byte(T1[1] shr 8)];

W2 := LastInverseTable[Byte(T1[0] shr 16)]; W3 := LastInverseTable[Byte(T1[3] shr 24)];

T0[2] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[2];

W0 := LastInverseTable[Byte(T1[3])]; W1 := LastInverseTable[Byte(T1[2] shr 8)];

W2 := LastInverseTable[Byte(T1[1] shr 16)]; W3 := LastInverseTable[Byte(T1[0] shr 24)];

T0[3] := (W0 xor ((W1 shl 8) or (W1 shr 24)) xor ((W2 shl 16) or (W2 shr 16))

xor ((W3 shl 24) or (W3 shr 8))) xor Key[3];

// finalizing

PLongWord(@OutBuf[0])^ := T0[0]; PLongWord(@OutBuf[4])^ := T0[1];

PLongWord(@OutBuf[8])^ := T0[2]; PLongWord(@OutBuf[12])^ := T0[3];

end;

// Stream encryption routines (ECB mode)

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey192; Dest: TStream);

var

ExpandedKey: TAESExpandedKey192;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey256; Dest: TStream);

var

ExpandedKey: TAESExpandedKey256;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

procedure EncryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

// Stream decryption routines (ECB mode)

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey128; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

DecryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

end;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey192; Dest: TStream);

var

ExpandedKey: TAESExpandedKey192;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

DecryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

end;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const Key: TAESKey256; Dest: TStream);

var

ExpandedKey: TAESExpandedKey256;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamECB(Source, Count, ExpandedKey, Dest);

end;

procedure DecryptAESStreamECB(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256; Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

DecryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Dec(Count, SizeOf(TAESBuffer));

end;

end;

// Stream encryption routines (CBC mode)

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut, Vector: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

Vector := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Vector := TempOut;

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey192;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut, Vector: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

Vector := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Vector := TempOut;

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey256;

begin

ExpandAESKeyForEncryption(Key, ExpandedKey);

EncryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure EncryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut, Vector: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

Vector := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError.Create(SReadError);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

Vector := TempOut;

Dec(Count, SizeOf(TAESBuffer));

end;

if Count > 0 then

begin

Done := Source.Read(TempIn, Count);

if Done < Count then

raise EStreamError.Create(SReadError);

FillChar(TempIn[Count], SizeOf(TempIn) - Count, 0);

PLongWord(@TempIn[0])^ := PLongWord(@TempIn[0])^ xor PLongWord(@Vector[0])^;

PLongWord(@TempIn[4])^ := PLongWord(@TempIn[4])^ xor PLongWord(@Vector[4])^;

PLongWord(@TempIn[8])^ := PLongWord(@TempIn[8])^ xor PLongWord(@Vector[8])^;

PLongWord(@TempIn[12])^ := PLongWord(@TempIn[12])^ xor PLongWord(@Vector[12])^;

EncryptAES(TempIn, ExpandedKey, TempOut);

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError.Create(SWriteError);

end;

end;

// Stream decryption routines (CBC mode)

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey128; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey128;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey128;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Vector1, Vector2: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

Vector1 := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError(SReadError);

Vector2 := TempIn;

DecryptAES(TempIn, ExpandedKey, TempOut);

PLongWord(@TempOut[0])^ := PLongWord(@TempOut[0])^ xor PLongWord(@Vector1[0])^;

PLongWord(@TempOut[4])^ := PLongWord(@TempOut[4])^ xor PLongWord(@Vector1[4])^;

PLongWord(@TempOut[8])^ := PLongWord(@TempOut[8])^ xor PLongWord(@Vector1[8])^;

PLongWord(@TempOut[12])^ := PLongWord(@TempOut[12])^ xor PLongWord(@Vector1[12])^;

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError(SWriteError);

Vector1 := Vector2;

Dec(Count, SizeOf(TAESBuffer));

end;

end;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey192; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey192;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey192;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Vector1, Vector2: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

Vector1 := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError(SReadError);

Vector2 := TempIn;

DecryptAES(TempIn, ExpandedKey, TempOut);

PLongWord(@TempOut[0])^ := PLongWord(@TempOut[0])^ xor PLongWord(@Vector1[0])^;

PLongWord(@TempOut[4])^ := PLongWord(@TempOut[4])^ xor PLongWord(@Vector1[4])^;

PLongWord(@TempOut[8])^ := PLongWord(@TempOut[8])^ xor PLongWord(@Vector1[8])^;

PLongWord(@TempOut[12])^ := PLongWord(@TempOut[12])^ xor PLongWord(@Vector1[12])^;

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError(SWriteError);

Vector1 := Vector2;

Dec(Count, SizeOf(TAESBuffer));

end;

end;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const Key: TAESKey256; const InitVector: TAESBuffer; Dest: TStream);

var

ExpandedKey: TAESExpandedKey256;

begin

ExpandAESKeyForDecryption(Key, ExpandedKey);

DecryptAESStreamCBC(Source, Count, ExpandedKey, InitVector, Dest);

end;

procedure DecryptAESStreamCBC(Source: TStream; Count: cardinal;

const ExpandedKey: TAESExpandedKey256;? const InitVector: TAESBuffer;

Dest: TStream);

var

TempIn, TempOut: TAESBuffer;

Vector1, Vector2: TAESBuffer;

Done: cardinal;

begin

if Count = 0 then

begin

Source.Position := 0;

Count := Source.Size;

end

else Count := Min(Count, Source.Size - Source.Position);

if Count = 0 then exit;

if (Count mod SizeOf(TAESBuffer)) > 0 then

raise EAESError.Create(SInvalidInBufSize);

Vector1 := InitVector;

while Count >= SizeOf(TAESBuffer) do

begin

Done := Source.Read(TempIn, SizeOf(TempIn));

if Done < SizeOf(TempIn) then

raise EStreamError(SReadError);

Vector2 := TempIn;

DecryptAES(TempIn, ExpandedKey, TempOut);

PLongWord(@TempOut[0])^ := PLongWord(@TempOut[0])^ xor PLongWord(@Vector1[0])^;

PLongWord(@TempOut[4])^ := PLongWord(@TempOut[4])^ xor PLongWord(@Vector1[4])^;

PLongWord(@TempOut[8])^ := PLongWord(@TempOut[8])^ xor PLongWord(@Vector1[8])^;

PLongWord(@TempOut[12])^ := PLongWord(@TempOut[12])^ xor PLongWord(@Vector1[12])^;

Done := Dest.Write(TempOut, SizeOf(TempOut));

if Done < SizeOf(TempOut) then

raise EStreamError(SWriteError);

Vector1 := Vector2;

Dec(Count, SizeOf(TAESBuffer));

end;

end;

function StringToHex(S: string): string;

var

i: integer;

begin

Result := '';

for i := 1 to Length( S ) do

Result := Result + IntToHex( Ord( S[i] ), 2 );

end;

function HexToString(S: string): string;

var

i: integer;

begin

Result := '';

for i := 1 to Length( S ) do

begin

if ((i mod 2) = 1) then

Result := Result + Chr( StrToInt( '0x' + Copy( S, i, 2 )));

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

var

Source: TStringStream;

Dest: TStringStream;

Start, Stop: cardinal;

Size: integer;

Key: TAESKey128;

RegCode:String;

begin

Source := TStringStream.Create(Edit1.Text);

Dest?? := TStringStream.Create( '' );

try

Size := Source.Size;

Dest.WriteBuffer( Size, SizeOf(Size) );

FillChar( Key, SizeOf(Key), 0 );

Move( PChar('ksaiy')^, Key, Min( SizeOf( Key ), Length('ksaiy')));//此處ksaiy為key,您可以自己設(shè)定自己的key;

Start := GetTickCount;

EncryptAESStreamECB( Source, 0, Key, Dest );

Stop := GetTickCount;

RegCode:= StringToHex( Dest.DataString );

finally

Source.Free;

Dest.Free;

end;

if RegCode=Edit2.Text then

ShowMessage('注冊(cè)成功!')

else

ShowMessage('注冊(cè)失敗');

///

end;

end.

總結(jié)

以上是生活随笔為你收集整理的java delphi aes加密算法_Delphi AES,又一个加密算法例子的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

免费观看一区 | 午夜 久久 tv | 国产美腿白丝袜足在线av | 十八岁免进欧美 | 国产精品99久久久久的智能播放 | 麻豆国产精品va在线观看不卡 | 久久电影色 | 欧美最猛性xxxxx(亚洲精品) | 久久久观看 | www久久com | 99久久这里有精品 | 99热精品免费观看 | 国产精品美女在线 | 国产高清专区 | 免费日韩一区二区 | 国产免费成人av | 色综合久久久久久中文网 | 六月丁香综合 | 97av在线视频 | 99综合影院在线 | 五月婷婷在线观看视频 | 天天干天天操天天操 | 麻豆视频在线播放 | 欧洲激情综合 | 午夜av网站 | 成人理论电影 | 国产免费午夜 | 天天射色综合 | 久草精品在线观看 | 日韩欧美在线观看一区二区 | 97福利 | 中文资源在线官网 | 午夜美女福利 | 亚洲h视频在线 | 精品国产乱码久久久久久天美 | 亚洲综合小说电影qvod | 中文字幕一区二区三区在线观看 | 日日干夜夜骑 | 精品在线免费观看 | 欧美一进一出抽搐大尺度视频 | 黄色影院在线免费观看 | 狠狠色狠狠色终合网 | avove黑丝 | 国产精品日韩欧美 | 国产视频精品久久 | 欧美日韩国产二区三区 | 亚洲热久久 | 在线精品播放 | 中文字幕在线观看视频网站 | 91成人小视频 | 91传媒免费观看 | 人人超碰在线 | 韩国一区视频 | 美女网站在线免费观看 | 亚洲成人一二三 | 国内三级在线观看 | 黄色一区二区在线观看 | 久久久久国产精品免费网站 | 成人在线免费观看网站 | 日韩免费视频播放 | 日日夜夜干 | 中文字幕免费国产精品 | 日韩精品视频在线观看免费 | 日本二区三区在线 | 亚洲精品裸体 | 黄色中文字幕 | 国产中文| 蜜臀久久99静品久久久久久 | 中文av一区二区 | 人人插人人澡 | 免费在线精品视频 | 在线观看成人网 | 久久99精品视频 | 成 人 黄 色 片 在线播放 | 国产精品国内免费一区二区三区 | 91成人久久 | 亚洲成人精品在线 | 蜜臀av网址| 色视频网页 | 成人蜜桃| 色资源中文字幕 | 特级黄色片免费看 | 91网站免费观看 | 99精品美女| 亚洲国产精品久久久久久 | 99亚洲天堂| 五月天久久精品 | 欧美一区二区三区免费观看 | 成人欧美亚洲 | 夜色成人网 | 久久免费在线观看 | 国产精品1区2区 | 99精品视频在线 | 在线视频一二区 | 中文区中文字幕免费看 | 国产成人精品亚洲日本在线观看 | 国产99在线播放 | 日本少妇高清做爰视频 | 青草视频免费观看 | 美女av在线免费 | 免费视频 三区 | 日韩中文字幕电影 | 五月激情姐姐 | 毛片888| 激情欧美xxxx | 999在线视频 | 亚洲一区不卡视频 | 91精品免费| 久久久久久久精 | 香蕉久草 | 国产性xxxx| 婷婷在线免费观看 | 新av在线 | 日韩av男人的天堂 | 久久久久看片 | 亚洲一区天堂 | 久久综合九色综合97婷婷女人 | 国产1区2区3区精品美女 | 日韩一二三在线 | 97在线视频网站 | 三级小视频在线观看 | 日韩久久精品一区二区 | 国产高清在线视频 | 黄色午夜| www狠狠操 | 国产成人精品一区二区三区网站观看 | 国内精品二区 | 欧美性春潮 | 一区二区三区韩国免费中文网站 | 久久精品视频观看 | 伊人伊成久久人综合网小说 | 国产成人一区二区啪在线观看 | 国产精品久久久久久久久久99 | 91视频免费看网站 | 波多野结衣小视频 | 免费看国产一级片 | 九九视频精品在线 | 国产亚洲精品福利 | 视频二区 | 久久免费激情视频 | 91超碰免费在线 | 五月婷婷中文网 | 亚洲精品中文字幕在线观看 | 久久久久久久久精 | 波多野结衣视频一区二区三区 | 521色香蕉网站在线观看 | 亚洲伊人成综合网 | 中文字幕黄色 | 国产精品久久久久久久久免费 | 亚洲 欧美 国产 va在线影院 | 青青河边草手机免费 | 97视频免费观看 | 中文在线免费看视频 | 亚洲欧美日韩精品久久奇米一区 | 伊人五月天av | 91看成人| 韩国在线一区 | 天天操天天操天天操天天 | 久久综合色播五月 | www.天天综合| 欧美日韩精品在线播放 | 婷婷色在线资源 | 日日干夜夜骑 | 久久99精品视频 | 国产精品一区二区三区四 | 久久黄色小说视频 | 在线亚洲播放 | 精品国产自 | 久久久精品在线观看 | 亚洲精品视频免费在线观看 | 欧美午夜理伦三级在线观看 | 午夜999| 又爽又黄在线观看 | 精品久久一二三区 | 久久国产精品99久久久久久进口 | 337p西西人体大胆瓣开下部 | 国内视频在线 | 精一区二区 | 在线成人一区二区 | 亚洲不卡av一区二区三区 | 色婷婷综合久久久中文字幕 | 安徽妇搡bbbb搡bbbb | 久久久久国产a免费观看rela | 欧美日韩一区二区视频在线观看 | 91大神精品视频在线观看 | 操操综合| 九色琪琪久久综合网天天 | 中文字幕日韩伦理 | 黄色福利网站 | 天天干天天操av | a色网站| 五月天久久综合网 | www.com黄 | 天天干天天拍天天操 | 亚州精品天堂中文字幕 | 91精品国产自产91精品 | 91九色网站 | 免费观看特级毛片 | 91在线亚洲 | 久久综合婷婷国产二区高清 | 久久国产影院 | 国产一二三在线视频 | 国产一级二级在线播放 | 丁香视频在线观看 | 欧美在线一二 | 天天碰天天操 | 久久理论影院 | 久久久久久久久久久免费av | 久久精品国产久精国产 | 成年人毛片在线观看 | 成人av在线网 | 亚洲最新在线 | 国产综合激情 | 丁香综合 | 午夜色影院 | 在线观看免费一级片 | 国产日本在线观看 | 亚洲理论在线观看电影 | 97人人模人人爽人人喊网 | 天天干天天射天天插 | 亚洲日韩中文字幕 | av免费高清观看 | 欧美国产日韩一区二区 | 亚洲综合成人专区片 | 欧美日韩国产二区 | 你操综合 | 日本一区二区不卡高清 | 免费福利视频网站 | 一区免费视频 | 精品久久久久久亚洲综合网站 | 四虎成人免费影院 | 最近日本字幕mv免费观看在线 | 天天玩夜夜操 | 在线免费观看国产精品 | 国产精品麻豆三级一区视频 | 午夜av在线电影 | 日韩视频一区二区三区在线播放免费观看 | 深爱五月激情五月 | 九九导航| 欧美日韩91| 亚洲精品资源在线 | 91精品久| 精品久久久久一区二区国产 | 久久精品99国产 | 涩涩爱夜夜爱 | 国产91免费在线 | 欧美激情视频一二三区 | 日日夜夜爱 | 97电影网站 | 精品国产综合区久久久久久 | 最近高清中文在线字幕在线观看 | 国产伦理精品一区二区 | 懂色av懂色av粉嫩av分享吧 | 黄污视频大全 | 日韩精品一区在线播放 | 九九视频免费观看视频精品 | 日韩精品免费在线播放 | 日韩中文字幕在线看 | 国产高清专区 | 久久久久www | 婷婷色在线播放 | 国产综合精品一区二区三区 | 免费大片黄在线 | 最近中文字幕mv | 免费av在线网 | 国产精品美女毛片真酒店 | 四虎永久国产精品 | 中国一 片免费观看 | 一本色道久久综合亚洲二区三区 | 国产视频1 | 成人中心免费视频 | 免费看毛片网站 | 91日韩国产| 日韩,中文字幕 | 欧美一区二区在线刺激视频 | 婷婷国产精品 | 久久久久这里只有精品 | 亚洲欧美精品在线 | 激情在线网址 | 高清有码中文字幕 | 狠狠色噜噜狠狠狠狠 | 久草在线资源观看 | 天天摸夜夜添 | 中文字幕a∨在线乱码免费看 | 九月婷婷色 | 日韩精品中文字幕在线 | 麻豆影视网站 | 日韩精品无码一区二区三区 | 国产精品中文字幕在线播放 | av品善网| 亚洲欧美在线综合 | 欧美日韩视频免费看 | 成人av久久 | 久久国产精品99久久人人澡 | 日本久久高清视频 | 日产乱码一二三区别免费 | av国产网站 | 日韩中文字幕亚洲一区二区va在线 | 欧美孕妇与黑人孕交 | 日本激情视频中文字幕 | 中文一区二区三区在线观看 | 麻豆va一区二区三区久久浪 | 久草在在线| 一区二区三区精品在线视频 | 91中文字幕一区 | 亚洲第一中文字幕 | 黄色片网站av | 色综合亚洲精品激情狠狠 | 五月网婷婷 | 人成在线免费视频 | av在线免费在线观看 | 久草在线在线精品观看 | 六月激情久久 | 久久精品超碰 | 免费在线观看黄 | 91在线公开视频 | av短片在线 | 91色蜜桃 | 天天曰夜夜操 | 久久久久久久久久毛片 | 麻豆av一区二区三区在线观看 | 免费麻豆 | 激情五月在线 | 亚洲精品视频第一页 | 黄色毛片大全 | 在线看片中文字幕 | 999男人的天堂 | 色99色| 国产a国产| 婷婷六月激情 | 日韩精品中文字幕在线 | 久久精品九色 | 热久久精品在线 | 特级西西444www大胆高清无视频 | 在线有码中文 | 亚洲精品午夜一区人人爽 | 99自拍视频在线观看 | 欧美久久久久久 | 久久天天躁狠狠躁亚洲综合公司 | 九九视频在线观看视频6 | 久久午夜电影 | 亚洲一区精品人人爽人人躁 | 国产成人久久av免费高清密臂 | 天天激情在线 | 2021国产精品 | 69久久久久久久 | 91经典在线 | 亚洲高清网站 | 久草在线在线视频 | 在线观看免费 | 欧美极品少妇xxxxⅹ欧美极品少妇xxxx亚洲精品 | 国产日韩三级 | 伊人网综合在线观看 | 中文字幕超清在线免费 | 麻豆视频免费在线播放 | 亚洲欧美国产精品18p | 国产一区二区三区在线 | 激情片av | 粉嫩av一区二区三区四区在线观看 | 久久久www成人免费精品 | 麻豆影视在线免费观看 | 中文字幕中文中文字幕 | 六月色播 | 日韩成人不卡 | 婷婷在线视频 | 久久久久久国产一区二区三区 | 日韩免费电影网 | 丁香花中文在线免费观看 | 中文永久免费观看 | 欧美日韩国产综合一区二区 | 色亚洲激情 | 中文字幕在线久一本久 | 久久视频免费看 | 91在线免费播放视频 | 337p日本欧洲亚洲大胆裸体艺术 | 五月婷丁香网 | 狠狠色丁香婷婷综合久小说久 | 亚洲经典在线 | 欧美一区二区三区在线 | 奇米777777| 久久国精品 | 国产人成免费视频 | 久久精品一二三区 | 五月开心婷婷网 | 国产一区免费在线 | 五月天色中色 | 毛片基地黄久久久久久天堂 | av天天色| 国产精品美女在线观看 | 中文字幕a∨在线乱码免费看 | 色播五月激情综合网 | 一区二区三区在线视频111 | 国产日韩在线观看一区 | 在线色吧 | 最近久乱中文字幕 | 日韩av免费观看网站 | 精品国产一区二区三区久久久蜜臀 | 国产精品欧美久久久久天天影视 | 国产激情小视频在线观看 | 日韩av视屏在线观看 | 国产裸体无遮挡 | 亚洲小视频在线 | 超碰人人草人人 | 狠狠色噜噜狠狠狠合久 | 日日夜夜人人精品 | 久草在线电影网 | 91黄色成人 | 国产高清区 | 在线视频日韩欧美 | 国产一区二区在线免费 | 91正在播放 | 日韩在线资源 | 91欧美精品 | 国产中文字幕亚洲 | 久久久久久高潮国产精品视 | 欧美日韩xxxxx | 久久综合久色欧美综合狠狠 | 欧美日韩p片 | 亚洲激情在线观看 | 久久久免费视频播放 | 欧美日韩国产二区 | 一区二区三区在线免费观看视频 | 精品国产黄色片 | 中文字幕亚洲精品日韩 | 国产91精品一区二区 | 免费视频一级片 | av福利超碰网站 | 国产精品一区二区三区在线播放 | 一区三区视频在线观看 | 又污又黄网站 | 2021国产精品 | 亚洲精品videossex少妇 | av福利电影 | 特级毛片在线免费观看 | 国产视频在线观看一区 | 久久久久久久久久久久电影 | 日韩欧美专区 | 99免费看片| 日韩三级在线 | 欧美精品午夜 | 综合天堂av久久久久久久 | 99久久综合精品五月天 | 精品v亚洲v欧美v高清v | 国产精品久久久久久久久久久久午 | 在线观看黄色小视频 | 91精品国产高清自在线观看 | 亚洲成人av在线 | 久久久久久综合 | av软件在线观看 | 久久久久女教师免费一区 | 亚洲国产午夜精品 | 免费av成人在线 | 国产精品毛片久久 | 国产在线视频一区二区三区 | 日韩性片| 91免费看黄 | 久久激五月天综合精品 | 天堂久久电影网 | 亚洲精品ww| 日韩偷拍精品 | 精品视频不卡 | 亚洲精品国产自产拍在线观看 | 一二三四精品 | 午夜av免费观看 | 又黄又爽又色无遮挡免费 | 久久久久久久久久久网站 | 国产小视频国产精品 | 国产原创av片 | 91原创在线观看 | 国产精品剧情在线亚洲 | 久久久国产精品久久久 | 手机av在线网站 | 成人四虎影院 | 麻豆国产精品va在线观看不卡 | 国产亚洲一区 | 国产无吗一区二区三区在线欢 | 成人97视频 | 久久天堂亚洲 | 国产精品 视频 | 91视频在线免费下载 | 成人av资源 | 亚洲一区视频免费观看 | 久草视频一区 | 久射网| 五月天欧美精品 | 午夜精品电影一区二区在线 | 国偷自产视频一区二区久 | 亚洲成人免费在线 | 久草在线综合 | 黄网站免费看 | 99精品免费久久久久久久久 | 国产精品福利在线播放 | 中文字幕资源网在线观看 | 特级西西www44高清大胆图片 | 91在线www | 欧美伦理一区二区三区 | 国产日本亚洲 | av一本久道久久波多野结衣 | 波多野结衣一区三区 | 久草网站在线 | 国产精品专区在线 | 国产精品入口66mio女同 | 黄色一级大片在线观看 | 日韩成人中文字幕 | 色播五月激情五月 | 五月天婷婷视频 | 探花视频免费在线观看 | 在线观看精品一区 | 国产伦理久久 | 在线亚洲欧美视频 | 日本韩国精品一区二区在线观看 | 免费av网站在线看 | 97av色| 日日夜夜av | 亚洲高清在线视频 | 成年人免费在线播放 | 五月婷色 | 日女人电影 | 中文字幕高清 | 日韩一区二区在线免费观看 | 国产精品自产拍在线观看网站 | 99久久精品国产欧美主题曲 | 涩av在线| 国产午夜三级一二三区 | 奇米影视777影音先锋 | 日日夜夜爱 | 超碰在线98 | 亚洲国产日韩欧美 | 黄色网址av| 国产视频日韩视频欧美视频 | 亚洲一区二区三区四区精品 | 天天天干天天射天天天操 | 国产精品国产三级在线专区 | 国偷自产视频一区二区久 | 91视频在线免费下载 | 国产99久久久精品视频 | av电影亚洲 | 97在线免费视频 | 在线不卡中文字幕播放 | 久久久久黄色 | 亚洲干视频在线观看 | 免费看黄色91 | 国产人成在线视频 | 日本大尺码专区mv | 久久成人免费电影 | 国产在线观看 | 国产在线观看高清视频 | 日本在线免费看 | 久草在线视频免费资源观看 | 国产欧美精品一区二区三区四区 | 在线看欧美 | 蜜桃av综合网 | 久久99偷拍视频 | 91久草视频 | 激情久久综合网 | 日韩在线网址 | 国产午夜精品一区二区三区嫩草 | 国内少妇自拍视频一区 | 天天色天天射天天操 | 精品一区二区久久久久久久网站 | 欧美一级片在线观看视频 | 青青河边草免费观看完整版高清 | 午夜国产福利在线观看 | 日韩av一区二区在线影视 | 欧美亚洲国产日韩 | 国产中文字幕91 | 国产精品男女啪啪 | 正在播放国产精品 | 国产免码va在线观看免费 | 久久精品看 | 欧洲一区二区三区精品 | 欧美性色综合 | 91看片在线播放 | 久久久久国产精品www | 国产亚洲精品美女 | 一区二区三区视频在线 | 在线电影中文字幕 | 日本在线精品视频 | 日韩av片免费在线观看 | 久久久国产成人 | 免费视频在线观看网站 | 国产日韩欧美在线观看 | 国产又粗又硬又爽视频 | 欧美最猛性xxxxx亚洲精品 | 91激情视频在线播放 | 日韩大片在线看 | 久久综合九色综合97婷婷女人 | 色视频在线看 | 中中文字幕av | www.在线观看视频 | 99色在线| 在线看片日韩 | 久久精品国产免费看久久精品 | 欧美怡红院 | 日本中文字幕电影在线免费观看 | 最近中文字幕免费av | 综合久久婷婷 | 国产精品麻豆果冻传媒在线播放 | 人人插人人澡 | 五月天久久精品 | 欧美日本三级 | 国产一区免费观看 | 色99视频 | 国产精品免费久久久久久 | 欧美福利久久 | 欧美人牲 | 丝袜少妇在线 | 日韩精品视频久久 | 久色婷婷 | 黄色av网站在线观看免费 | 国产中文字幕视频在线观看 | av成人在线看 | 中文字幕精| 国产精品久久久久婷婷二区次 | 超碰在线公开免费 | 国产高清在线永久 | 国产精品久久9 | 右手影院亚洲欧美 | 国产日女人 | 成人啪啪18免费游戏链接 | 欧美日本不卡高清 | 粉嫩高清一区二区三区 | 国产精品mv在线观看 | 午夜影院先 | 久久69精品久久久久久久电影好 | 在线观看国产 | 91精品国产亚洲 | 午夜狠狠干 | 色网站中文字幕 | 国产黄色免费在线观看 | 成人手机在线视频 | 久久国产成人午夜av影院潦草 | 久久亚洲综合国产精品99麻豆的功能介绍 | 成人免费在线看片 | 国产成人一区二区三区久久精品 | 精品国模一区二区 | 免费福利在线视频 | 99精品视频一区二区 | 久久久久黄色 | 亚洲欧美国产精品va在线观看 | 国产99久久九九精品免费 | 久久精品亚洲一区二区三区观看模式 | 久久与婷婷 | 91视频88av | 成人动漫精品一区二区 | 日韩二级毛片 | 黄色三级免费网址 | 日韩免费观看高清 | 色综合天天狠狠 | 国产又粗又硬又爽视频 | 亚洲精品99 | 色中射| 最近2019年日本中文免费字幕 | 日本精品视频免费观看 | 日韩在线电影一区二区 | 91日韩在线| 在线观看国产www | 久久99国产精品久久 | 在线观看视频国产一区 | 国产综合婷婷 | 久久久久福利视频 | 波多野结衣在线播放视频 | 亚洲97在线 | 婷婷六月天丁香 | 精品字幕在线 | 国产成人久久77777精品 | av高清网站在线观看 | 久久中国精品 | 亚洲成av人片在线观看无 | 热久久视久久精品18亚洲精品 | 99国产一区二区三精品乱码 | 国产18精品乱码免费看 | 在线观看亚洲视频 | 国产中文在线播放 | 国产一级黄色片免费看 | 午夜av片| 丁香六月综合网 | 在线看黄色的网站 | 97品白浆高清久久久久久 | 九色91在线 | 97碰在线 | 久草在线看片 | 国产精品视频在线观看 | 国产在线色视频 | 四虎海外影库www4hu | 亚洲九九影院 | 国产综合在线观看视频 | 在线国产福利 | 久久久亚洲国产精品麻豆综合天堂 | 99精品久久久久 | 成人av免费在线观看 | 成人在线你懂得 | 免费在线观看av网站 | 精品视频免费看 | 4hu视频| 美女国内精品自产拍在线播放 | 少妇搡bbbb搡bbb搡69 | 精品久久一级片 | 天干啦夜天干天干在线线 | 精品色999| 高清色免费 | 免费看成人| 五月天婷婷在线观看视频 | 制服丝袜欧美 | 黄色免费视频在线观看 | 正在播放 国产精品 | 婷婷色婷婷 | 亚洲精品av在线 | av天天草 | 射久久久 | 91精品免费视频 | 免费在线黄网 | 精品日韩在线 | 九九免费观看视频 | 婷婷激情影院 | 西西www4444大胆视频 | 三级黄色a | 欧洲色吧 | 奇米网777 | 8090yy亚洲精品久久 | a视频在线观看免费 | 国产黄网在线 | 激情五月六月婷婷 | 亚洲精品国产精品国自产在线 | 探花国产在线 | 91av在线视频免费观看 | 国产精品99免费看 | 在线观看国产麻豆 | 国产精品久久久久久久久免费看 | 天天色天天操综合网 | 国产麻豆精品在线观看 | 久久综合免费 | 日韩成人在线免费观看 | 久久激情婷婷 | 中文网丁香综合网 | 久久99久国产精品黄毛片入口 | 成人h视频在线 | 国产一级性生活 | 亚洲第一区精品 | 在线视频一区二区 | 天天色天天射天天操 | 天天射天天射天天 | 伊人影院av | 国产在线看一区 | 久久精品国产美女 | 91成人看片 | 中文字幕日本电影 | 精品黄色在线观看 | 国产成人在线精品 | a亚洲视频 | 中文字幕资源站 | 精品国产一区二区三区四区在线观看 | 亚洲精品tv | 波多野结衣在线视频免费观看 | 五月天中文字幕mv在线 | 男女啪啪网站 | 国产成人av网址 | 免费av大全 | 日本丰满少妇免费一区 | 成人毛片100免费观看 | 久久视频免费在线观看 | 九九视频网站 | 久久久久国产精品视频 | 欧美极品xxxxx | 91av色| 婷婷av网站 | 四虎精品成人免费网站 | 天堂视频一区 | 亚洲视频分类 | 99中文字幕在线观看 | 日日干夜夜爱 | 日韩av成人在线观看 | 麻豆91精品视频 | 日韩高清免费观看 | 高清不卡免费视频 | 中文字幕在线看视频 | 中文字幕一区二区在线播放 | 丁香 婷婷 激情 | 日日夜夜免费精品 | 91亚洲国产 | 国产精品自产拍在线观看 | 中文字幕一区二区三区在线播放 | 一区二区三区免费在线观看视频 | 日产av在线播放 | 久日精品 | 成人va在线观看 | 岛国av在线免费 | 在线观看aa | 999久久久久 | 精品国产精品久久 | av在线播放网址 | 婷香五月 | 狠狠色丁香久久婷婷综合丁香 | 国产美女在线精品免费观看 | 日韩电影在线观看一区二区三区 | 免费91麻豆精品国产自产在线观看 | 99视频国产精品免费观看 | 99久久精品国 | 中文字幕永久在线 | 国产高清不卡av | 久久久久免费网站 | 九九综合九九综合 | 天天操比| 欧美另类激情 | 精品久久91| 最新日韩视频 | 国产一级性生活视频 | 免费色网 | 久久久久久国产精品免费 | av大片免费 | 久久久久久蜜桃一区二区 | 久久国产精彩视频 | 欧美a视频| 亚洲国产精品推荐 | 麻豆视频网址 | 88av色| 欧美一级特黄高清视频 | 99av在线视频| 亚洲精品国偷自产在线99热 | www在线观看国产 | 中文字幕在线观看第一页 | 99精品久久久久久久 | 新版资源中文在线观看 | 美州a亚洲一视本频v色道 | 欧美性极品xxxx做受 | 欧美黑人性猛交 | 亚洲3级 | 黄色一级大片在线免费看国产一 | 在线黄频 | 久久婷婷丁香 | 国产91精品一区二区麻豆亚洲 | 国产区网址 | 亚洲狠狠操 | 手机在线观看国产精品 | 久久国产精品网站 | av观看免费在线 | 午夜精品福利一区二区三区蜜桃 | 999电影免费在线观看 | 久久久www成人免费毛片 | 91cn国产在线 | 日韩久久一区 | 婷婷在线免费观看 | 婷色| 91精品国产91久久久久福利 | 亚洲精品国产综合久久 | 婷婷丁香色综合狠狠色 | 亚洲成人国产精品 | 国产成人一区二区三区 | 欧美成人精品在线 | 亚洲综合成人在线 | 国产麻豆视频网站 | 国内免费久久久久久久久久久 | 日韩av图片 | 欧美精彩视频在线观看 | 在线视频精品 | 国产一二三四在线视频 | 天天天天天天天操 | 日韩精品欧美一区 | 日韩中文字幕在线不卡 | 日日摸日日添夜夜爽97 | 免费看一级片 | 午夜久久电影网 | 中文视频在线看 | 中文字幕av网站 | 成人黄色大片在线观看 | 99视频在线观看一区三区 | 欧美日韩精品二区第二页 | 丁香婷婷激情五月 | 欧美一级在线观看视频 | 久久免费激情视频 | av色图天堂网 | 国产精品精品国产婷婷这里av | 国产成人福利片 | 久久久穴| 在线精品一区二区 | 欧美精品成人在线 | 国产美女视频免费观看的网站 | 综合婷婷 | 中文字幕欲求不满 | 色吧久久 | 香蕉视频在线看 | 久久免费精彩视频 | 最近中文字幕国语免费av | 日韩高清在线一区 | 中文字幕一区二区三区四区在线视频 | 激情欧美一区二区三区 | 亚洲精品五月天 | 国产黄色一级大片 | 91视频免费看网站 | 日韩天堂在线观看 | 日韩在线精品一区 | 国产小视频在线观看免费 | 2021久久 | 久久久久久久久久久久久影院 | 久草在线综合网 | 欧美精品一区二区蜜臀亚洲 | 国产999精品久久久 免费a网站 | 国产免费专区 | 瑞典xxxx性hd极品 | 欧美一区二区三区四区夜夜大片 | 国产精品久久久久久久久久 | 一区二区三区在线观看免费 | 日本中文字幕系列 | 日本公妇色中文字幕 | 久久视频网 | 国产精品免费一区二区 | 日韩精品在线播放 | 亚洲小视频在线观看 | 日韩午夜剧场 | 国产高清视频 | 日本不卡一区二区 | 亚洲国产精品一区二区久久,亚洲午夜 | 一级片视频在线 | 欧美少妇xx| 亚洲国产日韩一区 | 少妇视频一区 | 国产精品免费不 | 国产成人精品久久久久 | 久久全国免费视频 | 日韩字幕| 91综合色 | 成人毛片一区二区三区 | 国产一区免费视频 | 在线中文字幕一区二区 | 97天天综合网 | 九九热在线视频免费观看 | 色网站在线免费 | 欧美午夜性生活 | 久久久免费毛片 | 欧美精品免费在线观看 | 人人躁| 欧美成人性战久久 | 毛片美女网站 | 黄www在线观看 | 色综合久久久网 | 国产一区二区在线视频观看 | 波多野结衣综合网 | 六月丁香六月婷婷 | 国产高清中文字幕 | 成 人 黄 色 视频播放1 | 蜜臀av性久久久久蜜臀aⅴ涩爱 | 天天干,狠狠干 | 日本久久久久久科技有限公司 | 日韩欧美一区二区在线观看 | 激情大尺度视频 | 成人av免费在线 | 久久香蕉一区 | 色狠狠综合| 免费在线黄 | 另类老妇性bbwbbw高清 | 91久久奴性调教 | 天天操狠狠操网站 | 成人综合日日夜夜 | 日本最新高清不卡中文字幕 | 久草国产在线 | 麻豆视频免费版 | 国产精品麻豆三级一区视频 | av电影在线观看完整版一区二区 | 亚洲精品视频免费在线观看 | 久久在线免费观看视频 | 久久婷婷精品 | 久久97精品 | 欧美成人精品欧美一级乱黄 | 视频在线国产 | 黄色av网站在线免费观看 | 亚洲伦理一区 | 日韩欧美69 | 久久伊人爱 | 国产成人久久av977小说 | 二区三区中文字幕 | 婷婷爱五月天 | 六月天色婷婷 | 在线看av网址 | 国产无套一区二区三区久久 | 天天插日日插 | 国产精品成人一区二区三区吃奶 | 国产高清视频色在线www | 97国产情侣爱久久免费观看 | 激情欧美丁香 | 国产精品亚洲片夜色在线 | 精品国产一二区 | 99国产在线| 五月婷婷丁香在线观看 | 国产999精品久久久久久麻豆 | 中文字幕人成一区 | 天天射天天搞 | 狠狠操狠狠干天天操 | 中文字幕亚洲在线观看 | 国产精品在线看 | 综合网色 | 国产+日韩欧美 | 婷婷久久亚洲 | 黄色电影网站在线观看 | 久久久久国产一区二区三区四区 | 久久久久久久av麻豆果冻 | 国产精品一区二 | 国产麻豆精品久久一二三 | 视频直播国产精品 |