xrpld
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>
19makeSeedPair() noexcept
20{
21 struct StateT
22 {
23 std::mutex mutex;
27
28 StateT() : gen(rng())
29 {
30 }
31 // state_t(state_t const&) = delete;
32 // state_t& operator=(state_t const&) = delete;
33 };
34 static StateT kState;
35 std::scoped_lock const lock(kState.mutex);
36 return {kState.dist(kState.gen), kState.dist(kState.gen)};
37}
38
39} // namespace detail
40
70
71template <class HashAlgorithm = beast::Xxhasher>
73{
74private:
76
77public:
78 using result_type = HashAlgorithm::result_type;
79
80 HardenedHash() = default;
81
82 template <class T>
84 operator()(T const& t) const noexcept
85 {
86 HashAlgorithm h(seeds_.first, seeds_.second);
87 hash_append(h, t);
88 return static_cast<result_type>(h);
89 }
90};
91
92} // 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:175