Loading...
Searching...
No Matches
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) { \
65 memcpy(&h, std::addressof(_v), sizeof(h)); \
71 struct hash<crypto::type> { \
72 std::size_t operator()(const crypto::type &_v) const { \
74 memcpy(&h, std::addressof(_v), sizeof(h)); \
80#define CRYPTO_MAKE_HASHABLE(type) \
81CRYPTO_MAKE_COMPARABLE(type) \
82CRYPTO_DEFINE_HASH_FUNCTIONS(type)
84#define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME(type) \
85CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \
86CRYPTO_DEFINE_HASH_FUNCTIONS(type)