File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ test_fuzz_fuzz_SOURCES = \
229
229
test/fuzz/locale.cpp \
230
230
test/fuzz/merkleblock.cpp \
231
231
test/fuzz/message.cpp \
232
+ test/fuzz/muhash.cpp \
232
233
test/fuzz/multiplication_overflow.cpp \
233
234
test/fuzz/net.cpp \
234
235
test/fuzz/net_permissions.cpp \
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2020 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include < crypto/muhash.h>
6
+ #include < test/fuzz/FuzzedDataProvider.h>
7
+ #include < test/fuzz/fuzz.h>
8
+ #include < test/fuzz/util.h>
9
+
10
+ #include < vector>
11
+
12
+ void test_one_input (const std::vector<uint8_t >& buffer)
13
+ {
14
+ FuzzedDataProvider fuzzed_data_provider{buffer.data (), buffer.size ()};
15
+ std::vector<uint8_t > data = ConsumeRandomLengthByteVector (fuzzed_data_provider);
16
+ std::vector<uint8_t > data2 = ConsumeRandomLengthByteVector (fuzzed_data_provider);
17
+ if (data.empty ()) {
18
+ data.resize (fuzzed_data_provider.ConsumeIntegralInRange <size_t >(1 , 4096 ), fuzzed_data_provider.ConsumeIntegral <uint8_t >());
19
+ }
20
+ if (data2.empty ()) {
21
+ data2.resize (fuzzed_data_provider.ConsumeIntegralInRange <size_t >(1 , 4096 ), fuzzed_data_provider.ConsumeIntegral <uint8_t >());
22
+ }
23
+
24
+ data = ConsumeRandomLengthByteVector (fuzzed_data_provider);
25
+ data2 = ConsumeRandomLengthByteVector (fuzzed_data_provider);
26
+
27
+ MuHash3072 muhash;
28
+
29
+ // Test that MuHash result is consistent independent of order of operations
30
+ muhash.Insert (data);
31
+ muhash.Insert (data2);
32
+
33
+ uint256 out;
34
+ muhash.Finalize (out);
35
+
36
+ muhash = MuHash3072 ();
37
+ muhash.Insert (data2);
38
+ muhash.Insert (data);
39
+
40
+ uint256 out2;
41
+ muhash.Finalize (out2);
42
+
43
+ assert (out == out2);
44
+
45
+ // Test that removing all added elements brings the object back to it's initial state
46
+ muhash /= muhash;
47
+ muhash.Finalize (out);
48
+
49
+ MuHash3072 muhash2;
50
+ muhash2.Finalize (out2);
51
+
52
+ assert (out == out2);
53
+ }
You can’t perform that action at this time.
0 commit comments