2013-06-07 22:59:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
#include <fc/fwd.hpp>
|
|
|
|
|
#include <fc/string.hpp>
|
|
|
|
|
|
|
|
|
|
namespace fc
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
class sha224
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
sha224();
|
|
|
|
|
explicit sha224( const string& hex_str );
|
|
|
|
|
|
|
|
|
|
string str()const;
|
|
|
|
|
operator string()const;
|
|
|
|
|
|
|
|
|
|
char* data()const;
|
|
|
|
|
|
|
|
|
|
static sha224 hash( const char* d, uint32_t dlen );
|
|
|
|
|
static sha224 hash( const string& );
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static sha224 hash( const T& t )
|
|
|
|
|
{
|
|
|
|
|
sha224::encoder e;
|
|
|
|
|
e << t;
|
|
|
|
|
return e.result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class encoder
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
encoder();
|
|
|
|
|
~encoder();
|
|
|
|
|
|
|
|
|
|
void write( const char* d, uint32_t dlen );
|
|
|
|
|
void put( char c ) { write( &c, 1 ); }
|
|
|
|
|
void reset();
|
|
|
|
|
sha224 result();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct impl;
|
|
|
|
|
fc::fwd<impl,112> my;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
inline friend T& operator<<( T& ds, const sha224& ep ) {
|
2013-07-06 00:29:07 +00:00
|
|
|
static_assert( sizeof(ep) == (8*3+4), "sha224 size mismatch" );
|
2013-06-07 22:59:08 +00:00
|
|
|
ds.write( ep.data(), sizeof(ep) );
|
|
|
|
|
return ds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
inline friend T& operator>>( T& ds, sha224& ep ) {
|
|
|
|
|
ds.read( ep.data(), sizeof(ep) );
|
|
|
|
|
return ds;
|
|
|
|
|
}
|
|
|
|
|
friend sha224 operator << ( const sha224& h1, uint32_t i );
|
|
|
|
|
friend bool operator == ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
friend bool operator != ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
friend sha224 operator ^ ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
friend bool operator >= ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
friend bool operator > ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
friend bool operator < ( const sha224& h1, const sha224& h2 );
|
|
|
|
|
|
2013-07-06 00:29:07 +00:00
|
|
|
uint32_t _hash[7];
|
2013-06-07 22:59:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class variant;
|
|
|
|
|
void to_variant( const sha224& bi, variant& v );
|
|
|
|
|
void from_variant( const variant& v, sha224& bi );
|
|
|
|
|
|
|
|
|
|
} // fc
|
2013-06-27 18:18:02 +00:00
|
|
|
namespace std
|
|
|
|
|
{
|
|
|
|
|
template<>
|
|
|
|
|
struct hash<fc::sha224>
|
|
|
|
|
{
|
|
|
|
|
size_t operator()( const fc::sha224& s )const
|
|
|
|
|
{
|
|
|
|
|
return *((size_t*)&s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|