Skip to content

Commit ec86ca1

Browse files
tests: Add fuzzing harness for poly1305_auth(...)
1 parent 4cee53b commit ec86ca1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-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_poly1305 \
3940
test/fuzz/cuckoocache \
4041
test/fuzz/decode_tx \
4142
test/fuzz/descriptor_parse \
@@ -506,6 +507,12 @@ test_fuzz_crypto_common_LDADD = $(FUZZ_SUITE_LD_COMMON)
506507
test_fuzz_crypto_common_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
507508
test_fuzz_crypto_common_SOURCES = test/fuzz/crypto_common.cpp
508509

510+
test_fuzz_crypto_poly1305_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
511+
test_fuzz_crypto_poly1305_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
512+
test_fuzz_crypto_poly1305_LDADD = $(FUZZ_SUITE_LD_COMMON)
513+
test_fuzz_crypto_poly1305_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
514+
test_fuzz_crypto_poly1305_SOURCES = test/fuzz/crypto_poly1305.cpp
515+
509516
test_fuzz_cuckoocache_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
510517
test_fuzz_cuckoocache_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
511518
test_fuzz_cuckoocache_LDADD = $(FUZZ_SUITE_LD_COMMON)

src/test/fuzz/crypto_poly1305.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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/poly1305.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 <vector>
12+
13+
void test_one_input(const std::vector<uint8_t>& buffer)
14+
{
15+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
16+
17+
const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, POLY1305_KEYLEN);
18+
const std::vector<uint8_t> in = ConsumeRandomLengthByteVector(fuzzed_data_provider);
19+
20+
std::vector<uint8_t> tag_out(POLY1305_TAGLEN);
21+
poly1305_auth(tag_out.data(), in.data(), in.size(), key.data());
22+
}

0 commit comments

Comments
 (0)