Commits

Snake Doctor committed ac43276

Fixed problem with initialization in KeccakInitializeRoundConstants
Added functions/macros for ROL32, ROL64, SHL64/SHR64, XOR64

Comments (0)

Files changed (1)

     end;
 end;
 
+function SHL64(a: UInt64; offset: Byte): UInt64; inline;
+begin
+    Result := a SHL offset;
+end;
+
+function SHR64(a: UInt64; offset: Byte): UInt64; inline;
+begin
+    Result := a SHR offset;
+end;
+
 function ROL64(a: UInt64; offset: Byte): UInt64; inline;
 begin
 	Result := a;
 	if offset <> 0 then
     begin
-		Result := (a SHL offset) XOR (a SHR (64-offset));
+		Result := SHL64(a, offset) XOR SHR64(a, 64-offset);
     end;
 end;
 
+function XOR64(a,b: UInt64): UInt64; inline;
+begin
+	Result := a xor b;
+end;
 
 {$REGION 'Sponge Functions'}
 function InitSponge;
     begin
         C[x] := 0;
         for y := 0 to 4 do
-            C[x] := C[x] xor A[index(x, y)];
+            C[x] := XOR64( C[x], A[index(x, y)] );
     end;
 
     for x := 0 to 4 do
-        D[x] := ROL64(C[(x+1) mod 5], 1) xor C[(x+4) mod 5];
+        D[x] := XOR64( ROL64(C[(x+1) mod 5], 1), C[(x+4) mod 5] );
 
     for x := 0 to 4 do
         for y := 0 to 4 do
-            A[index(x, y)] := A[index(x, y)] xor D[x];
+            A[index(x, y)] := XOR64( A[index(x, y)], D[x] );
 end;
 
 procedure rho(A: PUInt64Array);
     for y := 0 to 4 do
     begin
         for x := 0 to 4 do
-            C[x] := A[index(x, y)] xor (((NOT A[index(x+1, y)])+1) AND A[index(x+2, y)]);
+        begin
+            //C[x] := XOR64( A[index(x, y)], (((NOT A[index(x+1, y)])+1) AND A[index(x+2, y)]) );
+            C[x] := XOR64( A[index(x, y)], ((NOT A[index(x+1, y)]) AND A[index(x+2, y)]) );
+        end;
 
         for x := 0 to 4 do
             A[index(x, y)] := C[x];
 
 procedure iota(A: PUInt64Array; indexRound: UInt32);
 begin
-    A[index(0, 0)] := A[index(0, 0)] xor KeccakRoundConstants[indexRound];
+    A[index(0, 0)] := XOR64( A[index(0, 0)], KeccakRoundConstants[indexRound] );
 end;
 
 
             bitPosition := (1 SHL j)-1; //2^j-1
             if LFSR86540(@LFSRstate) then
             begin
-                KeccakRoundConstants[i] := KeccakRoundConstants[i] XOR (1 SHL bitPosition);
+                KeccakRoundConstants[i] := XOR64( KeccakRoundConstants[i], (UInt64(1) SHL bitPosition) );
             end;
         end;
 	end;