Skip to content

Commit ac43dc7

Browse files
authored
Merge branch 'master' into feature/bn254-curve-support
2 parents 1688966 + fa77a57 commit ac43dc7

File tree

5 files changed

+10
-1113
lines changed

5 files changed

+10
-1113
lines changed

benchmarks/Neo.Benchmarks/Benchmarks.Hash.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ public class Benchmarks_Hash
2525

2626
static readonly byte[] hash = "9182abedfbb9b18d81a05d8bcb45489e7daa2858".HexToBytes();
2727

28-
[Benchmark]
29-
public void RIPEMD160_ComputeHash()
30-
{
31-
using var ripemd160 = new RIPEMD160Managed();
32-
var result = ripemd160.ComputeHash(data);
33-
Debug.Assert(result.SequenceEqual(hash));
34-
}
35-
3628
[Benchmark]
3729
public void XxHash32_HashToUInt32()
3830
{

src/Neo/Cryptography/Helper.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public static class Helper
4242
/// <returns>The computed hash code.</returns>
4343
public static byte[] RIPEMD160(this byte[] value)
4444
{
45-
using var ripemd160 = new RIPEMD160Managed();
46-
return ripemd160.ComputeHash(value);
45+
var digest = new RipeMD160Digest();
46+
var buffer = new byte[digest.GetDigestSize()];
47+
digest.BlockUpdate(value, 0, value.Length);
48+
digest.DoFinal(buffer, 0);
49+
return buffer;
4750
}
4851

4952
/// <summary>
@@ -53,12 +56,11 @@ public static byte[] RIPEMD160(this byte[] value)
5356
/// <returns>The computed hash code.</returns>
5457
public static byte[] RIPEMD160(this ReadOnlySpan<byte> value)
5558
{
56-
using var ripemd160 = new RIPEMD160Managed();
57-
58-
var output = new byte[ripemd160.HashSize / 8];
59-
if (!ripemd160.TryComputeHash(value, output.AsSpan(), out _))
60-
throw new CryptographicException("Failed to compute RIPEMD160 hash. The hash computation operation could not be completed.");
61-
return output;
59+
var digest = new RipeMD160Digest();
60+
var buffer = new byte[digest.GetDigestSize()];
61+
digest.BlockUpdate(value);
62+
digest.DoFinal(buffer, 0);
63+
return buffer;
6264
}
6365

6466
/// <summary>

0 commit comments

Comments
 (0)