diff --git a/src/bip38.cpp b/src/bip38.cpp index 70388c855627c..fa4516cf98c9a 100644 --- a/src/bip38.cpp +++ b/src/bip38.cpp @@ -41,8 +41,7 @@ void ComputePassfactor(std::string ownersalt, uint256 prefactor, uint256& passfa { //concat prefactor and ownersalt uint512 temp = uint512S(ReverseEndianString(HexStr(prefactor) + ownersalt)); - Hash(temp.begin(), 40, passfactor.begin()); //40 bytes is the length of prefactor + salt - Hash(passfactor.begin(), 32, passfactor.begin()); + Hash(temp.begin(), temp.end(), passfactor.begin(), passfactor.end()); } bool ComputePasspoint(uint256 passfactor, CPubKey& passpoint) @@ -88,15 +87,12 @@ void ComputeSeedBPass(CPubKey passpoint, std::string strAddressHash, std::string void ComputeFactorB(uint256 seedB, uint256& factorB) { //factorB - a double sha256 hash of seedb - Hash(seedB.begin(), 24, factorB.begin()); //seedB is only 24 bytes - Hash(factorB.begin(), 32, factorB.begin()); + Hash(seedB.begin(), seedB.end(), factorB.begin(), factorB.end()); } -std::string AddressToBip38Hash(std::string address) +std::string AddressToBip38Hash(const std::string& address) { - uint256 addrCheck; - Hash((void*)address.c_str(), address.size(), addrCheck.begin()); - Hash(addrCheck.begin(), 32, addrCheck.begin()); + uint256 addrCheck = Hash(address.begin(), address.end()); return HexStr(addrCheck).substr(0, 8); } diff --git a/src/bip38.h b/src/bip38.h index c1ffd48afeec5..89d3c35ce9680 100644 --- a/src/bip38.h +++ b/src/bip38.h @@ -35,6 +35,6 @@ void ComputeFactorB(uint256 seedB, uint256& factorB); std::string BIP38_Encrypt(std::string strAddress, std::string strPassphrase, uint256 privKey, bool fCompressed); bool BIP38_Decrypt(std::string strPassphrase, std::string strEncryptedKey, uint256& privKey, bool& fCompressed); -std::string AddressToBip38Hash(std::string address); +std::string AddressToBip38Hash(const std::string& address); #endif // BIP38_H diff --git a/src/hash.h b/src/hash.h index d8a375b9a5fd0..172f019470eea 100644 --- a/src/hash.h +++ b/src/hash.h @@ -25,7 +25,6 @@ #include "crypto/sha512.h" #include -#include #include #include @@ -151,30 +150,6 @@ class CHash160 } }; -/** Compute the 256-bit hash of a std::string */ -inline std::string Hash(std::string input) -{ - unsigned char hash[SHA256_DIGEST_LENGTH]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, input.c_str(), input.size()); - SHA256_Final(hash, &sha256); - std::stringstream ss; - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - ss << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i]; - } - return ss.str(); -} - -/** Compute the 256-bit hash of a void pointer */ -inline void Hash(void* in, unsigned int len, unsigned char* out) -{ - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, in, len); - SHA256_Final(out, &sha256); -} - /** Compute the 512-bit hash of an object. */ template inline uint512 Hash512(const T1 pbegin, const T1 pend) diff --git a/test/functional/rpc_bip38.py b/test/functional/rpc_bip38.py index ef47b2c590e91..19c8f6ba491d8 100755 --- a/test/functional/rpc_bip38.py +++ b/test/functional/rpc_bip38.py @@ -22,6 +22,7 @@ def run_test(self): self.log.info('decrypt bip38 key %s' % (bip38key)) assert_equal(self.nodes[1].bip38decrypt(bip38key, password)['Address'], address) + assert_equal(self.nodes[1].dumpprivkey(address), privkey) if __name__ == '__main__': Bip38Test().main()