Browse Source

change XOFSize argument from THashSize to Int32

Ugochukwu Mmaduekwe 6 years ago
parent
commit
c5dfdcff09

+ 1 - 1
src/libraries/hashlib4pascal/HashLib.inc

@@ -1,6 +1,6 @@
 { *********************************************************************************** }
 { *********************************************************************************** }
 { *                                 HashLib Library                                 * }
 { *                                 HashLib Library                                 * }
-{ *                  Copyright (c) 2016 - 2018 Ugochukwu Mmaduekwe                  * }
+{ *                  Copyright (c) 2016 - 2019 Ugochukwu Mmaduekwe                  * }
 { *                 Github Repository <https://github.com/Xor-el>                   * }
 { *                 Github Repository <https://github.com/Xor-el>                   * }
 
 
 { *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
 { *  Distributed under the MIT software license, see the accompanying file LICENSE  * }

+ 1 - 1
src/libraries/hashlib4pascal/HashLibHelper.inc

@@ -1,6 +1,6 @@
 { *********************************************************************************** }
 { *********************************************************************************** }
 { *                                 HashLib Library                                 * }
 { *                                 HashLib Library                                 * }
-{ *                  Copyright (c) 2016 - 2018 Ugochukwu Mmaduekwe                  * }
+{ *                  Copyright (c) 2016 - 2019 Ugochukwu Mmaduekwe                  * }
 { *                 Github Repository <https://github.com/Xor-el>                   * }
 { *                 Github Repository <https://github.com/Xor-el>                   * }
 
 
 { *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
 { *  Distributed under the MIT software license, see the accompanying file LICENSE  * }

+ 6 - 6
src/libraries/hashlib4pascal/HlpHashFactory.pas

@@ -370,8 +370,8 @@ type
       class function CreateKeccak_384(): IHash; static;
       class function CreateKeccak_384(): IHash; static;
       class function CreateKeccak_512(): IHash; static;
       class function CreateKeccak_512(): IHash; static;
 
 
-      class function CreateShake_128(a_xof_size: THashSize): IHash; static;
-      class function CreateShake_256(a_xof_size: THashSize): IHash; static;
+      class function CreateShake_128(a_xof_size_in_bits: Int32): IHash; static;
+      class function CreateShake_256(a_xof_size_in_bits: Int32): IHash; static;
 
 
       class function CreateBlake2B(const config: IBlake2BConfig = Nil)
       class function CreateBlake2B(const config: IBlake2BConfig = Nil)
         : IHash; static;
         : IHash; static;
@@ -932,15 +932,15 @@ begin
 end;
 end;
 
 
 class function THashFactory.TCrypto.CreateShake_128
 class function THashFactory.TCrypto.CreateShake_128
-  (a_xof_size: THashSize): IHash;
+  (a_xof_size_in_bits: Int32): IHash;
 begin
 begin
-  Result := (TShake_128.Create() as IXOF).SetXOFOutputSize(a_xof_size);
+  Result := (TShake_128.Create() as IXOF).SetXOFOutputSize(a_xof_size_in_bits);
 end;
 end;
 
 
 class function THashFactory.TCrypto.CreateShake_256
 class function THashFactory.TCrypto.CreateShake_256
-  (a_xof_size: THashSize): IHash;
+  (a_xof_size_in_bits: Int32): IHash;
 begin
 begin
-  Result := (TShake_256.Create() as IXOF).SetXOFOutputSize(a_xof_size);
+  Result := (TShake_256.Create() as IXOF).SetXOFOutputSize(a_xof_size_in_bits);
 end;
 end;
 
 
 class function THashFactory.TCrypto.CreateKeccak_224: IHash;
 class function THashFactory.TCrypto.CreateKeccak_224: IHash;

+ 4 - 5
src/libraries/hashlib4pascal/HlpIHashInfo.pas

@@ -8,7 +8,6 @@ uses
   HlpHashLibTypes,
   HlpHashLibTypes,
   HlpIKDF,
   HlpIKDF,
   HlpIHash,
   HlpIHash,
-  HlpHashSize,
   HlpNullable;
   HlpNullable;
 
 
 type
 type
@@ -86,10 +85,10 @@ type
 
 
   IXOF = Interface(IHash)
   IXOF = Interface(IHash)
     ['{944ED7F0-D033-4489-A5DD-9C83353F23F0}']
     ['{944ED7F0-D033-4489-A5DD-9C83353F23F0}']
-    function GetXOFSize: THashSize;
-    procedure SetXOFSize(a_xof_size: THashSize);
-    property XOFSize: THashSize read GetXOFSize write SetXOFSize;
-    function SetXOFOutputSize(a_xof_size: THashSize): IXOF;
+    function GetXOFSize: Int32;
+    procedure SetXOFSize(a_xof_size_in_bits: Int32);
+    property XOFSize: Int32 read GetXOFSize write SetXOFSize;
+    function SetXOFOutputSize(a_xof_size: Int32): IXOF;
   end;
   end;
 
 
 implementation
 implementation

+ 14 - 14
src/libraries/hashlib4pascal/HlpSHA3.pas

@@ -160,13 +160,13 @@ type
   TShake = class abstract(TSHA3, IXOF)
   TShake = class abstract(TSHA3, IXOF)
   strict private
   strict private
   var
   var
-    FXOFSize: THashSize;
-    function GetXOFSize: THashSize; inline;
-    procedure SetXOFSize(a_xof_size: THashSize); inline;
+    FXOFSize: Int32;
+    function GetXOFSize: Int32; inline;
+    procedure SetXOFSize(a_xof_size_in_bits: Int32); inline;
   strict protected
   strict protected
     constructor Create(a_hash_size: THashSize);
     constructor Create(a_hash_size: THashSize);
-    function SetXOFOutputSize(a_xof_size: THashSize): IXOF;
-    property XOFSize: THashSize read GetXOFSize write SetXOFSize;
+    function SetXOFOutputSize(a_xof_size_in_bits: Int32): IXOF;
+    property XOFSize: Int32 read GetXOFSize write SetXOFSize;
 
 
   public
   public
     function GetResult(): THashLibByteArray; override;
     function GetResult(): THashLibByteArray; override;
@@ -237,7 +237,7 @@ begin
       Result := Self.ClassName;
       Result := Self.ClassName;
     TSHA3.THashMode.hmShake:
     TSHA3.THashMode.hmShake:
       Result := Format('%s_%s_%u', [Self.ClassName, 'XOFSizeInBits',
       Result := Format('%s_%s_%u', [Self.ClassName, 'XOFSizeInBits',
-        Int32((Self as IXOF).XOFSize) * 8]);
+        (Self as IXOF).XOFSize]);
   else
   else
     begin
     begin
       raise EArgumentInvalidHashLibException.CreateResFmt(@SInvalidHashMode,
       raise EArgumentInvalidHashLibException.CreateResFmt(@SInvalidHashMode,
@@ -3155,7 +3155,7 @@ begin
   buffer_pos := Fm_buffer.Pos;
   buffer_pos := Fm_buffer.Pos;
   block := Fm_buffer.GetBytesZeroPadded();
   block := Fm_buffer.GetBytesZeroPadded();
 
 
-  LXofSize := Int32(FXOFSize);
+  LXofSize := FXOFSize shr 3;
   Idx := 0;
   Idx := 0;
 
 
   while Idx < LXofSize do
   while Idx < LXofSize do
@@ -3175,7 +3175,7 @@ begin
 
 
 end;
 end;
 
 
-function TShake.GetXOFSize: THashSize;
+function TShake.GetXOFSize: Int32;
 begin
 begin
   Result := FXOFSize;
   Result := FXOFSize;
 end;
 end;
@@ -3190,25 +3190,25 @@ begin
 {$ENDIF DEBUG}
 {$ENDIF DEBUG}
   tempresult := GetResult();
   tempresult := GetResult();
 {$IFDEF DEBUG}
 {$IFDEF DEBUG}
-  System.Assert(System.Length(tempresult) = Int32(XOFSize));
+  System.Assert(System.Length(tempresult) = (XOFSize shr 3));
 {$ENDIF DEBUG}
 {$ENDIF DEBUG}
   Initialize();
   Initialize();
   Result := THashResult.Create(tempresult);
   Result := THashResult.Create(tempresult);
 end;
 end;
 
 
-function TShake.SetXOFOutputSize(a_xof_size: THashSize): IXOF;
+function TShake.SetXOFOutputSize(a_xof_size_in_bits: Int32): IXOF;
 begin
 begin
-  If ((Int32(a_xof_size) * 8) and $7) <> 0 then
+  If (a_xof_size_in_bits and $7) <> 0 then
   begin
   begin
     raise EArgumentInvalidHashLibException.CreateRes(@SInvalidXOFSize);
     raise EArgumentInvalidHashLibException.CreateRes(@SInvalidXOFSize);
   end;
   end;
-  FXOFSize := a_xof_size;
+  FXOFSize := a_xof_size_in_bits;
   Result := Self;
   Result := Self;
 end;
 end;
 
 
-procedure TShake.SetXOFSize(a_xof_size: THashSize);
+procedure TShake.SetXOFSize(a_xof_size_in_bits: Int32);
 begin
 begin
-  SetXOFOutputSize(a_xof_size);
+  SetXOFOutputSize(a_xof_size_in_bits);
 end;
 end;
 
 
 { TShake_128 }
 { TShake_128 }