Skip to content

Commit

Permalink
Merge pull request #3707 from Rohde-Schwarz/span/loadstor
Browse files Browse the repository at this point in the history
[std::span] {load,store}_{le,be}
  • Loading branch information
reneme authored Dec 22, 2023
2 parents 3ff4753 + 5e52e4b commit 36c2e9e
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 355 deletions.
12 changes: 12 additions & 0 deletions src/lib/utils/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ struct is_strong_type<Strong<Ts...>> : std::true_type {};
template <typename... Ts>
constexpr bool is_strong_type_v = is_strong_type<std::remove_const_t<Ts>...>::value;

template <typename T0, typename... Ts>
struct all_same {
static constexpr bool value = (std::is_same_v<T0, Ts> && ...);
};

template <typename... Ts>
static constexpr bool all_same_v = all_same<Ts...>::value;

namespace ranges {

/**
Expand Down Expand Up @@ -205,6 +213,10 @@ concept contiguous_strong_type = strong_type<T> && contiguous_container<T>;
template <typename T>
concept integral = std::is_integral_v<T>;

// TODO: C++20 - replace with std::unsigned_integral
template <typename T>
concept unsigned_integral = std::is_integral_v<T> && std::is_unsigned_v<T>;

} // namespace concepts

} // namespace Botan
Expand Down
11 changes: 8 additions & 3 deletions src/lib/utils/ghash/ghash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <botan/internal/ct_utils.h>
#include <botan/internal/loadstor.h>

#include <array>

namespace Botan {

std::string GHASH::provider() const {
Expand Down Expand Up @@ -177,9 +179,12 @@ void GHASH::add_final_block(secure_vector<uint8_t>& hash, size_t ad_len, size_t
* stack buffer is fine here since the text len is public
* and the length of the AD is probably not sensitive either.
*/
uint8_t final_block[GCM_BS];
store_be<uint64_t>(final_block, 8 * ad_len, 8 * text_len);
ghash_update(hash, {final_block, GCM_BS});
std::array<uint8_t, GCM_BS> final_block;

const uint64_t ad_bits = 8 * ad_len;
const uint64_t text_bits = 8 * text_len;
store_be(final_block, ad_bits, text_bits);
ghash_update(hash, final_block);
}

void GHASH::final(std::span<uint8_t> mac) {
Expand Down
Loading

0 comments on commit 36c2e9e

Please sign in to comment.