Browse Source

some minor refactorings.

Ugochukwu Mmaduekwe 7 years ago
parent
commit
ae0a37dc6e

+ 6 - 4
CryptoLib/src/Crypto/Signers/ClpECDsaSigner.pas

@@ -39,6 +39,7 @@ uses
   ClpRandomDsaKCalculator,
   ClpRandomDsaKCalculator,
   ClpIECKeyParameters,
   ClpIECKeyParameters,
   ClpIDsaKCalculator,
   ClpIDsaKCalculator,
+  ClpECCurveConstants,
   ClpIDsaExt,
   ClpIDsaExt,
   ClpIECDsaSigner;
   ClpIECDsaSigner;
 
 
@@ -229,14 +230,15 @@ function TECDsaSigner.GetDenominator(coordinateSystem: Int32; const p: IECPoint)
   : IECFieldElement;
   : IECFieldElement;
 begin
 begin
   case (coordinateSystem) of
   case (coordinateSystem) of
-    TECCurve.COORD_HOMOGENEOUS, TECCurve.COORD_LAMBDA_PROJECTIVE,
-      TECCurve.COORD_SKEWED:
+    TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE, TECCurveConstants.COORD_SKEWED:
       begin
       begin
         Result := p.GetZCoord(0);
         Result := p.GetZCoord(0);
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN, TECCurve.COORD_JACOBIAN_CHUDNOVSKY,
-      TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN,
+      TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+      TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         Result := p.GetZCoord(0).Square();
         Result := p.GetZCoord(0).Square();
       end
       end

+ 98 - 89
CryptoLib/src/Math/EC/ClpECC.pas

@@ -42,12 +42,12 @@ uses
   ClpWTauNafMultiplier,
   ClpWTauNafMultiplier,
   ClpFiniteFields,
   ClpFiniteFields,
   ClpSetWeakRef,
   ClpSetWeakRef,
+  ClpECCurveConstants,
   ClpTnaf,
   ClpTnaf,
   ClpValidityPrecompInfo,
   ClpValidityPrecompInfo,
   ClpIValidityPrecompInfo,
   ClpIValidityPrecompInfo,
   ClpIECC,
   ClpIECC,
   ClpIFiniteField,
   ClpIFiniteField,
-  ClpECCurveConstants,
   ClpIPreCompInfo;
   ClpIPreCompInfo;
 
 
 resourcestring
 resourcestring
@@ -533,18 +533,8 @@ type
 
 
   public
   public
 
 
-    const
-
-    COORD_AFFINE = Int32(0);
-    COORD_HOMOGENEOUS = Int32(1);
-    COORD_JACOBIAN = Int32(2);
-    COORD_JACOBIAN_CHUDNOVSKY = Int32(3);
-    COORD_JACOBIAN_MODIFIED = Int32(4);
-    COORD_LAMBDA_AFFINE = Int32(5);
-    COORD_LAMBDA_PROJECTIVE = Int32(6);
-    COORD_SKEWED = Int32(7);
+    type
 
 
-  type
     TConfig = class(TInterfacedObject, IConfig)
     TConfig = class(TInterfacedObject, IConfig)
 
 
     strict protected
     strict protected
@@ -763,7 +753,7 @@ type
 
 
   strict private
   strict private
   const
   const
-    FP_DEFAULT_COORDS = Int32(TECCurve.COORD_JACOBIAN_MODIFIED);
+    FP_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_JACOBIAN_MODIFIED);
 
 
   strict protected
   strict protected
   var
   var
@@ -878,7 +868,7 @@ type
 
 
   strict private
   strict private
   const
   const
-    F2M_DEFAULT_COORDS = Int32(TECCurve.COORD_LAMBDA_PROJECTIVE);
+    F2M_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_LAMBDA_PROJECTIVE);
 
 
   var
   var
     // /**
     // /**
