BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
sha224.cpp
Go to the documentation of this file.
1 #include <fc/crypto/hex.hpp>
2 #include <fc/crypto/hmac.hpp>
3 #include <fc/fwd_impl.hpp>
4 #include <openssl/sha.h>
5 #include <string.h>
6 #include <fc/crypto/sha224.hpp>
7 #include <fc/variant.hpp>
8 #include "_digest_common.hpp"
9 
10 namespace fc {
11 
12  sha224::sha224() { memset( _hash, 0, sizeof(_hash) ); }
13  sha224::sha224( const string& hex_str ) {
14  fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
15  }
16 
17  string sha224::str()const {
18  return fc::to_hex( (char*)_hash, sizeof(_hash) );
19  }
20  sha224::operator string()const { return str(); }
21 
22  char* sha224::data()const { return (char*)&_hash[0]; }
23 
24 
26  SHA256_CTX ctx;
27  };
28 
31  reset();
32  }
33 
34  sha224 sha224::hash( const char* d, uint32_t dlen ) {
35  encoder e;
36  e.write(d,dlen);
37  return e.result();
38  }
39  sha224 sha224::hash( const string& s ) {
40  return hash( s.c_str(), s.size() );
41  }
42 
43  void sha224::encoder::write( const char* d, uint32_t dlen ) {
44  SHA224_Update( &my->ctx, d, dlen);
45  }
47  sha224 h;
48  SHA224_Final((uint8_t*)h.data(), &my->ctx );
49  return h;
50  }
52  SHA224_Init( &my->ctx);
53  }
54 
55  sha224 operator << ( const sha224& h1, uint32_t i ) {
56  sha224 result;
57  fc::detail::shift_l( h1.data(), result.data(), result.data_size(), i );
58  return result;
59  }
60  sha224 operator ^ ( const sha224& h1, const sha224& h2 ) {
61  sha224 result;
62  for( uint32_t i = 0; i < 7; ++i )
63  result._hash[i] = h1._hash[i].value() ^ h2._hash[i].value();
64  return result;
65  }
66  bool operator >= ( const sha224& h1, const sha224& h2 ) {
67  return memcmp( h1._hash, h2._hash, sizeof(sha224) ) >= 0;
68  }
69  bool operator > ( const sha224& h1, const sha224& h2 ) {
70  return memcmp( h1._hash, h2._hash, sizeof(sha224) ) > 0;
71  }
72  bool operator < ( const sha224& h1, const sha224& h2 ) {
73  return memcmp( h1._hash, h2._hash, sizeof(sha224) ) < 0;
74  }
75  bool operator != ( const sha224& h1, const sha224& h2 ) {
76  return memcmp( h1._hash, h2._hash, sizeof(sha224) ) != 0;
77  }
78  bool operator == ( const sha224& h1, const sha224& h2 ) {
79  return memcmp( h1._hash, h2._hash, sizeof(sha224) ) == 0;
80  }
81 
82  void to_variant( const sha224& bi, variant& v, uint32_t max_depth )
83  {
84  to_variant( std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) ), v, max_depth );
85  }
86  void from_variant( const variant& v, sha224& bi, uint32_t max_depth )
87  {
88  std::vector<char> ve = v.as< std::vector<char> >( max_depth );
89  memset( &bi, char(0), sizeof(bi) );
90  if( ve.size() )
91  memcpy( &bi, ve.data(), std::min<size_t>(ve.size(),sizeof(bi)) );
92  }
93 
94  template<>
95  unsigned int hmac<sha224>::internal_block_size() const { return 64; }
96 }
fc::sha224::operator>=
friend bool operator>=(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:66
fc::sha224::encoder::encoder
encoder()
Definition: sha224.cpp:30
fc::from_hex
uint8_t from_hex(char c)
Definition: hex.cpp:6
fc::sha224::data_size
static constexpr size_t data_size()
Definition: sha224.hpp:19
fc::sha224::encoder::result
sha224 result()
Definition: sha224.cpp:46
fc::sha224::encoder
Definition: sha224.hpp:32
fc
Definition: api.hpp:15
fc::sha224::operator<<
friend T & operator<<(T &ds, const sha224 &ep)
Definition: sha224.hpp:49
hex.hpp
fc::sha224::encoder::impl::ctx
SHA256_CTX ctx
Definition: sha224.cpp:26
fc::sha224::operator^
friend sha224 operator^(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:60
fc::from_variant
void from_variant(const variant &var, flat_set< T, A... > &vo, uint32_t _max_depth)
Definition: flat.hpp:116
sha224.hpp
fc::to_hex
std::string to_hex(const char *d, uint32_t s)
Definition: hex.cpp:17
fc::sha224::encoder::reset
void reset()
Definition: sha224.cpp:51
_digest_common.hpp
fc::sha224::operator<
friend bool operator<(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:72
fc::variant::as
T as(uint32_t max_depth) const
Definition: variant.hpp:337
fc::sha224::operator>
friend bool operator>(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:69
fc::sha224::sha224
sha224()
Definition: sha224.cpp:12
fc::to_variant
void to_variant(const flat_set< T, A... > &var, variant &vo, uint32_t _max_depth)
Definition: flat.hpp:105
fc::sha224::encoder::~encoder
~encoder()
Definition: sha224.cpp:29
fc::sha224::operator!=
friend bool operator!=(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:75
fc::sha224::operator==
friend bool operator==(const sha224 &h1, const sha224 &h2)
Definition: sha224.cpp:78
fc::sha224::encoder::write
void write(const char *d, uint32_t dlen)
Definition: sha224.cpp:43
fc::sha224::encoder::impl
Definition: sha224.cpp:25
fc::sha224::data
char * data() const
Definition: sha224.cpp:22
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
hmac.hpp
fc::sha224::str
string str() const
Definition: sha224.cpp:17
variant.hpp
fc::sha224::_hash
boost::endian::little_uint32_buf_t _hash[7]
Definition: sha224.hpp:68
fc::sha224::hash
static sha224 hash(const char *d, uint32_t dlen)
Definition: sha224.cpp:34
fwd_impl.hpp
fc::sha224
Definition: sha224.hpp:9