From 9b45eabb00ec42a51f521e219865618c372d7b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 1 May 2016 15:27:13 -0400 Subject: [PATCH] infohash: remove std::hash InfoHash is an hash itself, std::hash reduces the precision, could cause potential security issues or bugs. --- include/opendht/infohash.h | 19 ------------------- python/opendht.pyx | 3 --- 2 files changed, 22 deletions(-) diff --git a/include/opendht/infohash.h b/include/opendht/infohash.h index e4b353ec..26d82d52 100644 --- a/include/opendht/infohash.h +++ b/include/opendht/infohash.h @@ -198,22 +198,3 @@ public: }; } - -namespace std -{ - template<> - struct hash<dht::InfoHash> - { - typedef dht::InfoHash argument_type; - typedef std::size_t result_type; - - result_type operator()(dht::InfoHash const& s) const - { - result_type r {}; - std::hash<uint8_t> hash_fn; - for (size_t i = 0; i < HASH_LEN; i++) - r = r ^ (hash_fn(s[i]) << i*4); - return r; - } - }; -} diff --git a/python/opendht.pyx b/python/opendht.pyx index f226945f..d7b1c485 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -84,9 +84,6 @@ cdef class InfoHash(_WithID): if op == 2: return self._infohash == other._infohash return NotImplemented - def __hash__(self): - cdef cpp.hash[cpp.InfoHash] hash_fn - return hash_fn.get(self._infohash) def getBit(InfoHash self, bit): return self._infohash.getBit(bit) def setBit(InfoHash self, bit, b): -- GitLab