Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sha3.hpp
Go to the documentation of this file.
1#pragma once
2#include <fc/fwd.hpp>
3#include <fc/string.hpp>
5#include <fc/io/raw_fwd.hpp>
6
7namespace fc
8{
9
10class sha3
11{
12public:
13 sha3();
15 explicit sha3(const string &hex_str);
16 explicit sha3(const char *data, size_t size);
17
18 string str() const;
19 operator string() const;
20
21 const char *data() const;
22 char* data();
23 size_t data_size() const { return 256 / 8; }
24
25 static sha3 hash(const char *d, uint32_t dlen, bool is_nist=true) {
26 encoder e;
27 e.write(d, dlen);
28 const auto& sha = e.result(is_nist);
29 return sha;
30 }
31 static sha3 hash(const string& s, bool is_nist=true) { return hash(s.c_str(), s.size(), is_nist); }
32 static sha3 hash(const sha3& s, bool is_nist=true) { return hash(s.data(), sizeof(s._hash), is_nist); }
33
34 template <typename T>
35 static sha3 hash(const T &t, bool is_nist=true)
36 {
38 fc::raw::pack(e, t);
39 return e.result(is_nist);
40 }
41
42 class encoder
43 {
44 public:
45 encoder();
46 ~encoder();
47
48 void write(const char *d, uint32_t dlen);
49 void put(char c) { write(&c, 1); }
50 void reset();
51 sha3 result(bool is_nist=true);
52
53 private:
54 struct impl;
56 };
57
58 template <typename T>
59 inline friend T &operator<<(T &ds, const sha3 &ep)
60 {
61 ds.write(ep.data(), sizeof(ep));
62 return ds;
63 }
64
65 template <typename T>
66 inline friend T &operator>>(T &ds, sha3 &ep)
67 {
68 ds.read(ep.data(), sizeof(ep));
69 return ds;
70 }
71 friend sha3 operator<<(const sha3 &h1, uint32_t i);
72 friend sha3 operator>>(const sha3 &h1, uint32_t i);
73 friend bool operator==(const sha3 &h1, const sha3 &h2);
74 friend bool operator!=(const sha3 &h1, const sha3 &h2);
75 friend sha3 operator^(const sha3 &h1, const sha3 &h2);
76 friend bool operator>=(const sha3 &h1, const sha3 &h2);
77 friend bool operator>(const sha3 &h1, const sha3 &h2);
78 friend bool operator<(const sha3 &h1, const sha3 &h2);
79
81};
82
83class variant;
84void to_variant(const sha3 &bi, variant &v);
85void from_variant(const variant &v, sha3 &bi);
86
87} // namespace fc
88
89namespace std
90{
91template <>
92struct hash<fc::sha3>
93{
94 size_t operator()(const fc::sha3 &s) const
95 {
96 return *((size_t *)&s);
97 }
98};
99
100} // namespace std
101
102namespace boost
103{
104template <>
105struct hash<fc::sha3>
106{
107 size_t operator()(const fc::sha3 &s) const
108 {
109 return s._hash[3]; //*((size_t*)&s);
110 }
111};
112} // namespace boost
113#include <fc/reflect/reflect.hpp>
Used to forward declare value types.
Definition fwd.hpp:11
sha3 result(bool is_nist=true)
Definition sha3.cpp:217
void write(const char *d, uint32_t dlen)
Definition sha3.cpp:213
void put(char c)
Definition sha3.hpp:49
static sha3 hash(const sha3 &s, bool is_nist=true)
Definition sha3.hpp:32
static sha3 hash(const string &s, bool is_nist=true)
Definition sha3.hpp:31
friend bool operator!=(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:262
friend T & operator<<(T &ds, const sha3 &ep)
Definition sha3.hpp:59
~sha3()
Definition sha3.hpp:14
const char * data() const
Definition sha3.cpp:199
size_t data_size() const
Definition sha3.hpp:23
friend bool operator>=(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:250
friend T & operator>>(T &ds, sha3 &ep)
Definition sha3.hpp:66
static sha3 hash(const T &t, bool is_nist=true)
Definition sha3.hpp:35
string str() const
Definition sha3.cpp:193
friend bool operator>(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:254
static sha3 hash(const char *d, uint32_t dlen, bool is_nist=true)
Definition sha3.hpp:25
friend bool operator<(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:258
friend bool operator==(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:266
uint64_t _hash[4]
Definition sha3.hpp:80
friend sha3 operator^(const sha3 &h1, const sha3 &h2)
Definition sha3.cpp:241
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
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)
Definition authority.cpp:4
Definition name.hpp:106
#define T(meth, val, expected)
#define FC_REFLECT_TYPENAME(TYPE)
Definition reflect.hpp:320
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
size_t operator()(const fc::sha3 &s) const
Definition sha3.hpp:107
size_t operator()(const fc::sha3 &s) const
Definition sha3.hpp:94
CK_ULONG d
char * s