Electroneum
Loading...
Searching...
No Matches
generic-ops.h File Reference
#include <cstddef>
#include <cstring>
#include <functional>
#include <sodium/crypto_verify_32.h>
Include dependency graph for generic-ops.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CRYPTO_MAKE_COMPARABLE(type)
#define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type)
#define CRYPTO_DEFINE_HASH_FUNCTIONS(type)
#define CRYPTO_MAKE_HASHABLE(type)
#define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME(type)

Macro Definition Documentation

◆ CRYPTO_DEFINE_HASH_FUNCTIONS

#define CRYPTO_DEFINE_HASH_FUNCTIONS ( type)
Value:
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); \
} \
} \
namespace std { \
template<> \
struct hash<crypto::type> { \
std::size_t operator()(const crypto::type &_v) const { \
return reinterpret_cast<const std::size_t &>(_v); \
} \
}; \
}
crypto namespace.
Definition crypto.cpp:58
POD_CLASS hash
Definition hash.h:50

Definition at line 60 of file generic-ops.h.

60#define CRYPTO_DEFINE_HASH_FUNCTIONS(type) \
61namespace crypto { \
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); \
65 } \
66} \
67namespace std { \
68 template<> \
69 struct hash<crypto::type> { \
70 std::size_t operator()(const crypto::type &_v) const { \
71 return reinterpret_cast<const std::size_t &>(_v); \
72 } \
73 }; \
74}

◆ CRYPTO_MAKE_COMPARABLE

#define CRYPTO_MAKE_COMPARABLE ( type)
Value:
namespace crypto { \
inline bool operator==(const type &_v1, const type &_v2) { \
return !memcmp(&_v1, &_v2, sizeof(_v1)); \
} \
inline bool operator!=(const type &_v1, const type &_v2) { \
return !operator==(_v1, _v2); \
} \
}
bool operator==(expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
Definition expect.h:401
bool operator!=(const ec_scalar &a, const ec_scalar &b)
Definition main.cpp:49

Definition at line 39 of file generic-ops.h.

39#define CRYPTO_MAKE_COMPARABLE(type) \
40namespace crypto { \
41 inline bool operator==(const type &_v1, const type &_v2) { \
42 return !memcmp(&_v1, &_v2, sizeof(_v1)); \
43 } \
44 inline bool operator!=(const type &_v1, const type &_v2) { \
45 return !operator==(_v1, _v2); \
46 } \
47}

◆ CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME

#define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME ( type)
Value:
namespace crypto { \
inline bool operator==(const type &_v1, const type &_v2) { \
static_assert(sizeof(_v1) == 32, "constant time comparison is only implenmted for 32 bytes"); \
return crypto_verify_32((const unsigned char*)&_v1, (const unsigned char*)&_v2) == 0; \
} \
inline bool operator!=(const type &_v1, const type &_v2) { \
return !operator==(_v1, _v2); \
} \
}
int crypto_verify_32(const unsigned char *, const unsigned char *)

Definition at line 49 of file generic-ops.h.

49#define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \
50namespace crypto { \
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; \
54 } \
55 inline bool operator!=(const type &_v1, const type &_v2) { \
56 return !operator==(_v1, _v2); \
57 } \
58}

◆ CRYPTO_MAKE_HASHABLE

#define CRYPTO_MAKE_HASHABLE ( type)
Value:
CRYPTO_DEFINE_HASH_FUNCTIONS(type)
#define CRYPTO_MAKE_COMPARABLE(type)
Definition generic-ops.h:39

Definition at line 76 of file generic-ops.h.

76#define CRYPTO_MAKE_HASHABLE(type) \
77CRYPTO_MAKE_COMPARABLE(type) \
78CRYPTO_DEFINE_HASH_FUNCTIONS(type)

◆ CRYPTO_MAKE_HASHABLE_CONSTANT_TIME

#define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME ( type)
Value:
CRYPTO_DEFINE_HASH_FUNCTIONS(type)
#define CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type)
Definition generic-ops.h:49

Definition at line 80 of file generic-ops.h.

80#define CRYPTO_MAKE_HASHABLE_CONSTANT_TIME(type) \
81CRYPTO_MAKE_COMPARABLE_CONSTANT_TIME(type) \
82CRYPTO_DEFINE_HASH_FUNCTIONS(type)