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
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Core.Test/RipemdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Nethermind.Core.Test
[TestFixture]
public class RipemdTests
{
public const string RipemdOfEmptyString = "9c1185a5c5e9fc54612808977ee8f548b2258d31";
public const string RipemdOfEmptyString = "0000000000000000000000009c1185a5c5e9fc54612808977ee8f548b2258d31";

[Test]
public void Empty_byte_array()
Expand Down
32 changes: 18 additions & 14 deletions src/Nethermind/Nethermind.Crypto/Ripemd.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Core.Extensions;
using Org.BouncyCastle.Crypto.Digests;

namespace Nethermind.Crypto
namespace Nethermind.Crypto;

public static class Ripemd
{
public static class Ripemd
const int HashOutputLength = 32;

public static byte[] Compute(ReadOnlySpan<byte> input)
{
public static byte[] Compute(byte[] input)
{
var digest = new RipeMD160Digest();
digest.BlockUpdate(input, 0, input.Length);
var result = new byte[digest.GetDigestSize()];
digest.DoFinal(result, 0);
return result;
}
RipeMD160Digest digest = new();
digest.BlockUpdate(input);
byte[] result = new byte[HashOutputLength];
int length = digest.GetDigestSize();
Span<byte> span = result.AsSpan(HashOutputLength - length, length);
digest.DoFinal(span);
return result;
}

public static string ComputeString(byte[] input)
{
return Compute(input).ToHexString(false);
}
public static string ComputeString(ReadOnlySpan<byte> input)
{
return Compute(input).ToHexString(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public long DataGasCost(ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec
{
Metrics.Ripemd160Precompile++;

return (Ripemd.Compute(inputData.ToArray()).PadLeft(32), true);
return (Ripemd.Compute(inputData.Span), true);
}
}