Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.CurveEdArith

This unit follows the pattern of StreamSec.DSI.CurveXArith (RFC 7748) but is
  deliberately self-contained: the field arithmetic over GF(2^255-19) and
  GF(2^448-2^224-1) is replicated here rather than imported.

  Scalar multiplication uses a Montgomery-ladder schedule over the COMPLETE
  twisted-Edwards (Ed25519, extended coordinates) / Edwards (Ed448, projective
  coordinates) addition formulas: a fixed trip count with one point addition,
  one point doubling and two branchless conditional swaps per scalar bit - no
  secret-dependent branches or memory indices.

  This unit contains the CURVE ARITHMETIC only. The RFC 8032 signature and
  verification schemes (hashing, key derivation, dom4) are implemented by
  tDSIEdDSA in StreamSec.DSI.EdDSA (obtain that pool via GetDSIED).

  The curve classes plug into the same group framework as the fixed-time
  ECDSA scheme (dlssaDSAFixedTime): the points implement iGroupElement with
  FixedGroupOpIteration, which here delegates to the (already constant-time)
  ladder.

Classes, interfaces and records

recordtFe25519

GF(2^255-19) field element, 8 x 32 bit little endian limbs

class procedure InvModTo(const aA: tFe25519; var aResult: tFe25519); static; class procedure PowP58To(const aA: tFe25519; var aResult: tFe25519); static;
aResult := aA^((p-5)/8) = aA^(2^252-3); used for the decompression root
class procedure Swap(var aA, aB: tFe25519; aBit: NativeUInt); static; class function Same(const aA, aB: tFe25519): Boolean; static; procedure Normalize;
Reduce to the canonical representative 0 <= Self < p (branchless)
function IsZero: Boolean;
canonical representative assumed
function IsOdd: NativeUInt;

recordtEdScalar25519

Ed25519 scalar, 8 x 32 bit little endian limbs (256 bits)

procedure Clear;
wipe the scalar (secret hygiene)
procedure Clamp;
RFC 8032 5.1.5 clamping of the secret scalar
function GetBit(aIndex: Integer): NativeUInt;

recordtGe25519

Ed25519 group element in extended homogeneous coordinates (X:Y:Z:T), x = X/Z, y = Y/Z, x*y = T/Z on -x^2+y^2 = 1+d*x^2*y^2

procedure SetNeutral; procedure FromAffine(const aX, aY: tFe25519); procedure ToAffineTo(var aX, aY: tFe25519); class procedure AddTo(const aA, aB: tGe25519; var aResult: tGe25519); static;
Complete addition (add-2008-hwcd-3 with k = 2d); no exceptional cases
class procedure DoubleTo(const aA: tGe25519; var aResult: tGe25519); static; class procedure Swap(var aA, aB: tGe25519; aBit: NativeUInt); static; class procedure ScalarMultTo(const aK: tEdScalar25519; const aP: tGe25519; var aResult: tGe25519); static;
Montgomery-ladder schedule: fixed 256 iterations, one add + one double + two branchless swaps per bit. aK is used as-is (clamp explicitly first where RFC 8032 requires it).
function Encode: tBytes;
RFC 8032 5.1.2 (32 bytes)
function Decode(const aEnc: tBytes): Boolean;
RFC 8032 5.1.3

recordtFeWide448

GF(2^448-2^224-1) field element, 14 x 32 bit little endian limbs

(no public members)

recordtFe448

class procedure InvModTo(const aA: tFe448; var aResult: tFe448); static; class procedure PowP34To(const aA: tFe448; var aResult: tFe448); static;
aResult := aA^((p-3)/4) = aA^(2^446-2^222-1); used for the decompression root
class procedure Swap(var aA, aB: tFe448; aBit: NativeUInt); static; class function Same(const aA, aB: tFe448): Boolean; static; procedure Normalize; function IsZero: Boolean; function IsOdd: NativeUInt;

recordtEdScalar448

Ed448 scalar, 14 x 32 bit little endian limbs (448 bits; byte 56 of the 57-byte RFC 8032 secret scalar is always zero after clamping)

procedure Clear;
wipe the scalar (secret hygiene)
procedure Clamp;
RFC 8032 5.2.5 clamping of the secret scalar
function GetBit(aIndex: Integer): NativeUInt;

recordtGe448

Ed448 group element in projective coordinates (X:Y:Z), x = X/Z, y = Y/Z on x^2+y^2 = 1+d*x^2*y^2 (a = 1, d = -39081; the addition law is complete)

procedure SetNeutral; procedure FromAffine(const aX, aY: tFe448); procedure ToAffineTo(var aX, aY: tFe448); class procedure AddTo(const aA, aB: tGe448; var aResult: tGe448); static; class procedure DoubleTo(const aA: tGe448; var aResult: tGe448); static; class procedure Swap(var aA, aB: tGe448; aBit: NativeUInt); static; class procedure ScalarMultTo(const aK: tEdScalar448; const aP: tGe448; var aResult: tGe448); static;
Montgomery-ladder schedule: fixed 448 iterations, branchless
function Encode: tBytes;
RFC 8032 5.2.2 (57 bytes)
function Decode(const aEnc: tBytes): Boolean;
RFC 8032 5.2.3

interfaceiEdDsaCurveInternal

function GroupOpIteration(const aGenerator : iGroupElement; const aIterationCount: iDSInteger; var aResult) : Boolean; procedure GroupOperation(const aFactor1: iGroupElement; const aFactor2: iGroupElement; var aDest); function GroupElementToInteger(const aElement: iGroupElement; var aResult : iDSInteger) : Boolean; function PointOnCurve(const aElement: iGroupElement): Boolean;

classtCustomEdDsaCurve

inherits from tCustomECurve

implements iEdDsaCurveInternal, iGroup

(no public members)

classtCustomEdDsaPointImpl

inherits from tECPointImpl

implements iGroupElement

(no public members)

classtEdDsaPointContained

inherits from tCustomEdDsaPointImpl

implements IUnknown, iGroupElement, iECPoint, iECPointInternal

constructor Create(const aCurve: iECurve);

classtEdDsaPointRefCounted

inherits from tCustomEdDsaPointImpl

implements IUnknown, iGroupElement, iECPoint, iECPointInternal

constructor Create(const aCurve: iECurve); procedure AfterConstruction; override; class function NewInstance: TObject{$IFDEF AUTOREFCOUNT} unsafe {$ENDIF}; override;

classtECurveEd25519

inherits from tCustomEdDsaCurve

implements IECurve

class function IsCurve(ACurve: iECurve): Boolean; override;

classtECurveEd448

inherits from tCustomEdDsaCurve

implements IECurve

class function IsCurve(ACurve: iECurve): Boolean; override;

Routines