Skip to content

Commit be3af4f

Browse files
committed
Merge #19934: tests: Add fuzzing harness for Keccak and SHA3_256
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
2 parents a518b1c + fc7f84a commit be3af4f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/test/fuzz/crypto.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <crypto/ripemd160.h>
88
#include <crypto/sha1.h>
99
#include <crypto/sha256.h>
10+
#include <crypto/sha3.h>
1011
#include <crypto/sha512.h>
1112
#include <hash.h>
1213
#include <test/fuzz/FuzzedDataProvider.h>
@@ -32,6 +33,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
3233
CSHA1 sha1;
3334
CSHA256 sha256;
3435
CSHA512 sha512;
36+
SHA3_256 sha3;
3537
CSipHasher sip_hasher{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
3638

3739
while (fuzzed_data_provider.ConsumeBool()) {
@@ -51,6 +53,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
5153
(void)ripemd160.Write(data.data(), data.size());
5254
(void)sha1.Write(data.data(), data.size());
5355
(void)sha256.Write(data.data(), data.size());
56+
(void)sha3.Write(data);
5457
(void)sha512.Write(data.data(), data.size());
5558
(void)sip_hasher.Write(data.data(), data.size());
5659

@@ -65,11 +68,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
6568
(void)ripemd160.Reset();
6669
(void)sha1.Reset();
6770
(void)sha256.Reset();
71+
(void)sha3.Reset();
6872
(void)sha512.Reset();
6973
break;
7074
}
7175
case 2: {
72-
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 8)) {
76+
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 9)) {
7377
case 0: {
7478
data.resize(CHash160::OUTPUT_SIZE);
7579
hash160.Finalize(data);
@@ -115,9 +119,21 @@ void test_one_input(const std::vector<uint8_t>& buffer)
115119
data[0] = sip_hasher.Finalize() % 256;
116120
break;
117121
}
122+
case 9: {
123+
data.resize(SHA3_256::OUTPUT_SIZE);
124+
sha3.Finalize(data);
125+
break;
126+
}
118127
}
119128
break;
120129
}
121130
}
122131
}
132+
if (fuzzed_data_provider.ConsumeBool()) {
133+
uint64_t state[25];
134+
for (size_t i = 0; i < 25; ++i) {
135+
state[i] = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
136+
}
137+
KeccakF(state);
138+
}
123139
}

0 commit comments

Comments
 (0)