فهرست منبع

Fix circular dependence in custom curves

Ugochukwu Mmaduekwe 6 سال پیش
والد
کامیت
84159aa3e9

+ 4 - 13
CryptoLib/src/Math/EC/Custom/Djb/ClpCurve25519Custom.pas

@@ -267,8 +267,6 @@ type
   var
   var
     Fq: TBigInteger;
     Fq: TBigInteger;
 
 
-    class function GetCurve25519_Q: TBigInteger; static; inline;
-
   strict protected
   strict protected
   var
   var
     Fm_infinity: ICurve25519Point;
     Fm_infinity: ICurve25519Point;
@@ -300,8 +298,6 @@ type
     property Infinity: IECPoint read GetInfinity;
     property Infinity: IECPoint read GetInfinity;
     property FieldSize: Int32 read GetFieldSize;
     property FieldSize: Int32 read GetFieldSize;
 
 
-    class property Curve25519_Q: TBigInteger read GetCurve25519_Q;
-
   end;
   end;
 
 
 implementation
 implementation
@@ -601,7 +597,7 @@ end;
 
 
 class function TCurve25519FieldElement.GetQ: TBigInteger;
 class function TCurve25519FieldElement.GetQ: TBigInteger;
 begin
 begin
-  result := TCurve25519.Curve25519_Q;
+  result := TNat256.ToBigInteger(TCurve25519Field.P);
 end;
 end;
 
 
 class procedure TCurve25519FieldElement.Boot;
 class procedure TCurve25519FieldElement.Boot;
@@ -708,10 +704,10 @@ begin
     * Q == 8m + 5, so we use Pocklington's method for this case.
     * Q == 8m + 5, so we use Pocklington's method for this case.
     *
     *
     * First, raise this element to the exponent 2^252 - 2^1 (i.e. m + 1)
     * First, raise this element to the exponent 2^252 - 2^1 (i.e. m + 1)
-    * 
+    *
     * Breaking up the exponent's binary representation into "repunits", we get:
     * Breaking up the exponent's binary representation into "repunits", we get:
     * { 251 1s } { 1 0s }
     * { 251 1s } { 1 0s }
-    * 
+    *
     * Therefore we need an addition chain containing 251 (the lengths of the repunits)
     * Therefore we need an addition chain containing 251 (the lengths of the repunits)
     * We use: 1, 2, 3, 4, 7, 11, 15, 30, 60, 120, 131, [251]
     * We use: 1, 2, 3, 4, 7, 11, 15, 30, 60, 120, 131, [251]
   *)
   *)
@@ -1236,14 +1232,9 @@ end;
 
 
 { TCurve25519 }
 { TCurve25519 }
 
 
-class function TCurve25519.GetCurve25519_Q: TBigInteger;
-begin
-  result := TNat256.ToBigInteger(TCurve25519Field.P);
-end;
-
 constructor TCurve25519.Create;
 constructor TCurve25519.Create;
 begin
 begin
-  Fq := Curve25519_Q;
+  Fq := TCurve25519FieldElement.Q;
   Inherited Create(Fq);
   Inherited Create(Fq);
   Fm_infinity := TCurve25519Point.Create(Self as IECCurve, Nil, Nil);
   Fm_infinity := TCurve25519Point.Create(Self as IECCurve, Nil, Nil);
 
 

+ 4 - 13
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256K1Custom.pas

@@ -240,8 +240,6 @@ type
   var
   var
     Fq: TBigInteger;
     Fq: TBigInteger;
 
 
-    class function GetSecP256K1Curve_Q: TBigInteger; static; inline;
-
   strict protected
   strict protected
   var
   var
     Fm_infinity: ISecP256K1Point;
     Fm_infinity: ISecP256K1Point;
@@ -273,8 +271,6 @@ type
     property Infinity: IECPoint read GetInfinity;
     property Infinity: IECPoint read GetInfinity;
     property FieldSize: Int32 read GetFieldSize;
     property FieldSize: Int32 read GetFieldSize;
 
 
-    class property SecP256K1Curve_Q: TBigInteger read GetSecP256K1Curve_Q;
-
   end;
   end;
 
 
 implementation
 implementation
