Skip to content

Commit

Permalink
windows compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoret committed Sep 26, 2023
1 parent 6160fee commit 64b1e9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/auth/sponge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ initialize(ascon_perm::ascon_perm_t& state, std::span<const uint8_t, klen / 8> 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
;

Expand Down
2 changes: 1 addition & 1 deletion include/hashing/sponge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rounds_a>();
Expand Down
12 changes: 8 additions & 4 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ bswap(const T a)
requires(std::unsigned_integral<T> && ((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) |
Expand Down Expand Up @@ -106,7 +110,7 @@ inline void
pad_msg_blk(std::span<uint8_t, len> 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<size_t>(len - used, 1ul));
}

// Converts byte array into hex string; see https://stackoverflow.com/a/14051107
Expand Down Expand Up @@ -191,7 +195,7 @@ random_data(std::span<T> data)
{
std::random_device rd;
std::mt19937_64 gen(rd());
std::uniform_int_distribution<T> dis;
std::uniform_int_distribution<> dis;

for (size_t i = 0; i < data.size(); i++) {
data[i] = dis(gen);
Expand Down

0 comments on commit 64b1e9b

Please sign in to comment.