Electroneum
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
STL namespace.

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

◆ 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); \
} \
}
crypto namespace.
Definition: crypto.cpp:58
bool operator==(const some_test_data &a, const some_test_data &b)
bool operator!=(const some_test_subdata &a, const some_test_subdata &b)

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

◆ 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 *)
crypto namespace.
Definition: crypto.cpp:58
bool operator==(const some_test_data &a, const some_test_data &b)
bool operator!=(const some_test_subdata &a, const some_test_subdata &b)

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

◆ 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.

◆ 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.