Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
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>
7#include <fc/variant.hpp>
8#include "_digest_common.hpp"
9
10namespace fc {
11
12 sha224::sha224() { memset( _hash, 0, sizeof(_hash) ); }
13 sha224::sha224( const string& hex_str ) {
14 auto bytes_written = fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
15 if( bytes_written < sizeof(_hash) )
16 memset( (char*)_hash + bytes_written, 0, (sizeof(_hash) - bytes_written) );
17 }
18
19 string sha224::str()const {
20 return fc::to_hex( (char*)_hash, sizeof(_hash) );
21 }
22 sha224::operator string()const { return str(); }
23
24 char* sha224::data() { return (char*)&_hash[0]; }
25 const char* sha224::data() const { return (const char*)&_hash[0]; }
26
28 SHA256_CTX ctx;
29 };
30
33 reset();
34 }
35
36 sha224 sha224::hash( const char* d, uint32_t dlen ) {
37 encoder e;
38 e.write(d,dlen);
39 return e.result();
40 }
41 sha224 sha224::hash( const string& s ) {
42 return hash( s.c_str(), s.size() );
43 }
44
45 void sha224::encoder::write( const char* d, uint32_t dlen ) {
46 SHA224_Update( &my->ctx, d, dlen);
47 }
49 sha224 h;
50 SHA224_Final((uint8_t*)h.data(), &my->ctx );
51 return h;
52 }
54 SHA224_Init( &my->ctx);
55 }
56
58 sha224 result;
59 fc::detail::shift_l( h1.data(), result.data(), result.data_size(), i );
60 return result;
61 }
62 sha224 operator ^ ( const sha224& h1, const sha224& h2 ) {
63 sha224 result;
64 for( uint32_t i = 0; i < 7; ++i )
65 result._hash[i] = h1._hash[i] ^ h2._hash[i];
66 return result;
67 }
68 bool operator >= ( const sha224& h1, const sha224& h2 ) {
69 return memcmp( h1._hash, h2._hash, sizeof(sha224) ) >= 0;
70 }
71 bool operator > ( const sha224& h1, const sha224& h2 ) {
72 return memcmp( h1._hash, h2._hash, sizeof(sha224) ) > 0;
73 }
74 bool operator < ( const sha224& h1, const sha224& h2 ) {
75 return memcmp( h1._hash, h2._hash, sizeof(sha224) ) < 0;
76 }
77 bool operator != ( const sha224& h1, const sha224& h2 ) {
78 return memcmp( h1._hash, h2._hash, sizeof(sha224) ) != 0;
79 }
80 bool operator == ( const sha224& h1, const sha224& h2 ) {
81 return memcmp( h1._hash, h2._hash, sizeof(sha224) ) == 0;
82 }
83
84 void to_variant( const sha224& bi, variant& v )
85 {
86 v = std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
87 }
88 void from_variant( const variant& v, sha224& bi )
89 {
90 std::vector<char> ve = v.as< std::vector<char> >();
91 if( ve.size() )
92 {
93 memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
94 }
95 else
96 memset( &bi, char(0), sizeof(bi) );
97 }
98
99 template<>
100 unsigned int hmac<sha224>::internal_block_size() const { return 64; }
101}
void write(const char *d, uint32_t dlen)
Definition sha224.cpp:45
friend bool operator>(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:71
static sha224 hash(const char *d, uint32_t dlen)
Definition sha224.cpp:36
friend bool operator==(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:80
friend bool operator<(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:74
string str() const
Definition sha224.cpp:19
friend bool operator!=(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:77
friend T & operator<<(T &ds, const sha224 &ep)
Definition sha224.hpp:51
uint32_t _hash[7]
Definition sha224.hpp:71
char * data()
Definition sha224.cpp:24
friend sha224 operator^(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:62
friend bool operator>=(const sha224 &h1, const sha224 &h2)
Definition sha224.cpp:68
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
T as() const
Definition variant.hpp:327
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
uint8_t from_hex(char c)
Definition hex.cpp:6
const T & min(const T &a, const T &b)
Definition utility.hpp:140
fc::string to_hex(const char *d, uint32_t s)
Definition hex.cpp:17
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
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
CK_ULONG d
char * s
memset(pInfo->slotDescription, ' ', 64)
memcpy((char *) pInfo->slotDescription, s, l)