From 64b1e9b8650614a7b4fe8eba2f132be4a0955aa9 Mon Sep 17 00:00:00 2001 From: mcoret <50789469+mcoret@users.noreply.github.com> Date: Tue, 26 Sep 2023 12:57:15 +0300 Subject: [PATCH] windows compatibility fixes --- include/auth/sponge.hpp | 2 +- include/hashing/sponge.hpp | 2 +- include/utils.hpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/auth/sponge.hpp b/include/auth/sponge.hpp index d137c98..fb9c79c 100644 --- a/include/auth/sponge.hpp +++ b/include/auth/sponge.hpp @@ -27,7 +27,7 @@ initialize(ascon_perm::ascon_perm_t& state, std::span k constexpr uint64_t iv = (klen << 56) | // 8 -bit wide bit length of secret key (out_rate << 48) | // 8 -bit wide bit length of output rate (((1ul << 7) ^ rounds_a) << 40) | // 8 -bit wide, 2^7 ⊕ a - (0b00000000ul << 32) | // 8 zero bits + (0b00000000ull << 32) | // 8 zero bits max_out_len // 32 -bit wide max. output bit length ; diff --git a/include/hashing/sponge.hpp b/include/hashing/sponge.hpp index da87046..a682101 100644 --- a/include/hashing/sponge.hpp +++ b/include/hashing/sponge.hpp @@ -86,7 +86,7 @@ finalize(ascon_perm::ascon_perm_t& state, size_t& offset) const size_t pad_bytes = rbytes - offset; const size_t pad_bits = pad_bytes * 8; - const uint64_t pad_mask = 1ul << (pad_bits - 1); + const uint64_t pad_mask = 1ull << (pad_bits - 1); state[0] ^= pad_mask; state.permute(); diff --git a/include/utils.hpp b/include/utils.hpp index 01b8b4c..2721e21 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -24,15 +24,19 @@ bswap(const T a) requires(std::unsigned_integral && ((sizeof(T) == 4) || (sizeof(T) == 8))) { if constexpr (sizeof(T) == 4) { -#if defined __GNUG__ +#if defined __GNUG__ || defined __MINGW64__ return __builtin_bswap32(a); +#elif defined _MSC_VER + return _byteswap_uint32(a); #else return ((a & 0x000000ffu) << 24) | ((a & 0x0000ff00u) << 8) | ((a & 0x00ff0000u) >> 8) | ((a & 0xff000000u) >> 24); #endif } else { -#if defined __GNUG__ +#if defined __GNUG__ || defined __MINGW64__ return __builtin_bswap64(a); +#elif defined _MSC_VER + return _byteswap_uint64(a); #else return ((a & 0x00000000000000fful) << 56) | ((a & 0x000000000000ff00ul) << 40) | ((a & 0x0000000000ff0000ul) << 24) | ((a & 0x00000000ff000000ul) << 0x8) | @@ -106,7 +110,7 @@ inline void pad_msg_blk(std::span msg_blk, const size_t used) { std::memset(msg_blk.subspan(used).data(), 0x00, len - used); - std::memset(msg_blk.subspan(used).data(), 0x80, std::min(len - used, 1ul)); + std::memset(msg_blk.subspan(used).data(), 0x80, std::min(len - used, 1ul)); } // Converts byte array into hex string; see https://stackoverflow.com/a/14051107 @@ -191,7 +195,7 @@ random_data(std::span data) { std::random_device rd; std::mt19937_64 gen(rd()); - std::uniform_int_distribution dis; + std::uniform_int_distribution<> dis; for (size_t i = 0; i < data.size(); i++) { data[i] = dis(gen);