xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
basics
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
10
namespace
xrpl
{
11
12
namespace
detail
{
13
14
using
SeedPair
=
std::pair<std::uint64_t, std::uint64_t>
;
15
16
template
<
bool
= true>
17
SeedPair
18
makeSeedPair
() noexcept
19
{
20
struct
StateT
21
{
22
std::mutex
mutex;
23
std::random_device
rng;
24
std::mt19937_64
gen;
25
std::uniform_int_distribution<std::uint64_t>
dist;
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
70
template
<
class
HashAlgorithm = beast::Xxhasher>
71
class
HardenedHash
72
{
73
private
:
74
detail::SeedPair
seeds_
{
detail::makeSeedPair<>
()};
75
76
public
:
77
using
result_type
= HashAlgorithm::result_type;
78
79
HardenedHash
() =
default
;
80
81
template
<
class
T>
82
result_type
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
xrpl::HardenedHash::HardenedHash
HardenedHash()=default
xrpl::HardenedHash::operator()
result_type operator()(T const &t) const noexcept
Definition
hardened_hash.h:83
xrpl::HardenedHash::result_type
HashAlgorithm::result_type result_type
Definition
hardened_hash.h:77
xrpl::HardenedHash::seeds_
detail::SeedPair seeds_
Definition
hardened_hash.h:74
cstdint
std::mt19937_64
mutex
xrpl::detail
Definition
base_uint.h:37
xrpl::detail::makeSeedPair
SeedPair makeSeedPair() noexcept
Definition
hardened_hash.h:18
xrpl::detail::SeedPair
std::pair< std::uint64_t, std::uint64_t > SeedPair
Definition
hardened_hash.h:14
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::hash_append
void hash_append(Hasher &h, Slice const &v)
Definition
Slice.h:194
std::pair
std::random_device
random
std::scoped_lock
std::uniform_int_distribution
utility
Generated by
1.17.0