rippled
Loading...
Searching...
No Matches
digest.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/protocol/digest.h>
21
22#include <openssl/ripemd.h>
23#include <openssl/sha.h>
24
25#include <cstddef>
26
27namespace ripple {
28
30{
31 static_assert(
32 sizeof(decltype(openssl_ripemd160_hasher::ctx_)) ==
33 sizeof(RIPEMD160_CTX),
34 "");
35 auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
36 RIPEMD160_Init(ctx);
37}
38
39void
41 void const* data,
42 std::size_t size) noexcept
43{
44 auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
45 RIPEMD160_Update(ctx, data, size);
46}
47
48openssl_ripemd160_hasher::operator result_type() noexcept
49{
50 auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
52 RIPEMD160_Final(digest.data(), ctx);
53 return digest;
54}
55
56//------------------------------------------------------------------------------
57
59{
60 static_assert(
61 sizeof(decltype(openssl_sha512_hasher::ctx_)) == sizeof(SHA512_CTX),
62 "");
63 auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
64 SHA512_Init(ctx);
65}
66
67void
68openssl_sha512_hasher::operator()(void const* data, std::size_t size) noexcept
69{
70 auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
71 SHA512_Update(ctx, data, size);
72}
73
74openssl_sha512_hasher::operator result_type() noexcept
75{
76 auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
78 SHA512_Final(digest.data(), ctx);
79 return digest;
80}
81
82//------------------------------------------------------------------------------
83
85{
86 static_assert(
87 sizeof(decltype(openssl_sha256_hasher::ctx_)) == sizeof(SHA256_CTX),
88 "");
89 auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
90 SHA256_Init(ctx);
91}
92
93void
94openssl_sha256_hasher::operator()(void const* data, std::size_t size) noexcept
95{
96 auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
97 SHA256_Update(ctx, data, size);
98}
99
100openssl_sha256_hasher::operator result_type() noexcept
101{
102 auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
104 SHA256_Final(digest.data(), ctx);
105 return digest;
106}
107
108} // namespace ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition tokens.cpp:156
void operator()(void const *data, std::size_t size) noexcept
Definition digest.cpp:40
void operator()(void const *data, std::size_t size) noexcept
Definition digest.cpp:94
void operator()(void const *data, std::size_t size) noexcept
Definition digest.cpp:68