Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/Neo/Cryptography/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,29 +322,5 @@ internal static bool Test(this BloomFilter filter, Transaction tx)
return true;
return false;
}

/// <summary>
/// Rotates the specified value left by the specified number of bits.
/// Similar in behavior to the x86 instruction ROL.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate by.
/// Any value outside the range [0..31] is treated as congruent mod 32.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint RotateLeft(uint value, int offset)
=> (value << offset) | (value >> (32 - offset));

/// <summary>
/// Rotates the specified value left by the specified number of bits.
/// Similar in behavior to the x86 instruction ROL.
/// </summary>
/// <param name="value">The value to rotate.</param>
/// <param name="offset">The number of bits to rotate by.
/// Any value outside the range [0..63] is treated as congruent mod 64.</param>
/// <returns>The rotated value.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong RotateLeft(ulong value, int offset)
=> (value << offset) | (value >> (64 - offset));
}
}
13 changes: 7 additions & 6 deletions src/Neo/Cryptography/Murmur128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Buffers.Binary;
using System.IO.Hashing;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -103,8 +104,8 @@ protected override void GetCurrentHashCore(Span<byte> destination)
var tail = _tail.AsSpan();
ulong k1 = BinaryPrimitives.ReadUInt64LittleEndian(tail);
ulong k2 = BinaryPrimitives.ReadUInt64LittleEndian(tail[8..]);
H2 ^= Helper.RotateLeft(k2 * c2, r2) * c1;
H1 ^= Helper.RotateLeft(k1 * c1, r1) * c2;
H2 ^= BitOperations.RotateLeft(k2 * c2, r2) * c1;
H1 ^= BitOperations.RotateLeft(k1 * c1, r1) * c2;
}

H1 ^= (ulong)_length;
Expand Down Expand Up @@ -139,12 +140,12 @@ private void Mix(ReadOnlySpan<byte> source)
ulong k1 = BinaryPrimitives.ReadUInt64LittleEndian(source);
ulong k2 = BinaryPrimitives.ReadUInt64LittleEndian(source[8..]);

H1 ^= Helper.RotateLeft(k1 * c1, r1) * c2;
H1 = Helper.RotateLeft(H1, 27) + H2;
H1 ^= BitOperations.RotateLeft(k1 * c1, r1) * c2;
H1 = BitOperations.RotateLeft(H1, 27) + H2;
H1 = H1 * m + n1;

H2 ^= Helper.RotateLeft(k2 * c2, r2) * c1;
H2 = Helper.RotateLeft(H2, 31) + H1;
H2 ^= BitOperations.RotateLeft(k2 * c2, r2) * c1;
H2 = BitOperations.RotateLeft(H2, 31) + H1;
H2 = H2 * m + n2;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Neo/Cryptography/Murmur32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Buffers.Binary;
using System.IO.Hashing;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace Neo.Cryptography
Expand Down Expand Up @@ -109,7 +110,7 @@ protected override void GetCurrentHashCore(Span<byte> destination)
internal uint GetCurrentHashUInt32()
{
if (_tailLength > 0)
_hash ^= Helper.RotateLeft(_tail * c1, r1) * c2;
_hash ^= BitOperations.RotateLeft(_tail * c1, r1) * c2;

var state = _hash ^ (uint)_length;
state ^= state >> 16;
Expand All @@ -124,10 +125,10 @@ internal uint GetCurrentHashUInt32()
private void Mix(uint k)
{
k *= c1;
k = Helper.RotateLeft(k, r1);
k = BitOperations.RotateLeft(k, r1);
k *= c2;
_hash ^= k;
_hash = Helper.RotateLeft(_hash, r2);
_hash = BitOperations.RotateLeft(_hash, r2);
_hash = _hash * m + n;
}

Expand Down