@@ -500,7 +496,9 @@ end;
 
 
 class function TSecP256K1FieldElement.GetQ: TBigInteger;
 class function TSecP256K1FieldElement.GetQ: TBigInteger;
 begin
 begin
-  result := TSecP256K1Curve.SecP256K1Curve_Q;
+  result := TBigInteger.Create(1,
+    THex.Decode
+    ('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F'));
 end;
 end;
 
 
 function TSecP256K1FieldElement.GetX: TCryptoLibUInt32Array;
 function TSecP256K1FieldElement.GetX: TCryptoLibUInt32Array;
@@ -1032,16 +1030,9 @@ end;
 
 
 { TSecP256K1Curve }
 { TSecP256K1Curve }
 
 
-class function TSecP256K1Curve.GetSecP256K1Curve_Q: TBigInteger;
-begin
-  result := TBigInteger.Create(1,
-    THex.Decode
-    ('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F'));
-end;
-
 constructor TSecP256K1Curve.Create;
 constructor TSecP256K1Curve.Create;
 begin
 begin
-  Fq := SecP256K1Curve_Q;
+  Fq := TSecP256K1FieldElement.Q;
   Inherited Create(Fq);
   Inherited Create(Fq);
   Fm_infinity := TSecP256K1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_infinity := TSecP256K1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_a := FromBigInteger(TBigInteger.Zero);
   Fm_a := FromBigInteger(TBigInteger.Zero);

+ 4 - 13
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256R1Custom.pas

@@ -241,8 +241,6 @@ type
   var
   var
     Fq: TBigInteger;
     Fq: TBigInteger;
 
 
-    class function GetSecP256R1Curve_Q: TBigInteger; static; inline;
-
   strict protected
   strict protected
   var
   var
     Fm_infinity: ISecP256R1Point;
     Fm_infinity: ISecP256R1Point;
@@ -274,8 +272,6 @@ type
     property Infinity: IECPoint read GetInfinity;
     property Infinity: IECPoint read GetInfinity;
     property FieldSize: Int32 read GetFieldSize;
     property FieldSize: Int32 read GetFieldSize;
 
 
-    class property SecP256R1Curve_Q: TBigInteger read GetSecP256R1Curve_Q;
-
   end;
   end;
 
 
 implementation
 implementation
@@ -650,7 +646,9 @@ end;
 
 
 class function TSecP256R1FieldElement.GetQ: TBigInteger;
 class function TSecP256R1FieldElement.GetQ: TBigInteger;
 begin
 begin
-  result := TSecP256R1Curve.SecP256R1Curve_Q;
+  result := TBigInteger.Create(1,
+    THex.Decode
+    ('FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF'));
 end;
 end;
 
 
 function TSecP256R1FieldElement.GetX: TCryptoLibUInt32Array;
 function TSecP256R1FieldElement.GetX: TCryptoLibUInt32Array;
@@ -1171,16 +1169,9 @@ end;
 
 
 { TSecP256R1Curve }
 { TSecP256R1Curve }
 
 
-class function TSecP256R1Curve.GetSecP256R1Curve_Q: TBigInteger;
-begin
-  result := TBigInteger.Create(1,
-    THex.Decode
-    ('FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF'));
-end;
-
 constructor TSecP256R1Curve.Create;
 constructor TSecP256R1Curve.Create;
 begin
 begin
