Skip to content

Commit e9e8aac

Browse files
tests: Add fuzzing harness for CHKDF_HMAC_SHA256_L32
1 parent ec86ca1 commit e9e8aac

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ FUZZ_TARGETS = \
3636
test/fuzz/crypto_aes256 \
3737
test/fuzz/crypto_aes256cbc \
3838
test/fuzz/crypto_common \
39+
test/fuzz/crypto_hkdf_hmac_sha256_l32 \
3940
test/fuzz/crypto_poly1305 \
4041
test/fuzz/cuckoocache \
4142
test/fuzz/decode_tx \
@@ -507,6 +508,12 @@ test_fuzz_crypto_common_LDADD = $(FUZZ_SUITE_LD_COMMON)
507508
test_fuzz_crypto_common_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
508509
test_fuzz_crypto_common_SOURCES = test/fuzz/crypto_common.cpp
509510

511+
test_fuzz_crypto_hkdf_hmac_sha256_l32_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
512+
test_fuzz_crypto_hkdf_hmac_sha256_l32_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
513+
test_fuzz_crypto_hkdf_hmac_sha256_l32_LDADD = $(FUZZ_SUITE_LD_COMMON)
514+
test_fuzz_crypto_hkdf_hmac_sha256_l32_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
515+
test_fuzz_crypto_hkdf_hmac_sha256_l32_SOURCES = test/fuzz/crypto_hkdf_hmac_sha256_l32.cpp
516+
510517
test_fuzz_crypto_poly1305_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
511518
test_fuzz_crypto_poly1305_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
512519
test_fuzz_crypto_poly1305_LDADD = $(FUZZ_SUITE_LD_COMMON)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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/hkdf_sha256_32.h>
6+
#include <test/fuzz/FuzzedDataProvider.h>
7+
#include <test/fuzz/fuzz.h>
8+
#include <test/fuzz/util.h>
9+
10+
#include <cstdint>
11+
#include <string>
12+
#include <vector>
13+
14+
void test_one_input(const std::vector<uint8_t>& buffer)
15+
{
16+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
17+
18+
const std::vector<uint8_t> initial_key_material = ConsumeRandomLengthByteVector(fuzzed_data_provider);
19+
20+
CHKDF_HMAC_SHA256_L32 hkdf_hmac_sha256_l32(initial_key_material.data(), initial_key_material.size(), fuzzed_data_provider.ConsumeRandomLengthString(1024));
21+
while (fuzzed_data_provider.ConsumeBool()) {
22+
std::vector<uint8_t> out(32);
23+
hkdf_hmac_sha256_l32.Expand32(fuzzed_data_provider.ConsumeRandomLengthString(128), out.data());
24+
}
25+
}

0 commit comments

Comments
 (0)