-
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 #44 from cppalliance/sha512
Implement SHA512
- Loading branch information
Showing
15 changed files
with
3,024 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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/sha512.hpp> | ||
#include <iostream> | ||
#include <exception> | ||
#include <string> | ||
|
||
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::sha512(c_data_str); | ||
boost::crypt::sha512(c_data, size); | ||
boost::crypt::sha512(data, size); | ||
|
||
#ifdef BOOST_CRYPT_HAS_STRING_VIEW | ||
std::string_view view {c_data_str}; | ||
boost::crypt::sha512(view); | ||
#endif | ||
|
||
#ifdef BOOST_CRYPT_HAS_SPAN | ||
std::span data_span {c_data, size}; | ||
boost::crypt::sha512(data_span); | ||
#endif | ||
|
||
// Fuzz the hasher object | ||
boost::crypt::sha512_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 | ||
} | ||
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.