diff --git a/src/ripple/basics/hardened_hash.h b/src/ripple/basics/hardened_hash.h index 80a670f702..abf0ac6464 100644 --- a/src/ripple/basics/hardened_hash.h +++ b/src/ripple/basics/hardened_hash.h @@ -32,17 +32,6 @@ #include #include -// When set to 1, makes the seed per-process instead -// of per default-constructed instance of hardened_hash -// -#ifndef RIPPLE_NO_HARDENED_HASH_INSTANCE_SEED -# ifdef __GLIBCXX__ -# define RIPPLE_NO_HARDENED_HASH_INSTANCE_SEED 1 -# else -# define RIPPLE_NO_HARDENED_HASH_INSTANCE_SEED 0 -# endif -#endif - namespace ripple { namespace detail { @@ -71,45 +60,38 @@ make_seed_pair() noexcept } -template -class basic_hardened_hash; - -/** - * Seed functor once per process -*/ -template -class basic_hardened_hash -{ -private: - static - detail::seed_pair const& - init_seed_pair() - { - static detail::seed_pair const p = detail::make_seed_pair<>(); - return p; - } - -public: - explicit basic_hardened_hash() = default; - - using result_type = typename HashAlgorithm::result_type; - - template - result_type - operator()(T const& t) const noexcept - { - auto const [seed0, seed1] = init_seed_pair(); - HashAlgorithm h(seed0, seed1); - hash_append(h, t); - return static_cast(h); - } -}; - /** * Seed functor once per construction + + A std compatible hash adapter that resists adversarial inputs. + For this to work, T must implement in its own namespace: + + @code + + template + void + hash_append (Hasher& h, T const& t) noexcept + { + // hash_append each base and member that should + // participate in forming the hash + using beast::hash_append; + hash_append (h, static_cast(t)); + hash_append (h, static_cast(t)); + // ... + hash_append (h, t.member1); + hash_append (h, t.member2); + // ... + } + + @endcode + + Do not use any version of Murmur or CityHash for the Hasher + template parameter (the hashing algorithm). For details + see https://131002.net/siphash/#at */ -template -class basic_hardened_hash + +template +class hardened_hash { private: detail::seed_pair m_seeds; @@ -117,7 +99,7 @@ private: public: using result_type = typename HashAlgorithm::result_type; - basic_hardened_hash() + hardened_hash() : m_seeds (detail::make_seed_pair<>()) {} @@ -131,42 +113,6 @@ public: } }; -//------------------------------------------------------------------------------ - -/** A std compatible hash adapter that resists adversarial inputs. - For this to work, T must implement in its own namespace: - - @code - - template - void - hash_append (Hasher& h, T const& t) noexcept - { - // hash_append each base and member that should - // participate in forming the hash - using beast::hash_append; - hash_append (h, static_cast(t)); - hash_append (h, static_cast(t)); - // ... - hash_append (h, t.member1); - hash_append (h, t.member2); - // ... - } - - @endcode - - Do not use any version of Murmur or CityHash for the Hasher - template parameter (the hashing algorithm). For details - see https://131002.net/siphash/#at -*/ -#if RIPPLE_NO_HARDENED_HASH_INSTANCE_SEED -template - using hardened_hash = basic_hardened_hash; -#else -template - using hardened_hash = basic_hardened_hash; -#endif - } // ripple #endif