The following demonstrates how to use Delphi language using the new SwiftRNG-32.dll to download data from a SwiftRNG device when used with the SwiftRNG Entropy Server for Windows. We recommend using the new SwiftRNG-32.dll which provides a simplified and flexible API for interracting with SwiftRNG Entropy Server. Before using the following examples, make sure your Delphi project is targeted for Windows 32 bit platform and the SwiftRNG device is plugged into one of USB ports available. Both SwiftRNG-32.dll and SwiftRNG-64.dll are included in the SwiftRNG software kit and can be downloaded from this location.

A sample source code for retrieving data from SwiftRNG device when using SwiftRNG Entropy Server for Windows and SwiftRNG-32.dll


//
//
// A sample Delphi program that demonstrates how to retrieve data from
// SwiftRNG device using SwiftRNG Entropy Server for Windows and SwiftRNG-32.dll
// when using 32-bit Windows as a target platform.
//
// For 64-bit applications use SwiftRNG-64.dll
//
//

program Project1;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils;

const
  randomNumberCount = 10; // How many random bytes to retrieve

type
  RandomBuffer = array [0 .. (randomNumberCount - 1)] of byte;
  xbuffer = ^RandomBuffer;
  IdentifierBuffer = array [0 .. 14] of byte;
  ibuffer = ^IdentifierBuffer;
  ModelBuffer = array [0 .. 14] of byte;
  mbuffer = ^ModelBuffer;

var
  i, status: integer;
  zbuffer: randombuffer;
  serialnumber: identifierbuffer;
  model: modelbuffer;

Function getEntropy(x: xbuffer; y: longword): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getEntropyAsByte(): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getDeviceIdentifier(p: ibuffer): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getDeviceModel(p: mbuffer): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getDeviceMajorVersion(): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getDeviceMinorVersion(): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getServerMajorVersion(): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getServerMinorVersion(): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';
Function getNoise(x: xbuffer; y: longword; z: integer): integer; stdcall; external 'C:\tools\windows-binaries\windows-x86\SwiftRNG-32.dll';

begin
  try

    status := getDeviceModel(@model);
    if status = 0 then
      begin
        writeln('Device model: ', TEncoding.ANSI.GetString(model));
        status := getDeviceIdentifier(@serialnumber);
        if status = 0 then
          begin
            writeln('Device identifier: ', TEncoding.ANSI.GetString(serialnumber));
          end
          else
            writeln('Could not retrieve device identifier');

        writeln('Device version: ', getDeviceMajorVersion(), '.', getDeviceMinorVersion());
        writeln('Entropy server version: ', getServerMajorVersion(), '.', getServerMinorVersion());
        writeln('Entropy sample byte: ', getEntropyAsByte);

        status := getEntropy(@zbuffer, randomNumberCount);
        if status = 0 then
          begin
            for i:=0 to randomNumberCount-1 do
              writeln('entropy byte[',i,'] = ', zbuffer[i]);
          end
          else
            writeln('Could not retrieve entropy');


        status := getNoise(@zbuffer, randomNumberCount, 1);
        if status = 0 then
          begin
            for i:=0 to randomNumberCount-1 do
              writeln('source noise 1 byte[',i,'] = ', zbuffer[i]);
          end
          else
            writeln('Could not retrieve bytes from noise source 1');


        status := getNoise(@zbuffer, randomNumberCount, 2);
        if status = 0 then
          begin
            for i:=0 to randomNumberCount-1 do
              writeln('source noise 2 byte[',i,'] = ', zbuffer[i]);
          end
          else
            writeln('Could not retrieve bytes from noise source 2');


      end
      else
        writeln('Could not retrieve device model, is entropy server running?');


  except
    on E: Exception do
      writeln(E.ClassName, ': ', E.Message);
  end;

end.