rippled
Loading...
Searching...
No Matches
hardened_hash.h
1#pragma once
2
3#include <xrpl/beast/hash/hash_append.h>
4#include <xrpl/beast/hash/xxhasher.h>
5
6#include <cstdint>
7#include <mutex>
8#include <random>
9#include <utility>
10
11namespace xrpl {
12
13namespace detail {
14
16
17template <bool = true>
20{
21 struct state_t
22 {
23 std::mutex mutex;
27
28 state_t() : gen(rng())
29 {
30 }
31 // state_t(state_t const&) = delete;
32 // state_t& operator=(state_t const&) = delete;
33 };
34 static state_t state;
35 std::lock_guard lock(state.mutex);
36 return {state.dist(state.gen), state.dist(state.gen)};
37}
38
39} // namespace detail
40
71template <class HashAlgorithm = beast::xxhasher>
73{
74private:
76
77public:
78 using result_type = typename HashAlgorithm::result_type;
79
80 hardened_hash() : m_seeds(detail::make_seed_pair<>())
81 {
82 }
83
84 template <class T>
86 operator()(T const& t) const noexcept
87 {
88 HashAlgorithm h(m_seeds.first, m_seeds.second);
89 hash_append(h, t);
90 return static_cast<result_type>(h);
91 }
92};
93
94} // namespace xrpl
Seed functor once per construction.
detail::seed_pair m_seeds
typename HashAlgorithm::result_type result_type
result_type operator()(T const &t) const noexcept
seed_pair make_seed_pair() noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void hash_append(Hasher &h, Slice const &v)
Definition Slice.h:174