@@ -2770,9 +2760,12 @@ end;
 
 
 class function TECCurve.GetAllCoordinateSystems: TCryptoLibInt32Array;
 class function TECCurve.GetAllCoordinateSystems: TCryptoLibInt32Array;
 begin
 begin
-  result := TCryptoLibInt32Array.Create(COORD_AFFINE, COORD_HOMOGENEOUS,
-    COORD_JACOBIAN, COORD_JACOBIAN_CHUDNOVSKY, COORD_JACOBIAN_MODIFIED,
-    COORD_LAMBDA_AFFINE, COORD_LAMBDA_PROJECTIVE, COORD_SKEWED);
+  result := TCryptoLibInt32Array.Create(TECCurveConstants.COORD_AFFINE,
+    TECCurveConstants.COORD_HOMOGENEOUS, TECCurveConstants.COORD_JACOBIAN,
+    TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED,
+    TECCurveConstants.COORD_LAMBDA_AFFINE,
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE, TECCurveConstants.COORD_SKEWED);
 end;
 end;
 
 
 function TECCurve.GetB: IECFieldElement;
 function TECCurve.GetB: IECFieldElement;
@@ -2884,7 +2877,7 @@ var
 begin
 begin
   CheckPoints(points, off, len);
   CheckPoints(points, off, len);
   case CoordinateSystem of
   case CoordinateSystem of
-    COORD_AFFINE, COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         if (iso <> Nil) then
         if (iso <> Nil) then
         begin
         begin
@@ -2984,7 +2977,7 @@ end;
 
 
 function TECCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TECCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
-  result := coord = COORD_AFFINE;
+  result := coord = TECCurveConstants.COORD_AFFINE;
 end;
 end;
 
 
 function TECCurve.ValidatePoint(const x, y: TBigInteger;
 function TECCurve.ValidatePoint(const x, y: TBigInteger;
@@ -3203,11 +3196,14 @@ end;
 
 
 function TFpCurve.ImportPoint(const P: IECPoint): IECPoint;
 function TFpCurve.ImportPoint(const P: IECPoint): IECPoint;
 begin
 begin
-  if ((Self as IECCurve <> P.curve) and (CoordinateSystem = COORD_JACOBIAN) and
-    (not P.IsInfinity)) then
+  if ((Self as IECCurve <> P.curve) and
+    (CoordinateSystem = TECCurveConstants.COORD_JACOBIAN) and (not P.IsInfinity))
+  then
   begin
   begin
     case P.curve.CoordinateSystem of
     case P.curve.CoordinateSystem of
-      COORD_JACOBIAN, COORD_JACOBIAN_CHUDNOVSKY, COORD_JACOBIAN_MODIFIED:
+      TECCurveConstants.COORD_JACOBIAN,
+        TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+        TECCurveConstants.COORD_JACOBIAN_MODIFIED:
         begin
         begin
           result := TFpPoint.Create(Self as IECCurve,
           result := TFpPoint.Create(Self as IECCurve,
             FromBigInteger(P.RawXCoord.ToBigInteger()),
             FromBigInteger(P.RawXCoord.ToBigInteger()),
@@ -3225,7 +3221,9 @@ end;
 function TFpCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TFpCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_AFFINE, COORD_HOMOGENEOUS, COORD_JACOBIAN, COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_JACOBIAN,
+      TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := true;
         result := true;
       end
       end
@@ -3285,7 +3283,8 @@ begin
   LY := FromBigInteger(y);
   LY := FromBigInteger(y);
 
 
   case CoordinateSystem of
   case CoordinateSystem of
-    COORD_LAMBDA_AFFINE, COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         if (Lx.IsZero) then
         if (Lx.IsZero) then
         begin
         begin
@@ -3329,7 +3328,8 @@ begin
       end;
       end;
 
 
       case CoordinateSystem of
       case CoordinateSystem of
-        COORD_LAMBDA_AFFINE, COORD_LAMBDA_PROJECTIVE:
+        TECCurveConstants.COORD_LAMBDA_AFFINE,
+          TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
           begin
           begin
             yp := z.Add(xp);
             yp := z.Add(xp);
           end
           end
@@ -3611,7 +3611,8 @@ end;
 function TF2mCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TF2mCurve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_AFFINE, COORD_HOMOGENEOUS, COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         result := true;
         result := true;
       end
       end
@@ -3769,7 +3770,7 @@ begin
   end;
   end;
 
 
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_AFFINE, TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         result := Self;
         result := Self;
         Exit;
         Exit;
@@ -4053,7 +4054,7 @@ begin
   // Cope with null curve, most commonly used by implicitlyCa
   // Cope with null curve, most commonly used by implicitlyCa
   if curve = Nil then
   if curve = Nil then
   begin
   begin
-    coord := TECCurve.COORD_AFFINE;
+    coord := TECCurveConstants.COORD_AFFINE;
   end
   end
   else
   else
   begin
   begin
@@ -4061,7 +4062,7 @@ begin
   end;
   end;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE, TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         result := FEMPTY_ZS;
         result := FEMPTY_ZS;
         Exit;
         Exit;
@@ -4072,20 +4073,20 @@ begin
 
 
   case coord of
   case coord of
 
 
-    TECCurve.COORD_HOMOGENEOUS, TECCurve.COORD_JACOBIAN,
-      TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_HOMOGENEOUS, TECCurveConstants.COORD_JACOBIAN,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One);
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN_CHUDNOVSKY:
+    TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY:
       begin
       begin
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One, One, One);
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One, One, One);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One, curve.a);
         result := TCryptoLibGenericArray<IECFieldElement>.Create(One, curve.a);
         Exit;
         Exit;
