-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from cppalliance/SHAKE256
- Loading branch information
Showing
17 changed files
with
9,445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;" |
Oops, something went wrong.