-  Fq := SecP256R1Curve_Q;
+  Fq := TSecP256R1FieldElement.Q;
   Inherited Create(Fq);
   Inherited Create(Fq);
   Fm_infinity := TSecP256R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_infinity := TSecP256R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_a := FromBigInteger(TBigInteger.Create(1,
   Fm_a := FromBigInteger(TBigInteger.Create(1,

+ 5 - 14
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP384R1Custom.pas

@@ -239,8 +239,6 @@ type
   var
   var
     Fq: TBigInteger;
     Fq: TBigInteger;
 
 
-    class function GetSecP384R1Curve_Q: TBigInteger; static; inline;
-
   strict protected
   strict protected
   var
   var
     Fm_infinity: ISecP384R1Point;
     Fm_infinity: ISecP384R1Point;
@@ -272,8 +270,6 @@ type
     property Infinity: IECPoint read GetInfinity;
     property Infinity: IECPoint read GetInfinity;
     property FieldSize: Int32 read GetFieldSize;
     property FieldSize: Int32 read GetFieldSize;
 
 
-    class property SecP384R1Curve_Q: TBigInteger read GetSecP384R1Curve_Q;
-
   end;
   end;
 
 
 implementation
 implementation
@@ -631,7 +627,10 @@ end;
 
 
 class function TSecP384R1FieldElement.GetQ: TBigInteger;
 class function TSecP384R1FieldElement.GetQ: TBigInteger;
 begin
 begin
-  result := TSecP384R1Curve.SecP384R1Curve_Q;
+  result := TBigInteger.Create(1,
+    THex.Decode
+    ('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF')
+    );
 end;
 end;
 
 
 function TSecP384R1FieldElement.GetX: TCryptoLibUInt32Array;
 function TSecP384R1FieldElement.GetX: TCryptoLibUInt32Array;
@@ -1173,17 +1172,9 @@ end;
 
 
 { TSecP384R1Curve }
 { TSecP384R1Curve }
 
 
-class function TSecP384R1Curve.GetSecP384R1Curve_Q: TBigInteger;
-begin
-  result := TBigInteger.Create(1,
-    THex.Decode
-    ('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF')
-    );
-end;
-
 constructor TSecP384R1Curve.Create;
 constructor TSecP384R1Curve.Create;
 begin
 begin
-  Fq := SecP384R1Curve_Q;
+  Fq := TSecP384R1FieldElement.Q;
   Inherited Create(Fq);
   Inherited Create(Fq);
   Fm_infinity := TSecP384R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_infinity := TSecP384R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_a := FromBigInteger(TBigInteger.Create(1,
   Fm_a := FromBigInteger(TBigInteger.Create(1,

+ 5 - 14
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP521R1Custom.pas

@@ -236,8 +236,6 @@ type
   var
   var
     Fq: TBigInteger;
     Fq: TBigInteger;
 
 
-    class function GetSecP521R1Curve_Q: TBigInteger; static; inline;
-
   strict protected
   strict protected
   var
   var
     Fm_infinity: ISecP521R1Point;
     Fm_infinity: ISecP521R1Point;
@@ -269,8 +267,6 @@ type
     property Infinity: IECPoint read GetInfinity;
     property Infinity: IECPoint read GetInfinity;
     property FieldSize: Int32 read GetFieldSize;
     property FieldSize: Int32 read GetFieldSize;
 
 
-    class property SecP521R1Curve_Q: TBigInteger read GetSecP521R1Curve_Q;
-
   end;
   end;
 
 
 implementation
 implementation
@@ -472,7 +468,10 @@ end;
 
 
 class function TSecP521R1FieldElement.GetQ: TBigInteger;
 class function TSecP521R1FieldElement.GetQ: TBigInteger;
 begin
 begin
-  result := TSecP521R1Curve.SecP521R1Curve_Q;
+  result := TBigInteger.Create(1,
+    THex.Decode
+    ('01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
+    );
 end;
 end;
 
 
 function TSecP521R1FieldElement.GetX: TCryptoLibUInt32Array;
 function TSecP521R1FieldElement.GetX: TCryptoLibUInt32Array;
@@ -966,17 +965,9 @@ end;
 
 
 { TSecP521R1Curve }
 { TSecP521R1Curve }
 
 
-class function TSecP521R1Curve.GetSecP521R1Curve_Q: TBigInteger;
-begin
-  result := TBigInteger.Create(1,
-    THex.Decode
-    ('01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF')
-    );
-end;
-
 constructor TSecP521R1Curve.Create;
 constructor TSecP521R1Curve.Create;
 begin
 begin
-  Fq := SecP521R1Curve_Q;
+  Fq := TSecP521R1FieldElement.Q;
   Inherited Create(Fq);
   Inherited Create(Fq);
   Fm_infinity := TSecP521R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_infinity := TSecP521R1Point.Create(Self as IECCurve, Nil, Nil);
   Fm_a := FromBigInteger(TBigInteger.Create(1,
   Fm_a := FromBigInteger(TBigInteger.Create(1,