Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
ripemd160.cpp
Go to the documentation of this file.
1#include <fc/crypto/hex.hpp>
2#include <fc/fwd_impl.hpp>
3#include <openssl/sha.h>
4#include <openssl/ripemd.h>
5#include <string.h>
9#include <fc/variant.hpp>
10#include <vector>
11#include "_digest_common.hpp"
12
13namespace fc
14{
15
17ripemd160::ripemd160( const string& hex_str ) {
18 auto bytes_written = fc::from_hex( hex_str, (char*)_hash, sizeof(_hash) );
19 if( bytes_written < sizeof(_hash) )
20 memset( (char*)_hash + bytes_written, 0, (sizeof(_hash) - bytes_written) );
21}
22
23string ripemd160::str()const {
24 return fc::to_hex( (char*)_hash, sizeof(_hash) );
25}
26ripemd160::operator string()const { return str(); }
27
28char* ripemd160::data()const { return (char*)&_hash[0]; }
29
30
33 {
34 memset( (char*)&ctx, 0, sizeof(ctx) );
35 }
36 RIPEMD160_CTX ctx;
37};
38
41 reset();
42}
43
45{
46 return hash( (const char*)&h, sizeof(h) );
47}
49{
50 return hash( (const char*)&h, sizeof(h) );
51}
52ripemd160 ripemd160::hash( const char* d, uint32_t dlen ) {
53 encoder e;
54 e.write(d,dlen);
55 return e.result();
56}
57ripemd160 ripemd160::hash( const string& s ) {
58 return hash( s.c_str(), s.size() );
59}
60
61void ripemd160::encoder::write( const char* d, uint32_t dlen ) {
62 RIPEMD160_Update( &my->ctx, d, dlen);
63}
65 ripemd160 h;
66 RIPEMD160_Final((uint8_t*)h.data(), &my->ctx );
67 return h;
68}
70 RIPEMD160_Init( &my->ctx);
71}
72
74 ripemd160 result;
75 fc::detail::shift_l( h1.data(), result.data(), result.data_size(), i );
76 return result;
77}
78ripemd160 operator ^ ( const ripemd160& h1, const ripemd160& h2 ) {
79 ripemd160 result;
80 result._hash[0] = h1._hash[0] ^ h2._hash[0];
81 result._hash[1] = h1._hash[1] ^ h2._hash[1];
82 result._hash[2] = h1._hash[2] ^ h2._hash[2];
83 result._hash[3] = h1._hash[3] ^ h2._hash[3];
84 result._hash[4] = h1._hash[4] ^ h2._hash[4];
85 return result;
86}
87bool operator >= ( const ripemd160& h1, const ripemd160& h2 ) {
88 return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) >= 0;
89}
90bool operator > ( const ripemd160& h1, const ripemd160& h2 ) {
91 return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) > 0;
92}
93bool operator < ( const ripemd160& h1, const ripemd160& h2 ) {
94 return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) < 0;
95}
96bool operator != ( const ripemd160& h1, const ripemd160& h2 ) {
97 return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) != 0;
98}
99bool operator == ( const ripemd160& h1, const ripemd160& h2 ) {
100 return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
101}
102
103 void to_variant( const ripemd160& bi, variant& v )
104 {
105 v = std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
106 }
107 void from_variant( const variant& v, ripemd160& bi )
108 {
109 std::vector<char> ve = v.as< std::vector<char> >();
110 if( ve.size() )
111 {
112 memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
113 }
114 else
115 memset( &bi, char(0), sizeof(bi) );
116 }
117
118} // fc
void write(const char *d, uint32_t dlen)
Definition ripemd160.cpp:61
friend bool operator>(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:90
string str() const
Definition ripemd160.cpp:23
friend bool operator!=(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:96
friend bool operator>=(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:87
friend bool operator<(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:93
friend ripemd160 operator^(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:78
uint32_t _hash[5]
Definition ripemd160.hpp:71
char * data() const
Definition ripemd160.cpp:28
static ripemd160 hash(const fc::sha512 &h)
Definition ripemd160.cpp:44
friend bool operator==(const ripemd160 &h1, const ripemd160 &h2)
Definition ripemd160.cpp:99
friend T & operator<<(T &ds, const ripemd160 &ep)
Definition ripemd160.hpp:53
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)