diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-10-20 14:53:43 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-10-20 14:53:43 -0700 |
commit | f50fb5470b1d3a65a513b3a9a77209ccad590a19 (patch) | |
tree | 9f6418cfadbd89a3cfac923b0d3c5cdd7822ffb5 /src | |
parent | cf9b49fa50f439e57896ce2c176214052833a09a (diff) | |
parent | 8980a509240107730eae8b517d80b444d1e31ccd (diff) |
Merge pull request #1936 from sipa/morehashwriter
Use CHashWriter also in SignatureHash(), and for message signing
Diffstat (limited to 'src')
-rw-r--r-- | src/rpcwallet.cpp | 8 | ||||
-rw-r--r-- | src/script.cpp | 5 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index cc2e8ab46b..6f8728e979 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -329,12 +329,12 @@ Value signmessage(const Array& params, bool fHelp) if (!pwalletMain->GetKey(keyID, key)) throw JSONRPCError(RPC_WALLET_ERROR, "Private key not available"); - CDataStream ss(SER_GETHASH, 0); + CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; ss << strMessage; vector<unsigned char> vchSig; - if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) + if (!key.SignCompact(ss.GetHash(), vchSig)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); return EncodeBase64(&vchSig[0], vchSig.size()); @@ -365,12 +365,12 @@ Value verifymessage(const Array& params, bool fHelp) if (fInvalid) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); - CDataStream ss(SER_GETHASH, 0); + CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; ss << strMessage; CKey key; - if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) + if (!key.SetCompactSignature(ss.GetHash(), vchSig)) return false; return (key.GetPubKey().GetID() == keyID); diff --git a/src/script.cpp b/src/script.cpp index 61112b17c0..36d208c247 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1183,10 +1183,9 @@ uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int } // Serialize and hash - CDataStream ss(SER_GETHASH, 0); - ss.reserve(10000); + CHashWriter ss(SER_GETHASH, 0); ss << txTmp << nHashType; - return Hash(ss.begin(), ss.end()); + return ss.GetHash(); } |