@@ -4167,8 +4168,8 @@ var
 begin
 begin
   coord := CurveCoordinateSystem;
   coord := CurveCoordinateSystem;
 
 
-  result := (coord = TECCurve.COORD_AFFINE) or
-    (coord = TECCurve.COORD_LAMBDA_AFFINE) or (IsInfinity) or
+  result := (coord = TECCurveConstants.COORD_AFFINE) or
+    (coord = TECCurveConstants.COORD_LAMBDA_AFFINE) or (IsInfinity) or
     (RawZCoords[0].IsOne);
     (RawZCoords[0].IsOne);
 end;
 end;
 
 
@@ -4187,14 +4188,16 @@ var
   zInv2, zInv3: IECFieldElement;
   zInv2, zInv3: IECFieldElement;
 begin
 begin
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_HOMOGENEOUS, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         result := CreateScaledPoint(zInv, zInv);
         result := CreateScaledPoint(zInv, zInv);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN, TECCurve.COORD_JACOBIAN_CHUDNOVSKY,
-      TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN,
+      TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+      TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         zInv2 := zInv.Square();
         zInv2 := zInv.Square();
         zInv3 := zInv2.Multiply(zInv);
         zInv3 := zInv2.Multiply(zInv);
@@ -4232,7 +4235,7 @@ begin
   // Cope with null curve, most commonly used by implicitlyCa
   // Cope with null curve, most commonly used by implicitlyCa
   if Fm_curve = Nil then
   if Fm_curve = Nil then
   begin
   begin
-    result := TECCurve.COORD_AFFINE;
+    result := TECCurveConstants.COORD_AFFINE;
   end
   end
   else
   else
   begin
   begin
@@ -4302,7 +4305,7 @@ begin
   x2 := b.RawXCoord;
   x2 := b.RawXCoord;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         Y2 := b.RawYCoord;
         Y2 := b.RawYCoord;
