Go to the documentation of this file. 38 #define CRYPTO_MAKE_COMPARABLE(type) \ 40 inline bool operator==(const type &_v1, const type &_v2) { \ 41 return !memcmp(&_v1, &_v2, sizeof(_v1)); \ 43 inline bool operator!=(const type &_v1, const type &_v2) { \ 44 return !operator==(_v1, _v2); \ 48 #define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \ 50 inline bool operator==(const type &_v1, const type &_v2) { \ 51 static_assert(sizeof(_v1) == 32, "constant time comparison is only implenmted for 32 bytes"); \ 52 return crypto_verify_32((const unsigned char*)&_v1, (const unsigned char*)&_v2) == 0; \ 54 inline bool operator!=(const type &_v1, const type &_v2) { \ 55 return !operator==(_v1, _v2); \ 59 #define CRYPTO_DEFINE_HASH_FUNCTIONS(type) \ 61 static_assert(sizeof(std::size_t) <= sizeof(type), "Size of " #type " must be at least that of size_t"); \ 62 inline std::size_t hash_value(const type &_v) { \ 63 return reinterpret_cast<const std::size_t &>(_v); \ 68 struct hash<crypto::type> { \ 69 std::size_t operator()(const crypto::type &_v) const { \ 70 return reinterpret_cast<const std::size_t &>(_v); \ 75 #define CRYPTO_MAKE_HASHABLE(type) \ 76 CRYPTO_MAKE_COMPARABLE(type) \ 77 CRYPTO_DEFINE_HASH_FUNCTIONS(type) 79 #define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME(type) \ 80 CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \ 81 CRYPTO_DEFINE_HASH_FUNCTIONS(type)