Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
name: Make

on:
schedule:
- cron: '0 0 1 * *'
- cron: '0 0 1 * *'
push:
branches:
- "**"
Expand All @@ -27,37 +26,43 @@ jobs:
- windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Build on Linux
if: runner.os == 'Linux'
shell: bash
run: |
set -xeuo pipefail
sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null
instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \
-B '.github/workflows/make.pas'

- name: Build on Windows
if: runner.os == 'Windows'
shell: powershell
run: |
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict
New-Variable -Option Constant -Name VAR -Value @{
Uri =
'https://icolo.dl.sourceforge.net/project/lazarus/Lazarus%20Windows%2064%20bits/Lazarus%204.0/lazarus-4.0-fpc-3.2.2-win64.exe?viasf=1'
OutFile = (New-TemporaryFile).FullName + '.exe'
}
Invoke-WebRequest @VAR
& $VAR.OutFile.Replace('Temp', 'Temp\.') /SP- /VERYSILENT /NORESTART `
/SUPPRESSMSGBOXES | Out-Null
$Env:PATH+=';C:\Lazarus'
(Get-Command 'lazbuild').Source | Out-Host
$Env:PATH+=';C:\Lazarus\fpc\3.2.2\bin\x86_64-win64'
(Get-Command 'instantfpc').Source | Out-Host
instantfpc -FuC:\Lazarus\components\lazutils `
-B '.github/workflows/make.pas'
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Build on Linux
if: runner.os == 'Linux'
shell: bash
run: |
set -xeuo pipefail
sudo bash -c 'apt-get update; apt-get install -y lazarus' >/dev/null
instantfpc -Fu/usr/lib/lazarus/*/components/lazutils \
-B '.github/workflows/make.pas'

- name: Build on Windows
if: runner.os == 'Windows'
shell: powershell
run: |
$ErrorActionPreference = 'stop'
Set-PSDebug -Strict

Write-Host "Installing Lazarus and OpenSSL 1.1 via Chocolatey..."
choco upgrade chocolatey -y
choco install lazarus -y
choco install openssl.light --version=1.1.1.20181020 -y

Write-Host "Verifying installed packages..."
choco list

# Lazarus installs to C:\Lazarus by default
# Add Lazarus and OpenSSL paths for instantfpc
$env:Path += ';C:\Lazarus;C:\Lazarus\fpc\3.2.2\bin\x86_64-win64;C:\ProgramData\chocolatey\lib\openssl.light\tools'

Write-Host "Checking lazbuild and instantfpc availability..."
Get-Command lazbuild
Get-Command instantfpc

Write-Host "Building make.pas..."
instantfpc -FuC:\Lazarus\components\lazutils `
-B '.github/workflows/make.pas'
2 changes: 2 additions & 0 deletions CryptoLib/src/Interfaces/ClpIECC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ interface

function ThreeTimes(): IECPoint;

function Clone: IECPoint;

function Equals(const other: IECPoint): Boolean;
function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI}
function ToString(): String;
Expand Down
2 changes: 1 addition & 1 deletion CryptoLib/src/Math/EC/Abc/ClpTnaf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class function TTnaf.GetPreComp(const p: IAbstractF2mPoint; a: ShortInt)

System.SetLength(pu, UInt32(System.Length(alphaTnaf) + 1) shr 1);

pu[0] := p;
pu[0] := p.Clone() as IAbstractF2mPoint;

precompLen := UInt32(System.Length(alphaTnaf));

Expand Down
27 changes: 0 additions & 27 deletions CryptoLib/src/Math/EC/ClpECAlgorithms.pas
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,6 @@ class function TECAlgorithms.ImplShamirsTrickWNaf(const endomorphism
result := ImplShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ,
preCompNegQ, wnafQ);

infoP.PreComp := Nil; // Review
infoP.PreCompNeg := Nil; // Review
infoQ.PreComp := Nil; // Review
infoQ.PreCompNeg := Nil; // Review

end;

class function TECAlgorithms.ImplShamirsTrickWNaf(const p: IECPoint;
Expand Down Expand Up @@ -435,10 +430,6 @@ class function TECAlgorithms.ImplShamirsTrickWNaf(const p: IECPoint;
then
begin
result := ImplShamirsTrickFixedPoint(p, k, q, l);
infoP.PreComp := Nil; // Review
infoP.PreCompNeg := Nil; // Review
infoQ.PreComp := Nil; // Review
infoQ.PreCompNeg := Nil; // Review
Exit;
end;

Expand Down Expand Up @@ -486,10 +477,6 @@ class function TECAlgorithms.ImplShamirsTrickWNaf(const p: IECPoint;

result := ImplShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ,
preCompNegQ, wnafQ);
infoP.PreComp := Nil; // Review
infoP.PreCompNeg := Nil; // Review
infoQ.PreComp := Nil; // Review
infoQ.PreCompNeg := Nil; // Review
end;

class function TECAlgorithms.ImplShamirsTrickWNaf(const preCompP,
Expand Down Expand Up @@ -642,13 +629,6 @@ class function TECAlgorithms.ImplSumOfMultiplies(const endomorphism
end;

result := ImplSumOfMultiplies(negs, infos, wnafs);

for i := System.Low(infos) to System.High(infos) do
begin
infos[i].PreComp := Nil; // Review
infos[i].PreCompNeg := Nil; // Review
end;

end;

class function TECAlgorithms.ImplSumOfMultiplies
Expand Down Expand Up @@ -684,13 +664,6 @@ class function TECAlgorithms.ImplSumOfMultiplies
end;

result := ImplSumOfMultiplies(negs, infos, wnafs);

for i := System.Low(infos) to System.High(infos) do
begin
infos[i].PreComp := Nil; // Review
infos[i].PreCompNeg := Nil; // Review
end;

end;

class function TECAlgorithms.ImplSumOfMultiplies
Expand Down
90 changes: 84 additions & 6 deletions CryptoLib/src/Math/EC/ClpECC.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ interface
ClpTnaf,
ClpValidityPreCompInfo,
ClpIValidityPreCompInfo,
ClpIWNafPreCompInfo,
ClpIEndoPreCompInfo,
ClpIWTauNafPreCompInfo,
ClpIFixedPointPreCompInfo,
ClpIECC,
ClpIFiniteField,
ClpIPreCompInfo;
Expand Down Expand Up @@ -722,6 +726,8 @@ TSimpleLookupTable = class abstract(TAbstractECLookupTable,
constructor Create(const points: TCryptoLibGenericArray<IECPoint>;
off, len: Int32);

destructor Destroy; override;

function Lookup(index: Int32): IECPoint; override;
function LookupVar(index: Int32): IECPoint; override;

Expand All @@ -744,6 +750,8 @@ TDefaultLookupTable = class(TAbstractECLookupTable, IDefaultLookupTable)
constructor Create(const outer: IECCurve; const table: TCryptoLibByteArray;
Size: Int32);

destructor Destroy; override;

function Lookup(index: Int32): IECPoint; override;
function LookupVar(index: Int32): IECPoint; override;

Expand Down Expand Up @@ -781,6 +789,8 @@ TDefaultF2mLookupTable = class(TAbstractECLookupTable, IDefaultF2mLookupTable)
constructor Create(const outer: IF2mCurve;
const table: TCryptoLibInt64Array; Size: Int32);

destructor Destroy; override;

function Lookup(index: Int32): IECPoint; override;
function LookupVar(index: Int32): IECPoint; override;

Expand Down Expand Up @@ -1222,6 +1232,8 @@ TValidityCallback = class(TInterfacedObject, IPreCompCallback,

function ThreeTimes(): IECPoint; virtual;

function Clone(): IECPoint; virtual;

function Equals(const other: IECPoint): Boolean; reintroduce;
function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
{$ENDIF DELPHI}override;
Expand Down Expand Up @@ -2993,6 +3005,21 @@ procedure TECCurve.SetMultiplier(const Value: IECMultiplier);

function TECCurve.Precompute(const point: IECPoint; const name: String;
const callback: IPreCompCallback): IPreCompInfo;

function IsHeavy(const info: IPreCompInfo): Boolean;
var
wnaf: IWNafPreCompInfo;
wtnaf: IWTauNafPreCompInfo;
endo: IEndoPreCompInfo;
fixed: IFixedPointPreCompInfo;
begin
Result :=
Supports(info, IWNafPreCompInfo, wnaf) or
Supports(info, IWTauNafPreCompInfo, wtnaf) or
Supports(info, IEndoPreCompInfo, endo) or
Supports(info, IFixedPointPreCompInfo, fixed);
end;

var
table: TDictionary<String, IPreCompInfo>;
existing: IPreCompInfo;
Expand All @@ -3012,10 +3039,10 @@ function TECCurve.Precompute(const point: IECPoint; const name: String;

result := callback.Precompute(existing);

if (result <> existing) then
begin
table.AddOrSetValue(name, result);
end;
if (result <> existing) and ((existing <> Nil) or (not IsHeavy(result))) then
begin
table.AddOrSetValue(name, result);
end;

finally
FLock.Release;
Expand Down Expand Up @@ -3718,6 +3745,13 @@ function TDefaultLookupTable.CreatePoint(const x, y: TCryptoLibByteArray)
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
end;

destructor TDefaultLookupTable.Destroy;
begin
Fm_outer := nil;
Fm_table := nil;
inherited;
end;

function TDefaultLookupTable.GetSize: Int32;
begin
result := Fm_size;
Expand Down Expand Up @@ -3804,6 +3838,14 @@ function TDefaultF2mLookupTable.CreatePoint(const x, y: TCryptoLibInt64Array)
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
end;


destructor TDefaultF2mLookupTable.Destroy;
begin
Fm_outer := nil;
Fm_table := nil;
inherited;
end;

function TDefaultF2mLookupTable.GetSize: Int32;
begin
result := Fm_size;
Expand Down Expand Up @@ -4084,12 +4126,23 @@ function TECPoint.CreateScaledPoint(const sx, sy: IECFieldElement): IECPoint;
end;

destructor TECPoint.Destroy;
var
Key: string;
begin
TSetWeakRef.SetWeakReference(@Fm_curve, Nil);
Fm_preCompTable.Free;
TSetWeakRef.SetWeakReference(@Fm_curve, nil);

if Assigned(Fm_preCompTable) then
begin
for Key in Fm_preCompTable.Keys do
Fm_preCompTable[Key] := nil;

Fm_preCompTable.Free;
end;

inherited Destroy;
end;


class constructor TECPoint.ECPoint;
begin
System.SetLength(FEMPTY_ZS, 0);
Expand Down Expand Up @@ -4400,6 +4453,18 @@ function TECPoint.GetDetachedPoint: IECPoint;
result := Normalize().Detach();
end;

function TECPoint.Clone: IECPoint;
var
baseNorm: IECPoint;
begin
baseNorm := Self.Normalize();
Result := Fm_curve.CreatePoint(
baseNorm.XCoord.ToBigInteger,
baseNorm.YCoord.ToBigInteger,
baseNorm.IsCompressed
);
end;

{ TF2mPoint }

constructor TF2mPoint.Create(const curve: IECCurve;
Expand Down Expand Up @@ -6703,6 +6768,19 @@ constructor TSimpleLookupTable.Create(const points
FPoints := Copy(points, off, len);
end;

destructor TSimpleLookupTable.Destroy;
var
i: Integer;
begin
if Assigned(FPoints) then
begin
for i := 0 to Length(FPoints) - 1 do
FPoints[i] := nil;
FPoints := nil;
end;
inherited;
end;

function TSimpleLookupTable.GetSize: Int32;
begin
result := System.Length(FPoints);
Expand Down
2 changes: 1 addition & 1 deletion CryptoLib/src/Math/EC/ClpECCompUtilities.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ function TWNafUtilities.TWNafCallback.Precompute(const existing: IPreCompInfo)
curPreCompLen := iniPreCompLen;
if (curPreCompLen = 0) then
begin
PreComp[0] := Fm_p;
PreComp[0] := Fm_p.Clone();
curPreCompLen := 1;
end;

Expand Down
9 changes: 9 additions & 0 deletions CryptoLib/src/Math/EC/Endo/ClpEndoPreCompInfo.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TEndoPreCompInfo = class sealed(TInterfacedObject, IPreCompInfo,

public

destructor Destroy; override;

property Endomorphism: IECEndomorphism read GetEndomorphism
write SetEndomorphism;
property MappedPoint: IECPoint read GetMappedPoint write SetMappedPoint;
Expand All @@ -52,6 +54,13 @@ implementation

{ TEndoPreCompInfo }

destructor TEndoPreCompInfo.Destroy;
begin
FEndomorphism := nil;
FMappedPoint := nil;
inherited;
end;

function TEndoPreCompInfo.GetEndomorphism: IECEndomorphism;
begin
result := FEndomorphism;
Expand Down
Loading