@@ -4329,7 +4332,7 @@ begin
         result := TF2mPoint.Create(ecCurve, x3, Y3, IsCompressed);
         result := TF2mPoint.Create(ecCurve, x3, Y3, IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
@@ -4407,7 +4410,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         if (x1.IsZero) then
         if (x1.IsZero) then
         begin
         begin
@@ -4555,7 +4558,8 @@ begin
   LY := RawYCoord;
   LY := RawYCoord;
 
 
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_LAMBDA_AFFINE, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         // Y is actually Lambda (X + Y/X) here
         // Y is actually Lambda (X + Y/X) here
         result := LY.TestBitZero() <> Lx.TestBitZero();
         result := LY.TestBitZero() <> Lx.TestBitZero();
@@ -4577,7 +4581,8 @@ begin
   coord := CurveCoordinateSystem;
   coord := CurveCoordinateSystem;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_LAMBDA_AFFINE, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         Lx := RawXCoord;
         Lx := RawXCoord;
         L := RawYCoord;
         L := RawYCoord;
@@ -4590,7 +4595,7 @@ begin
 
 
         // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly
         // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly
         LY := L.Add(Lx).Multiply(Lx);
         LY := L.Add(Lx).Multiply(Lx);
-        if (TECCurve.COORD_LAMBDA_PROJECTIVE = coord) then
+        if (TECCurveConstants.COORD_LAMBDA_PROJECTIVE = coord) then
         begin
         begin
           z := RawZCoords[0];
           z := RawZCoords[0];
           if (not z.IsOne) then
           if (not z.IsOne) then
@@ -4632,14 +4637,14 @@ begin
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         bigY := RawYCoord;
         bigY := RawYCoord;
         result := TF2mPoint.Create(ecCurve, Lx, bigY.Add(Lx), IsCompressed);
         result := TF2mPoint.Create(ecCurve, Lx, bigY.Add(Lx), IsCompressed);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         LY := RawYCoord;
         LY := RawYCoord;
         z := RawZCoords[0];
         z := RawZCoords[0];
@@ -4648,14 +4653,14 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         L := RawYCoord;
         L := RawYCoord;
         result := TF2mPoint.Create(ecCurve, Lx, L.AddOne(), IsCompressed);
         result := TF2mPoint.Create(ecCurve, Lx, L.AddOne(), IsCompressed);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         // L is actually Lambda (X + Y/X) here
         // L is actually Lambda (X + Y/X) here
         L := RawYCoord;
         L := RawYCoord;
@@ -4701,7 +4706,7 @@ begin
 
 
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
 
 
@@ -4713,7 +4718,7 @@ begin
         result := TF2mPoint.Create(ecCurve, x3, Y3, IsCompressed);
         result := TF2mPoint.Create(ecCurve, x3, Y3, IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
@@ -4753,7 +4758,7 @@ begin
           TCryptoLibGenericArray<IECFieldElement>.Create(Z3), IsCompressed);
           TCryptoLibGenericArray<IECFieldElement>.Create(Z3), IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         L1 := RawYCoord;
         L1 := RawYCoord;
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
@@ -4889,7 +4894,7 @@ begin
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
 
 
         // NOTE: twicePlus() only optimized for lambda-affine argument
         // NOTE: twicePlus() only optimized for lambda-affine argument
@@ -5061,12 +5066,12 @@ begin
   lhs := LY.Square();
   lhs := LY.Square();
 
 
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         // do nothing
         // do nothing
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         z := RawZCoords[0];
         z := RawZCoords[0];
         if (not z.IsOne) then
         if (not z.IsOne) then
@@ -5079,8 +5084,9 @@ begin
         end;
         end;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN, TECCurve.COORD_JACOBIAN_CHUDNOVSKY,
-      TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN,
+      TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+      TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         z := RawZCoords[0];
         z := RawZCoords[0];
         if (not z.IsOne) then
         if (not z.IsOne) then
@@ -5155,7 +5161,7 @@ begin
   Y2 := b.RawYCoord;
   Y2 := b.RawYCoord;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
 
 
         dx := x2.Subtract(x1);
         dx := x2.Subtract(x1);
@@ -5182,7 +5188,7 @@ begin
         result := TFpPoint.Create(curve, x3, Y3, IsCompressed);
         result := TFpPoint.Create(curve, x3, Y3, IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
         Z2 := b.RawZCoords[0];
         Z2 := b.RawZCoords[0];
@@ -5274,7 +5280,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN, TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN, TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
         Z2 := b.RawZCoords[0];
         Z2 := b.RawZCoords[0];
@@ -5400,7 +5406,7 @@ begin
           end;
           end;
         end;
         end;
 
 
-        if (coord = TECCurve.COORD_JACOBIAN_MODIFIED) then
+        if (coord = TECCurveConstants.COORD_JACOBIAN_MODIFIED) then
         begin
         begin
           // TODO If the result will only be used in a subsequent addition, we don't need W3
           // TODO If the result will only be used in a subsequent addition, we don't need W3
           W3 := CalculateJacobianModifiedW(Z3, Z3Squared);
           W3 := CalculateJacobianModifiedW(Z3, Z3Squared);
@@ -5525,8 +5531,8 @@ end;
 
 
 function TFpPoint.GetZCoord(index: Int32): IECFieldElement;
 function TFpPoint.GetZCoord(index: Int32): IECFieldElement;
 begin
 begin
-  if ((index = 1) and (TECCurve.COORD_JACOBIAN_MODIFIED = CurveCoordinateSystem))
-  then
+  if ((index = 1) and (TECCurveConstants.COORD_JACOBIAN_MODIFIED =
+    CurveCoordinateSystem)) then
   begin
   begin
     result := GetJacobianModifiedW();
     result := GetJacobianModifiedW();
     Exit;
     Exit;
@@ -5549,7 +5555,7 @@ begin
   Lcurve := curve;
   Lcurve := curve;
   coord := Lcurve.CoordinateSystem;
   coord := Lcurve.CoordinateSystem;
 
 
-  if (TECCurve.COORD_AFFINE <> coord) then
+  if (TECCurveConstants.COORD_AFFINE <> coord) then
   begin
   begin
     result := TFpPoint.Create(Lcurve, RawXCoord, RawYCoord.Negate(), RawZCoords,
     result := TFpPoint.Create(Lcurve, RawXCoord, RawYCoord.Negate(), RawZCoords,
       IsCompressed);
       IsCompressed);
@@ -5588,7 +5594,7 @@ begin
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
 
 
         x1 := RawXCoord;
         x1 := RawXCoord;
@@ -5615,7 +5621,7 @@ begin
         result := TFpPoint.Create(curve, X4, Y4, IsCompressed);
         result := TFpPoint.Create(curve, X4, Y4, IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := TwiceJacobianModified(false).Add(Self);
         result := TwiceJacobianModified(false).Add(Self);
         Exit;
         Exit;
@@ -5677,19 +5683,19 @@ begin
   if (not Z1.IsOne) then
   if (not Z1.IsOne) then
   begin
   begin
     case coord of
     case coord of
-      TECCurve.COORD_HOMOGENEOUS:
+      TECCurveConstants.COORD_HOMOGENEOUS:
         begin
         begin
           Z1Sq := Z1.Square();
           Z1Sq := Z1.Square();
           x1 := x1.Multiply(Z1);
           x1 := x1.Multiply(Z1);
           Y1 := Y1.Multiply(Z1Sq);
           Y1 := Y1.Multiply(Z1Sq);
           W1 := CalculateJacobianModifiedW(Z1, Z1Sq);
           W1 := CalculateJacobianModifiedW(Z1, Z1Sq);
         end;
         end;
-      TECCurve.COORD_JACOBIAN:
+      TECCurveConstants.COORD_JACOBIAN:
         begin
         begin
           W1 := CalculateJacobianModifiedW(Z1, Nil);
           W1 := CalculateJacobianModifiedW(Z1, Nil);
         end;
         end;
 
 
-      TECCurve.COORD_JACOBIAN_MODIFIED:
+      TECCurveConstants.COORD_JACOBIAN_MODIFIED:
         begin
         begin
           W1 := GetJacobianModifiedW();
           W1 := GetJacobianModifiedW();
         end;
         end;
@@ -5735,7 +5741,7 @@ begin
   end;
   end;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         zInv := Z1.Invert();
         zInv := Z1.Invert();
         zInv2 := zInv.Square();
         zInv2 := zInv.Square();
@@ -5746,7 +5752,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         x1 := x1.Multiply(Z1);
         x1 := x1.Multiply(Z1);
         Z1 := Z1.Multiply(Z1.Square());
         Z1 := Z1.Multiply(Z1.Square());
@@ -5754,14 +5760,14 @@ begin
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1), IsCompressed);
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1), IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       begin
       begin
         result := TFpPoint.Create(ecCurve, x1, Y1,
         result := TFpPoint.Create(ecCurve, x1, Y1,
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1), IsCompressed);
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1), IsCompressed);
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := TFpPoint.Create(ecCurve, x1, Y1,
         result := TFpPoint.Create(ecCurve, x1, Y1,
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1, W1), IsCompressed);
           TCryptoLibGenericArray<IECFieldElement>.Create(Z1, W1), IsCompressed);
