4#include <openssl/sha.h>
15template <
class... Ts>
struct overloaded : Ts... {
using Ts::operator()...; };
18#if defined(__BYTE_ORDER__)
19#if defined(__ORDER_LITTLE_ENDIAN__)
20inline constexpr bool is_little_endian =
true;
22inline constexpr bool is_little_endian =
false;
25#error "sha3 implementation needs __BYTE_ORDER__ and __ORDER_LITTLE/BIG_ENDIAN__ defined"
28#if defined(__builtin_rotateleft64)
54 static constexpr uint8_t rot_constants[
number_of_rounds] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44};
55 static constexpr uint8_t pi_lanes[
number_of_rounds] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1};
61 if constexpr (!is_little_endian)
75 #pragma clang loop vectorize(enable) interleave(enable)
79 #pragma clang loop vectorize(enable) interleave(enable)
80 for (std::size_t
j = 0;
j < 5;
j++)
84 #pragma clang loop vectorize(enable) interleave(enable)
85 for (std::size_t
j = 0;
j < 5;
j++)
87 t = bc[(
j + 4) % 5] ^ rotl64(bc[(
j + 1) % 5], 1);
88 #pragma clang loop vectorize(enable) interleave(enable)
95 #pragma clang loop vectorize(enable) interleave(enable)
105 #pragma clang loop vectorize(enable) interleave(enable)
108 #pragma clang loop vectorize(enable) interleave(enable)
109 for (std::size_t k = 0; k < 5; k++)
111 #pragma clang loop vectorize(enable) interleave(enable)
112 for (std::size_t k = 0; k < 5; k++)
113 words[k +
j] ^= (~bc[(k + 1) % 5]) & bc[(k + 2) % 5];
120 if constexpr (!is_little_endian)
125 for (std::size_t i = 0; i <
sizeof(
words); i++)
130 v[1] = (tmp >> 8) & 0xFF;
131 v[2] = (tmp >> 16) & 0xFF;
132 v[3] = (tmp >> 24) & 0xFF;
133 v[4] = (tmp >> 32) & 0xFF;
134 v[5] = (tmp >> 40) & 0xFF;
135 v[6] = (tmp >> 48) & 0xFF;
136 v[7] = (tmp >> 56) & 0xFF;
142 memset((
char *)
this, 0,
sizeof(*
this));
148 for (std::size_t i = 0; i <
len; i++)
182 if (size !=
sizeof(
_hash))
189 if (bytes_written <
sizeof(
_hash))
197sha3::operator
string()
const {
return str(); }
215 my->ctx.update((
const uint8_t*)
d, dlen);
220 my->ctx.keccak = !is_nist;
221 my->ctx.finalize((
char*)h.
data());
232 fc::detail::shift_l(h1.
data(), result.data(), result.data_size(), i);
238 fc::detail::shift_r(h1.
data(), result.data(), result.data_size(), i);
278 v = std::vector<char>((
const char *)&bi, ((
const char *)&bi) +
sizeof(bi));
282 const auto &ve = v.
as<std::vector<char>>();
286 memset(&bi,
char(0),
sizeof(bi));
Used to generate a useful error report when an exception is thrown.
sha3 result(bool is_nist=true)
void write(const char *d, uint32_t dlen)
friend bool operator!=(const sha3 &h1, const sha3 &h2)
friend T & operator<<(T &ds, const sha3 &ep)
const char * data() const
friend bool operator>=(const sha3 &h1, const sha3 &h2)
friend T & operator>>(T &ds, sha3 &ep)
friend bool operator>(const sha3 &h1, const sha3 &h2)
friend bool operator<(const sha3 &h1, const sha3 &h2)
friend bool operator==(const sha3 &h1, const sha3 &h2)
friend sha3 operator^(const sha3 &h1, const sha3 &h2)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Defines exception's used by fc.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
__attribute__((always_inline)) inline uint64_t rotl64(uint64_t x
std::vector< char > bytes
const T & min(const T &a, const T &b)
fc::string to_hex(const char *d, uint32_t s)
overloaded(Ts...) -> overloaded< Ts... >
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
unsigned __int64 uint64_t
void finalize(char *buffer)
static constexpr uint8_t number_of_rounds
static constexpr uint64_t round_constants[number_of_rounds]
static constexpr uint8_t pi_lanes[number_of_rounds]
static constexpr uint8_t digest_size
uint64_t words[number_of_words *5]
static constexpr uint8_t number_of_words
void update(const uint8_t *data, std::size_t len)
static constexpr uint8_t rot_constants[number_of_rounds]
memset(pInfo->slotDescription, ' ', 64)
memcpy((char *) pInfo->slotDescription, s, l)