Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions include/boost/crypt2/hash/detail/sha3_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ class sha3_base final {
[[nodiscard("Digest is the function return value")]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
auto get_digest() noexcept -> compat::expected<return_type, state>;

template <compat::size_t Extent>
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
auto get_digest(compat::span<compat::byte> data) noexcept -> state;
auto get_digest(compat::span<compat::byte, Extent> data) noexcept -> state;

template <concepts::writable_output_range Range>
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED auto get_digest(Range&& data) noexcept -> state;
Expand Down Expand Up @@ -357,8 +358,9 @@ auto sha3_base<digest_size, is_xof>::get_digest() noexcept -> compat::expected<r
}

template <compat::size_t digest_size, bool is_xof>
template <compat::size_t Extent>
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto
sha3_base<digest_size, is_xof>::get_digest(compat::span<compat::byte> data) noexcept -> state
sha3_base<digest_size, is_xof>::get_digest(compat::span<compat::byte, Extent> data) noexcept -> state
{
if (!computed_ || corrupted_)
{
Expand Down Expand Up @@ -398,6 +400,11 @@ template <concepts::writable_output_range Range>
{
using value_type = compat::range_value_t<Range>;

if (!computed_ || corrupted_)
{
return state::state_error;
}

auto data_span {compat::span<value_type>(compat::forward<Range>(data))};

#if defined(__clang__) && __clang_major__ >= 19
Expand All @@ -407,7 +414,7 @@ template <concepts::writable_output_range Range>

if constexpr (is_xof)
{
return get_digest(compat::span<compat::byte>(compat::as_writable_bytes(data_span).data()));
xof_digest_impl(compat::span<compat::byte>(compat::as_writable_bytes(data_span).data()));
}
else
{
Expand All @@ -416,7 +423,7 @@ template <concepts::writable_output_range Range>
return state::insufficient_output_length;
}

return get_digest(
sha_digest_impl(
compat::span<compat::byte, digest_size>(
compat::as_writable_bytes(data_span).data(),
digest_size
Expand All @@ -427,6 +434,8 @@ template <concepts::writable_output_range Range>
#if defined(__clang__) && __clang_major__ >= 19
#pragma clang diagnostic pop
#endif

return state::success;
}

} // namespace boost::crypt::hash_detail
Expand Down
50 changes: 50 additions & 0 deletions include/boost/crypt2/hash/sha3_384.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 - 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_CRYPT2_HASH_SHA3_384_HPP
#define BOOST_CRYPT2_HASH_SHA3_384_HPP

#include <boost/crypt2/hash/detail/sha3_base.hpp>
#include <boost/crypt2/hash/detail/hash_file.hpp>
#include <boost/crypt2/detail/compat.hpp>
#include <boost/crypt2/detail/concepts.hpp>

namespace boost::crypt {

BOOST_CRYPT_EXPORT using sha3_384_hasher = hash_detail::sha3_base<48U>;

// One shot functions
[[nodiscard]] BOOST_CRYPT_EXPORT BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
auto sha3_384(compat::span<const compat::byte> data) noexcept -> compat::expected<sha3_384_hasher::return_type, state>
{
sha3_384_hasher hasher;
hasher.process_bytes(data);
hasher.finalize();
return hasher.get_digest();
}

template <compat::sized_range SizedRange>
[[nodiscard]] BOOST_CRYPT_EXPORT BOOST_CRYPT_GPU_ENABLED
auto sha3_384(SizedRange&& data) noexcept -> compat::expected<sha3_384_hasher::return_type, state>
{
sha3_384_hasher hasher;
hasher.process_bytes(data);
hasher.finalize();
return hasher.get_digest();
}

#if !BOOST_CRYPT_HAS_CUDA

template <concepts::file_system_path T>
[[nodiscard]] BOOST_CRYPT_EXPORT
auto sha3_384_file(const T& filepath) -> compat::expected<sha3_384_hasher::return_type, state>
{
return hash_detail::hash_file_impl<sha3_384_hasher>(filepath);
}

#endif // BOOST_CRYPT_HAS_CUDA

} // namespace boost::crypt

#endif // BOOST_CRYPT2_HASH_SHA3_384_HPP
6 changes: 3 additions & 3 deletions include/boost/crypt2/hash/sha3_512.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_CRYPT2_HASH_SHA384_HPP
#define BOOST_CRYPT2_HASH_SHA384_HPP
#ifndef BOOST_CRYPT2_HASH_SHA3_512_HPP
#define BOOST_CRYPT2_HASH_SHA3_512_HPP

#include <boost/crypt2/hash/detail/sha3_base.hpp>
#include <boost/crypt2/hash/detail/hash_file.hpp>
Expand Down Expand Up @@ -47,4 +47,4 @@ auto sha3_512_file(const T& filepath) -> compat::expected<sha3_512_hasher::retur

} // namespace boost::crypt

#endif //BOOST_CRYPT2_HASH_SHA384_HPP
#endif //BOOST_CRYPT2_HASH_SHA3_512_HPP
6 changes: 3 additions & 3 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ run test_sha512.cpp ;
run test_sha512_224.cpp ;
run test_sha512_256.cpp ;
run test_sha3_512.cpp ;
#run test_sha3_384.cpp ;
run test_sha3_384.cpp ;
#run test_sha3_256.cpp ;
#run test_sha3_224.cpp ;
#run test_shake128.cpp ;
Expand Down Expand Up @@ -128,8 +128,8 @@ run test_nist_cavs_sha3_512_monte.cpp ;
run test_nist_cavs_sha3_512_short_long.cpp ;
#run test_nist_cavs_sha3_512_hmac.cpp ;

#run test_nist_cavs_sha3_384_monte.cpp ;
#run test_nist_cavs_sha3_384_short_long.cpp ;
run test_nist_cavs_sha3_384_monte.cpp ;
run test_nist_cavs_sha3_384_short_long.cpp ;
#run test_nist_cavs_sha3_384_hmac.cpp ;

#run test_nist_cavs_sha3_256_monte.cpp ;
Expand Down
2 changes: 1 addition & 1 deletion test/nvcc_jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ run test_sha512_nvcc.cu ;
run test_sha512_224_nvcc.cu ;
run test_sha512_256_nvcc.cu ;
run test_sha3_512_nvcc.cu ;
#run test_sha3_384_nvcc.cu ;
run test_sha3_384_nvcc.cu ;
#run test_sha3_256_nvcc.cu ;
#run test_sha3_224_nvcc.cu ;
#run test_shake128_nvcc.cu ;
Expand Down
6 changes: 3 additions & 3 deletions test/test_nist_cavs_sha3_384_monte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/crypt/hash/sha3_384.hpp>
#include <boost/crypt2/hash/sha3_384.hpp>

#include "test_nist_cavs_detail.hpp"

auto main() -> int
{
bool result_is_ok { true };
bool result_is_ok { true };

{
nist::cavs::test_vector_container_type my_test_vectors_monte { };
Expand All @@ -27,5 +27,5 @@ auto main() -> int
BOOST_TEST(result_is_ok);
}

return boost::report_errors();
return boost::report_errors();
}
2 changes: 1 addition & 1 deletion test/test_nist_cavs_sha3_384_short_long.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/crypt/hash/sha3_384.hpp>
#include <boost/crypt2/hash/sha3_384.hpp>

#include "test_nist_cavs_detail.hpp"

Expand Down
Loading
Loading