Andreas Software - Source Code - LEA256CTRSpeedTest.DPR

A speed test for my implementation of the block cipher LEA-256 in CTR mode for Embarcadero Delphi

program LEA256CTRSpeedTest;

{
  A speed test for my implementation of the block cipher LEA-256 in CTR mode for Embarcadero Delphi.

  Speed Reference: Approximately 120 MB/sec. (Intel Core i3-9100)

  Original Author: Andreas Jonsson. (www.andreas-software.com)

  NOTICE: YOU MAY USE AND MODIFY THIS SOURCE CODE FREELY, THE ONLY REQUIREMENT IS THAT THE COMMENT ABOUT THE ORIGINAL AUTHOR AND THIS NOTICE REMAINS IN THE SOURCE CODE.
}

{$APPTYPE CONSOLE}

uses
  Winapi.Windows, Winapi.Messages,
  System.SysUtils, System.Variants, System.Classes,
  LEA256CTR;

const FACTOR = 1024;

const BUFFER_SIZE = FACTOR * FACTOR;

procedure Main();
var Bytes: TBytes;
var Keys: TLEA256CTRKeys;
var NumbersOnce: TLEA256CTRNumbersOnce;
var Context: TLEA256CTRContext;
var MinI: Integer;
var MaxI: Integer;
var MinJ: Integer;
var MaxJ: Integer;
var I: Integer;
var J: Integer;
var QPC_TF: TLargeInteger; // Query Performance Counter - Tick Frequency
var QPC_CS: TLargeInteger; // Query Performance Counter - Counter Start
var QPC_CE: TLargeInteger; // Query Performance Counter - Counter End
var QPC_EM: TLargeInteger; // Query Performance Counter - Elapsed Microseconds
var MBPS: string;
begin
  try
    SetLength(Bytes, BUFFER_SIZE);
  except
    WriteLn('Error: Out of memory.');
    Exit;
  end;
  Keys[0] := $10101010;
  Keys[1] := $20202020;
  Keys[2] := $30303030;
  Keys[3] := $40404040;
  Keys[4] := $50505050;
  Keys[5] := $60606060;
  Keys[6] := $70707070;
  Keys[7] := $80808080;
  NumbersOnce[0] := $10101010;
  NumbersOnce[1] := $20202020;
  NumbersOnce[2] := $30303030;
  NumbersOnce[3] := $40404040;
  LEA256CTR_Initialize(Context, Keys, NumbersOnce);
  WriteLn('Generating 1 GB of keystream. Please wait...');
  MinI := 0;
  MaxI := FACTOR - 1;
  MinJ := 0;
  MaxJ := BUFFER_SIZE - 1;
  QueryPerformanceFrequency(QPC_TF);
  QueryPerformanceCounter(QPC_CS);
  for I := MinI to MaxI do begin
    for J := MinJ to MaxJ do begin
      Bytes[J] := LEA256CTR_GenerateByte(Context);
    end;
  end;
  QueryPerformanceCounter(QPC_CE);
  QPC_EM := QPC_CE - QPC_CS;
  QPC_EM := QPC_EM * 1000000;
  QPC_EM := QPC_EM div QPC_TF;
  try
    MBPS := FormatFloat('#,##0.00;-#,##0.00;0.00', FACTOR / (QPC_EM / 1000000));
  except
    MBPS := '?';
  end;
  WriteLn('Speed: ' + MBPS + ' MB/sec.');
  LEA256CTR_Burn(Context);
end;

begin
  Main;
end.

⎙ Print LEA256CTRSpeedTest.DPR

You can also view the source code as plain text, LEA256CTRSpeedTest.DPR.TXT.

The source code is related to LEA256.PAS, LEA256CTR.PAS and LEA256Test.DPR.

www.andreas-software.com

Copyright © 1998-2021, Andreas Jönsson. All rights reserved.

In Swedish?
View this page in Swedish