Skip to content

Commit 76ce780

Browse files
authored
Remove local Endianness methods and use the Endianness utility in Tiger implementation
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 0c6899e commit 76ce780

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

HashifyNet/Algorithms/Tiger/Tiger_Implementation.cs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected override void TransformByteGroupsInternal(ArraySegment<byte> data)
124124
var block = new ulong[8];
125125
for (int i = 0; i < 8; i++)
126126
{
127-
block[i] = LoadLe64(data.Array, data.Offset + (i * 8));
127+
block[i] = Endianness.ToUInt64LittleEndian(data.Array, data.Offset + (i * 8));
128128
}
129129

130130
ProcessBlock(block);
@@ -143,41 +143,38 @@ protected override IHashValue FinalizeHashValueInternal(CancellationToken cancel
143143

144144
if (remainderCount < 56)
145145
{
146-
StoreLe64(totalBytesProcessed * 8, finalData, 56);
146+
Endianness.ToLittleEndianBytes(totalBytesProcessed * 8, finalData, 56);
147147

148148
var block = new ulong[8];
149149
for (int i = 0; i < 8; i++)
150150
{
151-
block[i] = LoadLe64(finalData, i * 8);
151+
block[i] = Endianness.ToUInt64LittleEndian(finalData, i * 8);
152152
}
153153

154154
ProcessBlock(block);
155155
}
156156
else
157157
{
158-
StoreLe64(totalBytesProcessed * 8, finalData, 120);
158+
Endianness.ToLittleEndianBytes(totalBytesProcessed * 8, finalData, 120);
159159

160160
var block1 = new ulong[8];
161161
for (int i = 0; i < 8; i++)
162162
{
163-
block1[i] = LoadLe64(finalData, i * 8);
163+
block1[i] = Endianness.ToUInt64LittleEndian(finalData, i * 8);
164164
}
165165

166166
ProcessBlock(block1);
167167

168168
var block2 = new ulong[8];
169169
for (int i = 0; i < 8; i++)
170170
{
171-
block2[i] = LoadLe64(finalData, 64 + (i * 8));
171+
block2[i] = Endianness.ToUInt64LittleEndian(finalData, 64 + (i * 8));
172172
}
173173

174174
ProcessBlock(block2);
175175
}
176176

177-
var fullHash = new byte[24];
178-
StoreLe64(_a, fullHash, 0);
179-
StoreLe64(_b, fullHash, 8);
180-
StoreLe64(_c, fullHash, 16);
177+
var fullHash = Endianness.GetBytesLittleEndian(_a, _b, _c);
181178

182179
int bytesNeeded = _hashSizeInBits / 8;
183180
if (bytesNeeded < 24)
@@ -261,30 +258,6 @@ private void KeySchedule(ref ulong[] x)
261258
x[7] -= x[6] ^ 0x0123456789ABCDEFUL;
262259
}
263260

264-
private static ulong LoadLe64(byte[] buf, int offset)
265-
{
266-
return buf[offset] |
267-
(((ulong)buf[offset + 1]) << 8) |
268-
(((ulong)buf[offset + 2]) << 16) |
269-
(((ulong)buf[offset + 3]) << 24) |
270-
(((ulong)buf[offset + 4]) << 32) |
271-
(((ulong)buf[offset + 5]) << 40) |
272-
(((ulong)buf[offset + 6]) << 48) |
273-
(((ulong)buf[offset + 7]) << 56);
274-
}
275-
276-
private static void StoreLe64(ulong value, byte[] buf, int offset)
277-
{
278-
buf[offset] = (byte)(value & 0xFF);
279-
buf[offset + 1] = (byte)((value >> 8) & 0xFF);
280-
buf[offset + 2] = (byte)((value >> 16) & 0xFF);
281-
buf[offset + 3] = (byte)((value >> 24) & 0xFF);
282-
buf[offset + 4] = (byte)((value >> 32) & 0xFF);
283-
buf[offset + 5] = (byte)((value >> 40) & 0xFF);
284-
buf[offset + 6] = (byte)((value >> 48) & 0xFF);
285-
buf[offset + 7] = (byte)((value >> 56) & 0xFF);
286-
}
287-
288261
private static class S
289262
{
290263
public static readonly ulong[] T1 = new ulong[256]
@@ -558,5 +531,4 @@ private static class S
558531
}
559532
}
560533
}
561-
562534
}

0 commit comments

Comments
 (0)