xrpld
Loading...
Searching...
No Matches
hardened_hash.h
1#pragma once
2
3#include <xrpl/beast/hash/xxhasher.h>
4
5#include <cstdint>
6#include <mutex>
7#include <random>
8#include <utility>
9
10namespace xrpl {
11
12namespace detail {
13
15
16template <bool = true>
18makeSeedPair() noexcept
19{
20 struct StateT
21 {
22 std::mutex mutex;
26
27 StateT() : gen(rng())
28 {
29 }
30 // state_t(state_t const&) = delete;
31 // state_t& operator=(state_t const&) = delete;
32 };
33 static StateT kState;
34 std::scoped_lock const lock(kState.mutex);
35 return {kState.dist(kState.gen), kState.dist(kState.gen)};
36}
37
38} // namespace detail
39
69
70template <class HashAlgorithm = beast::Xxhasher>
72{
73private:
75
76public:
77 using result_type = HashAlgorithm::result_type;
78
79 HardenedHash() = default;
80
81 template <class T>
83 operator()(T const& t) const noexcept
84 {
85 HashAlgorithm h(seeds_.first, seeds_.second);
86 hash_append(h, t);
87 return static_cast<result_type>(h);
88 }
89};
90
91} // namespace xrpl
detail::seed_pair seeds_
HardenedHash()=default
result_type operator()(T const &t) const noexcept
HashAlgorithm::result_type result_type
seed_pair makeSeedPair() noexcept
std::pair< std::uint64_t, std::uint64_t > seed_pair
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:194