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
2 changes: 1 addition & 1 deletion include/boost/crypt2/detail/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#endif

#if !defined(NDEBUG) && !defined(BOOST_CRYPT_HAS_CUDA)
#if !defined(NDEBUG) && !BOOST_CRYPT_HAS_CUDA

namespace boost::crypt::assert_detail {

Expand Down
2 changes: 1 addition & 1 deletion include/boost/crypt2/detail/clear_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <boost/crypt2/detail/config.hpp>
#include <boost/crypt2/detail/compat.hpp>

#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA

#include <cuda/std/span>
#include <cuda/std/array>
Expand Down
52 changes: 26 additions & 26 deletions include/boost/crypt2/detail/compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

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

#if !defined(BOOST_CRYPT_HAS_CUDA)
#if !BOOST_CRYPT_HAS_CUDA
#include <boost/crypt2/detail/expected.hpp>
#endif

#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !BOOST_CRYPT_HAS_CUDA

#include <span>
#include <array>
Expand All @@ -26,7 +26,7 @@
#include <utility>
#include <bit>

#elif defined(BOOST_CRYPT_HAS_CUDA)
#elif BOOST_CRYPT_HAS_CUDA

#include <cuda/std/span>
#include <cuda/std/array>
Expand All @@ -44,7 +44,7 @@
namespace boost::crypt::compat {

// Fixed width types
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
using size_t = cuda::std::size_t;
using uint32_t = cuda::std::uint32_t;
using uint64_t = cuda::std::uint64_t;
Expand All @@ -56,13 +56,13 @@ using uint64_t = std::uint64_t;

// Arrays and spans
template <typename T, compat::size_t N>
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
using array = cuda::std::array<T, N>;
#else
using array = std::array<T, N>;
#endif

#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
template<typename T, cuda::std::size_t Extent = cuda::std::dynamic_extent>
using span = cuda::std::span<T, Extent>;
#else
Expand All @@ -71,7 +71,7 @@ using span = std::span<T, Extent>;
#endif

// Byte and friends
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
using byte = cuda::std::byte;
#else
using byte = std::byte;
Expand All @@ -80,7 +80,7 @@ using byte = std::byte;
template <typename T>
BOOST_CRYPT_GPU_ENABLED constexpr auto as_bytes(span<T> s) noexcept
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::as_bytes(s);
#else
return std::as_bytes(s);
Expand All @@ -90,15 +90,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto as_bytes(span<T> s) noexcept
template <typename T>
BOOST_CRYPT_GPU_ENABLED constexpr auto as_writable_bytes(span<T> s) noexcept
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::as_writable_bytes(s);
#else
return std::as_writable_bytes(s);
#endif
}

// Type traits
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
template <typename T, T v>
using integral_constant = cuda::std::integral_constant<T, v>;
template <bool b>
Expand All @@ -116,23 +116,23 @@ using false_type = std::false_type;

template <typename T>
inline constexpr bool is_trivially_copyable_v =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::is_trivially_copyable_v<T>;
#else
std::is_trivially_copyable_v<T>;
#endif

template <typename T>
using remove_reference_t =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::remove_reference_t<T>;
#else
std::remove_reference_t<T>;
#endif

template <typename T>
using remove_cvref_t =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::remove_cv_t<cuda::std::remove_reference_t<T>>;
#else
std::remove_cv_t<std::remove_reference_t<T>>;
Expand All @@ -141,23 +141,23 @@ using remove_cvref_t =
// Ranges concepts and utilities
template <typename R>
concept sized_range =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::ranges::sized_range<R>;
#else
std::ranges::sized_range<R>;
#endif

template <typename R, typename T>
concept output_range =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::ranges::output_range<R, T>;
#else
std::ranges::output_range<R, T>;
#endif

template <typename R>
using range_value_t =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::ranges::range_value_t<R>;
#else
std::ranges::range_value_t<R>;
Expand All @@ -167,7 +167,7 @@ using range_value_t =
template <typename T>
BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>& t) noexcept -> T&&
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::forward<T>(t);
#else
return std::forward<T>(t);
Expand All @@ -177,7 +177,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>& t) noexcep
template <typename T>
BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>&& t) noexcept -> T&&
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::forward<T>(cuda::std::move(t));
#else
return std::forward<T>(std::move(t));
Expand All @@ -203,15 +203,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto make_span(R&& r)
{
if constexpr (is_span_v<remove_cvref_t<R>>)
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::forward<R>(r);
#else
return std::forward<R>(r);
#endif
}
else
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::span(cuda::std::forward<R>(r));
#else
return std::span(std::forward<R>(r));
Expand All @@ -228,7 +228,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto make_span(R& r)
}
else
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::span(r);
#else
return std::span(r);
Expand All @@ -247,7 +247,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotl(T val, int shift) noexcept
#pragma clang diagnostic ignored "-Wsign-conversion"
#endif

#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::rotl(val, shift);
#else
return std::rotl(val, shift);
Expand All @@ -268,7 +268,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotr(T val, int shift) noexcept
#pragma clang diagnostic ignored "-Wsign-conversion"
#endif

#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
return cuda::std::rotr(val, shift);
#else
return std::rotr(val, shift);
Expand All @@ -282,15 +282,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotr(T val, int shift) noexcept
// Expected
template <typename T, typename E>
using expected =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::expected<T, E>;
#else
boost::crypt::detail::expected_impl::expected<T, E>;
#endif