@@ -5806,7 +5812,7 @@ begin
   x1 := RawXCoord;
   x1 := RawXCoord;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         X1Squared := x1.Square();
         X1Squared := x1.Square();
         gamma := Three(X1Squared).Add(curve.a).Divide(Two(Y1));
         gamma := Three(X1Squared).Add(curve.a).Divide(Two(Y1));
@@ -5817,7 +5823,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS:
+    TECCurveConstants.COORD_HOMOGENEOUS:
       begin
       begin
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
 
 
@@ -5874,7 +5880,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       begin
       begin
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
 
 
@@ -5951,7 +5957,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := TwiceJacobianModified(true);
         result := TwiceJacobianModified(true);
         Exit;
         Exit;
@@ -6041,7 +6047,7 @@ begin
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE:
+    TECCurveConstants.COORD_AFFINE:
       begin
       begin
         x1 := RawXCoord;
         x1 := RawXCoord;
         x2 := b.RawXCoord;
         x2 := b.RawXCoord;
@@ -6088,7 +6094,7 @@ begin
         result := TFpPoint.Create(curve, X4, Y4, IsCompressed);
         result := TFpPoint.Create(curve, X4, Y4, IsCompressed);
         Exit;
         Exit;
       end;
       end;
-    TECCurve.COORD_JACOBIAN_MODIFIED:
+    TECCurveConstants.COORD_JACOBIAN_MODIFIED:
       begin
       begin
         result := TwiceJacobianModified(false).Add(b);
         result := TwiceJacobianModified(false).Add(b);
         Exit;
         Exit;
