|
@@ -44,6 +44,10 @@ uses
|
|
|
ClpTnaf,
|
|
ClpTnaf,
|
|
|
ClpValidityPreCompInfo,
|
|
ClpValidityPreCompInfo,
|
|
|
ClpIValidityPreCompInfo,
|
|
ClpIValidityPreCompInfo,
|
|
|
|
|
+ ClpIWNafPreCompInfo,
|
|
|
|
|
+ ClpIEndoPreCompInfo,
|
|
|
|
|
+ ClpIWTauNafPreCompInfo,
|
|
|
|
|
+ ClpIFixedPointPreCompInfo,
|
|
|
ClpIECC,
|
|
ClpIECC,
|
|
|
ClpIFiniteField,
|
|
ClpIFiniteField,
|
|
|
ClpIPreCompInfo;
|
|
ClpIPreCompInfo;
|
|
@@ -722,6 +726,8 @@ type
|
|
|
constructor Create(const points: TCryptoLibGenericArray<IECPoint>;
|
|
constructor Create(const points: TCryptoLibGenericArray<IECPoint>;
|
|
|
off, len: Int32);
|
|
off, len: Int32);
|
|
|
|
|
|
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
|
+
|
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
|
|
|
|
|
@@ -744,6 +750,8 @@ type
|
|
|
constructor Create(const outer: IECCurve; const table: TCryptoLibByteArray;
|
|
constructor Create(const outer: IECCurve; const table: TCryptoLibByteArray;
|
|
|
Size: Int32);
|
|
Size: Int32);
|
|
|
|
|
|
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
|
+
|
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
|
|
|
|
|
@@ -781,6 +789,8 @@ type
|
|
|
constructor Create(const outer: IF2mCurve;
|
|
constructor Create(const outer: IF2mCurve;
|
|
|
const table: TCryptoLibInt64Array; Size: Int32);
|
|
const table: TCryptoLibInt64Array; Size: Int32);
|
|
|
|
|
|
|
|
|
|
+ destructor Destroy; override;
|
|
|
|
|
+
|
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
function Lookup(index: Int32): IECPoint; override;
|
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
function LookupVar(index: Int32): IECPoint; override;
|
|
|
|
|
|
|
@@ -1222,6 +1232,8 @@ type
|
|
|
|
|
|
|
|
function ThreeTimes(): IECPoint; virtual;
|
|
function ThreeTimes(): IECPoint; virtual;
|
|
|
|
|
|
|
|
|
|
+ function Clone(): IECPoint; virtual;
|
|
|
|
|
+
|
|
|
function Equals(const other: IECPoint): Boolean; reintroduce;
|
|
function Equals(const other: IECPoint): Boolean; reintroduce;
|
|
|
function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
|
|
function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
|
|
|
{$ENDIF DELPHI}override;
|
|
{$ENDIF DELPHI}override;
|
|
@@ -2993,6 +3005,21 @@ end;
|
|
|
|
|
|
|
|
function TECCurve.Precompute(const point: IECPoint; const name: String;
|
|
function TECCurve.Precompute(const point: IECPoint; const name: String;
|
|
|
const callback: IPreCompCallback): IPreCompInfo;
|
|
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
|
|
var
|
|
|
table: TDictionary<String, IPreCompInfo>;
|
|
table: TDictionary<String, IPreCompInfo>;
|
|
|
existing: IPreCompInfo;
|
|
existing: IPreCompInfo;
|
|
@@ -3012,10 +3039,10 @@ begin
|
|
|
|
|
|
|
|
result := callback.Precompute(existing);
|
|
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
|
|
finally
|
|
|
FLock.Release;
|
|
FLock.Release;
|
|
@@ -3718,6 +3745,13 @@ begin
|
|
|
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
|
|
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
+destructor TDefaultLookupTable.Destroy;
|
|
|
|
|
+begin
|
|
|
|
|
+ Fm_outer := nil;
|
|
|
|
|
+ Fm_table := nil;
|
|
|
|
|
+ inherited;
|
|
|
|
|
+end;
|
|
|
|
|
+
|
|
|
function TDefaultLookupTable.GetSize: Int32;
|
|
function TDefaultLookupTable.GetSize: Int32;
|
|
|
begin
|
|
begin
|
|
|
result := Fm_size;
|
|
result := Fm_size;
|
|
@@ -3804,6 +3838,14 @@ begin
|
|
|
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
|
|
result := Fm_outer.CreateRawPoint(XFieldElement, YFieldElement, false);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+destructor TDefaultF2mLookupTable.Destroy;
|
|
|
|
|
+begin
|
|
|
|
|
+ Fm_outer := nil;
|
|
|
|
|
+ Fm_table := nil;
|
|
|
|
|
+ inherited;
|
|
|
|
|
+end;
|
|
|
|
|
+
|
|
|
function TDefaultF2mLookupTable.GetSize: Int32;
|
|
function TDefaultF2mLookupTable.GetSize: Int32;
|
|
|
begin
|
|
begin
|
|
|
result := Fm_size;
|
|
result := Fm_size;
|
|
@@ -4084,12 +4126,23 @@ begin
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
destructor TECPoint.Destroy;
|
|
destructor TECPoint.Destroy;
|
|
|
|
|
+var
|
|
|
|
|
+ Key: string;
|
|
|
begin
|
|
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;
|
|
inherited Destroy;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
class constructor TECPoint.ECPoint;
|
|
class constructor TECPoint.ECPoint;
|
|
|
begin
|
|
begin
|
|
|
System.SetLength(FEMPTY_ZS, 0);
|
|
System.SetLength(FEMPTY_ZS, 0);
|
|
@@ -4400,6 +4453,18 @@ begin
|
|
|
result := Normalize().Detach();
|
|
result := Normalize().Detach();
|
|
|
end;
|
|
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 }
|
|
{ TF2mPoint }
|
|
|
|
|
|
|
|
constructor TF2mPoint.Create(const curve: IECCurve;
|
|
constructor TF2mPoint.Create(const curve: IECCurve;
|
|
@@ -6703,6 +6768,19 @@ begin
|
|
|
FPoints := Copy(points, off, len);
|
|
FPoints := Copy(points, off, len);
|
|
|
end;
|
|
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;
|
|
function TSimpleLookupTable.GetSize: Int32;
|
|
|
begin
|
|
begin
|
|
|
result := System.Length(FPoints);
|
|
result := System.Length(FPoints);
|