|
@@ -46,32 +46,7 @@ type
|
|
|
strict private
|
|
strict private
|
|
|
|
|
|
|
|
type
|
|
type
|
|
|
- IPointAccum = interface(IInterface)
|
|
|
|
|
- ['{8A257C67-674F-4F62-B937-4E83B46CAF36}']
|
|
|
|
|
- function GetX: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetX(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property X: TCryptoLibInt32Array read GetX write SetX;
|
|
|
|
|
-
|
|
|
|
|
- function GetY: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetY(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Y: TCryptoLibInt32Array read GetY write SetY;
|
|
|
|
|
-
|
|
|
|
|
- function GetZ: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetZ(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Z: TCryptoLibInt32Array read GetZ write SetZ;
|
|
|
|
|
-
|
|
|
|
|
- function GetU: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetU(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property U: TCryptoLibInt32Array read GetU write SetU;
|
|
|
|
|
-
|
|
|
|
|
- function GetV: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetV(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property V: TCryptoLibInt32Array read GetV write SetV;
|
|
|
|
|
-
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
- type
|
|
|
|
|
- TPointAccum = class sealed(TInterfacedObject, IPointAccum)
|
|
|
|
|
|
|
+ TPointAccum = record
|
|
|
private
|
|
private
|
|
|
Fx, Fy, Fz, Fu, Fv: TCryptoLibInt32Array;
|
|
Fx, Fy, Fz, Fu, Fv: TCryptoLibInt32Array;
|
|
|
|
|
|
|
@@ -93,32 +68,11 @@ type
|
|
|
property U: TCryptoLibInt32Array read GetU write SetU;
|
|
property U: TCryptoLibInt32Array read GetU write SetU;
|
|
|
property V: TCryptoLibInt32Array read GetV write SetV;
|
|
property V: TCryptoLibInt32Array read GetV write SetV;
|
|
|
|
|
|
|
|
- constructor Create();
|
|
|
|
|
|
|
+ class function CreatePointAccum(): TPointAccum; static;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
type
|
|
type
|
|
|
- IPointExt = interface(IInterface)
|
|
|
|
|
- ['{20C8CC66-D9E6-4626-B09D-BC500223F103}']
|
|
|
|
|
- function GetX: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetX(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property X: TCryptoLibInt32Array read GetX write SetX;
|
|
|
|
|
-
|
|
|
|
|
- function GetY: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetY(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Y: TCryptoLibInt32Array read GetY write SetY;
|
|
|
|
|
-
|
|
|
|
|
- function GetZ: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetZ(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Z: TCryptoLibInt32Array read GetZ write SetZ;
|
|
|
|
|
-
|
|
|
|
|
- function GetT: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetT(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property T: TCryptoLibInt32Array read GetT write SetT;
|
|
|
|
|
-
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
- type
|
|
|
|
|
- TPointExt = class sealed(TInterfacedObject, IPointExt)
|
|
|
|
|
|
|
+ TPointExt = record
|
|
|
private
|
|
private
|
|
|
Fx, Fy, Fz, Ft: TCryptoLibInt32Array;
|
|
Fx, Fy, Fz, Ft: TCryptoLibInt32Array;
|
|
|
|
|
|
|
@@ -137,26 +91,11 @@ type
|
|
|
property Z: TCryptoLibInt32Array read GetZ write SetZ;
|
|
property Z: TCryptoLibInt32Array read GetZ write SetZ;
|
|
|
property T: TCryptoLibInt32Array read GetT write SetT;
|
|
property T: TCryptoLibInt32Array read GetT write SetT;
|
|
|
|
|
|
|
|
- constructor Create();
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
- type
|
|
|
|
|
- IPointPrecomp = interface(IInterface)
|
|
|
|
|
- ['{9EADAD66-FE44-4A1E-8458-3AE7D2AF14C2}']
|
|
|
|
|
- function GetYpx_h: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetYpx_h(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Ypx_h: TCryptoLibInt32Array read GetYpx_h write SetYpx_h;
|
|
|
|
|
- function GetYmx_h: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetYmx_h(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Ymx_h: TCryptoLibInt32Array read GetYmx_h write SetYmx_h;
|
|
|
|
|
- function GetXyd: TCryptoLibInt32Array;
|
|
|
|
|
- procedure SetXyd(const value: TCryptoLibInt32Array);
|
|
|
|
|
- property Xyd: TCryptoLibInt32Array read GetXyd write SetXyd;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ class function CreatePointExt(): TPointExt; static;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
type
|
|
type
|
|
|
- TPointPrecomp = class sealed(TInterfacedObject, IPointPrecomp)
|
|
|
|
|
|
|
+ TPointPrecomp = record
|
|
|
private
|
|
private
|
|
|
Fypx_h, Fymx_h, Fxyd: TCryptoLibInt32Array;
|
|
Fypx_h, Fymx_h, Fxyd: TCryptoLibInt32Array;
|
|
|
|
|
|
|
@@ -172,7 +111,7 @@ type
|
|
|
property Ymx_h: TCryptoLibInt32Array read GetYmx_h write SetYmx_h;
|
|
property Ymx_h: TCryptoLibInt32Array read GetYmx_h write SetYmx_h;
|
|
|
property Xyd: TCryptoLibInt32Array read GetXyd write SetXyd;
|
|
property Xyd: TCryptoLibInt32Array read GetXyd write SetXyd;
|
|
|
|
|
|
|
|
- constructor Create();
|
|
|
|
|
|
|
+ class function CreatePointPrecomp(): TPointPrecomp; static;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
const
|
|
const
|
|
@@ -204,7 +143,7 @@ type
|
|
|
FB_x, FB_y, FC_d, FC_d2, FC_d4: TCryptoLibInt32Array;
|
|
FB_x, FB_y, FC_d, FC_d2, FC_d4: TCryptoLibInt32Array;
|
|
|
FPrecompLock: TCriticalSection;
|
|
FPrecompLock: TCriticalSection;
|
|
|
// TODO[ed25519] Convert to PointPrecomp
|
|
// TODO[ed25519] Convert to PointPrecomp
|
|
|
- FPrecompBaseTable: TCryptoLibGenericArray<IPointExt>;
|
|
|
|
|
|
|
+ FPrecompBaseTable: TCryptoLibGenericArray<TPointExt>;
|
|
|
FPrecompBase: TCryptoLibInt32Array;
|
|
FPrecompBase: TCryptoLibInt32Array;
|
|
|
|
|
|
|
|
class function CalculateS(const r, k, s: TCryptoLibByteArray)
|
|
class function CalculateS(const r, k, s: TCryptoLibByteArray)
|
|
@@ -230,7 +169,7 @@ type
|
|
|
static; inline;
|
|
static; inline;
|
|
|
|
|
|
|
|
class function DecodePointVar(const p: TCryptoLibByteArray; pOff: Int32;
|
|
class function DecodePointVar(const p: TCryptoLibByteArray; pOff: Int32;
|
|
|
- ANegate: Boolean; const r: IPointExt): Boolean; static;
|
|
|
|
|
|
|
+ ANegate: Boolean; var r: TPointExt): Boolean; static;
|
|
|
|
|
|
|
|
class procedure DecodeScalar(const k: TCryptoLibByteArray; kOff: Int32;
|
|
class procedure DecodeScalar(const k: TCryptoLibByteArray; kOff: Int32;
|
|
|
const n: TCryptoLibUInt32Array); static; inline;
|
|
const n: TCryptoLibUInt32Array); static; inline;
|
|
@@ -247,7 +186,7 @@ type
|
|
|
class procedure Encode56(n: UInt64; const bs: TCryptoLibByteArray;
|
|
class procedure Encode56(n: UInt64; const bs: TCryptoLibByteArray;
|
|
|
off: Int32); static; inline;
|
|
off: Int32); static; inline;
|
|
|
|
|
|
|
|
- class procedure EncodePoint(const p: IPointAccum;
|
|
|
|
|
|
|
+ class procedure EncodePoint(var p: TPointAccum;
|
|
|
const r: TCryptoLibByteArray; rOff: Int32); static;
|
|
const r: TCryptoLibByteArray; rOff: Int32); static;
|
|
|
|
|
|
|
|
class function GetWnaf(const n: TCryptoLibUInt32Array; width: Int32)
|
|
class function GetWnaf(const n: TCryptoLibUInt32Array; width: Int32)
|
|
@@ -275,39 +214,37 @@ type
|
|
|
const ctx: TCryptoLibCustomByteArrayBuffer; phflag: Byte;
|
|
const ctx: TCryptoLibCustomByteArrayBuffer; phflag: Byte;
|
|
|
const m: TCryptoLibByteArray; mOff, mLen: Int32): Boolean;
|
|
const m: TCryptoLibByteArray; mOff, mLen: Int32): Boolean;
|
|
|
|
|
|
|
|
- class procedure PointAddVar(negate: Boolean; const p: IPointExt;
|
|
|
|
|
- const r: IPointAccum); overload; static;
|
|
|
|
|
|
|
+ class procedure PointAddVar(negate: Boolean; var p: TPointExt;
|
|
|
|
|
+ var r: TPointAccum); overload; static;
|
|
|
|
|
|
|
|
- class procedure PointAddVar(negate: Boolean; const p, q, r: IPointExt);
|
|
|
|
|
|
|
+ class procedure PointAddVar(negate: Boolean; var p, q, r: TPointExt);
|
|
|
overload; static;
|
|
overload; static;
|
|
|
|
|
|
|
|
- class procedure PointAddPrecomp(const p: IPointPrecomp;
|
|
|
|
|
- const r: IPointAccum); overload; static;
|
|
|
|
|
|
|
+ class procedure PointAddPrecomp(var p: TPointPrecomp; var r: TPointAccum);
|
|
|
|
|
+ overload; static;
|
|
|
|
|
|
|
|
- class function PointCopy(const p: IPointAccum): IPointExt; overload;
|
|
|
|
|
|
|
+ class function PointCopy(var p: TPointAccum): TPointExt; overload;
|
|
|
static; inline;
|
|
static; inline;
|
|
|
|
|
|
|
|
- class function PointCopy(const p: IPointExt): IPointExt; overload;
|
|
|
|
|
|
|
+ class function PointCopy(var p: TPointExt): TPointExt; overload;
|
|
|
static; inline;
|
|
static; inline;
|
|
|
|
|
|
|
|
- class procedure PointDouble(const r: IPointAccum); static;
|
|
|
|
|
|
|
+ class procedure PointDouble(var r: TPointAccum); static;
|
|
|
|
|
|
|
|
- class procedure PointExtendXY(const p: IPointAccum); overload;
|
|
|
|
|
- static; inline;
|
|
|
|
|
|
|
+ class procedure PointExtendXY(var p: TPointAccum); overload; static; inline;
|
|
|
|
|
|
|
|
- class procedure PointExtendXY(const p: IPointExt); overload; static; inline;
|
|
|
|
|
|
|
+ class procedure PointExtendXY(var p: TPointExt); overload; static; inline;
|
|
|
|
|
|
|
|
class procedure PointLookup(block, index: Int32;
|
|
class procedure PointLookup(block, index: Int32;
|
|
|
- const p: IPointPrecomp); static;
|
|
|
|
|
|
|
+ var p: TPointPrecomp); static;
|
|
|
|
|
|
|
|
- class function PointPrecompVar(const p: IPointExt; count: Int32)
|
|
|
|
|
- : TCryptoLibGenericArray<IPointExt>; static;
|
|
|
|
|
|
|
+ class function PointPrecompVar(var p: TPointExt; count: Int32)
|
|
|
|
|
+ : TCryptoLibGenericArray<TPointExt>; static;
|
|
|
|
|
|
|
|
- class procedure PointSetNeutral(const p: IPointAccum); overload;
|
|
|
|
|
|
|
+ class procedure PointSetNeutral(var p: TPointAccum); overload;
|
|
|
static; inline;
|
|
static; inline;
|
|
|
|
|
|
|
|
- class procedure PointSetNeutral(const p: IPointExt); overload;
|
|
|
|
|
- static; inline;
|
|
|
|
|
|
|
+ class procedure PointSetNeutral(var p: TPointExt); overload; static; inline;
|
|
|
|
|
|
|
|
class procedure PruneScalar(const n: TCryptoLibByteArray; nOff: Int32;
|
|
class procedure PruneScalar(const n: TCryptoLibByteArray; nOff: Int32;
|
|
|
const r: TCryptoLibByteArray); static; inline;
|
|
const r: TCryptoLibByteArray); static; inline;
|
|
@@ -316,13 +253,13 @@ type
|
|
|
: TCryptoLibByteArray; static;
|
|
: TCryptoLibByteArray; static;
|
|
|
|
|
|
|
|
class procedure ScalarMultBase(const k: TCryptoLibByteArray;
|
|
class procedure ScalarMultBase(const k: TCryptoLibByteArray;
|
|
|
- const r: IPointAccum); static;
|
|
|
|
|
|
|
+ var r: TPointAccum); static;
|
|
|
|
|
|
|
|
class procedure ScalarMultBaseEncoded(const k, r: TCryptoLibByteArray;
|
|
class procedure ScalarMultBaseEncoded(const k, r: TCryptoLibByteArray;
|
|
|
rOff: Int32); static; inline;
|
|
rOff: Int32); static; inline;
|
|
|
|
|
|
|
|
class procedure ScalarMultStraussVar(const nb, np: TCryptoLibUInt32Array;
|
|
class procedure ScalarMultStraussVar(const nb, np: TCryptoLibUInt32Array;
|
|
|
- const p: IPointExt; const r: IPointAccum); static;
|
|
|
|
|
|
|
+ var p: TPointExt; var r: TPointAccum); static;
|
|
|
|
|
|
|
|
class function ValidateDigestOutputSize(const ADigest: IDigest)
|
|
class function ValidateDigestOutputSize(const ADigest: IDigest)
|
|
|
: TCryptoLibByteArray; static; inline;
|
|
: TCryptoLibByteArray; static; inline;
|
|
@@ -422,13 +359,13 @@ implementation
|
|
|
|
|
|
|
|
{ TEd25519.TPointExt }
|
|
{ TEd25519.TPointExt }
|
|
|
|
|
|
|
|
-constructor TEd25519.TPointExt.Create;
|
|
|
|
|
|
|
+class function TEd25519.TPointExt.CreatePointExt(): TPointExt;
|
|
|
begin
|
|
begin
|
|
|
- Inherited Create();
|
|
|
|
|
- Fx := TX25519Field.Create();
|
|
|
|
|
- Fy := TX25519Field.Create();
|
|
|
|
|
- Fz := TX25519Field.Create();
|
|
|
|
|
- Ft := TX25519Field.Create();
|
|
|
|
|
|
|
+ result := Default (TPointExt);
|
|
|
|
|
+ result.Fx := TX25519Field.Create();
|
|
|
|
|
+ result.Fy := TX25519Field.Create();
|
|
|
|
|
+ result.Fz := TX25519Field.Create();
|
|
|
|
|
+ result.Ft := TX25519Field.Create();
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TEd25519.TPointExt.GetT: TCryptoLibInt32Array;
|
|
function TEd25519.TPointExt.GetT: TCryptoLibInt32Array;
|
|
@@ -473,14 +410,14 @@ end;
|
|
|
|
|
|
|
|
{ TEd25519.TPointAccum }
|
|
{ TEd25519.TPointAccum }
|
|
|
|
|
|
|
|
-constructor TEd25519.TPointAccum.Create;
|
|
|
|
|
|
|
+class function TEd25519.TPointAccum.CreatePointAccum(): TPointAccum;
|
|
|
begin
|
|
begin
|
|
|
- Inherited Create();
|
|
|
|
|
- Fx := TX25519Field.Create();
|
|
|
|
|
- Fy := TX25519Field.Create();
|
|
|
|
|
- Fz := TX25519Field.Create();
|
|
|
|
|
- Fu := TX25519Field.Create();
|
|
|
|
|
- Fv := TX25519Field.Create();
|
|
|
|
|
|
|
+ result := Default (TPointAccum);
|
|
|
|
|
+ result.Fx := TX25519Field.Create();
|
|
|
|
|
+ result.Fy := TX25519Field.Create();
|
|
|
|
|
+ result.Fz := TX25519Field.Create();
|
|
|
|
|
+ result.Fu := TX25519Field.Create();
|
|
|
|
|
+ result.Fv := TX25519Field.Create();
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TEd25519.TPointAccum.GetU: TCryptoLibInt32Array;
|
|
function TEd25519.TPointAccum.GetU: TCryptoLibInt32Array;
|
|
@@ -535,12 +472,12 @@ end;
|
|
|
|
|
|
|
|
{ TEd25519.TPointPrecomp }
|
|
{ TEd25519.TPointPrecomp }
|
|
|
|
|
|
|
|
-constructor TEd25519.TPointPrecomp.Create;
|
|
|
|
|
|
|
+class function TEd25519.TPointPrecomp.CreatePointPrecomp(): TPointPrecomp;
|
|
|
begin
|
|
begin
|
|
|
- Inherited Create();
|
|
|
|
|
- Fypx_h := TX25519Field.Create();
|
|
|
|
|
- Fymx_h := TX25519Field.Create();
|
|
|
|
|
- Fxyd := TX25519Field.Create();
|
|
|
|
|
|
|
+ result := Default (TPointPrecomp);
|
|
|
|
|
+ result.Fypx_h := TX25519Field.Create();
|
|
|
|
|
+ result.Fymx_h := TX25519Field.Create();
|
|
|
|
|
+ result.Fxyd := TX25519Field.Create();
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TEd25519.TPointPrecomp.GetXyd: TCryptoLibInt32Array;
|
|
function TEd25519.TPointPrecomp.GetXyd: TCryptoLibInt32Array;
|
|
@@ -754,21 +691,21 @@ begin
|
|
|
result := n;
|
|
result := n;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointExtendXY(const p: IPointAccum);
|
|
|
|
|
|
|
+class procedure TEd25519.PointExtendXY(var p: TPointAccum);
|
|
|
begin
|
|
begin
|
|
|
TX25519Field.One(p.Z);
|
|
TX25519Field.One(p.Z);
|
|
|
TX25519Field.Copy(p.X, 0, p.U, 0);
|
|
TX25519Field.Copy(p.X, 0, p.U, 0);
|
|
|
TX25519Field.Copy(p.Y, 0, p.V, 0);
|
|
TX25519Field.Copy(p.Y, 0, p.V, 0);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointExtendXY(const p: IPointExt);
|
|
|
|
|
|
|
+class procedure TEd25519.PointExtendXY(var p: TPointExt);
|
|
|
begin
|
|
begin
|
|
|
TX25519Field.One(p.Z);
|
|
TX25519Field.One(p.Z);
|
|
|
TX25519Field.Mul(p.X, p.Y, p.T);
|
|
TX25519Field.Mul(p.X, p.Y, p.T);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
class function TEd25519.DecodePointVar(const p: TCryptoLibByteArray;
|
|
class function TEd25519.DecodePointVar(const p: TCryptoLibByteArray;
|
|
|
- pOff: Int32; ANegate: Boolean; const r: IPointExt): Boolean;
|
|
|
|
|
|
|
+ pOff: Int32; ANegate: Boolean; var r: TPointExt): Boolean;
|
|
|
var
|
|
var
|
|
|
py: TCryptoLibByteArray;
|
|
py: TCryptoLibByteArray;
|
|
|
U, V: TCryptoLibInt32Array;
|
|
U, V: TCryptoLibInt32Array;
|
|
@@ -836,7 +773,7 @@ begin
|
|
|
end;
|
|
end;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.EncodePoint(const p: IPointAccum;
|
|
|
|
|
|
|
+class procedure TEd25519.EncodePoint(var p: TPointAccum;
|
|
|
const r: TCryptoLibByteArray; rOff: Int32);
|
|
const r: TCryptoLibByteArray; rOff: Int32);
|
|
|
var
|
|
var
|
|
|
X, Y: TCryptoLibInt32Array;
|
|
X, Y: TCryptoLibInt32Array;
|
|
@@ -874,9 +811,9 @@ end;
|
|
|
class procedure TEd25519.ScalarMultBaseEncoded(const k, r: TCryptoLibByteArray;
|
|
class procedure TEd25519.ScalarMultBaseEncoded(const k, r: TCryptoLibByteArray;
|
|
|
rOff: Int32);
|
|
rOff: Int32);
|
|
|
var
|
|
var
|
|
|
- p: IPointAccum;
|
|
|
|
|
|
|
+ p: TPointAccum;
|
|
|
begin
|
|
begin
|
|
|
- p := TPointAccum.Create();
|
|
|
|
|
|
|
+ p := TPointAccum.CreatePointAccum();
|
|
|
ScalarMultBase(k, p);
|
|
ScalarMultBase(k, p);
|
|
|
EncodePoint(p, r, rOff);
|
|
EncodePoint(p, r, rOff);
|
|
|
end;
|
|
end;
|
|
@@ -1062,8 +999,8 @@ function TEd25519.ImplVerify(const sig: TCryptoLibByteArray; sigOff: Int32;
|
|
|
var
|
|
var
|
|
|
r, s, h, k, check: TCryptoLibByteArray;
|
|
r, s, h, k, check: TCryptoLibByteArray;
|
|
|
nS, nA: TCryptoLibUInt32Array;
|
|
nS, nA: TCryptoLibUInt32Array;
|
|
|
- pA: IPointExt;
|
|
|
|
|
- pR: IPointAccum;
|
|
|
|
|
|
|
+ pA: TPointExt;
|
|
|
|
|
+ pR: TPointAccum;
|
|
|
d: IDigest;
|
|
d: IDigest;
|
|
|
begin
|
|
begin
|
|
|
if (not CheckContextVar(ctx, phflag)) then
|
|
if (not CheckContextVar(ctx, phflag)) then
|
|
@@ -1087,7 +1024,7 @@ begin
|
|
|
Exit;
|
|
Exit;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
- pA := TPointExt.Create();
|
|
|
|
|
|
|
+ pA := TPointExt.CreatePointExt();
|
|
|
if (not DecodePointVar(pk, pkOff, true, pA)) then
|
|
if (not DecodePointVar(pk, pkOff, true, pA)) then
|
|
|
begin
|
|
begin
|
|
|
result := false;
|
|
result := false;
|
|
@@ -1112,7 +1049,7 @@ begin
|
|
|
|
|
|
|
|
DecodeScalar(k, 0, nA);
|
|
DecodeScalar(k, 0, nA);
|
|
|
|
|
|
|
|
- pR := TPointAccum.Create();
|
|
|
|
|
|
|
+ pR := TPointAccum.CreatePointAccum();
|
|
|
ScalarMultStraussVar(nS, nA, pA, pR);
|
|
ScalarMultStraussVar(nS, nA, pA, pR);
|
|
|
|
|
|
|
|
System.SetLength(check, PointBytes);
|
|
System.SetLength(check, PointBytes);
|
|
@@ -1122,8 +1059,8 @@ begin
|
|
|
result := TArrayUtils.ConstantTimeAreEqual(check, r);
|
|
result := TArrayUtils.ConstantTimeAreEqual(check, r);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointAddPrecomp(const p: IPointPrecomp;
|
|
|
|
|
- const r: IPointAccum);
|
|
|
|
|
|
|
+class procedure TEd25519.PointAddPrecomp(var p: TPointPrecomp;
|
|
|
|
|
+ var r: TPointAccum);
|
|
|
var
|
|
var
|
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG: TCryptoLibInt32Array;
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG: TCryptoLibInt32Array;
|
|
|
begin
|
|
begin
|
|
@@ -1148,7 +1085,7 @@ begin
|
|
|
TX25519Field.Mul(bigE, bigF, r.Z);
|
|
TX25519Field.Mul(bigE, bigF, r.Z);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointAddVar(negate: Boolean; const p, q, r: IPointExt);
|
|
|
|
|
|
|
+class procedure TEd25519.PointAddVar(negate: Boolean; var p, q, r: TPointExt);
|
|
|
var
|
|
var
|
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG, bigH, c, d, f,
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG, bigH, c, d, f,
|
|
|
g: TCryptoLibInt32Array;
|
|
g: TCryptoLibInt32Array;
|
|
@@ -1194,8 +1131,8 @@ begin
|
|
|
TX25519Field.Mul(bigE, bigH, r.T);
|
|
TX25519Field.Mul(bigE, bigH, r.T);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointAddVar(negate: Boolean; const p: IPointExt;
|
|
|
|
|
- const r: IPointAccum);
|
|
|
|
|
|
|
+class procedure TEd25519.PointAddVar(negate: Boolean; var p: TPointExt;
|
|
|
|
|
+ var r: TPointAccum);
|
|
|
var
|
|
var
|
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG, bigH, c, d, f,
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG, bigH, c, d, f,
|
|
|
g: TCryptoLibInt32Array;
|
|
g: TCryptoLibInt32Array;
|
|
@@ -1241,11 +1178,11 @@ begin
|
|
|
TX25519Field.Mul(bigF, bigG, r.Z);
|
|
TX25519Field.Mul(bigF, bigG, r.Z);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class function TEd25519.PointCopy(const p: IPointAccum): IPointExt;
|
|
|
|
|
|
|
+class function TEd25519.PointCopy(var p: TPointAccum): TPointExt;
|
|
|
var
|
|
var
|
|
|
- r: IPointExt;
|
|
|
|
|
|
|
+ r: TPointExt;
|
|
|
begin
|
|
begin
|
|
|
- r := TPointExt.Create();
|
|
|
|
|
|
|
+ r := TPointExt.CreatePointExt();
|
|
|
TX25519Field.Copy(p.X, 0, r.X, 0);
|
|
TX25519Field.Copy(p.X, 0, r.X, 0);
|
|
|
TX25519Field.Copy(p.Y, 0, r.Y, 0);
|
|
TX25519Field.Copy(p.Y, 0, r.Y, 0);
|
|
|
TX25519Field.Copy(p.Z, 0, r.Z, 0);
|
|
TX25519Field.Copy(p.Z, 0, r.Z, 0);
|
|
@@ -1253,11 +1190,11 @@ begin
|
|
|
result := r;
|
|
result := r;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class function TEd25519.PointCopy(const p: IPointExt): IPointExt;
|
|
|
|
|
|
|
+class function TEd25519.PointCopy(var p: TPointExt): TPointExt;
|
|
|
var
|
|
var
|
|
|
- r: IPointExt;
|
|
|
|
|
|
|
+ r: TPointExt;
|
|
|
begin
|
|
begin
|
|
|
- r := TPointExt.Create();
|
|
|
|
|
|
|
+ r := TPointExt.CreatePointExt();
|
|
|
TX25519Field.Copy(p.X, 0, r.X, 0);
|
|
TX25519Field.Copy(p.X, 0, r.X, 0);
|
|
|
TX25519Field.Copy(p.Y, 0, r.Y, 0);
|
|
TX25519Field.Copy(p.Y, 0, r.Y, 0);
|
|
|
TX25519Field.Copy(p.Z, 0, r.Z, 0);
|
|
TX25519Field.Copy(p.Z, 0, r.Z, 0);
|
|
@@ -1265,7 +1202,7 @@ begin
|
|
|
result := r;
|
|
result := r;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointDouble(const r: IPointAccum);
|
|
|
|
|
|
|
+class procedure TEd25519.PointDouble(var r: TPointAccum);
|
|
|
var
|
|
var
|
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG: TCryptoLibInt32Array;
|
|
bigA, bigB, bigC, bigD, bigE, bigF, bigG: TCryptoLibInt32Array;
|
|
|
begin
|
|
begin
|
|
@@ -1292,8 +1229,7 @@ begin
|
|
|
TX25519Field.Mul(bigE, bigF, r.Z);
|
|
TX25519Field.Mul(bigE, bigF, r.Z);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointLookup(block, index: Int32;
|
|
|
|
|
- const p: IPointPrecomp);
|
|
|
|
|
|
|
+class procedure TEd25519.PointLookup(block, index: Int32; var p: TPointPrecomp);
|
|
|
var
|
|
var
|
|
|
off, i, mask: Int32;
|
|
off, i, mask: Int32;
|
|
|
begin
|
|
begin
|
|
@@ -1315,17 +1251,17 @@ begin
|
|
|
end;
|
|
end;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class function TEd25519.PointPrecompVar(const p: IPointExt; count: Int32)
|
|
|
|
|
- : TCryptoLibGenericArray<IPointExt>;
|
|
|
|
|
|
|
+class function TEd25519.PointPrecompVar(var p: TPointExt; count: Int32)
|
|
|
|
|
+ : TCryptoLibGenericArray<TPointExt>;
|
|
|
var
|
|
var
|
|
|
- d: IPointExt;
|
|
|
|
|
- table: TCryptoLibGenericArray<IPointExt>;
|
|
|
|
|
|
|
+ d: TPointExt;
|
|
|
|
|
+ table: TCryptoLibGenericArray<TPointExt>;
|
|
|
i: Int32;
|
|
i: Int32;
|
|
|
begin
|
|
begin
|
|
|
{$IFDEF DEBUG}
|
|
{$IFDEF DEBUG}
|
|
|
System.Assert(count > 0);
|
|
System.Assert(count > 0);
|
|
|
{$ENDIF DEBUG}
|
|
{$ENDIF DEBUG}
|
|
|
- d := TPointExt.Create();
|
|
|
|
|
|
|
+ d := TPointExt.CreatePointExt();
|
|
|
PointAddVar(false, p, p, d);
|
|
PointAddVar(false, p, p, d);
|
|
|
|
|
|
|
|
System.SetLength(table, count);
|
|
System.SetLength(table, count);
|
|
@@ -1333,13 +1269,13 @@ begin
|
|
|
table[0] := PointCopy(p);
|
|
table[0] := PointCopy(p);
|
|
|
for i := 1 to System.Pred(count) do
|
|
for i := 1 to System.Pred(count) do
|
|
|
begin
|
|
begin
|
|
|
- table[i] := TPointExt.Create() as IPointExt;
|
|
|
|
|
|
|
+ table[i] := TPointExt.CreatePointExt();
|
|
|
PointAddVar(false, table[i - 1], d, table[i]);
|
|
PointAddVar(false, table[i - 1], d, table[i]);
|
|
|
end;
|
|
end;
|
|
|
result := table;
|
|
result := table;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointSetNeutral(const p: IPointAccum);
|
|
|
|
|
|
|
+class procedure TEd25519.PointSetNeutral(var p: TPointAccum);
|
|
|
begin
|
|
begin
|
|
|
TX25519Field.Zero(p.X);
|
|
TX25519Field.Zero(p.X);
|
|
|
TX25519Field.One(p.Y);
|
|
TX25519Field.One(p.Y);
|
|
@@ -1348,7 +1284,7 @@ begin
|
|
|
TX25519Field.One(p.V);
|
|
TX25519Field.One(p.V);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
-class procedure TEd25519.PointSetNeutral(const p: IPointExt);
|
|
|
|
|
|
|
+class procedure TEd25519.PointSetNeutral(var p: TPointExt);
|
|
|
begin
|
|
begin
|
|
|
TX25519Field.Zero(p.X);
|
|
TX25519Field.Zero(p.X);
|
|
|
TX25519Field.One(p.Y);
|
|
TX25519Field.One(p.Y);
|
|
@@ -1358,15 +1294,15 @@ end;
|
|
|
|
|
|
|
|
class procedure TEd25519.Precompute;
|
|
class procedure TEd25519.Precompute;
|
|
|
var
|
|
var
|
|
|
- bigB: IPointExt;
|
|
|
|
|
- p: IPointAccum;
|
|
|
|
|
|
|
+ bigB: TPointExt;
|
|
|
|
|
+ p: TPointAccum;
|
|
|
X, Y: TCryptoLibInt32Array;
|
|
X, Y: TCryptoLibInt32Array;
|
|
|
off, b, T, s, k, Size, j, i: Int32;
|
|
off, b, T, s, k, Size, j, i: Int32;
|
|
|
- // ds, points: TCryptoLibGenericArray<IPointExt>;
|
|
|
|
|
- ds: array [0 .. (PrecompTeeth - 1)] of IPointExt;
|
|
|
|
|
- points: array [0 .. (PrecompPoints - 1)] of IPointExt;
|
|
|
|
|
- sum, q: IPointExt;
|
|
|
|
|
- r: IPointPrecomp;
|
|
|
|
|
|
|
+ // ds, points: TCryptoLibGenericArray<TPointExt>;
|
|
|
|
|
+ ds: array [0 .. (PrecompTeeth - 1)] of TPointExt;
|
|
|
|
|
+ points: array [0 .. (PrecompPoints - 1)] of TPointExt;
|
|
|
|
|
+ sum, q: TPointExt;
|
|
|
|
|
+ r: TPointPrecomp;
|
|
|
begin
|
|
begin
|
|
|
FPrecompLock.Acquire;
|
|
FPrecompLock.Acquire;
|
|
|
try
|
|
try
|
|
@@ -1377,14 +1313,14 @@ begin
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
// Precomputed table for the base point in verification ladder
|
|
// Precomputed table for the base point in verification ladder
|
|
|
- bigB := TPointExt.Create();
|
|
|
|
|
|
|
+ bigB := TPointExt.CreatePointExt();
|
|
|
TX25519Field.Copy(FB_x, 0, bigB.X, 0);
|
|
TX25519Field.Copy(FB_x, 0, bigB.X, 0);
|
|
|
TX25519Field.Copy(FB_y, 0, bigB.Y, 0);
|
|
TX25519Field.Copy(FB_y, 0, bigB.Y, 0);
|
|
|
PointExtendXY(bigB);
|
|
PointExtendXY(bigB);
|
|
|
|
|
|
|
|
FPrecompBaseTable := PointPrecompVar(bigB, 1 shl (WnafWidthBase - 2));
|
|
FPrecompBaseTable := PointPrecompVar(bigB, 1 shl (WnafWidthBase - 2));
|
|
|
|
|
|
|
|
- p := TPointAccum.Create();
|
|
|
|
|
|
|
+ p := TPointAccum.CreatePointAccum();
|
|
|
TX25519Field.Copy(FB_x, 0, p.X, 0);
|
|
TX25519Field.Copy(FB_x, 0, p.X, 0);
|
|
|
TX25519Field.Copy(FB_y, 0, p.Y, 0);
|
|
TX25519Field.Copy(FB_y, 0, p.Y, 0);
|
|
|
PointExtendXY(p);
|
|
PointExtendXY(p);
|
|
@@ -1397,7 +1333,7 @@ begin
|
|
|
begin
|
|
begin
|
|
|
// System.SetLength(ds, PrecompTeeth); // **
|
|
// System.SetLength(ds, PrecompTeeth); // **
|
|
|
|
|
|
|
|
- sum := TPointExt.Create() as IPointExt;
|
|
|
|
|
|
|
+ sum := TPointExt.CreatePointExt();
|
|
|
PointSetNeutral(sum);
|
|
PointSetNeutral(sum);
|
|
|
|
|
|
|
|
for T := 0 to System.Pred(PrecompTeeth) do
|
|
for T := 0 to System.Pred(PrecompTeeth) do
|
|
@@ -1431,7 +1367,7 @@ begin
|
|
|
j := 0;
|
|
j := 0;
|
|
|
while j < Size do
|
|
while j < Size do
|
|
|
begin
|
|
begin
|
|
|
- points[k] := TPointExt.Create() as IPointExt;
|
|
|
|
|
|
|
+ points[k] := TPointExt.CreatePointExt();
|
|
|
PointAddVar(false, points[k - Size], ds[T], points[k]);
|
|
PointAddVar(false, points[k - Size], ds[T], points[k]);
|
|
|
System.Inc(k);
|
|
System.Inc(k);
|
|
|
System.Inc(j);
|
|
System.Inc(j);
|
|
@@ -1454,7 +1390,7 @@ begin
|
|
|
TX25519Field.Mul(q.X, Y, X);
|
|
TX25519Field.Mul(q.X, Y, X);
|
|
|
TX25519Field.Mul(q.Y, Y, Y);
|
|
TX25519Field.Mul(q.Y, Y, Y);
|
|
|
|
|
|
|
|
- r := TPointPrecomp.Create();
|
|
|
|
|
|
|
+ r := TPointPrecomp.CreatePointPrecomp();
|
|
|
TX25519Field.Apm(Y, X, r.Ypx_h, r.Ymx_h);
|
|
TX25519Field.Apm(Y, X, r.Ypx_h, r.Ymx_h);
|
|
|
TX25519Field.Mul(X, Y, r.Xyd);
|
|
TX25519Field.Mul(X, Y, r.Xyd);
|
|
|
TX25519Field.Mul(r.Xyd, FC_d4, r.Xyd);
|
|
TX25519Field.Mul(r.Xyd, FC_d4, r.Xyd);
|
|
@@ -1645,12 +1581,12 @@ begin
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
class procedure TEd25519.ScalarMultBase(const k: TCryptoLibByteArray;
|
|
class procedure TEd25519.ScalarMultBase(const k: TCryptoLibByteArray;
|
|
|
- const r: IPointAccum);
|
|
|
|
|
|
|
+ var r: TPointAccum);
|
|
|
var
|
|
var
|
|
|
n: TCryptoLibUInt32Array;
|
|
n: TCryptoLibUInt32Array;
|
|
|
w, c1, c2: UInt32;
|
|
w, c1, c2: UInt32;
|
|
|
i, cOff, b, LSign, abs: Int32;
|
|
i, cOff, b, LSign, abs: Int32;
|
|
|
- p: IPointPrecomp;
|
|
|
|
|
|
|
+ p: TPointPrecomp;
|
|
|
begin
|
|
begin
|
|
|
Precompute();
|
|
Precompute();
|
|
|
|
|
|
|
@@ -1673,7 +1609,7 @@ begin
|
|
|
n[i] := TInterleave.Shuffle2(n[i]);
|
|
n[i] := TInterleave.Shuffle2(n[i]);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
- p := TPointPrecomp.Create();
|
|
|
|
|
|
|
+ p := TPointPrecomp.CreatePointPrecomp();
|
|
|
|
|
|
|
|
cOff := (PrecompSpacing - 1) * PrecompTeeth;
|
|
cOff := (PrecompSpacing - 1) * PrecompTeeth;
|
|
|
while true do
|
|
while true do
|
|
@@ -1710,23 +1646,23 @@ class procedure TEd25519.ScalarMultBaseYZ(const k: TCryptoLibByteArray;
|
|
|
kOff: Int32; const Y, Z: TCryptoLibInt32Array);
|
|
kOff: Int32; const Y, Z: TCryptoLibInt32Array);
|
|
|
var
|
|
var
|
|
|
n: TCryptoLibByteArray;
|
|
n: TCryptoLibByteArray;
|
|
|
- p: IPointAccum;
|
|
|
|
|
|
|
+ p: TPointAccum;
|
|
|
begin
|
|
begin
|
|
|
System.SetLength(n, ScalarBytes);
|
|
System.SetLength(n, ScalarBytes);
|
|
|
PruneScalar(k, kOff, n);
|
|
PruneScalar(k, kOff, n);
|
|
|
|
|
|
|
|
- p := TPointAccum.Create();
|
|
|
|
|
|
|
+ p := TPointAccum.CreatePointAccum();
|
|
|
ScalarMultBase(n, p);
|
|
ScalarMultBase(n, p);
|
|
|
TX25519Field.Copy(p.Y, 0, Y, 0);
|
|
TX25519Field.Copy(p.Y, 0, Y, 0);
|
|
|
TX25519Field.Copy(p.Z, 0, Z, 0);
|
|
TX25519Field.Copy(p.Z, 0, Z, 0);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
class procedure TEd25519.ScalarMultStraussVar(const nb,
|
|
class procedure TEd25519.ScalarMultStraussVar(const nb,
|
|
|
- np: TCryptoLibUInt32Array; const p: IPointExt; const r: IPointAccum);
|
|
|
|
|
|
|
+ np: TCryptoLibUInt32Array; var p: TPointExt; var r: TPointAccum);
|
|
|
var
|
|
var
|
|
|
width, bit, wb, wp, LSign, index: Int32;
|
|
width, bit, wb, wp, LSign, index: Int32;
|
|
|
ws_b, ws_p: TCryptoLibShortIntArray;
|
|
ws_b, ws_p: TCryptoLibShortIntArray;
|
|
|
- tp: TCryptoLibGenericArray<IPointExt>;
|
|
|
|
|
|
|
+ tp: TCryptoLibGenericArray<TPointExt>;
|
|
|
begin
|
|
begin
|
|
|
Precompute();
|
|
Precompute();
|
|
|
|
|
|