--- a/trb aa5e26e2c9d1766536fe673bbd27e6be3beb9eddb13de483c80b5ce5dd7c2f21caefff8af367d1e84264cfae5cb17817bd572604d99412b184f13cbf4ea29217 +++ b/trb 10f3479116bca9247bc048b4e8c0b2cabdf091c9b946303bf6b901248d78b09ed2daf74a11dcdc584efd64b3a2ac8d20434b1a44e7068da65d0fdc729471110f @@ -4138,7 +4138,7 @@ #endif ############################################################################## -12660 @ ./bitcoin/src/key.h +13800 @ ./bitcoin/src/key.h ############################################################################## // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers @@ -4433,12 +4433,46 @@ bool Sign(uint256 hash, std::vector& vchSig) { vchSig.clear(); - unsigned char pchSig[10000]; - unsigned int nSize = 0; - if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey)) + ECDSA_SIG *sig = ECDSA_do_sign((unsigned char *) &hash, sizeof(hash), pkey); + + if (sig == NULL) + { + printf("ERROR, ECDSA_sign failed in key.h:Sign()\n"); return false; - vchSig.resize(nSize); - memcpy(&vchSig[0], pchSig, nSize); + } + + BN_CTX *ctx = BN_CTX_new(); + BN_CTX_start(ctx); + const EC_GROUP *group = EC_KEY_get0_group(pkey); + BIGNUM *order = BN_CTX_get(ctx); + BIGNUM *halforder = BN_CTX_get(ctx); + EC_GROUP_get_order(group, order, ctx); + BN_rshift1(halforder, order); + + if (fHighS && (BN_cmp(sig->s, halforder) < 0)) + { + // enforce high S values + BN_sub(sig->s, order, sig->s); + } + + if (fLowS && (BN_cmp(sig->s, halforder) > 0)) + { + // enforce low S values + BN_sub(sig->s, order, sig->s); + } + + BN_CTX_end(ctx); + BN_CTX_free(ctx); + unsigned int nSize = ECDSA_size(pkey); + vchSig.resize(nSize); // Make sure it is big enough + unsigned char *pos = &vchSig[0]; + nSize = i2d_ECDSA_SIG(sig, &pos); + //printf("DEBUG DER R: 0x%s\n", BN_bn2hex(sig->r)); + //printf("DEBUG DER R: %s\n", BN_bn2dec(sig->r)); + //printf("DEBUG DER S: 0x%s\n", BN_bn2hex(sig->s)); + //printf("DEBUG DER S: %s\n", BN_bn2dec(sig->s)); + ECDSA_SIG_free(sig); + vchSig.resize(nSize); // Shrink to fit actual size return true; } @@ -19504,7 +19538,7 @@ } ############################################################################## -17758 @ ./bitcoin/src/util.h +17797 @ ./bitcoin/src/util.h ############################################################################## // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers @@ -19630,6 +19664,8 @@ extern bool fNoListen; extern bool fLogTimestamps; extern std::string CLIENT_NAME; +extern bool fLowS; +extern bool fHighS; void RandAddSeed(); void RandAddSeedPerfmon(); @@ -20379,7 +20415,7 @@ } ############################################################################## -15916 @ ./bitcoin/src/init.cpp +16315 @ ./bitcoin/src/init.cpp ############################################################################## // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers @@ -20560,6 +20596,8 @@ " -verifyall \t\t " + _("Forbid the skipping of ECDSA signature verification between checkpoints.\n") + " -setverstring \t\t " + _("Set a custom version string.\n") + " -setvernum \t\t " + _("Set a custom version number.\n") + + " -highs \t\t " + _("Set all transactions to have DER 'S' Value set to 'high'.\n") + + " -lows \t\t " + _("Set all transactions to have DER 'S' Value set to 'low'.\n") + " -logtimestamps \t " + _("Prepend debug output with timestamp\n") + " -printtoconsole \t " + _("Send trace/debug info to console instead of debug.log file\n") + " -rpcuser= \t " + _("Username for JSON-RPC connections\n") + @@ -20583,6 +20621,14 @@ fDaemon = GetBoolArg("-daemon"); fCanEat = GetBoolArg("-caneat"); fVerifyAll = GetBoolArg("-verifyall"); + fHighS = GetBoolArg("-highs"); + fLowS = GetBoolArg("-lows"); + + if (fHighS && fLowS) + { + printf("Error: '-highs' and '-lows' can not be set at the same time.\n"); + return false; + } if (mapArgs.count("-setverstring")) { @@ -23380,7 +23426,7 @@ #endif ############################################################################## -27815 @ ./bitcoin/src/util.cpp +27856 @ ./bitcoin/src/util.cpp ############################################################################## // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers @@ -23416,6 +23462,8 @@ string strMiscWarning; bool fNoListen = false; bool fLogTimestamps = false; +bool fLowS = false; +bool fHighS = false; std::string CLIENT_NAME(DEFAULT_CLIENT_NAME);