From c554c7e56ddd88bde71cd26bef09c62c2444aec5 Mon Sep 17 00:00:00 2001 From: John Jones Date: Wed, 15 Apr 2020 09:52:18 -0500 Subject: [PATCH] add impl to hash160 --- include/fc/crypto/hash160.hpp | 6 ++---- src/crypto/hash160.cpp | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/fc/crypto/hash160.hpp b/include/fc/crypto/hash160.hpp index 4edb718..28121bc 100644 --- a/include/fc/crypto/hash160.hpp +++ b/include/fc/crypto/hash160.hpp @@ -22,11 +22,10 @@ * THE SOFTWARE. */ #pragma once -#include #include #include +#include #include -#include namespace fc{ @@ -66,8 +65,7 @@ class hash160 private: class impl; - fc::fwd my; - SHA256_CTX sha_ctx;; + fc::fwd my; }; template diff --git a/src/crypto/hash160.cpp b/src/crypto/hash160.cpp index 985f8ad..3c65e81 100644 --- a/src/crypto/hash160.cpp +++ b/src/crypto/hash160.cpp @@ -23,12 +23,15 @@ */ #include +#include #include +#include #include #include +#include #include #include -#include +#include #include "_digest_common.hpp" namespace fc @@ -48,13 +51,12 @@ hash160::operator string()const { return str(); } char* hash160::data()const { return (char*)&_hash[0]; } -class hash160::encoder::impl { - public: - impl() { } +struct hash160::encoder::impl { + SHA256_CTX ctx; }; hash160::encoder::~encoder() {} -hash160::encoder::encoder() { SHA256_Init(&sha_ctx); } +hash160::encoder::encoder() { SHA256_Init(&my->ctx); } hash160 hash160::hash( const char* d, uint32_t dlen ) { encoder e; @@ -68,13 +70,13 @@ hash160 hash160::hash( const string& s ) { void hash160::encoder::write( const char* d, uint32_t dlen ) { - SHA256_Update( &sha_ctx, d, dlen); + SHA256_Update( &my->ctx, d, dlen); } hash160 hash160::encoder::result() { // finalize the first hash unsigned char sha_hash[SHA256_DIGEST_LENGTH]; - SHA256_Final( sha_hash, &sha_ctx ); + SHA256_Final( sha_hash, &my->ctx ); // perform the second hashing function RIPEMD160_CTX ripe_ctx; RIPEMD160_Init(&ripe_ctx); @@ -86,7 +88,7 @@ hash160 hash160::encoder::result() { void hash160::encoder::reset() { - SHA256_Init(&sha_ctx); + SHA256_Init(&my->ctx); } hash160 operator << ( const hash160& h1, uint32_t i ) {