Skip to content

Commit ff0c6df

Browse files
authored
Merge pull request #44 from cppalliance/sha512
Implement SHA512
2 parents dd59858 + 828e1af commit ff0c6df

File tree

15 files changed

+3024
-0
lines changed

15 files changed

+3024
-0
lines changed

fuzzing/fuzz_sha512.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2024 Matt Borland
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
#include <boost/crypt/hash/sha512.hpp>
6+
#include <iostream>
7+
#include <exception>
8+
#include <string>
9+
10+
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
11+
{
12+
try
13+
{
14+
auto c_data = reinterpret_cast<const char*>(data);
15+
std::string c_data_str {c_data, size}; // Guarantee null termination since we can't pass the size argument
16+
17+
boost::crypt::sha512(c_data_str);
18+
boost::crypt::sha512(c_data, size);
19+
boost::crypt::sha512(data, size);
20+
21+
#ifdef BOOST_CRYPT_HAS_STRING_VIEW
22+
std::string_view view {c_data_str};
23+
boost::crypt::sha512(view);
24+
#endif
25+
26+
#ifdef BOOST_CRYPT_HAS_SPAN
27+
std::span data_span {c_data, size};
28+
boost::crypt::sha512(data_span);
29+
#endif
30+
31+
// Fuzz the hasher object
32+
boost::crypt::sha512_hasher hasher;
33+
hasher.process_bytes(data, size);
34+
hasher.process_bytes(data, size);
35+
hasher.process_bytes(data, size);
36+
hasher.get_digest();
37+
hasher.process_bytes(data, size); // State is invalid but should not crash
38+
}
39+
catch(...)
40+
{
41+
std::cerr << "Error with: " << data << std::endl;
42+
std::terminate();
43+
}
44+
45+
return 0;
46+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"The quick brown fox jumps over the lazy dog"
2+
"The quick brown fox jumps over the lazy dog."
3+
""
4+
"aB3$x9Yz"
5+
"12345"
6+
"!@#$%^&*()"
7+
"FuzzTest123"
8+
" "
9+
"Lorem ipsum dolor sit amet"
10+
"a"
11+
"9876543210"
12+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
13+
"ñÑáéíóúÁÉÍÓÚ"
14+
"\n\r\t"
15+
"0"
16+
"ThisIsAVeryLongStringWithNoSpacesOrPunctuationToTestEdgeCases"
17+
"<?php echo 'test'; ?>"
18+
"SELECT * FROM users;"

0 commit comments

Comments
 (0)