Skip to content

Commit

Permalink
sync from ppc-0.5.4,fix 32bits keylength bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xdwangchn committed May 10, 2016
1 parent 9755afb commit fda09d7
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 23 deletions.
6 changes: 3 additions & 3 deletions share/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SetCompressor /SOLID lzma

# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"
!define VERSION 0.5.1
!define VERSION 0.5.4
!define COMPANY "LoMoCoin project"
!define URL http://github.com/lomocoin/lomocoin/

Expand Down Expand Up @@ -45,13 +45,13 @@ Var StartMenuGroup
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile lomocoin-0.5.1rc2-win32-setup.exe
OutFile lomocoin-0.5.4-win32-setup.exe
InstallDir $PROGRAMFILES\LoMoCoin
CRCCheck on
XPStyle on
BrandingText " "
ShowInstDetails show
VIProductVersion 0.5.1.0
VIProductVersion 0.5.4.0
VIAddVersionKey ProductName LoMoCoin
VIAddVersionKey ProductVersion "${VERSION}"
VIAddVersionKey CompanyName "${COMPANY}"
Expand Down
4 changes: 4 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ void TxToJSON(const CTransaction& tx, Object& txdata)
{
vin.push_back(Pair("txid", txin.prevout.hash.ToString().c_str()));
vin.push_back(Pair("vout", (int)txin.prevout.n));
Object o;
o.push_back(Pair("asm", txin.scriptSig.ToString()));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
vin.push_back(Pair("scriptSig", o));
}

vin.push_back(Pair("sequence", (boost::uint64_t)txin.nSequence));
Expand Down
125 changes: 108 additions & 17 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,28 +350,119 @@ bool CKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& v
return false;
}

bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSigParam)
static bool ParseLength(
const std::vector<unsigned char>::iterator& begin,
const std::vector<unsigned char>::iterator& end,
size_t& nLengthRet,
size_t& nLengthSizeRet)
{
// Prevent the problem described here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html
// by removing the extra length bytes
std::vector<unsigned char> vchSig(vchSigParam.begin(), vchSigParam.end());
if (vchSig.size() > 1 && vchSig[1] & 0x80)
{
unsigned char nLengthBytes = vchSig[1] & 0x7f;
std::vector<unsigned char>::iterator it = begin;
if (it == end)
return false;

nLengthRet = *it;
nLengthSizeRet = 1;

if (vchSig.size() < 2 + nLengthBytes)
if (!(nLengthRet & 0x80))
return true;

unsigned char nLengthBytes = nLengthRet & 0x7f;

// Lengths on more than 8 bytes are rejected by OpenSSL 64 bits
if (nLengthBytes > 8)
return false;

int64 nLength = 0;
for (unsigned char i = 0; i < nLengthBytes; i++)
{
it++;
if (it == end)
return false;
nLength = (nLength << 8) | *it;
if (nLength > 0x7fffffff)
return false;
nLengthSizeRet++;
}
nLengthRet = nLength;
return true;
}

if (nLengthBytes > 4)
{
unsigned char nExtraBytes = nLengthBytes - 4;
for (unsigned char i = 0; i < nExtraBytes; i++)
if (vchSig[2 + i])
return false;
vchSig.erase(vchSig.begin() + 2, vchSig.begin() + 2 + nExtraBytes);
vchSig[1] = 0x80 | (nLengthBytes - nExtraBytes);
}
static std::vector<unsigned char> EncodeLength(size_t nLength)
{
std::vector<unsigned char> vchRet;
if (nLength < 0x80)
vchRet.push_back(nLength);
else
{
vchRet.push_back(0x84);
vchRet.push_back((nLength >> 24) & 0xff);
vchRet.push_back((nLength >> 16) & 0xff);
vchRet.push_back((nLength >> 8) & 0xff);
vchRet.push_back(nLength & 0xff);
}
return vchRet;
}

static bool NormalizeSignature(std::vector<unsigned char>& vchSig)
{
// Prevent the problem described here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html
// by removing the extra length bytes

if (vchSig.size() < 2 || vchSig[0] != 0x30)
return false;

size_t nTotalLength, nTotalLengthSize;
if (!ParseLength(vchSig.begin() + 1, vchSig.end(), nTotalLength, nTotalLengthSize))
return false;

size_t nRStart = 1 + nTotalLengthSize;
if (vchSig.size() < nRStart + 2 || vchSig[nRStart] != 0x02)
return false;

size_t nRLength, nRLengthSize;
if (!ParseLength(vchSig.begin() + nRStart + 1, vchSig.end(), nRLength, nRLengthSize))
return false;
const size_t nRDataStart = nRStart + 1 + nRLengthSize;
std::vector<unsigned char> R(vchSig.begin() + nRDataStart, vchSig.begin() + nRDataStart + nRLength);

size_t nSStart = nRStart + 1 + nRLengthSize + nRLength;
if (vchSig.size() < nSStart + 2 || vchSig[nSStart] != 0x02)
return false;

size_t nSLength, nSLengthSize;
if (!ParseLength(vchSig.begin() + nSStart + 1, vchSig.end(), nSLength, nSLengthSize))
return false;
const size_t nSDataStart = nSStart + 1 + nSLengthSize;
std::vector<unsigned char> S(vchSig.begin() + nSDataStart, vchSig.begin() + nSDataStart + nSLength);

std::vector<unsigned char> vchRLength = EncodeLength(R.size());
std::vector<unsigned char> vchSLength = EncodeLength(S.size());

nTotalLength = 1 + vchRLength.size() + R.size() + 1 + vchSLength.size() + S.size();
std::vector<unsigned char> vchTotalLength = EncodeLength(nTotalLength);

vchSig.clear();
vchSig.reserve(1 + vchTotalLength.size() + nTotalLength);
vchSig.push_back(0x30);
vchSig.insert(vchSig.end(), vchTotalLength.begin(), vchTotalLength.end());

vchSig.push_back(0x02);
vchSig.insert(vchSig.end(), vchRLength.begin(), vchRLength.end());
vchSig.insert(vchSig.end(), R.begin(), R.end());

vchSig.push_back(0x02);
vchSig.insert(vchSig.end(), vchSLength.begin(), vchSLength.end());
vchSig.insert(vchSig.end(), S.begin(), S.end());

return true;
}

bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& vchSigParam)
{
std::vector<unsigned char> vchSig(vchSigParam.begin(), vchSigParam.end());

if (!NormalizeSignature(vchSig))
return false;

if (vchSig.empty())
return false;
Expand Down
6 changes: 5 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,14 @@ void ThreadMapPort2(void* parg)
#ifndef UPNPDISCOVER_SUCCESS
/* miniupnpc 1.5 */
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
#else
#elif MINIUPNPC_API_VERSION < 14
/* miniupnpc 1.6 */
int error = 0;
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
#else
/* miniupnpc 1.9.20150730 */
int error = 0;
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
#endif

struct UPNPUrls urls;
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
ret = vprintf(pszFormat, arg_ptr);
va_end(arg_ptr);
}
else
else if (!fPrintToDebugger)
{
// print to debug.log
if (!fileout)
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern const std::string CLIENT_DATE;
// lomocoin version - intended for display purpose ONLY
#define PPCOIN_VERSION_MAJOR 0
#define PPCOIN_VERSION_MINOR 5
#define PPCOIN_VERSION_REVISION 3
#define PPCOIN_VERSION_REVISION 4
#define PPCOIN_VERSION_BUILD 0

static const int PPCOIN_VERSION =
Expand Down

0 comments on commit fda09d7

Please sign in to comment.