| 10 | #include <vector> |
| 11 | |
| 12 | FUZZ_TARGET(muhash) |
| 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 | |
| 18 | MuHash3072 muhash; |
| 19 | |
| 20 | muhash.Insert(data); |
| 21 | muhash.Insert(data2); |
| 22 | |
| 23 | const std::string initial_state_hash{"dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8"}; |
| 24 | uint256 out; |
| 25 | uint256 out2; |
| 26 | CallOneOf( |
| 27 | fuzzed_data_provider, |
| 28 | [&] { |
| 29 | // Test that MuHash result is consistent independent of order of operations |
| 30 | muhash.Finalize(out); |
| 31 | |
| 32 | muhash = MuHash3072(); |
| 33 | muhash.Insert(data2); |
| 34 | muhash.Insert(data); |
| 35 | muhash.Finalize(out2); |
| 36 | }, |
| 37 | [&] { |
| 38 | // Test that multiplication with the initial state never changes the finalized result |
| 39 | muhash.Finalize(out); |
| 40 | MuHash3072 muhash3; |
| 41 | muhash3 *= muhash; |
| 42 | muhash3.Finalize(out2); |
| 43 | }, |
| 44 | [&] { |
| 45 | // Test that dividing a MuHash by itself brings it back to it's initial state |
| 46 | muhash /= muhash; |
| 47 | muhash.Finalize(out); |
| 48 | out2 = uint256S(initial_state_hash); |
| 49 | }, |
| 50 | [&] { |
| 51 | // Test that removing all added elements brings the object back to it's initial state |
| 52 | muhash.Remove(data); |
| 53 | muhash.Remove(data2); |
| 54 | muhash.Finalize(out); |
| 55 | out2 = uint256S(initial_state_hash); |
| 56 | }); |
| 57 | assert(out == out2); |
| 58 | } |
nothing calls this directly
no test coverage detected