-
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 #49 from cppalliance/SHA384
Implement SHA384
- Loading branch information
Showing
19 changed files
with
2,624 additions
and
1 deletion.
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
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,131 @@ | ||
//// | ||
Copyright 2024 Matt Borland | ||
Distributed under the Boost Software License, Version 1.0. | ||
https://www.boost.org/LICENSE_1_0.txt | ||
//// | ||
|
||
[#sha384] | ||
:idprefix: sha384_ | ||
|
||
= SHA384 | ||
|
||
This library supports sha384 as described in https://datatracker.ietf.org/doc/html/rfc6234[RFC 6234]. | ||
There is a wide range of acceptable inputs for the base sha384 function: | ||
|
||
== Hashing Functions | ||
|
||
[source, c++] | ||
---- | ||
namespace boost { | ||
namespace crypt { | ||
uisng return_type = boost::crypt::array<uint8_t, 48>; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char* str) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char* str, size_t len) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const unsigned char* str) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const unsigned char* str, size_t len) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char16_t* str) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char16_t* str, size_t len) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char32_t* str) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const char32_t* str, size_t len) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const wchar_t* str) noexcept -> return_type; | ||
BOOST_CRYPT_GPU_ENABLED inline auto sha384(const wchar_t* str, size_t len) noexcept -> return_type; | ||
inline auto sha384(const std::string& str) noexcept -> return_type; | ||
inline auto sha384(const std::u16string& str) noexcept -> return_type; | ||
inline auto sha384(const std::u32string& str) noexcept -> return_type; | ||
inline auto sha384(const std::wstring& str) noexcept -> return_type; | ||
#ifdef BOOST_CRYPT_HAS_STRING_VIEW | ||
inline auto sha384(std::string_view str) noexcept -> return_type; | ||
inline auto sha384(std::u16string_view str) noexcept -> return_type; | ||
inline auto sha384(std::u32string_view str) noexcept -> return_type; | ||
inline auto sha384(std::wstring_view str) noexcept -> return_type; | ||
#endif // BOOST_CRYPT_HAS_STRING_VIEW | ||
#ifdef BOOST_CRYPT_HAS_SPAN | ||
template <typename T, std::size_t extent> | ||
inline auto md5(std::span<T, extent> data) noexcept -> return_type; | ||
#endif // BOOST_CRYPT_HAS_SPAN | ||
#ifdef BOOST_CRYPT_HAS_CUDA | ||
template <typename T, boost::crypt::size_t extent> | ||
BOOST_CRYPT_GPU_ENABLED inline auto md5(cuda::std::span<T, extent> data) noexcept -> return_type; | ||
#endif // BOOST_CRYPT_HAS_CUDA | ||
} //namespace crypt | ||
} //namespace boost | ||
---- | ||
|
||
== File Hashing Functions | ||
|
||
We also have the ability to scan files and return the sha384 value: | ||
|
||
[source, c++] | ||
---- | ||
namespace boost { | ||
namespace crypt { | ||
uisng return_type = boost::crypt::array<uint8_t, 16>; | ||
inline auto sha384_file(const char* filepath) noexcept -> return_type; | ||
inline auto sha384_file(const std::string& filepath) noexcept -> return_type; | ||
inline auto sha384_file(std::string_view filepath) noexcept -> return_type; | ||
} // namespace crypt | ||
} // namespace boost | ||
---- | ||
|
||
== Hashing Object | ||
|
||
[#sha384_hasher] | ||
Lastly, there is also the ability to create a sha384 hashing object and feed it bytes as the user parses them. | ||
This class does not use any dynamic memory allocation. | ||
|
||
[source, c++] | ||
---- | ||
namespace boost { | ||
namespace crypt { | ||
class sha384_hasher | ||
{ | ||
uisng return_type = boost::crypt::array<uint8_t, 48>; | ||
void init(); | ||
template <typename ByteType> | ||
BOOST_CRYPT_GPU_ENABLED inline auto process_byte(ByteType byte) noexcept -> hasher_state; | ||
template <typename ForwardIter> | ||
BOOST_CRYPT_GPU_ENABLED inline auto process_bytes(ForwardIter buffer, size_t byte_count) noexcept -> hasher_state; | ||
inline auto get_digest() noexcept -> return_type; | ||
}; | ||
} // namespace crypt | ||
} // namespace boost | ||
---- |
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,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/sha384.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::sha384(c_data_str); | ||
boost::crypt::sha384(c_data, size); | ||
boost::crypt::sha384(data, size); | ||
|
||
#ifdef BOOST_CRYPT_HAS_STRING_VIEW | ||
std::string_view view {c_data_str}; | ||
boost::crypt::sha384(view); | ||
#endif | ||
|
||
#ifdef BOOST_CRYPT_HAS_SPAN | ||
std::span data_span {c_data, size}; | ||
boost::crypt::sha384(data_span); | ||
#endif | ||
|
||
// Fuzz the hasher object | ||
boost::crypt::sha384_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.