{AES Speed Test Hagen Reddmann's DEC, W.Ehrhardt Dec 2005}
{New edition for DEC Vers.5.1+, NOT DELPHI 3 COMPATIBLE}
{Now including OFB, CFB modes, still missing: CTR mode}
program t_AES_CBC;
{$apptype console}
{$J+}
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);
var
ct:
array[0..63]
of byte;
function CompMem(psrc, pdest: pointer; size: word): boolean;
{-compare memory block}
var
i: word;
type
pByte = ^byte;
begin
CompMem := false;
for i:=1
to size
do begin
if pByte(psrc)^<>pByte(pdest)^
then exit;
inc(longint(psrc));
inc(longint(pdest));
end;
CompMem := true;
end;
function test(px,py: pointer):
string;
begin
if compmem(px,py,64)
then test := '
OK'
else test := '
Error';
end;
procedure TestCBC;
begin
AES.Mode := cmCBCx;
AES.Init(key128,16,IV,16);
AES.Encode(plain,ct,sizeof(plain));
writeln('
CBC test: ', test(@ct,@ct_cbc));
end;
begin
AES := TCipher_Rijndael.Create;
TestCBC;
end.