{-Test program to measure AES encr/decr speed for 128 bit keys, we 07.2006} { displays alignment info for compressed encryption table (if available)} program t_gsp128; {$i STD.INC} {$ifdef APPCONS} {$apptype console} {$endif} {$ifndef FPC} {$N+} {$endif} {$ifdef X_Opt} {$x+} {$endif} uses {$ifdef WINCRT} wincrt, {$endif} AES_Type, AES_Encr, AES_Decr, hrtimer; {$i aes_conf.inc} const LOOPS = 100; var ctx: TAESContext; key: array[0..31] of byte; ct : TAESBlock; pt : TAESBlock; {---------------------------------------------------------------------------} procedure RandFill(var block; size: word); var ba: array[1..$F000] of byte absolute block; i: word; begin for i:=1 to size do ba[i] := random(256); end; {---------------------------------------------------------------------------} function EncrCycles(keybits: word): longint; var i: integer; cyc0, cyc1, cyc2: comp; t1,t2,c1,c2: longint; begin RandFill(key, sizeof(key)); RandFill(pt, sizeof(pt)); i := AES_Init_Encr(Key, KeyBits, ctx); if i<>0 then begin writeln('Error AES_Init_Encr'); halt; end; AES_Encrypt(ctx, pt, ct); c1 := MaxLongint; c2 := MaxLongint; for i:=1 to LOOPS do begin RandFill(pt, sizeof(pt)); ReadTSC(cyc0); AES_Encrypt(ctx, pt, ct); ReadTSC(cyc1); AES_Encrypt(ctx, ct, ct); AES_Encrypt(ctx, ct, ct); AES_Encrypt(ctx, ct, ct); AES_Encrypt(ctx, ct, ct); AES_Encrypt(ctx, ct, ct); ReadTSC(cyc2); t2 := round(cyc2-cyc1); t1 := round(cyc1-cyc0); if t10 then begin writeln('Error AES_Init_Decr'); halt; end; AES_Decrypt(ctx, pt, ct); AES_Decrypt(ctx, pt, ct); c1 := MaxLongint; c2 := MaxLongint; for i:=1 to LOOPS do begin RandFill(pt, sizeof(pt)); ReadTSC(cyc0); AES_Decrypt(ctx, pt, ct); ReadTSC(cyc1); AES_Decrypt(ctx, ct, ct); AES_Decrypt(ctx, ct, ct); AES_Decrypt(ctx, ct, ct); AES_Decrypt(ctx, ct, ct); AES_Decrypt(ctx, ct, ct); ReadTSC(cyc2); t2 := round(cyc2-cyc1); t1 := round(cyc1-cyc0); if t10 then begin writeln('Error AES_Init_Encr'); halt; end; for i:=1 to LOOPS do begin RandFill(key, sizeof(key)); ReadTSC(cyc0); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); ReadTSC(cyc1); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Encr(Key, KeyBits, ctx); ReadTSC(cyc2); t2 := round(cyc2-cyc1); t1 := round(cyc1-cyc0); if t10 then begin writeln('Error AES_Init_Encr'); halt; end; for i:=1 to LOOPS do begin RandFill(key, sizeof(key)); ReadTSC(cyc0); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); ReadTSC(cyc1); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); {$ifndef X_Opt} j := {$endif} AES_Init_Decr(Key, KeyBits, ctx); ReadTSC(cyc2); t2 := round(cyc2-cyc1); t1 := round(cyc1-cyc0); if t1