Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::sha3 Class Reference

#include <sha3.hpp>

Classes

class  encoder
 

Public Member Functions

 sha3 ()
 
 ~sha3 ()
 
 sha3 (const string &hex_str)
 
 sha3 (const char *data, size_t size)
 
string str () const
 
 operator string () const
 
const char * data () const
 
char * data ()
 
size_t data_size () const
 

Static Public Member Functions

static sha3 hash (const char *d, uint32_t dlen, bool is_nist=true)
 
static sha3 hash (const string &s, bool is_nist=true)
 
static sha3 hash (const sha3 &s, bool is_nist=true)
 
template<typename T >
static sha3 hash (const T &t, bool is_nist=true)
 

Public Attributes

uint64_t _hash [4]
 

Friends

template<typename T >
Toperator<< (T &ds, const sha3 &ep)
 
template<typename T >
Toperator>> (T &ds, sha3 &ep)
 
sha3 operator<< (const sha3 &h1, uint32_t i)
 
sha3 operator>> (const sha3 &h1, uint32_t i)
 
bool operator== (const sha3 &h1, const sha3 &h2)
 
bool operator!= (const sha3 &h1, const sha3 &h2)
 
sha3 operator^ (const sha3 &h1, const sha3 &h2)
 
bool operator>= (const sha3 &h1, const sha3 &h2)
 
bool operator> (const sha3 &h1, const sha3 &h2)
 
bool operator< (const sha3 &h1, const sha3 &h2)
 

Detailed Description

Definition at line 10 of file sha3.hpp.

Constructor & Destructor Documentation

◆ sha3() [1/3]

fc::sha3::sha3 ( )

Definition at line 176 of file sha3.cpp.

177{
178 memset(_hash, 0, sizeof(_hash));
179}
uint64_t _hash[4]
Definition sha3.hpp:80
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function:

◆ ~sha3()

fc::sha3::~sha3 ( )
inline

Definition at line 14 of file sha3.hpp.

14{}

◆ sha3() [2/3]

fc::sha3::sha3 ( const string & hex_str)
explicit

Definition at line 186 of file sha3.cpp.

187{
188 auto bytes_written = fc::from_hex(hex_str, (char *)_hash, sizeof(_hash));
189 if (bytes_written < sizeof(_hash))
190 memset((char *)_hash + bytes_written, 0, (sizeof(_hash) - bytes_written));
191}
uint8_t from_hex(char c)
Definition hex.cpp:6
Here is the call graph for this function:

◆ sha3() [3/3]

fc::sha3::sha3 ( const char * data,
size_t size )
explicit

Definition at line 180 of file sha3.cpp.

181{
182 if (size != sizeof(_hash))
183 FC_THROW_EXCEPTION(exception, "sha3: size mismatch");
184 memcpy(_hash, data, size);
185}
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

Member Function Documentation

◆ data() [1/2]

char * fc::sha3::data ( )

Definition at line 200 of file sha3.cpp.

200{ return (char *)&_hash[0]; }

◆ data() [2/2]

const char * fc::sha3::data ( ) const

Definition at line 199 of file sha3.cpp.

199{ return (const char *)&_hash[0]; }
Here is the caller graph for this function:

◆ data_size()

size_t fc::sha3::data_size ( ) const
inline

Definition at line 23 of file sha3.hpp.

23{ return 256 / 8; }

◆ hash() [1/4]

static sha3 fc::sha3::hash ( const char * d,
uint32_t dlen,
bool is_nist = true )
inlinestatic

Definition at line 25 of file sha3.hpp.

