浏览代码

add ZeroFill method for bytearray

Ugochukwu Mmaduekwe 6 年之前
父节点
当前提交
8305276614

+ 1 - 1
CryptoLib.Tests/src/Crypto/PaddingTests.pas

@@ -253,7 +253,7 @@ begin
   //
   if (ZeroVector <> Nil) then
   begin
-    TArrayUtils.Fill(data, 0, 8, Byte(0));
+    TArrayUtils.ZeroFill(data);
     padding.AddPadding(data, 4);
 
     if (not TArrayUtils.AreEqual(data, ZeroVector)) then

+ 1 - 1
CryptoLib/src/Crypto/ClpBufferedBlockCipher.pas

@@ -540,7 +540,7 @@ end;
 
 procedure TBufferedBlockCipher.Reset;
 begin
-  TArrayUtils.Fill(Fbuf, 0, System.length(Fbuf), Byte(0));
+  TArrayUtils.ZeroFill(Fbuf);
   FbufOff := 0;
 
   Fcipher.Reset();

+ 2 - 2
CryptoLib/src/Crypto/Engines/ClpIESEngine.pas

@@ -608,7 +608,7 @@ begin
   if (System.Length(FV) <> 0) then
   begin
     VZ := TArrayUtils.Concatenate(FV, BigZ);
-    TArrayUtils.Fill(BigZ, 0, System.Length(BigZ), Byte(0));
+    TArrayUtils.ZeroFill(BigZ);
     BigZ := VZ;
   end;
 
@@ -629,7 +629,7 @@ begin
     end;
 
   finally
-    TArrayUtils.Fill(BigZ, 0, System.Length(BigZ), Byte(0));
+    TArrayUtils.ZeroFill(BigZ);
   end;
 end;
 

+ 1 - 1
CryptoLib/src/Crypto/Engines/ClpPascalCoinIESEngine.pas

@@ -313,7 +313,7 @@ begin
     end;
 
   finally
-    TArrayUtils.Fill(BigZ, 0, System.Length(BigZ), Byte(0));
+    TArrayUtils.ZeroFill(BigZ);
   end;
 end;
 

+ 2 - 2
CryptoLib/src/Crypto/Modes/ClpBlockCipherModes.pas

@@ -789,7 +789,7 @@ end;
 procedure TCbcBlockCipher.Reset;
 begin
   System.Move(FIV[0], FcbcV[0], System.Length(FIV));
-  TArrayUtils.Fill(FcbcNextV, 0, System.Length(FcbcNextV), Byte(0));
+  TArrayUtils.ZeroFill(FcbcNextV);
 
   Fcipher.Reset();
 end;
@@ -1179,7 +1179,7 @@ end;
 
 procedure TSicBlockCipher.Reset;
 begin
-  TArrayUtils.Fill(Fcounter, 0, System.Length(Fcounter), Byte(0));
+  TArrayUtils.ZeroFill(Fcounter);
   System.Move(FIV[0], Fcounter[0], System.Length(FIV) * System.SizeOf(Byte));
 
   Fcipher.Reset();

+ 1 - 1
CryptoLib/src/Crypto/Parameters/ClpKeyParameter.pas

@@ -67,7 +67,7 @@ end;
 
 procedure TKeyParameter.Clear;
 begin
-  TArrayUtils.Fill(Fkey, 0, System.Length(Fkey), Byte(0));
+  TArrayUtils.ZeroFill(Fkey);
 end;
 
 constructor TKeyParameter.Create(const key: TCryptoLibByteArray;

+ 1 - 1
CryptoLib/src/Crypto/Parameters/ClpParametersWithIV.pas

@@ -66,7 +66,7 @@ end;
 
 procedure TParametersWithIV.Clear;
 begin
-  TArrayUtils.Fill(Fiv, 0, System.Length(Fiv), Byte(0));
+  TArrayUtils.ZeroFill(Fiv);
 end;
 
 constructor TParametersWithIV.Create(const parameters: ICipherParameters;

+ 1 - 1
CryptoLib/src/Crypto/Signers/ClpHMacDsaKCalculator.pas

@@ -128,7 +128,7 @@ var
 begin
   Fn := n;
   TArrayUtils.Fill(FV, 0, System.Length(FV), Byte($01));
-  TArrayUtils.Fill(FK, 0, System.Length(FK), Byte(0));
+  TArrayUtils.ZeroFill(FK);
 
   size := TBigIntegers.GetUnsignedByteLength(n);
   System.SetLength(x, size);

+ 7 - 0
CryptoLib/src/Utils/ClpArrayUtils.pas

@@ -95,6 +95,8 @@ type
     class procedure Fill(const buf: TCryptoLibUInt32Array; from, &to: Int32;
       filler: UInt32); overload; static;
 
+    class procedure ZeroFill(const buf: TCryptoLibByteArray); static;
+
   end;
 
 implementation
@@ -282,6 +284,11 @@ begin
 {$ENDIF}
 end;
 
+class procedure TArrayUtils.ZeroFill(const buf: TCryptoLibByteArray);
+begin
+  TArrayUtils.Fill(buf, 0, System.Length(buf), Byte(0));
+end;
+
 class function TArrayUtils.GetArrayHashCode(const data
   : TCryptoLibByteArray): Int32;
 var