diff --git a/src/script/sigencoding.cpp b/src/script/sigencoding.cpp --- a/src/script/sigencoding.cpp +++ b/src/script/sigencoding.cpp @@ -169,6 +169,11 @@ return true; } +static bool CheckRawSignatureEncoding(const slicedvaltype &sig, uint32_t flags, + ScriptError *serror) { + return CheckRawECDSASignatureEncoding(sig, flags, serror); +} + bool CheckDataSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror) { // Empty signature. Not strictly DER encoded, but allowed to provide a @@ -177,26 +182,12 @@ return true; } - return CheckRawECDSASignatureEncoding( + return CheckRawSignatureEncoding( vchSig | boost::adaptors::sliced(0, vchSig.size()), flags, serror); } -bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, - uint32_t flags, - ScriptError *serror) { - // Empty signature. Not strictly DER encoded, but allowed to provide a - // compact way to provide an invalid signature for use with CHECK(MULTI)SIG - if (vchSig.size() == 0) { - return true; - } - - if (!CheckRawECDSASignatureEncoding( - vchSig | boost::adaptors::sliced(0, vchSig.size() - 1), flags, - serror)) { - // serror is set - return false; - } - +static bool CheckSighashEncoding(const valtype &vchSig, uint32_t flags, + ScriptError *serror) { if (flags & SCRIPT_VERIFY_STRICTENC) { if (!GetHashType(vchSig).isDefined()) { return set_error(serror, SCRIPT_ERR_SIG_HASHTYPE); @@ -216,9 +207,41 @@ return true; } +bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, + uint32_t flags, + ScriptError *serror) { + // Empty signature. Not strictly DER encoded, but allowed to provide a + // compact way to provide an invalid signature for use with CHECK(MULTI)SIG + if (vchSig.size() == 0) { + return true; + } + + if (!CheckRawECDSASignatureEncoding( + vchSig | boost::adaptors::sliced(0, vchSig.size() - 1), flags, + serror)) { + // serror is set + return false; + } + + return CheckSighashEncoding(vchSig, flags, serror); +} + bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror) { - return CheckTransactionECDSASignatureEncoding(vchSig, flags, serror); + // Empty signature. Not strictly DER encoded, but allowed to provide a + // compact way to provide an invalid signature for use with CHECK(MULTI)SIG + if (vchSig.size() == 0) { + return true; + } + + if (!CheckRawSignatureEncoding( + vchSig | boost::adaptors::sliced(0, vchSig.size() - 1), flags, + serror)) { + // serror is set + return false; + } + + return CheckSighashEncoding(vchSig, flags, serror); } static bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey) {