Skip to content

Commit

Permalink
Merge #19934: tests: Add fuzzing harness for Keccak and SHA3_256
Browse files Browse the repository at this point in the history
fc7f84a tests: Add fuzzing harness for Keccak and SHA3_256 (practicalswift)

Pull request description:

  Add fuzzing harness for Keccak and SHA3_256.

  See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets).

  Happy fuzzing :)

ACKs for top commit:
  laanwj:
    uACK fc7f84a
  elichai:
    utACK :) fc7f84a

Tree-SHA512: 01e1610e1c178d5f42578e2dd5644a4165596db34cf5037d574a5285e0ace4b06dc33ab81a308595246117537fe175294efd4bfc174ffc2e8eac98f0ec9dd3e9
  • Loading branch information
laanwj committed Sep 16, 2020
2 parents a518b1c + fc7f84a commit be3af4f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/test/fuzz/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <crypto/ripemd160.h>
#include <crypto/sha1.h>
#include <crypto/sha256.h>
#include <crypto/sha3.h>
#include <crypto/sha512.h>
#include <hash.h>
#include <test/fuzz/FuzzedDataProvider.h>
Expand All @@ -32,6 +33,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
CSHA1 sha1;
CSHA256 sha256;
CSHA512 sha512;
SHA3_256 sha3;
CSipHasher sip_hasher{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};

while (fuzzed_data_provider.ConsumeBool()) {
Expand All @@ -51,6 +53,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
(void)ripemd160.Write(data.data(), data.size());
(void)sha1.Write(data.data(), data.size());
(void)sha256.Write(data.data(), data.size());
(void)sha3.Write(data);
(void)sha512.Write(data.data(), data.size());
(void)sip_hasher.Write(data.data(), data.size());

Expand All @@ -65,11 +68,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
(void)ripemd160.Reset();
(void)sha1.Reset();
(void)sha256.Reset();
(void)sha3.Reset();
(void)sha512.Reset();
break;
}
case 2: {
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 8)) {
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 9)) {
case 0: {
data.resize(CHash160::OUTPUT_SIZE);
hash160.Finalize(data);
Expand Down Expand Up @@ -115,9 +119,21 @@ void test_one_input(const std::vector<uint8_t>& buffer)
data[0] = sip_hasher.Finalize() % 256;
break;
}
case 9: {
data.resize(SHA3_256::OUTPUT_SIZE);
sha3.Finalize(data);
break;
}
}
break;
}
}
}
if (fuzzed_data_provider.ConsumeBool()) {
uint64_t state[25];
for (size_t i = 0; i < 25; ++i) {
state[i] = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
}
KeccakF(state);
}
}

0 comments on commit be3af4f

Please sign in to comment.