program t_AES_CBC;
{$apptype console}
uses
SysUtils, Classes, DECCipher;
var
AES: TCipher_Rijndael;
var
key128 :
array[0..15]
of byte = ($2b,$7e,$15,$16,$28,$ae,$d2,$a6,
$ab,$f7,$15,$88,$09,$cf,$4f,$3c);
IV :
array[0..15]
of byte = ($00,$01,$02,$03,$04,$05,$06,$07,
$08,$09,$0a,$0b,$0c,$0d,$0e,$0f);
plain :
array[0..63]
of byte = ($6b,$c1,$be,$e2,$2e,$40,$9f,$96,
$e9,$3d,$7e,$11,$73,$93,$17,$2a,
$ae,$2d,$8a,$57,$1e,$03,$ac,$9c,
$9e,$b7,$6f,$ac,$45,$af,$8e,$51,
$30,$c8,$1c,$46,$a3,$5c,$e4,$11,
$e5,$
fb,$c1,$19,$1a,$0a,$52,$ef,
$f6,$9f,$24,$45,$
df,$4f,$9b,$17,
$ad,$2b,$41,$7b,$e6,$6c,$37,$10);
ct_cbc :
array[0..63]
of byte = ($76,$49,$ab,$ac,$81,$19,$b2,$46,
$ce,$e9,$8e,$9b,$12,$e9,$19,$7d,
$50,$86,$cb,$9b,$50,$72,$19,$ee,
$95,$
db,$11,$3a,$91,$76,$78,$b2,
$73,$be,$d6,$b8,$e3,$c1,$74,$3b,
$71,$16,$e6,$9e,$22,$22,$95,$16,
$3f,$f1,$ca,$a1,$68,$1f,$ac,$09,
$12,$0e,$ca,$30,$75,$86,$e1,$a7);
function test(px,py: pointer):
string;
begin
if CompareMem(px,py,64)
then test := '
OK'
else test := '
Error';
end;
var
pt,ct:
array[0..63]
of byte;
begin
AES := TCipher_Rijndael.Create;
//Verschl³sseln
AES.Mode := cmCBCx;
AES.Init(key128,16,IV,16);
AES.Encode(plain,ct,sizeof(plain));
writeln('
CBC test: ', test(@ct,@ct_cbc));
//Entschl³sseln
AES.Mode := cmCBCx;
AES.Init(key128,16,IV,16);
AES.Decode(ct,pt,sizeof(plain));
writeln('
CBC test: ', test(@pt,@plain));
end.