Kagome
Polkadot Runtime Engine in C++17
twox.cpp
Go to the documentation of this file.
1 
6 #include "crypto/twox/twox.hpp"
7 
8 #include <xxhash/xxhash.h>
9 
10 namespace kagome::crypto {
11 
12  void make_twox64(const uint8_t *in, uint32_t len, uint8_t *out) {
13  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
14  auto *ptr = reinterpret_cast<uint64_t *>(out);
15  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
16  ptr[0] = XXH64(in, len, 0);
17  }
18 
19  common::Hash64 make_twox64(gsl::span<const uint8_t> buf) {
20  common::Hash64 hash{};
21  make_twox64(buf.data(), buf.size(), hash.data());
22  return hash;
23  }
24 
25  void make_twox128(const uint8_t *in, uint32_t len, uint8_t *out) {
26  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
27  auto *ptr = reinterpret_cast<uint64_t *>(out);
28  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
29  ptr[0] = XXH64(in, len, 0);
30  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
31  ptr[1] = XXH64(in, len, 1);
32  }
33 
34  common::Hash128 make_twox128(gsl::span<const uint8_t> buf) {
35  common::Hash128 hash{};
36  make_twox128(buf.data(), buf.size(), hash.data());
37  return hash;
38  }
39 
40  void make_twox256(const uint8_t *in, uint32_t len, uint8_t *out) {
41  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
42  auto *ptr = reinterpret_cast<uint64_t *>(out);
43  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
44  ptr[0] = XXH64(in, len, 0);
45  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
46  ptr[1] = XXH64(in, len, 1);
47  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
48  ptr[2] = XXH64(in, len, 2);
49  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
50  ptr[3] = XXH64(in, len, 3);
51  }
52 
53  common::Hash256 make_twox256(gsl::span<const uint8_t> buf) {
54  common::Hash256 hash{};
55  make_twox256(buf.data(), buf.size(), hash.data());
56  return hash;
57  }
58 
59 } // namespace kagome::crypto
void make_twox64(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:12
void make_twox256(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:40
void make_twox128(const uint8_t *in, uint32_t len, uint8_t *out)
Definition: twox.cpp:25