rippled
Loading...
Searching...
No Matches
digest.h
1#ifndef XRPL_PROTOCOL_DIGEST_H_INCLUDED
2#define XRPL_PROTOCOL_DIGEST_H_INCLUDED
3
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/crypto/secure_erase.h>
6
7#include <boost/endian/conversion.hpp>
8
9#include <array>
10
11namespace ripple {
12
22//------------------------------------------------------------------------------
23
29{
30public:
31 static constexpr auto const endian = boost::endian::order::native;
32
34
36
37 void
38 operator()(void const* data, std::size_t size) noexcept;
39
40 explicit
41 operator result_type() noexcept;
42
43private:
44 char ctx_[96];
45};
46
52{
53public:
54 static constexpr auto const endian = boost::endian::order::native;
55
57
59
60 void
61 operator()(void const* data, std::size_t size) noexcept;
62
63 explicit
64 operator result_type() noexcept;
65
66private:
67 char ctx_[216];
68};
69
75{
76public:
77 static constexpr auto const endian = boost::endian::order::native;
78
80
82
83 void
84 operator()(void const* data, std::size_t size) noexcept;
85
86 explicit
87 operator result_type() noexcept;
88
89private:
90 char ctx_[112];
91};
92
93//------------------------------------------------------------------------------
94
98
99//------------------------------------------------------------------------------
100
117{
118private:
120
121public:
122 static constexpr auto const endian = boost::endian::order::native;
123
125
126 void
127 operator()(void const* data, std::size_t size) noexcept
128 {
129 h_(data, size);
130 }
131
132 explicit
133 operator result_type() noexcept
134 {
135 auto const d0 = sha256_hasher::result_type(h_);
137 rh(d0.data(), d0.size());
139 }
140};
141
142//------------------------------------------------------------------------------
143
144namespace detail {
145
151template <bool Secure>
153{
154private:
156
157public:
158 static constexpr auto const endian = boost::endian::order::big;
159
161
166
167 void
168 operator()(void const* data, std::size_t size) noexcept
169 {
170 h_(data, size);
171 }
172
173 explicit
174 operator result_type() noexcept
175 {
176 auto const digest = sha512_hasher::result_type(h_);
177 return result_type::fromVoid(digest.data());
178 }
179
180private:
181 inline void
183 {
184 }
185
186 inline void
188 {
189 secure_erase(&h_, sizeof(h_));
190 }
191};
192
193} // namespace detail
194
196
197// secure version
199
200//------------------------------------------------------------------------------
201
203template <class... Args>
205sha512Half(Args const&... args)
206{
208 using beast::hash_append;
209 hash_append(h, args...);
210 return static_cast<typename sha512_half_hasher::result_type>(h);
211}
212
219template <class... Args>
221sha512Half_s(Args const&... args)
222{
224 using beast::hash_append;
225 hash_append(h, args...);
226 return static_cast<typename sha512_half_hasher_s::result_type>(h);
227}
228
229} // namespace ripple
230
231#endif
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:6
sha512_half_hasher_s::result_type sha512Half_s(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:221
void hash_append(Hasher &h, Slice const &v)
Definition Slice.h:180
void erase(STObject &st, TypedField< U > const &f)
Remove a field in an STObject.
Definition STExchange.h:153
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:205
void secure_erase(void *dest, std::size_t bytes)
Attempts to clear the given blob of memory.
Returns the SHA512-Half digest of a message.
Definition digest.h:153
void operator()(void const *data, std::size_t size) noexcept
Definition digest.h:168
Message digest functions used in the codebase.
Definition digest.h:29
static constexpr auto const endian
Definition digest.h:31
void operator()(void const *data, std::size_t size) noexcept
Definition digest.cpp:21
std::array< std::uint8_t, 20 > result_type
Definition digest.h:33
std::array< std::uint8_t, 32 > result_type
Definition digest.h:79
Returns the RIPEMD-160 digest of the SHA256 hash of the message.
Definition digest.h:117
sha256_hasher h_
Definition digest.h:119
void operator()(void const *data, std::size_t size) noexcept
Definition digest.h:127