Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sha256.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#include <boost/functional/hash.hpp>
7
8namespace fc
9{
10
11class sha256
12{
13 public:
14 sha256();
15 explicit sha256( const string& hex_str );
16 explicit sha256( 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 sha256 hash( const char* d, uint32_t dlen );
26 static sha256 hash( const string& );
27 static sha256 hash( const sha256& );
28
29 template<typename T>
30 static sha256 hash( const T& t )
31 {
33 fc::raw::pack(e,t);
34 return e.result();
35 }
36
37 class encoder
38 {
39 public:
40 encoder();
41 ~encoder();
42
43 void write( const char* d, uint32_t dlen );
44 void put( char c ) { write( &c, 1 ); }
45 void reset();
46 sha256 result();
47
48 private:
49 struct impl;
51 };
52
53 template<typename T>
54 inline friend T& operator<<( T& ds, const sha256& ep ) {
55 ds.write( ep.data(), sizeof(ep) );
56 return ds;
57 }
58
59 template<typename T>
60 inline friend T& operator>>( T& ds, sha256& ep ) {
61 ds.read( ep.data(), sizeof(ep) );
62 return ds;
63 }
64 friend sha256 operator << ( const sha256& h1, uint32_t i );
65 friend sha256 operator >> ( const sha256& h1, uint32_t i );
66 friend bool operator == ( const sha256& h1, const sha256& h2 );
67 friend bool operator != ( const sha256& h1, const sha256& h2 );
68 friend sha256 operator ^ ( const sha256& h1, const sha256& h2 );
69 friend bool operator >= ( const sha256& h1, const sha256& h2 );
70 friend bool operator > ( const sha256& h1, const sha256& h2 );
71 friend bool operator < ( const sha256& h1, const sha256& h2 );
72
74 {
75 return (uint32_t)(__builtin_popcountll(_hash[0]) +
76 __builtin_popcountll(_hash[1]) +
77 __builtin_popcountll(_hash[2]) +
78 __builtin_popcountll(_hash[3]));
79 }
80
84 uint16_t clz()const;
85
96
98 static double inverse_approx_log_32_double( uint32_t x );
99
101};
102
104
105 class variant;
106 void to_variant( const sha256& bi, variant& v );
107 void from_variant( const variant& v, sha256& bi );
108
109 uint64_t hash64(const char* buf, size_t len);
110
111} // fc
112
113namespace std
114{
115 template<>
116 struct hash<fc::sha256>
117 {
118 size_t operator()( const fc::sha256& s )const
119 {
120 return *((size_t*)&s);
121 }
122 };
123
124}
125
126namespace boost
127{
128 template<>
129 struct hash<fc::sha256>
130 {
131 size_t operator()( const fc::sha256& s )const
132 {
133 return s._hash[3];//*((size_t*)&s);
134 }
135 };
136}
137#include <fc/reflect/reflect.hpp>
Used to forward declare value types.
Definition fwd.hpp:11
void write(const char *d, uint32_t dlen)
Definition sha256.cpp:59
void put(char c)
Definition sha256.hpp:44
static double inverse_approx_log_32_double(uint32_t x)
Definition sha256.cpp:163
friend sha256 operator^(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:81
uint32_t approx_log_32() const
Definition sha256.cpp:111
void set_to_inverse_approx_log_32(uint32_t x)
Definition sha256.cpp:136
uint32_t pop_count() const
Definition sha256.hpp:73
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
friend bool operator!=(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:98
string str() const
Definition sha256.cpp:26
friend T & operator>>(T &ds, sha256 &ep)
Definition sha256.hpp:60
const char * data() const
Definition sha256.cpp:31
size_t data_size() const
Definition sha256.hpp:23
uint64_t _hash[4]
Definition sha256.hpp:100
static sha256 hash(const T &t)
Definition sha256.hpp:30
friend T & operator<<(T &ds, const sha256 &ep)
Definition sha256.hpp:54
friend bool operator==(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:101
friend bool operator>(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:92
friend bool operator<(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:95
friend bool operator>=(const sha256 &h1, const sha256 &h2)
Definition sha256.cpp:89
uint16_t clz() const
Definition sha256.cpp:173
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
uint64_t hash64(const char *buf, size_t len)
Definition sha256.cpp:221
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
sha256 uint256
Definition sha256.hpp:103
Definition name.hpp:106
#define T(meth, val, expected)
#define FC_REFLECT_TYPENAME(TYPE)
Definition reflect.hpp:320
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
size_t operator()(const fc::sha256 &s) const
Definition sha256.hpp:131
size_t operator()(const fc::sha256 &s) const
Definition sha256.hpp:118
CK_ULONG d
char * s
size_t len
uint8_t buf[2048]