1 #ifndef GENESIS_UTILS_TOOLS_HASH_SHA256_H_
2 #define GENESIS_UTILS_TOOLS_HASH_SHA256_H_
145 static std::string
read_hex( std::shared_ptr<BaseInputSource> source );
164 void update( std::shared_ptr<BaseInputSource> source );
165 void update( std::string
const& s );
166 void update( std::istream& is );
189 void update_(
unsigned char const* message,
size_t len );
191 void transform_(
unsigned char const* message,
unsigned int block_nb );
193 static inline uint32_t SHA2_SHFR( uint32_t x, uint32_t n )
198 static inline uint32_t SHA2_ROTR( uint32_t x, uint32_t n )
200 return ((x >> n) | (x << ((
sizeof(x) << 3) - n)));
203 static inline uint32_t SHA2_ROTL( uint32_t x, uint32_t n )
205 return ((x << n) | (x >> ((
sizeof(x) << 3) - n)));
208 static inline uint32_t SHA2_CH( uint32_t x, uint32_t y, uint32_t z )
210 return ((x & y) ^ (~x & z));
213 static inline uint32_t SHA2_MAJ( uint32_t x, uint32_t y, uint32_t z )
215 return ((x & y) ^ (x & z) ^ (y & z));
218 static inline uint32_t SHA256_F1( uint32_t x )
220 return (SHA2_ROTR(x, 2) ^ SHA2_ROTR(x, 13) ^ SHA2_ROTR(x, 22));
223 static inline uint32_t SHA256_F2( uint32_t x )
225 return (SHA2_ROTR(x, 6) ^ SHA2_ROTR(x, 11) ^ SHA2_ROTR(x, 25));
228 static inline uint32_t SHA256_F3( uint32_t x )
230 return (SHA2_ROTR(x, 7) ^ SHA2_ROTR(x, 18) ^ SHA2_SHFR(x, 3));
233 static inline uint32_t SHA256_F4( uint32_t x )
235 return (SHA2_ROTR(x, 17) ^ SHA2_ROTR(x, 19) ^ SHA2_SHFR(x, 10));
238 static inline uint32_t SHA2_PACK32(
unsigned char const* str )
240 return ((uint32_t) *((str) + 3) )
241 | ((uint32_t) *((str) + 2) << 8)
242 | ((uint32_t) *((str) + 1) << 16)
243 | ((uint32_t) *((str) + 0) << 24)
247 static inline void SHA2_UNPACK32( uint32_t x,
unsigned char* str)
249 *((str) + 3) = (uint8_t) ((x) );
250 *((str) + 2) = (uint8_t) ((x) >> 8);
251 *((str) + 1) = (uint8_t) ((x) >> 16);
252 *((str) + 0) = (uint8_t) ((x) >> 24);
261 const static uint32_t sha256_k[];
263 unsigned int tot_len_;
287 struct hash<
genesis::utils::SHA256::DigestType>
294 result ^= s[0] ^ (
static_cast<result_type>( s[1] ) << 32 );
295 result ^= s[2] ^ (
static_cast<result_type>( s[3] ) << 32 );
296 result ^= s[4] ^ (
static_cast<result_type>( s[5] ) << 32 );
297 result ^= s[6] ^ (
static_cast<result_type>( s[7] ) << 32 );
303 #endif // include guard