Browse Source

minor refactoring

Ugochukwu Mmaduekwe 6 years ago
parent
commit
bbfa2dad58
2 changed files with 19 additions and 20 deletions
  1. 16 17
      CryptoLib/src/Math/EC/Rfc8032/ClpEd25519.pas
  2. 3 3
      CryptoLib/src/Math/Raw/ClpNat.pas

+ 16 - 17
CryptoLib/src/Math/EC/Rfc8032/ClpEd25519.pas

@@ -765,18 +765,28 @@ begin
   TX25519Field.Copy(table, off, r.T, 0);
 end;
 
+class function TEd25519.GetWindow4(const X: TCryptoLibUInt32Array;
+  n: Int32): Int32;
+var
+  w, b: Int32;
+begin
+  w := TBits.Asr32(n, 3);
+  b := (n and 7) shl 2;
+  result := (X[w] shr b) and 15;
+end;
+
 class procedure TEd25519.PointLookup(const X: TCryptoLibUInt32Array; n: Int32;
   const table: TCryptoLibInt32Array; var r: TPointExt);
 var
-  w, Sign, abs, i, off, cond: Int32;
+  w, LSign, abs, i, off, cond: Int32;
 begin
   w := GetWindow4(X, n);
 
-  Sign := (TBits.Asr32(w, (PrecompTeeth - 1))) xor 1;
-  abs := (w xor -Sign) and PrecompMask;
+  LSign := (TBits.Asr32(w, (PrecompTeeth - 1))) xor 1;
+  abs := (w xor -LSign) and PrecompMask;
 
 {$IFDEF DEBUG}
-  System.Assert((Sign = 0) or (Sign = 1));
+  System.Assert((LSign = 0) or (LSign = 1));
   System.Assert((abs <= 0) and (abs < PrecompPoints));
 {$ENDIF DEBUG}
   i := 0;
@@ -796,8 +806,8 @@ begin
     System.Inc(i);
   end;
 
-  TX25519Field.CNegate(Sign, r.X);
-  TX25519Field.CNegate(Sign, r.T);
+  TX25519Field.CNegate(LSign, r.X);
+  TX25519Field.CNegate(LSign, r.T);
 end;
 
 class function TEd25519.DecodePointVar(const p: TCryptoLibByteArray;
@@ -932,17 +942,6 @@ begin
   ScalarMultBaseEncoded(s, pk, pkOff);
 end;
 
-class function TEd25519.GetWindow4(const X: TCryptoLibUInt32Array;
-  n: Int32): Int32;
-var
-  w, b: Int32;
-begin
-  w := TBits.Asr32(n, 3);
-  b := (n and 7) shl 2;
-  result := (X[w] shr b) and 15;
-  // result := (TBits.Asr32(X[w], b)) and 15;
-end;
-
 class function TEd25519.GetWnaf(const n: TCryptoLibUInt32Array; width: Int32)
   : TCryptoLibShortIntArray;
 var

+ 3 - 3
CryptoLib/src/Math/Raw/ClpNat.pas

@@ -961,7 +961,7 @@ end;
 class procedure TNat.CMov(len, mask: Int32; const x: TCryptoLibUInt32Array;
   xOff: Int32; const z: TCryptoLibUInt32Array; zOff: Int32);
 var
-  LMASK, z_i, Diff: UInt32;
+  LMASK, z_i, LDiff: UInt32;
   I: Int32;
 begin
   LMASK := UInt32(-(mask and 1));
@@ -969,8 +969,8 @@ begin
   for I := 0 to System.Pred(len) do
   begin
     z_i := z[zOff + I];
-    Diff := z_i xor x[xOff + I];
-    z_i := z_i xor ((Diff and LMASK));
+    LDiff := z_i xor x[xOff + I];
+    z_i := z_i xor ((LDiff and LMASK));
     z[zOff + I] := z_i;
   end;
 end;