diff options
| author | tobtoht <tob@featherwallet.org> | 2025-01-22 22:54:33 +0000 |
|---|---|---|
| committer | tobtoht <tob@featherwallet.org> | 2025-01-22 22:54:33 +0000 |
| commit | b08d3b5b83fc54bf6729db0a968ae92c00708eea (patch) | |
| tree | e6d1275cf1f70b5fa7a2c9a826a23a23951d1fd7 /src | |
| parent | 90290011276c55f24ef2a4097030947e08657834 (diff) | |
| parent | 27858049da753ea7d0ce44829a6c06f1597d72d5 (diff) | |
| download | monzero-core-b08d3b5b83fc54bf6729db0a968ae92c00708eea.tar.gz monzero-core-b08d3b5b83fc54bf6729db0a968ae92c00708eea.tar.xz monzero-core-b08d3b5b83fc54bf6729db0a968ae92c00708eea.zip | |
Merge pull request #9692
27858049d crypto: make CRYPTO_DEFINE_HASH_FUNCTIONS adhere strict aliasing (jeffro256)
Diffstat (limited to 'src')
| -rw-r--r-- | src/crypto/generic-ops.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/crypto/generic-ops.h b/src/crypto/generic-ops.h index 5a5e09f9b..3ff3619fe 100644 --- a/src/crypto/generic-ops.h +++ b/src/crypto/generic-ops.h @@ -33,6 +33,7 @@ #include <cstddef> #include <cstring> #include <functional> +#include <memory> #include <sodium/crypto_verify_32.h> #define CRYPTO_MAKE_COMPARABLE(type) \ @@ -60,14 +61,18 @@ namespace crypto { \ namespace crypto { \ static_assert(sizeof(std::size_t) <= sizeof(type), "Size of " #type " must be at least that of size_t"); \ inline std::size_t hash_value(const type &_v) { \ - return reinterpret_cast<const std::size_t &>(_v); \ + std::size_t h; \ + memcpy(&h, std::addressof(_v), sizeof(h)); \ + return h; \ } \ } \ namespace std { \ template<> \ struct hash<crypto::type> { \ std::size_t operator()(const crypto::type &_v) const { \ - return reinterpret_cast<const std::size_t &>(_v); \ + std::size_t h; \ + memcpy(&h, std::addressof(_v), sizeof(h)); \ + return h; \ } \ }; \ } |
