Kagome
Polkadot Runtime Engine in C++17
hasher_impl.cpp
Go to the documentation of this file.
1 
7 
8 #include <gsl/span>
9 
10 #include "crypto/blake2/blake2b.h"
11 #include "crypto/blake2/blake2s.h"
12 #include "crypto/keccak/keccak.h"
13 #include "crypto/sha/sha256.hpp"
14 #include "crypto/twox/twox.hpp"
15 
16 namespace kagome::crypto {
17  using common::Hash128;
18  using common::Hash256;
19  using common::Hash512;
20  using common::Hash64;
21 
22  Hash64 HasherImpl::twox_64(gsl::span<const uint8_t> buffer) const {
23  return make_twox64(buffer);
24  }
25 
26  Hash64 HasherImpl::blake2b_64(gsl::span<const uint8_t> buffer) const {
27  Hash64 out;
28  blake2b(out.data(), out.size(), nullptr, 0, buffer.data(), buffer.size());
29  return out;
30  }
31 
32  Hash128 HasherImpl::twox_128(gsl::span<const uint8_t> buffer) const {
33  return make_twox128(buffer);
34  }
35 
36  Hash128 HasherImpl::blake2b_128(gsl::span<const uint8_t> buffer) const {
37  Hash128 out;
38  blake2b(out.data(), out.size(), nullptr, 0, buffer.data(), buffer.size());
39  return out;
40  }
41 
42  Hash256 HasherImpl::twox_256(gsl::span<const uint8_t> buffer) const {
43  return make_twox256(buffer);
44  }
45 
46  Hash256 HasherImpl::blake2b_256(gsl::span<const uint8_t> buffer) const {
47  Hash256 out;
48  blake2b(out.data(), 32, nullptr, 0, buffer.data(), buffer.size());
49  return out;
50  }
51 
52  Hash512 HasherImpl::blake2b_512(gsl::span<const uint8_t> buffer) const {
53  Hash512 out;
54  blake2b(out.data(), 64, nullptr, 0, buffer.data(), buffer.size());
55  return out;
56  }
57 
58  Hash256 HasherImpl::keccak_256(gsl::span<const uint8_t> buffer) const {
59  Hash256 out;
60  sha3_HashBuffer(256,
62  buffer.data(),
63  buffer.size(),
64  out.data(),
65  32);
66  return out;
67  }
68 
69  Hash256 HasherImpl::blake2s_256(gsl::span<const uint8_t> buffer) const {
70  Hash256 out;
71  blake2s(out.data(), 32, nullptr, 0, buffer.data(), buffer.size());
72  return out;
73  }
74 
75  Hash256 HasherImpl::sha2_256(gsl::span<const uint8_t> buffer) const {
76  return crypto::sha256(buffer);
77  }
78 } // namespace kagome::crypto
Hash128 twox_128(gsl::span< const uint8_t > buffer) const override
twox_128 calculates 16-byte twox hash
Definition: hasher_impl.cpp:32
Hash256 twox_256(gsl::span< const uint8_t > buffer) const override
twox_256 calculates 32-byte twox hash
Definition: hasher_impl.cpp:42
Hash64 twox_64(gsl::span< const uint8_t > buffer) const override
twox_64 calculates 8-byte twox hash
Definition: hasher_impl.cpp:22
Blob< 32 > Hash256
Definition: blob.hpp:230
int blake2s(void *out, size_t outlen, const void *key, size_t keylen, const void *in, size_t inlen)
All in one blake2s hashing function.
Definition: blake2s.cpp:194
Blob< 16 > Hash128
Definition: blob.hpp:229
sha3_return_t sha3_HashBuffer(unsigned bitSize, enum SHA3_FLAGS flags, const void *in, unsigned inBytes, void *out, unsigned outBytes)
Definition: keccak.c:286
Blob< 64 > Hash512
Definition: blob.hpp:231
int blake2b(void *out, size_t outlen, const void *key, size_t keylen, const void *in, size_t inlen)
Definition: blake2b.cpp:190
void make_twox64(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:12
Hash256 blake2s_256(gsl::span< const uint8_t > buffer) const override
blake2s_256 function calculates 32-byte blake2s hash
Definition: hasher_impl.cpp:69
Blob< 8 > Hash64
Definition: blob.hpp:228
Hash256 sha2_256(gsl::span< const uint8_t > buffer) const override
sha2_256 function calculates 32-byte sha2-256 hash
Definition: hasher_impl.cpp:75
Hash512 blake2b_512(gsl::span< const uint8_t > buffer) const override
blake2b_512 function calculates 64-byte blake2b hash
Definition: hasher_impl.cpp:52
void make_twox256(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:40
Hash128 blake2b_128(gsl::span< const uint8_t > buffer) const override
blake2b_128 function calculates 16-byte blake2b hash
Definition: hasher_impl.cpp:36
Hash256 keccak_256(gsl::span< const uint8_t > buffer) const override
keccak_256 function calculates 32-byte keccak hash
Definition: hasher_impl.cpp:58
Hash64 blake2b_64(gsl::span< const uint8_t > buffer) const override
blake2b_64 function calculates 8-byte blake2b hash
Definition: hasher_impl.cpp:26
static constexpr size_t size()
Definition: blob.hpp:146
common::Hash256 sha256(std::string_view input)
Definition: sha256.cpp:11
void make_twox128(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:25
Hash256 blake2b_256(gsl::span< const uint8_t > buffer) const override
blake2b_256 function calculates 32-byte blake2b hash
Definition: hasher_impl.cpp:46