Skip to content

Commit

Permalink
Merge pull request #78 from cppalliance/SHAKE256
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland authored Nov 1, 2024
2 parents 5dee018 + 9102ca7 commit d14c1c6
Show file tree
Hide file tree
Showing 17 changed files with 9,445 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ jobs:
- "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
source_keys:
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
- toolset: clang
compiler: clang++-18
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-24.04
install:
- clang-18
sources:
- "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main"
source_keys:
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
- toolset: clang
compiler: clang++-19
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-24.04
install:
- clang-19
sources:
- "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main"
source_keys:
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
- name: UBSAN
toolset: clang
compiler: clang++-14
Expand Down
58 changes: 58 additions & 0 deletions fuzzing/fuzz_shake256.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2024 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/crypt/hash/shake256.hpp>
#include <iostream>
#include <exception>
#include <string>
#include <cstdlib>

extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
{
try
{
auto c_data = reinterpret_cast<const char*>(data);
std::string c_data_str {c_data, size}; // Guarantee null termination since we can't pass the size argument

boost::crypt::shake256(c_data_str);
boost::crypt::shake256(c_data, size);
boost::crypt::shake256(data, size);

#ifdef BOOST_CRYPT_HAS_STRING_VIEW
std::string_view view {c_data_str};
boost::crypt::shake256(view);
#endif

#ifdef BOOST_CRYPT_HAS_SPAN
std::span data_span {c_data, size};
boost::crypt::shake256(data_span);
#endif

// Fuzz the hasher object
boost::crypt::shake256_hasher hasher;
hasher.process_bytes(data, size);
hasher.process_bytes(data, size);
hasher.process_bytes(data, size);
hasher.get_digest();
hasher.process_bytes(data, size); // State is invalid but should not crash

hasher.init();
std::uint8_t* return_buffer = static_cast<std::uint8_t*>(std::malloc(size));
hasher.process_bytes(data, size);
hasher.get_digest(return_buffer, size);
if (return_buffer != nullptr)
{
std::free(return_buffer);
return_buffer = nullptr;
}
hasher.get_digest(return_buffer, size);
}
catch(...)
{
std::cerr << "Error with: " << data << std::endl;
std::terminate();
}

return 0;
}
18 changes: 18 additions & 0 deletions fuzzing/seedcorpus/fuzz_shake256/shake256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"The quick brown fox jumps over the lazy dog"
"The quick brown fox jumps over the lazy dog."
""
"aB3$x9Yz"
"12345"
"!@#$%^&*()"
"FuzzTest123"
" "
"Lorem ipsum dolor sit amet"
"a"
"9876543210"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ñÑáéíóúÁÉÍÓÚ"
"\n\r\t"
"0"
"ThisIsAVeryLongStringWithNoSpacesOrPunctuationToTestEdgeCases"
"<?php echo 'test'; ?>"
"SELECT * FROM users;"
Loading

0 comments on commit d14c1c6

Please sign in to comment.