template <typename E>
using unexpected =
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
cuda::std::unexpected<E>;
#else
boost::crypt::detail::expected_impl::unexpected<E>;
Expand All @@ -299,7 +299,7 @@ using unexpected =
// Endian
enum class endian : int
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
little = static_cast<int>(cuda::std::endian::little),
big = static_cast<int>(cuda::std::endian::big),
native = static_cast<int>(cuda::std::endian::native),
Expand Down
4 changes: 2 additions & 2 deletions include/boost/crypt2/detail/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

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

#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !BOOST_CRYPT_HAS_CUDA
#include <filesystem>
#include <type_traits>
#endif

namespace boost::crypt::concepts {

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA

template <typename T>
concept file_system_path =
Expand Down
25 changes: 6 additions & 19 deletions include/boost/crypt2/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#ifdef __CUDACC__
# ifndef BOOST_CRYPT_HAS_CUDA
# define BOOST_CRYPT_HAS_CUDA
# define BOOST_CRYPT_HAS_CUDA 1
# endif
# define BOOST_CRYPT_GPU_ENABLED __host__ __device__
# define BOOST_CRYPT_GPU_HOST_ENABLED __host__
Expand All @@ -17,14 +17,18 @@

#ifdef __CUDACC_RTC__
# ifndef BOOST_CRYPT_HAS_CUDA
# define BOOST_CRYPT_HAS_CUDA
# define BOOST_CRYPT_HAS_CUDA 1
# endif
# define BOOST_CRYPT_HAS_NVRTC
# define BOOST_CRYPT_GPU_ENABLED __host__ __device__
# define BOOST_CRYPT_GPU_HOST_ENABLED __host__
# define BOOST_CRYPT_GPU_DEVICE_ENABLED __device__
#endif

#ifndef BOOST_CRYPT_HAS_CUDA
# define BOOST_CRYPT_HAS_CUDA 0
#endif

#ifndef BOOST_CRYPT_GPU_ENABLED
# define BOOST_CRYPT_GPU_ENABLED
#endif
Expand All @@ -47,21 +51,4 @@
# define BOOST_CRYPT_EXPORT
#endif

// See: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#hardware-implementation
#if defined(_WIN32) || defined(BOOST_CRYPT_HAS_CUDA)

#define BOOST_CRYPT_ENDIAN_BIG_BYTE 0
#define BOOST_CRYPT_ENDIAN_LITTLE_BYTE 1

#elif defined(__BYTE_ORDER__)

#define BOOST_CRYPT_ENDIAN_BIG_BYTE (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define BOOST_CRYPT_ENDIAN_LITTLE_BYTE (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)

#else

#error Could not determine endian type. Please file an issue at https://github.com/cppalliance/crypt with your architecture

#endif // Determine endianness

#endif // BOOST_CRYPT_DETAIL_CONFIG_HPP
2 changes: 1 addition & 1 deletion include/boost/crypt2/detail/file_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA

#ifndef BOOST_CRYPT_BUILD_MODULE
#include <fstream>
Expand Down
2 changes: 1 addition & 1 deletion include/boost/crypt2/hash/detail/hash_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA

#include <boost/crypt2/detail/file_reader.hpp>
#include <boost/crypt2/detail/concepts.hpp>
Expand Down
4 changes: 2 additions & 2 deletions include/boost/crypt2/hash/detail/sha224_256_hasher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace sha256_detail {

// On the host device we prefer this array to be static,
// but in a CUDA environment we move it into the function to make it available to host and device
#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA
inline constexpr compat::array<compat::uint32_t, 64U> sha256_k {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
Expand Down Expand Up @@ -102,7 +102,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_maj(const compat::uint32_t x,
template <compat::size_t digest_size>
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_224_256_hasher<digest_size>::process_message_block() noexcept -> void
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA
constexpr compat::uint32_t sha256_k[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
Expand Down
4 changes: 2 additions & 2 deletions include/boost/crypt2/hash/detail/sha3_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class sha3_base final {

namespace sha3_detail {

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA

inline constexpr compat::size_t num_rounds {24U};

Expand Down Expand Up @@ -108,7 +108,7 @@ inline constexpr compat::array<compat::uint64_t, num_rounds> iota {
template <compat::size_t digest_size, bool is_xof>
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha3_base<digest_size, is_xof>::process_message_block() noexcept -> void
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA

constexpr compat::size_t num_rounds {24U};

Expand Down
4 changes: 2 additions & 2 deletions include/boost/crypt2/hash/detail/sha512_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512_base<digest_size>::init() noexcept

namespace sha512_detail {

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA

// On the host device we prefer this array to be static,
// but in a CUDA environment we move it into the function to make it available to host and device
Expand Down Expand Up @@ -377,7 +377,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_maj(const compat::uint64_t x,
template <compat::size_t digest_size>
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512_base<digest_size>::process_message_block() noexcept -> void
{
#ifdef BOOST_CRYPT_HAS_CUDA
#if BOOST_CRYPT_HAS_CUDA

constexpr compat::array<compat::uint64_t, 80U> sha512_k = {
0x428A2F98D728AE22ULL, 0x7137449123EF65CDULL, 0xB5C0FBCFEC4D3B2FULL,
Expand Down
2 changes: 1 addition & 1 deletion include/boost/crypt2/hash/sha1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ auto sha1(SizedRange&& data) noexcept -> compat::expected<sha1_hasher::return_ty
return hasher.get_digest();
}

#ifndef BOOST_CRYPT_HAS_CUDA
#if !BOOST_CRYPT_HAS_CUDA


template <concepts::file_system_path T>
Expand Down
Loading
Loading