@@ -6141,7 +6147,7 @@ begin
   b := ecCurve.b;
   b := ecCurve.b;
 
 
   coord := ecCurve.CoordinateSystem;
   coord := ecCurve.CoordinateSystem;
-  if (coord = TECCurve.COORD_LAMBDA_PROJECTIVE) then
+  if (coord = TECCurveConstants.COORD_LAMBDA_PROJECTIVE) then
   begin
   begin
     z := RawZCoords[0];
     z := RawZCoords[0];
     ZIsOne := z.IsOne;
     ZIsOne := z.IsOne;
@@ -6182,12 +6188,12 @@ begin
     lhs := LY.Add(x).Multiply(LY);
     lhs := LY.Add(x).Multiply(LY);
 
 
     case coord of
     case coord of
-      TECCurve.COORD_AFFINE:
+      TECCurveConstants.COORD_AFFINE:
         begin
         begin
           // do nothing;
           // do nothing;
         end;
         end;
 
 
-      TECCurve.COORD_HOMOGENEOUS:
+      TECCurveConstants.COORD_HOMOGENEOUS:
         begin
         begin
           z := RawZCoords[0];
           z := RawZCoords[0];
           if (not z.IsOne) then
           if (not z.IsOne) then
@@ -6275,7 +6281,7 @@ begin
   end;
   end;
 
 
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         // Y is actually Lambda (X + Y/X) here
         // Y is actually Lambda (X + Y/X) here
         Lx := RawXCoord;
         Lx := RawXCoord;
