Skip to content

Commit fb774a1

Browse files
committed
Update original Muhash PR and fix benchmarks
1 parent 00fc7ff commit fb774a1

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/bench/crypto_hash.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ static void MuHash(benchmark::State& state)
9797
FastRandomContext rng(true);
9898
MuHash3072 acc;
9999
unsigned char key[32] = {0};
100+
int i = 0;
100101
while (state.KeepRunning()) {
101-
for (int i = 0; i < 1000; i++) {
102-
key[0] = i;
103-
acc *= MuHash3072(key);
104-
}
102+
key[0] = ++i;
103+
acc *= MuHash3072(key);
105104
}
106105
}
107106

@@ -116,4 +115,4 @@ BENCHMARK(SHA256D64_1024, 7400);
116115
BENCHMARK(FastRandom_32bit, 110 * 1000 * 1000);
117116
BENCHMARK(FastRandom_1bit, 440 * 1000 * 1000);
118117

119-
BENCHMARK(MuHash);
118+
BENCHMARK(MuHash, 5000);

src/crypto/muhash.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include "muhash.h"
5+
#include <crypto/muhash.h>
66

7-
#include <limits>
8-
#include "common.h"
9-
#include "chacha20.h"
7+
#include <crypto/common.h>
8+
#include <crypto/chacha20.h>
109

1110
#include <assert.h>
1211
#include <stdio.h>
1312

13+
#include <limits>
14+
1415
namespace {
1516

1617
/** Extract the lowest limb of [c0,c1,c2] into n, and left shift the number by 1 limb. */
@@ -286,7 +287,7 @@ MuHash3072::MuHash3072() noexcept
286287
MuHash3072::MuHash3072(const unsigned char* key32) noexcept
287288
{
288289
unsigned char tmp[384];
289-
ChaCha20(key32, 32).Output(tmp, 384);
290+
ChaCha20(key32, 32).Keystream(tmp, 384);
290291
for (int i = 0; i < Num3072::LIMBS; ++i) {
291292
if (sizeof(Num3072::limb_type) == 4) {
292293
data.limbs[i] = ReadLE32(tmp + 4 * i);

src/crypto/muhash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define BITCOIN_CRYPTO_MUHASH_H
77

88
#if defined(HAVE_CONFIG_H)
9-
#include "bitcoin-config.h"
9+
#include <bitcoin-config.h>
1010
#endif
1111

1212
#include <stdint.h>

src/test/crypto_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ BOOST_AUTO_TEST_CASE(muhash_tests)
763763
unsigned char res[384];
764764
int table[4];
765765
for (int i = 0; i < 4; ++i) {
766-
table[i] = insecure_rand_ctx.randbits(3);
766+
table[i] = g_insecure_rand_ctx.randbits(3);
767767
}
768768
for (int order = 0; order < 4; ++order) {
769769
MuHash3072 acc;
@@ -783,8 +783,8 @@ BOOST_AUTO_TEST_CASE(muhash_tests)
783783
}
784784
}
785785

786-
MuHash3072 x = FromInt(insecure_rand_ctx.randbits(4)); // x=X
787-
MuHash3072 y = FromInt(insecure_rand_ctx.randbits(4)); // x=X, y=Y
786+
MuHash3072 x = FromInt(g_insecure_rand_ctx.randbits(4)); // x=X
787+
MuHash3072 y = FromInt(g_insecure_rand_ctx.randbits(4)); // x=X, y=Y
788788
MuHash3072 z; // x=X, y=Y, z=1
789789
z *= x; // x=X, y=Y, z=X
790790
z /= y; // x=X, y=Y, z=X/Y
@@ -800,7 +800,7 @@ BOOST_AUTO_TEST_CASE(muhash_tests)
800800
acc *= FromInt(1);
801801
acc /= FromInt(2);
802802
acc.Finalize(out);
803-
uint256 x = (TruncatedSHA512Writer(SER_DISK, 0) << FLATDATA(out)).GetHash();
803+
uint256 x = (TruncatedSHA512Writer(SER_DISK, 0) << out).GetHash();
804804
BOOST_CHECK(x == uint256S("0e94c56c180f27fd6b182f091c5b007e2d6eba5ae28daa5aa92d2af8c26ea9a6"));
805805
}
806806

0 commit comments

Comments
 (0)