Skip to content

Commit

Permalink
crypto: make CRYPTO_DEFINE_HASH_FUNCTIONS adhere strict aliasing
Browse files Browse the repository at this point in the history
This code could've caused issues if the pointer to the `public_key`, `key_image`, `hash`, etc wasn't aligned on an 8-byte boundary.
  • Loading branch information
jeffro256 committed Jan 9, 2025
1 parent 2e8a128 commit e4396bd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/crypto/generic-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,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, &_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, &_v, sizeof(h)); \
return h; \
} \
}; \
}
Expand Down

0 comments on commit e4396bd

Please sign in to comment.