@@ -6288,7 +6294,7 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         // Y is actually Lambda (X + Y/X) here
         // Y is actually Lambda (X + Y/X) here
         Lx := RawXCoord;
         Lx := RawXCoord;
@@ -6324,7 +6330,8 @@ begin
   end;
   end;
 
 
   case CurveCoordinateSystem of
   case CurveCoordinateSystem of
-    TECCurve.COORD_LAMBDA_AFFINE, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_AFFINE,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         Lx := RawXCoord;
         Lx := RawXCoord;
         L := RawYCoord;
         L := RawYCoord;
@@ -6372,7 +6379,7 @@ begin
   x1 := RawXCoord;
   x1 := RawXCoord;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE, TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         result := ecCurve.CreateRawPoint(x1.Square(), Y1.Square(), IsCompressed)
         result := ecCurve.CreateRawPoint(x1.Square(), Y1.Square(), IsCompressed)
@@ -6380,7 +6387,8 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];
@@ -6417,7 +6425,7 @@ begin
   x1 := RawXCoord;
   x1 := RawXCoord;
 
 
   case coord of
   case coord of
-    TECCurve.COORD_AFFINE, TECCurve.COORD_LAMBDA_AFFINE:
+    TECCurveConstants.COORD_AFFINE, TECCurveConstants.COORD_LAMBDA_AFFINE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         result := ecCurve.CreateRawPoint(x1.SquarePow(pow), Y1.SquarePow(pow),
         result := ecCurve.CreateRawPoint(x1.SquarePow(pow), Y1.SquarePow(pow),
@@ -6425,7 +6433,8 @@ begin
         Exit;
         Exit;
       end;
       end;
 
 
-    TECCurve.COORD_HOMOGENEOUS, TECCurve.COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_HOMOGENEOUS,
+      TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       begin
       begin
         Y1 := RawYCoord;
         Y1 := RawYCoord;
         Z1 := RawZCoords[0];
         Z1 := RawZCoords[0];

+ 3 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256K1Custom.pas

@@ -31,6 +31,7 @@ uses
   ClpBigInteger,
   ClpBigInteger,
   ClpArrayUtils,
   ClpArrayUtils,
   ClpCryptoLibTypes,
   ClpCryptoLibTypes,
+  ClpECCurveConstants,
   ClpIECC,
   ClpIECC,
   ClpISecP256K1Custom;
   ClpISecP256K1Custom;
 
 
@@ -233,7 +234,7 @@ type
     end;
     end;
 
 
   const
   const
-    SECP256K1_DEFAULT_COORDS = Int32(TECCurve.COORD_JACOBIAN);
+    SECP256K1_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_JACOBIAN);
     SECP256K1_FE_INTS = Int32(8);
     SECP256K1_FE_INTS = Int32(8);
 
 
   var
   var
@@ -1115,7 +1116,7 @@ end;
 function TSecP256K1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TSecP256K1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       result := true
       result := true
   else
   else
     result := false;
     result := false;

+ 3 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256R1Custom.pas

@@ -31,6 +31,7 @@ uses
   ClpBigInteger,
   ClpBigInteger,
   ClpArrayUtils,
   ClpArrayUtils,
   ClpCryptoLibTypes,
   ClpCryptoLibTypes,
+  ClpECCurveConstants,
   ClpIECC,
   ClpIECC,
   ClpISecP256R1Custom;
   ClpISecP256R1Custom;
 
 
@@ -234,7 +235,7 @@ type
     end;
     end;
 
 
   const
   const
-    SECP256R1_DEFAULT_COORDS = Int32(TECCurve.COORD_JACOBIAN);
+    SECP256R1_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_JACOBIAN);
     SECP256R1_FE_INTS = Int32(8);
     SECP256R1_FE_INTS = Int32(8);
 
 
   var
   var
