Go to the documentation of this file. 39 #define CRYPTO_MAKE_COMPARABLE(type) \ 41 inline bool operator==(const type &_v1, const type &_v2) { \ 42 return !memcmp(&_v1, &_v2, sizeof(_v1)); \ 44 inline bool operator!=(const type &_v1, const type &_v2) { \ 45 return !operator==(_v1, _v2); \ 49 #define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \ 51 inline bool operator==(const type &_v1, const type &_v2) { \ 52 static_assert(sizeof(_v1) == 32, "constant time comparison is only implenmted for 32 bytes"); \ 53 return crypto_verify_32((const unsigned char*)&_v1, (const unsigned char*)&_v2) == 0; \ 55 inline bool operator!=(const type &_v1, const type &_v2) { \ 56 return !operator==(_v1, _v2); \ 60 #define CRYPTO_DEFINE_HASH_FUNCTIONS(type) \ 62 static_assert(sizeof(std::size_t) <= sizeof(type), "Size of " #type " must be at least that of size_t"); \ 63 inline std::size_t hash_value(const type &_v) { \ 64 return reinterpret_cast<const std::size_t &>(_v); \ 69 struct hash<crypto::type> { \ 70 std::size_t operator()(const crypto::type &_v) const { \ 71 return reinterpret_cast<const std::size_t &>(_v); \ 76 #define CRYPTO_MAKE_HASHABLE(type) \ 77 CRYPTO_MAKE_COMPARABLE(type) \ 78 CRYPTO_DEFINE_HASH_FUNCTIONS(type) 80 #define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME(type) \ 81 CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \ 82 CRYPTO_DEFINE_HASH_FUNCTIONS(type)