summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-07-26 20:43:44 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-07-26 20:43:44 +0700
commit612c0e0f7eb2f8851ba50852b60132bc7cef31f0 (patch)
tree520cb569b3910c31950a3df93571348d23d3ddc6 /crypto
parentmove KEMExtractor to KemExtractor (diff)
downloadBouncyCastle.NET-ed25519-612c0e0f7eb2f8851ba50852b60132bc7cef31f0.tar.xz
Refactoring Tiger
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/crypto/digests/TigerDigest.cs51
1 files changed, 13 insertions, 38 deletions
diff --git a/crypto/src/crypto/digests/TigerDigest.cs b/crypto/src/crypto/digests/TigerDigest.cs
index ce9efdbed..a452d3f0b 100644
--- a/crypto/src/crypto/digests/TigerDigest.cs
+++ b/crypto/src/crypto/digests/TigerDigest.cs
@@ -1,6 +1,6 @@
 using System;
 
-using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Utilities;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crypto.Digests
@@ -553,7 +553,7 @@ namespace Org.BouncyCastle.Crypto.Digests
         //
         // buffers
         //
-        private byte[]  Buffer = new byte[8];
+        private byte[]  m_buffer = new byte[8];
         private int     bOff;
 
         private long[]  x = new long[8];
@@ -591,18 +591,9 @@ namespace Org.BouncyCastle.Crypto.Digests
 			return MyByteLength;
 		}
 
-		private void ProcessWord(
-            byte[]  b,
-            int     off)
+		private void ProcessWord(byte[] b, int off)
         {
-            x[xOff++] =   ((long)(b[off + 7] & 0xff) << 56)
-                        | ((long)(b[off + 6] & 0xff) << 48)
-                        | ((long)(b[off + 5] & 0xff) << 40)
-                        | ((long)(b[off + 4] & 0xff) << 32)
-                        | ((long)(b[off + 3] & 0xff) << 24)
-                        | ((long)(b[off + 2] & 0xff) << 16)
-                        | ((long)(b[off + 1] & 0xff) << 8)
-                        | ((uint)(b[off + 0] & 0xff));
+            x[xOff++] = (long)Pack.LE_To_UInt64(b, off);
 
             if (xOff == x.Length)
             {
@@ -615,11 +606,11 @@ namespace Org.BouncyCastle.Crypto.Digests
         public void Update(
             byte input)
         {
-            Buffer[bOff++] = input;
+            m_buffer[bOff++] = input;
 
-            if (bOff == Buffer.Length)
+            if (bOff == m_buffer.Length)
             {
-                ProcessWord(Buffer, 0);
+                ProcessWord(m_buffer, 0);
             }
 
             byteCount++;
@@ -781,21 +772,6 @@ namespace Org.BouncyCastle.Crypto.Digests
             }
         }
 
-        private void UnpackWord(
-            long    r,
-            byte[]  output,
-            int     outOff)
-        {
-            output[outOff + 7]     = (byte)(r >> 56);
-            output[outOff + 6] = (byte)(r >> 48);
-            output[outOff + 5] = (byte)(r >> 40);
-            output[outOff + 4] = (byte)(r >> 32);
-            output[outOff + 3] = (byte)(r >> 24);
-            output[outOff + 2] = (byte)(r >> 16);
-            output[outOff + 1] = (byte)(r >> 8);
-            output[outOff] = (byte)r;
-        }
-
         private void ProcessLength(
             long    bitLength)
         {
@@ -824,9 +800,9 @@ namespace Org.BouncyCastle.Crypto.Digests
         {
             Finish();
 
-            UnpackWord(a, output, outOff);
-            UnpackWord(b, output, outOff + 8);
-            UnpackWord(c, output, outOff + 16);
+            Pack.UInt64_To_LE((ulong)a, output, outOff);
+            Pack.UInt64_To_LE((ulong)b, output, outOff + 8);
+            Pack.UInt64_To_LE((ulong)c, output, outOff + 16);
 
             Reset();
 
@@ -849,9 +825,9 @@ namespace Org.BouncyCastle.Crypto.Digests
             }
 
             bOff = 0;
-            for (int i = 0; i != Buffer.Length; i++)
+            for (int i = 0; i != m_buffer.Length; i++)
             {
-                Buffer[i] = 0;
+                m_buffer[i] = 0;
             }
 
             byteCount = 0;
@@ -873,11 +849,10 @@ namespace Org.BouncyCastle.Crypto.Digests
 			Array.Copy(t.x, 0, x, 0, t.x.Length);
 			xOff = t.xOff;
 
-			Array.Copy(t.Buffer, 0, Buffer, 0, t.Buffer.Length);
+			Array.Copy(t.m_buffer, 0, m_buffer, 0, t.m_buffer.Length);
 			bOff = t.bOff;
 
 			byteCount = t.byteCount;
 		}    
-
 	}
 }