Skip to content

Commit

Permalink
Change in reference implementation
Browse files Browse the repository at this point in the history
Co-authored-by: Ruhi <44024636+stratospher@users.noreply.github.com>
  • Loading branch information
prakash1512 and stratospher committed Oct 23, 2021
1 parent e0ce94b commit 88fae2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/crypto_chacha20.cpp \
test/fuzz/crypto_chacha20_poly1305_aead.cpp \
test/fuzz/crypto_common.cpp \
test/fuzz/crypto_diff_fuzz_poly1305.cpp \
test/fuzz/crypto_hkdf_hmac_sha256_l32.cpp \
test/fuzz/crypto_poly1305.cpp \
test/fuzz/cuckoocache.cpp \
Expand Down
22 changes: 21 additions & 1 deletion src/test/fuzz/crypto_diff_fuzz_poly1305.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ static INLINE void fU32TO8_LE_FAST(uint8_t* p, const uint32_t v) { *(uint32_t*)p
#define U8TO32_LE(p) fU8TO32_LE_FAST(p)
#define U32TO8_LE(p, v) fU32TO8_LE_FAST(p, v)

void poly1305_auth(unsigned char out[16], const unsigned char* m, size_t inlen, const unsigned char key[32])
/*
Same function name in both bitcoin core implementation and floodyberry's implementation
So changing the function name "poly1305_auth" to "poly1305_auth_floodyberry" in reference implementation
*/
void poly1305_auth_floodyberry(unsigned char out[16], const unsigned char* m, size_t inlen, const unsigned char key[32])
{
uint32_t t0, t1, t2, t3;
uint32_t h0, h1, h2, h3, h4;
Expand Down Expand Up @@ -189,3 +193,19 @@ void poly1305_auth(unsigned char out[16], const unsigned char* m, size_t inlen,
f3 += (f2 >> 32);
U32TO8_LE(&out[12], f3);
}

FUZZ_TARGET(crypto_diff_fuzz_poly1305)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};

const std::vector<uint8_t> key = ConsumeFixedLengthByteVector(fuzzed_data_provider, POLY1305_KEYLEN);
const std::vector<uint8_t> in = ConsumeRandomLengthByteVector(fuzzed_data_provider);

std::vector<uint8_t> tag_out(POLY1305_TAGLEN);
std::vector<uint8_t> tag_out_floodyberry(POLY1305_TAGLEN);
poly1305_auth(tag_out.data(), in.data(), in.size(), key.data());
poly1305_auth_floodyberry(tag_out_floodyberry.data(), in.data(), in.size(), key.data());

assert(memcmp(tag_out.data(), tag_out_floodyberry.data(), POLY1305_TAGLEN) == 0);
}

0 comments on commit 88fae2a

Please sign in to comment.