diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-19 19:04:47 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2011-12-19 19:10:34 -0500 |
commit | 9ef7fa344741cb34ba4e15cff06d61d1c7a74e24 (patch) | |
tree | 254f76dfa15c36a359e661caa1b4cfd158e204f4 /src/key.h | |
parent | 26ce92b3526430d4a40b2faccef4facb966d6a0a (diff) |
Code cleanup: use ECDSA_size() instead of fixed 10,000 byte sig buffer, and explicity init static var
Diffstat (limited to 'src/key.h')
-rw-r--r-- | src/key.h | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -178,13 +178,14 @@ public: bool Sign(uint256 hash, std::vector<unsigned char>& vchSig) { - vchSig.clear(); - unsigned char pchSig[10000]; - unsigned int nSize = 0; - if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey)) + unsigned int nSize = ECDSA_size(pkey); + vchSig.resize(nSize); // Make sure it is big enough + if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), &vchSig[0], &nSize, pkey)) + { + vchSig.clear(); return false; - vchSig.resize(nSize); - memcpy(&vchSig[0], pchSig, nSize); + } + vchSig.resize(nSize); // Shrink to fit actual size return true; } |