Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade HMAC class #212

Merged
merged 17 commits into from
Jan 16, 2025
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
6 changes: 3 additions & 3 deletions include/boost/crypt2/detail/clear_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ constexpr void clear_mem(std::span<std::byte> data)
}
*/

using generic_meset_t = void(*)(void*, size_t);
using generic_meset_t = void(*)(void*, compat::size_t);

inline void generic_runtime_memset_func_impl(void* ptr, size_t size)
inline void generic_runtime_memset_func_impl(void* ptr, compat::size_t size)
{
#if defined(__clang__) && __clang_major__ >= 20
#pragma clang diagnostic push
Expand All @@ -120,7 +120,7 @@ constexpr void clear_mem(T& data)
}
else
{
generic_runtime_memset_func_impl(data.data(), data.size());
generic_runtime_memset_func(data.data(), data.size());
}
}

Expand Down
4 changes: 2 additions & 2 deletions include/boost/crypt2/detail/compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto make_span(R&& r)
else
{
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::span(cuda::std::forward<R>(r));
return cuda::std::span{cuda::std::forward<R>(r).data(), cuda::std::forward<R>(r).size()};
#else
return std::span(std::forward<R>(r));
return std::span{std::forward<R>(r).data(), std::forward<R>(r).size()};
#endif
}
}
Expand Down
29 changes: 29 additions & 0 deletions include/boost/crypt2/detail/unreachable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 - 2025 Matt Borland
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#ifndef BOOST_CRYPT_DETAIL_UNREACHABLE_HPP
#define BOOST_CRYPT_DETAIL_UNREACHABLE_HPP

#include <boost/crypt2/detail/config.hpp>
#include <boost/crypt2/detail/compat.hpp>

namespace boost::crypt::detail {

// LCOV_EXCL_START
[[noreturn]] inline void unreachable()
{
// Uses compiler specific extensions if possible.
// Even if no extension is used, undefined behavior is still raised by
// an empty function body and the noreturn attribute.
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
__assume(false);
#else // GCC, Clang, NVCC
__builtin_unreachable();
#endif
}
// LCOV_EXCL_STOP

} // namespace boost::crypt::detail

#endif // BOOST_CRYPT_DETAIL_UNREACHABLE_HPP
4 changes: 2 additions & 2 deletions include/boost/crypt2/hash/detail/sha_1_2_hasher_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class sha_1_2_hasher_base
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto finalize() noexcept -> state;

// TODO(mborland): Allow this to take dynamic extent, check the length and then use a fixed amount. See sha512_base
[[nodiscard("Digest is the function return value")]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto get_digest() noexcept -> compat::expected<return_type, state>;
[[nodiscard("Digest is the function return value")]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto get_digest() const noexcept -> compat::expected<return_type, state>;

template <compat::size_t Extent = compat::dynamic_extent>
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto get_digest(compat::span<compat::byte, Extent> data) const noexcept -> state;
Expand Down Expand Up @@ -145,7 +145,7 @@ sha_1_2_hasher_base<digest_size, intermediate_hash_size>::get_digest(compat::spa

template <compat::size_t digest_size, compat::size_t intermediate_hash_size>
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto
sha_1_2_hasher_base<digest_size, intermediate_hash_size>::get_digest() noexcept -> compat::expected<return_type, state>
sha_1_2_hasher_base<digest_size, intermediate_hash_size>::get_digest() const noexcept -> compat::expected<return_type, state>
{
if (corrupted_ || !computed_)
{
Expand Down
Loading
Loading