25 {
26 encoder e;
27 e.write(d, dlen);
28 const auto& sha = e.result(is_nist);
29 return sha;
30 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash() [2/4]

static sha3 fc::sha3::hash ( const sha3 & s,
bool is_nist = true )
inlinestatic

Definition at line 32 of file sha3.hpp.

32{ return hash(s.data(), sizeof(s._hash), is_nist); }
static sha3 hash(const char *d, uint32_t dlen, bool is_nist=true)
Definition sha3.hpp:25
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash() [3/4]

static sha3 fc::sha3::hash ( const string & s,
bool is_nist = true )
inlinestatic

Definition at line 31 of file sha3.hpp.

31{ return hash(s.c_str(), s.size(), is_nist); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash() [4/4]

template<typename T >
static sha3 fc::sha3::hash ( const T & t,
bool is_nist = true )
inlinestatic

Definition at line 35 of file sha3.hpp.

36 {
37 sha3::encoder e;
38 fc::raw::pack(e, t);
39 return e.result(is_nist);
40 }
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
Here is the call graph for this function:

◆ operator string()

fc::sha3::operator string ( ) const

Definition at line 197 of file sha3.cpp.

197{ return str(); }
string str() const
Definition sha3.cpp:193

◆ str()

string fc::sha3::str ( ) const

Definition at line 193 of file sha3.cpp.

194{
195 return fc::to_hex((char *)_hash, sizeof(_hash));
196}
fc::string to_hex(const char *d, uint32_t s)
Definition hex.cpp:17
Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 262 of file sha3.cpp.

263{
264 return !(h1 == h2);
265}

◆ operator<

bool operator< ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 258 of file sha3.cpp.

259{
260 return memcmp(h1._hash, h2._hash, sizeof(h1._hash)) < 0;
261}

◆ operator<< [1/2]

sha3 operator<< ( const sha3 & h1,
uint32_t i )
friend

Definition at line 229 of file sha3.cpp.

230{
231 sha3 result;
232 fc::detail::shift_l(h1.data(), result.data(), result.data_size(), i);
233 return result;
234}

◆ operator<< [2/2]

template<typename T >
T & operator<< ( T & ds,
const sha3 & ep )
friend

Definition at line 59 of file sha3.hpp.

60 {
61 ds.write(ep.data(), sizeof(ep));
62 return ds;
63 }
static const Segment ds(Segment::ds)

◆ operator==

bool operator== ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 266 of file sha3.cpp.

267{
268 // idea to not use memcmp, from:
269 // https://lemire.me/blog/2018/08/22/avoid-lexicographical-comparisons-when-testing-for-string-equality/
270 return h1._hash[0] == h2._hash[0] &&
271 h1._hash[1] == h2._hash[1] &&
272 h1._hash[2] == h2._hash[2] &&
273 h1._hash[3] == h2._hash[3];
274}

◆ operator>

bool operator> ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 254 of file sha3.cpp.

255{
256 return memcmp(h1._hash, h2._hash, sizeof(h1._hash)) > 0;
257}

◆ operator>=

bool operator>= ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 250 of file sha3.cpp.

251{
252 return memcmp(h1._hash, h2._hash, sizeof(h1._hash)) >= 0;
253}

◆ operator>> [1/2]

sha3 operator>> ( const sha3 & h1,
uint32_t i )
friend

Definition at line 235 of file sha3.cpp.

236{
237 sha3 result;
238 fc::detail::shift_r(h1.data(), result.data(), result.data_size(), i);
239 return result;
240}

◆ operator>> [2/2]

template<typename T >
T & operator>> ( T & ds,
sha3 & ep )
friend

Definition at line 66 of file sha3.hpp.

67 {
68 ds.read(ep.data(), sizeof(ep));
69 return ds;
70 }

◆ operator^

sha3 operator^ ( const sha3 & h1,
const sha3 & h2 )
friend

Definition at line 241 of file sha3.cpp.

242{
243 sha3 result;
244 result._hash[0] = h1._hash[0] ^ h2._hash[0];
245 result._hash[1] = h1._hash[1] ^ h2._hash[1];
246 result._hash[2] = h1._hash[2] ^ h2._hash[2];
247 result._hash[3] = h1._hash[3] ^ h2._hash[3];
248 return result;
249}

Member Data Documentation

◆ _hash

uint64_t fc::sha3::_hash[4]

Definition at line 80 of file sha3.hpp.


The documentation for this class was generated from the following files: