rippled
Loading...
Searching...
No Matches
digest.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/crypto/secure_erase.h>
5
6#include <boost/endian/conversion.hpp>
7
8#include <array>
9
10namespace xrpl {
11
21//------------------------------------------------------------------------------
22
28{
29public:
30 static constexpr auto const endian = boost::endian::order::native;
31
33
35
36 void
37 operator()(void const* data, std::size_t size) noexcept;
38
39 explicit
40 operator result_type() noexcept;
41
42private:
43 char ctx_[96];
44};
45
51{
52public:
53 static constexpr auto const endian = boost::endian::order::native;
54
56
58
59 void
60 operator()(void const* data, std::size_t size) noexcept;
61
62 explicit
63 operator result_type() noexcept;
64
65private:
66 char ctx_[216];
67};
68
74{
75public:
76 static constexpr auto const endian = boost::endian::order::native;
77
79
81
82 void
83 operator()(void const* data, std::size_t size) noexcept;
84
85 explicit
86 operator result_type() noexcept;
87
88private:
89 char ctx_[112];
90};
91
92//------------------------------------------------------------------------------
93
97
98//------------------------------------------------------------------------------
99
116{
117private:
119
120public:
121 static constexpr auto const endian = boost::endian::order::native;
122
124
125 void
126 operator()(void const* data, std::size_t size) noexcept
127 {
128 h_(data, size);
129 }
130
131 explicit
132 operator result_type() noexcept
133 {
134 auto const d0 = sha256_hasher::result_type(h_);
136 rh(d0.data(), d0.size());
138 }
139};
140
141//------------------------------------------------------------------------------
142
143namespace detail {
144
150template <bool Secure>
152{
153private:
155
156public:
157 static constexpr auto const endian = boost::endian::order::big;
158
160
165
166 void
167 operator()(void const* data, std::size_t size) noexcept
168 {
169 h_(data, size);
170 }
171
172 explicit
173 operator result_type() noexcept
174 {
175 auto const digest = sha512_hasher::result_type(h_);
176 return result_type::fromVoid(digest.data());
177 }
178
179private:
180 inline void
182 {
183 }
184
185 inline void
187 {
188 secure_erase(&h_, sizeof(h_));
189 }
190};
191
192} // namespace detail
193
195
196// secure version
198
199//------------------------------------------------------------------------------
200
202template <class... Args>
204sha512Half(Args const&... args)
205{
207 using beast::hash_append;
208 hash_append(h, args...);
209 return static_cast<typename sha512_half_hasher::result_type>(h);
210}
211
218template <class... Args>
220sha512Half_s(Args const&... args)
221{
223 using beast::hash_append;
224 hash_append(h, args...);
225 return static_cast<typename sha512_half_hasher_s::result_type>(h);
226}
227
228} // namespace xrpl
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:204
void secure_erase(void *dest, std::size_t bytes)
Attempts to clear the given blob of memory.
void hash_append(Hasher &h, Slice const &v)
Definition Slice.h:174
void erase(STObject &st, TypedField< U > const &f)
Remove a field in an STObject.
Definition STExchange.h:148
sha512_half_hasher_s::result_type sha512Half_s(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:220
Returns the SHA512-Half digest of a message.
Definition digest.h:152
void operator()(void const *data, std::size_t size) noexcept
Definition digest.h:167
void erase(std::false_type)
Definition digest.h:181
Message digest functions used in the codebase.
Definition digest.h:28
void operator()(void const *data, std::size_t size) noexcept
Definition digest.cpp:18
std::array< std::uint8_t, 20 > result_type
Definition digest.h:32
static constexpr auto const endian
Definition digest.h:30
SHA-256 digest.
Definition digest.h:74
std::array< std::uint8_t, 32 > result_type
Definition digest.h:78
SHA-512 digest.
Definition digest.h:51
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
Definition digest.h:116
void operator()(void const *data, std::size_t size) noexcept
Definition digest.h:126
sha256_hasher h_
Definition digest.h:118