@@ -1258,7 +1259,7 @@ end;
 function TSecP256R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TSecP256R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       result := true
       result := true
   else
   else
     result := false;
     result := false;

+ 3 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP384R1Custom.pas

@@ -31,6 +31,7 @@ uses
   ClpBigInteger,
   ClpBigInteger,
   ClpArrayUtils,
   ClpArrayUtils,
   ClpCryptoLibTypes,
   ClpCryptoLibTypes,
+  ClpECCurveConstants,
   ClpIECC,
   ClpIECC,
   ClpISecP384R1Custom;
   ClpISecP384R1Custom;
 
 
@@ -232,7 +233,7 @@ type
     end;
     end;
 
 
   const
   const
-    SECP384R1_DEFAULT_COORDS = Int32(TECCurve.COORD_JACOBIAN);
+    SECP384R1_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_JACOBIAN);
     SECP384R1_FE_INTS = Int32(12);
     SECP384R1_FE_INTS = Int32(12);
 
 
   var
   var
@@ -1266,7 +1267,7 @@ end;
 function TSecP384R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TSecP384R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       result := true
       result := true
   else
   else
     result := false;
     result := false;

+ 3 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP521R1Custom.pas

@@ -32,6 +32,7 @@ uses
   ClpArrayUtils,
   ClpArrayUtils,
   ClpIECC,
   ClpIECC,
   ClpCryptoLibTypes,
   ClpCryptoLibTypes,
+  ClpECCurveConstants,
   ClpISecP521R1Custom;
   ClpISecP521R1Custom;
 
 
 resourcestring
 resourcestring
@@ -229,7 +230,7 @@ type
     end;
     end;
 
 
   const
   const
-    SECP521R1_DEFAULT_COORDS = Int32(TECCurve.COORD_JACOBIAN);
+    SECP521R1_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_JACOBIAN);
     SECP521R1_FE_INTS = Int32(17);
     SECP521R1_FE_INTS = Int32(17);
 
 
   var
   var
@@ -1059,7 +1060,7 @@ end;
 function TSecP521R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TSecP521R1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_JACOBIAN:
+    TECCurveConstants.COORD_JACOBIAN:
       result := true
       result := true
   else
   else
     result := false;
     result := false;

+ 3 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecT283Custom.pas

@@ -33,6 +33,7 @@ uses
   ClpIECC,
   ClpIECC,
   ClpWTauNafMultiplier,
   ClpWTauNafMultiplier,
   ClpCryptoLibTypes,
   ClpCryptoLibTypes,
+  ClpECCurveConstants,
   ClpISecT283Custom;
   ClpISecT283Custom;
 
 
 resourcestring
 resourcestring
@@ -271,7 +272,7 @@ type
     end;
     end;
 
 
   const
   const
-    SECT283K1_DEFAULT_COORDS = Int32(TECCurve.COORD_LAMBDA_PROJECTIVE);
+    SECT283K1_DEFAULT_COORDS = Int32(TECCurveConstants.COORD_LAMBDA_PROJECTIVE);
     SECT283K1_FE_LONGS = Int32(5);
     SECT283K1_FE_LONGS = Int32(5);
 
 
     function GetM: Int32; inline;
     function GetM: Int32; inline;
@@ -1520,7 +1521,7 @@ end;
 function TSecT283K1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 function TSecT283K1Curve.SupportsCoordinateSystem(coord: Int32): Boolean;
 begin
 begin
   case coord of
   case coord of
-    COORD_LAMBDA_PROJECTIVE:
+    TECCurveConstants.COORD_LAMBDA_PROJECTIVE:
       result := true
       result := true
   else
   else
     result := false;
     result := false;