mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 16:19:21 +02:00
* Remove circular use, add lazarus test project file
This commit is contained in:
parent
f1cb5e678c
commit
ff7febc06c
@ -1135,13 +1135,16 @@ Var
|
|||||||
i : Integer;
|
i : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
P:=@VLI;
|
if (Pointer(@GetRandomBytes)=Nil) or not GetRandomBytes(@VLI,Sizeof(VLI)) then
|
||||||
For I:=0 to SizeOf(TVLI)-1 do
|
|
||||||
begin
|
begin
|
||||||
P^:=Random(256);
|
P:=@VLI;
|
||||||
Inc(P);
|
For I:=0 to SizeOf(TVLI)-1 do
|
||||||
|
begin
|
||||||
|
P^:=Random(256);
|
||||||
|
Inc(P);
|
||||||
|
end;
|
||||||
|
Result:=True;
|
||||||
end;
|
end;
|
||||||
Result:=True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function EccPublicKeyFromHexa(const Hexa: String) : TEccPublicKey;
|
Function EccPublicKeyFromHexa(const Hexa: String) : TEccPublicKey;
|
||||||
|
@ -16,7 +16,10 @@ unit fphashutils;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, fpECC;
|
SysUtils;
|
||||||
|
|
||||||
|
Type
|
||||||
|
EHashUtil = Class(Exception);
|
||||||
|
|
||||||
Procedure BytesFromVar(out aBytes : TBytes; aLocation : Pointer; aSize : Integer);
|
Procedure BytesFromVar(out aBytes : TBytes; aLocation : Pointer; aSize : Integer);
|
||||||
Function BytesFromVar(aLocation : Pointer; aSize : Integer) : TBytes;
|
Function BytesFromVar(aLocation : Pointer; aSize : Integer) : TBytes;
|
||||||
@ -39,6 +42,13 @@ Function BytesEncodeBase64(Source: Tbytes; const IsURL, MultiLines, Padding: Boo
|
|||||||
function CryptoGetRandomBytes(Buffer: PByte; const Count: Integer): Boolean;
|
function CryptoGetRandomBytes(Buffer: PByte; const Count: Integer): Boolean;
|
||||||
Function ExtractBetween(const ASource,aStart,aEnd : String) : String;
|
Function ExtractBetween(const ASource,aStart,aEnd : String) : String;
|
||||||
|
|
||||||
|
Type
|
||||||
|
TGetRandomBytes = function(aBytes : PByte; aCount: Integer): Boolean;
|
||||||
|
|
||||||
|
var
|
||||||
|
GetRandomBytes : TGetRandomBytes;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
Procedure BytesFromVar(out aBytes : TBytes; aLocation : Pointer; aSize : Integer);
|
Procedure BytesFromVar(out aBytes : TBytes; aLocation : Pointer; aSize : Integer);
|
||||||
@ -319,15 +329,24 @@ type
|
|||||||
function Next: UInt32;
|
function Next: UInt32;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// TODO: explore Xorshift* instead of CryptoGetRandomNumber
|
|
||||||
procedure TLecuyer.Seed;
|
procedure TLecuyer.Seed;
|
||||||
var
|
var
|
||||||
VLI: TVLI;
|
VLI: Array[0..2] of byte;
|
||||||
|
I : Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
EccGetRandomNumber(VLI);
|
I:=0;
|
||||||
rs1 := VLI[0];
|
Repeat
|
||||||
rs2 := VLI[1];
|
Inc(I);
|
||||||
rs3 := VLI[2];
|
if (Pointer(GetRandomBytes)=Nil) or not GetRandomBytes(@VLI,Sizeof(VLI)) then
|
||||||
|
Raise EHashUtil.Create('Cannot seed Lecuyer: no random bytes');
|
||||||
|
rs1 := VLI[0];
|
||||||
|
rs2 := VLI[1];
|
||||||
|
rs3 := VLI[2];
|
||||||
|
Until ((RS1>1) and (rs2>7) and (RS3>15)) or (I>100);
|
||||||
|
if I>100 then
|
||||||
|
Raise EHashUtil.Create('Cannot seed Lecuyer: no suitable random bytes');
|
||||||
SeedCount := 1;
|
SeedCount := 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -384,6 +403,23 @@ begin
|
|||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function IntGetRandomNumber(aBytes : PByte; aCount: Integer): Boolean;
|
||||||
|
|
||||||
|
Var
|
||||||
|
i : Integer;
|
||||||
|
P : PByte;
|
||||||
|
|
||||||
|
begin
|
||||||
|
P:=aBytes;
|
||||||
|
For I:=0 to aCount-1 do
|
||||||
|
begin
|
||||||
|
P^:=Random(256);
|
||||||
|
Inc(P);
|
||||||
|
end;
|
||||||
|
Result:=True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
GetRandomBytes:=@IntGetRandomNumber;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
102
packages/fcl-hash/tests/testhash.lpi
Normal file
102
packages/fcl-hash/tests/testhash.lpi
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
<UseDefaultCompilerOptions Value="True"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<Title Value="testhash"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<BuildModes>
|
||||||
|
<Item Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<UseFileFilters Value="True"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
</RunParams>
|
||||||
|
<Units>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="testhash.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="utestsha256.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fpsha256.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fphashutils.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fpecc.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="fpECC"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="utestonetimepass.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="utestpem.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fpasn.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fpecdsa.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fppem.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/fpsha512.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="../src/onetimepass.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="testhash"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<OtherUnitFiles Value="../src"/>
|
||||||
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -5,7 +5,7 @@ program testhash;
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
consoletestrunner, utestsha256, utestonetimepass, utestsha512, utestpem;
|
consoletestrunner, utestsha256, utestonetimepass, utestsha512, utestpem, fpECC, fphashutils, fpsha256;
|
||||||
|
|
||||||
var
|
var
|
||||||
Application: TTestRunner;
|
Application: TTestRunner;
|
||||||
|
Loading…
Reference in New Issue
Block a user