|
@@ -11,8 +11,8 @@
|
|
|
*/
|
|
*/
|
|
|
/****/
|
|
/****/
|
|
|
|
|
|
|
|
-#ifndef ZT_HASH_HPP
|
|
|
|
|
-#define ZT_HASH_HPP
|
|
|
|
|
|
|
+#ifndef ZT_FINGERPRINT_HPP
|
|
|
|
|
+#define ZT_FINGERPRINT_HPP
|
|
|
|
|
|
|
|
#include "Constants.hpp"
|
|
#include "Constants.hpp"
|
|
|
#include "TriviallyCopyable.hpp"
|
|
#include "TriviallyCopyable.hpp"
|
|
@@ -20,7 +20,7 @@
|
|
|
namespace ZeroTier {
|
|
namespace ZeroTier {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Container for cryptographic hashes
|
|
|
|
|
|
|
+ * Container for 384-bit identity hashes
|
|
|
*
|
|
*
|
|
|
* The size of the hash used with this container must be a multiple of 64 bits.
|
|
* The size of the hash used with this container must be a multiple of 64 bits.
|
|
|
* Currently it's used as H<384> and H<512>.
|
|
* Currently it's used as H<384> and H<512>.
|
|
@@ -29,25 +29,17 @@ namespace ZeroTier {
|
|
|
*
|
|
*
|
|
|
* @tparam BITS Bits in hash, must be a multiple of 64
|
|
* @tparam BITS Bits in hash, must be a multiple of 64
|
|
|
*/
|
|
*/
|
|
|
-template<unsigned int BITS>
|
|
|
|
|
-class Hash : public TriviallyCopyable
|
|
|
|
|
|
|
+class Fingerprint : public TriviallyCopyable
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
- ZT_ALWAYS_INLINE Hash() noexcept {}
|
|
|
|
|
|
|
+ ZT_ALWAYS_INLINE Fingerprint() noexcept {}
|
|
|
|
|
+ explicit ZT_ALWAYS_INLINE Fingerprint(const void *h384) noexcept { memcpy(_h,h384,48); }
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @param h Hash value of size BITS / 8
|
|
|
|
|
- */
|
|
|
|
|
- explicit ZT_ALWAYS_INLINE Hash(const void *h) noexcept { memcpy(_h,h,BITS / 8); }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @param h Hash value of size BITS / 8
|
|
|
|
|
- */
|
|
|
|
|
- ZT_ALWAYS_INLINE void set(const void *h) noexcept { memcpy(_h,h,BITS / 8); }
|
|
|
|
|
|
|
+ ZT_ALWAYS_INLINE void set(const void *h384) noexcept { memcpy(_h,h384,48); }
|
|
|
|
|
|
|
|
ZT_ALWAYS_INLINE void zero() noexcept
|
|
ZT_ALWAYS_INLINE void zero() noexcept
|
|
|
{
|
|
{
|
|
|
- for(int i=0;i<(BITS / (sizeof(unsigned long) * 8));++i)
|
|
|
|
|
|
|
+ for(int i=0;i<(384 / (sizeof(unsigned long) * 8));++i)
|
|
|
_h[i] = 0;
|
|
_h[i] = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -57,28 +49,28 @@ public:
|
|
|
ZT_ALWAYS_INLINE uint8_t operator[](const unsigned int i) const noexcept { return reinterpret_cast<const uint8_t *>(_h)[i]; }
|
|
ZT_ALWAYS_INLINE uint8_t operator[](const unsigned int i) const noexcept { return reinterpret_cast<const uint8_t *>(_h)[i]; }
|
|
|
ZT_ALWAYS_INLINE uint8_t &operator[](const unsigned int i) noexcept { return reinterpret_cast<uint8_t *>(_h)[i]; }
|
|
ZT_ALWAYS_INLINE uint8_t &operator[](const unsigned int i) noexcept { return reinterpret_cast<uint8_t *>(_h)[i]; }
|
|
|
|
|
|
|
|
- static constexpr unsigned int size() noexcept { return BITS / 8; }
|
|
|
|
|
|
|
+ static constexpr unsigned int size() noexcept { return 48; }
|
|
|
|
|
|
|
|
ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return _h[0]; }
|
|
ZT_ALWAYS_INLINE unsigned long hashCode() const noexcept { return _h[0]; }
|
|
|
|
|
|
|
|
ZT_ALWAYS_INLINE operator bool() const noexcept
|
|
ZT_ALWAYS_INLINE operator bool() const noexcept
|
|
|
{
|
|
{
|
|
|
- for(int i=0;i<(BITS / (sizeof(unsigned long) * 8));++i) {
|
|
|
|
|
|
|
+ for(int i=0;i<(384 / (sizeof(unsigned long) * 8));++i) {
|
|
|
if (_h[i] != 0)
|
|
if (_h[i] != 0)
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator==(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) == 0; }
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator!=(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) != 0; }
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator<(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) < 0; }
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator>(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) > 0; }
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator<=(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) <= 0; }
|
|
|
|
|
- ZT_ALWAYS_INLINE bool operator>=(const Hash &h) const noexcept { return memcmp(_h,h._h,BITS / 8) >= 0; }
|
|
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator==(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) == 0; }
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator!=(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) != 0; }
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator<(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) < 0; }
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator>(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) > 0; }
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator<=(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) <= 0; }
|
|
|
|
|
+ ZT_ALWAYS_INLINE bool operator>=(const Fingerprint &h) const noexcept { return memcmp(_h,h._h,48) >= 0; }
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- unsigned long _h[BITS / (sizeof(unsigned long) * 8)];
|
|
|
|
|
|
|
+ unsigned long _h[384 / (sizeof(unsigned long) * 8)];
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
} // namespace ZeroTier
|