diff --git a/README.md b/README.md index 5109a650f4..f8a7e6e56d 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,11 @@ Bitmark aims to be a relatively stable, user focused crypto currency, which refi All Bitmark software releases are published through the github release process, you can download the [latest release](https://github.com/project-bitmark/bitmark/releases) from the releases tab above. -## -v0.9.7.3 Dev Version towards: v0.9.7.4, Stable Release, compatible with latest TLS/SSL Libraries + +## v0.9.7.4 Works with newer TLS / SSL libraries in Ubuntu 18-20 and Debian 10 +This release uses the latest TLS/SSL libraries. +v0.9.7.4, is compatible with all previous 0.9.7.x series versions. + ## Eight Algortihm mPoW Hard Fork (v0.9.7) diff --git a/configure.ac b/configure.ac index d009b7120c..4a12e7e596 100644 --- a/configure.ac +++ b/configure.ac @@ -5,8 +5,9 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 9) define(_CLIENT_VERSION_REVISION, 7) -define(_CLIENT_VERSION_BUILD, 3) -define(_CLIENT_VERSION_IS_RELEASE, false) +define(_CLIENT_VERSION_BUILD, 4) +define(_CLIENT_VERSION_IS_RELEASE, true) + define(_COPYRIGHT_YEAR, 2021) AC_INIT([Bitmark Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@bitmark.org],[bitmark]) AC_CONFIG_AUX_DIR([src/build-aux]) diff --git a/src/bignum.h b/src/bignum.h index 5e89f0e2c9..8a186012f4 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -17,6 +17,8 @@ #include +#include "util.h" // for uint64 + /** Errors thrown by the bignum class */ class bignum_error : public std::runtime_error { @@ -54,75 +56,87 @@ class CAutoBN_CTX /** C++ wrapper for BIGNUM (OpenSSL bignum) */ -class CBigNum : public BIGNUM +class CBigNum { +protected: + BIGNUM *bn; + + void init() + { + bn = BN_new(); + } + public: CBigNum() { - BN_init(this); + init(); } CBigNum(const CBigNum& b) { - BN_init(this); - if (!BN_copy(this, &b)) + init(); + if (!BN_copy(bn, &b)) { - BN_clear_free(this); + BN_clear_free(bn); throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); } } CBigNum& operator=(const CBigNum& b) { - if (!BN_copy(this, &b)) + if (!BN_copy(bn, &b)) throw bignum_error("CBigNum::operator= : BN_copy failed"); return (*this); } ~CBigNum() { - BN_clear_free(this); + BN_clear_free(bn); } - //CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. - CBigNum(signed char n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } - CBigNum(long long n) { BN_init(this); setint64(n); } - CBigNum(unsigned char n) { BN_init(this); setulong(n); } - CBigNum(unsigned short n) { BN_init(this); setulong(n); } - CBigNum(unsigned int n) { BN_init(this); setulong(n); } - CBigNum(unsigned long n) { BN_init(this); setulong(n); } - CBigNum(unsigned long long n) { BN_init(this); setuint64(n); } - explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } + BIGNUM *operator &() const + { + return bn; + } + CBigNum(signed char n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(short n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(int n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long n) { init(); if (n >= 0) setulong(n); else setint64(n); } + CBigNum(long long n) { init(); setint64(n); } + + CBigNum(unsigned char n) { init(); setulong(n); } + CBigNum(unsigned short n) { init(); setulong(n); } + CBigNum(unsigned int n) { init(); setulong(n); } + CBigNum(unsigned long n) { init(); setulong(n); } + CBigNum(unsigned long long n) { init(); setuint64(n); } + explicit CBigNum(uint256 n) { init(); setuint256(n); } explicit CBigNum(const std::vector& vch) { - BN_init(this); + init(); setvch(vch); } void setulong(unsigned long n) { - if (!BN_set_word(this, n)) + if (!BN_set_word(bn, n)) throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed"); } unsigned long getulong() const { - return BN_get_word(this); + return BN_get_word(bn); } unsigned int getuint() const { - return BN_get_word(this); + return BN_get_word(bn); } int getint() const { - unsigned long n = BN_get_word(this); - if (!BN_is_negative(this)) + unsigned long n = BN_get_word(bn); + if (!BN_is_negative(bn)) return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::max() : n); else return (n > (unsigned long)std::numeric_limits::max() ? std::numeric_limits::min() : -(int)n); @@ -170,7 +184,22 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, p - pch, bn); + } + + uint64 getuint64() + { + unsigned int nSize = BN_bn2mpi(bn, NULL); + if (nSize < 4) + return 0; + std::vector vch(nSize); + BN_bn2mpi(bn, &vch[0]); + if (vch.size() > 4) + vch[4] &= 0x7f; + uint64 n = 0; + for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) + ((unsigned char*)&n)[i] = vch[j]; + return n; } void setuint64(uint64_t n) @@ -197,7 +226,7 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, p - pch, bn); } void setuint256(uint256 n) @@ -225,16 +254,16 @@ class CBigNum : public BIGNUM pch[1] = (nSize >> 16) & 0xff; pch[2] = (nSize >> 8) & 0xff; pch[3] = (nSize >> 0) & 0xff; - BN_mpi2bn(pch, p - pch, this); + BN_mpi2bn(pch, p - pch, bn); } uint256 getuint256() const { - unsigned int nSize = BN_bn2mpi(this, NULL); + unsigned int nSize = BN_bn2mpi(bn, NULL); if (nSize < 4) return 0; std::vector vch(nSize); - BN_bn2mpi(this, &vch[0]); + BN_bn2mpi(bn, &vch[0]); if (vch.size() > 4) vch[4] &= 0x7f; uint256 n = 0; @@ -255,16 +284,16 @@ class CBigNum : public BIGNUM vch2[3] = (nSize >> 0) & 0xff; // swap data to big endian reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4); - BN_mpi2bn(&vch2[0], vch2.size(), this); + BN_mpi2bn(&vch2[0], vch2.size(), bn); } std::vector getvch() const { - unsigned int nSize = BN_bn2mpi(this, NULL); + unsigned int nSize = BN_bn2mpi(bn, NULL); if (nSize <= 4) return std::vector(); std::vector vch(nSize); - BN_bn2mpi(this, &vch[0]); + BN_bn2mpi(bn, &vch[0]); vch.erase(vch.begin(), vch.begin() + 4); reverse(vch.begin(), vch.end()); return vch; @@ -300,28 +329,28 @@ class CBigNum : public BIGNUM if (nSize <= 3) { nWord >>= 8*(3-nSize); - BN_set_word(this, nWord); + BN_set_word(bn, nWord); } else { - BN_set_word(this, nWord); - BN_lshift(this, this, 8*(nSize-3)); + BN_set_word(bn, nWord); + BN_lshift(bn, bn, 8*(nSize-3)); } - BN_set_negative(this, fNegative); + BN_set_negative(bn, fNegative); return *this; } unsigned int GetCompact() const { - unsigned int nSize = BN_num_bytes(this); + unsigned int nSize = BN_num_bytes(bn); unsigned int nCompact = 0; if (nSize <= 3) - nCompact = BN_get_word(this) << 8*(3-nSize); + nCompact = BN_get_word(bn) << 8*(3-nSize); else { - CBigNum bn; - BN_rshift(&bn, this, 8*(nSize-3)); - nCompact = BN_get_word(&bn); + CBigNum bn1; + BN_rshift(&bn1, bn, 8*(nSize-3)); + nCompact = BN_get_word(&bn1); } // The 0x00800000 bit denotes the sign. // Thus, if it is already set, divide the mantissa by 256 and increase the exponent. @@ -331,7 +360,7 @@ class CBigNum : public BIGNUM nSize++; } nCompact |= nSize << 24; - nCompact |= (BN_is_negative(this) ? 0x00800000 : 0); + nCompact |= (BN_is_negative(bn) ? 0x00800000 : 0); return nCompact; } @@ -353,6 +382,14 @@ class CBigNum : public BIGNUM psz++; // hex string to bignum + // static const signed char phexdigit[256] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0xa,0xb,0xc,0xd,0xe,0xf,0,0,0,0,0,0,0,0,0 }; + // *this = 0; + // while (isxdigit(*psz)) + // { + // *this <<= 4; + // int n = phexdigit[(unsigned char)*psz++]; + // *this += n; + // } *this = 0; int n; while ((n = HexDigit(*psz)) != -1) @@ -371,21 +408,21 @@ class CBigNum : public BIGNUM CBigNum bnBase = nBase; CBigNum bn0 = 0; std::string str; - CBigNum bn = *this; - BN_set_negative(&bn, false); + CBigNum bn1 = *this; + BN_set_negative(&bn1, false); CBigNum dv; CBigNum rem; - if (BN_cmp(&bn, &bn0) == 0) + if (BN_cmp(&bn1, &bn0) == 0) return "0"; - while (BN_cmp(&bn, &bn0) > 0) + while (BN_cmp(&bn1, &bn0) > 0) { - if (!BN_div(&dv, &rem, &bn, &bnBase, pctx)) + if (!BN_div(&dv, &rem, &bn1, &bnBase, pctx)) throw bignum_error("CBigNum::ToString() : BN_div failed"); - bn = dv; + bn1 = dv; unsigned int c = rem.getulong(); str += "0123456789abcdef"[c]; } - if (BN_is_negative(this)) + if (BN_is_negative(bn)) str += "-"; reverse(str.begin(), str.end()); return str; @@ -418,12 +455,12 @@ class CBigNum : public BIGNUM bool operator!() const { - return BN_is_zero(this); + return BN_is_zero(bn); } CBigNum& operator+=(const CBigNum& b) { - if (!BN_add(this, this, &b)) + if (!BN_add(bn, bn, &b)) throw bignum_error("CBigNum::operator+= : BN_add failed"); return *this; } @@ -437,7 +474,7 @@ class CBigNum : public BIGNUM CBigNum& operator*=(const CBigNum& b) { CAutoBN_CTX pctx; - if (!BN_mul(this, this, &b, pctx)) + if (!BN_mul(bn, bn, &b, pctx)) throw bignum_error("CBigNum::operator*= : BN_mul failed"); return *this; } @@ -456,7 +493,7 @@ class CBigNum : public BIGNUM CBigNum& operator<<=(unsigned int shift) { - if (!BN_lshift(this, this, shift)) + if (!BN_lshift(bn, bn, shift)) throw bignum_error("CBigNum:operator<<= : BN_lshift failed"); return *this; } @@ -467,13 +504,13 @@ class CBigNum : public BIGNUM // if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL CBigNum a = 1; a <<= shift; - if (BN_cmp(&a, this) > 0) + if (BN_cmp(&a, bn) > 0) { *this = 0; return *this; } - if (!BN_rshift(this, this, shift)) + if (!BN_rshift(bn, bn, shift)) throw bignum_error("CBigNum:operator>>= : BN_rshift failed"); return *this; } @@ -482,7 +519,7 @@ class CBigNum : public BIGNUM CBigNum& operator++() { // prefix operator - if (!BN_add(this, this, BN_value_one())) + if (!BN_add(bn, bn, BN_value_one())) throw bignum_error("CBigNum::operator++ : BN_add failed"); return *this; } @@ -499,7 +536,7 @@ class CBigNum : public BIGNUM { // prefix operator CBigNum r; - if (!BN_sub(&r, this, BN_value_one())) + if (!BN_sub(&r, bn, BN_value_one())) throw bignum_error("CBigNum::operator-- : BN_sub failed"); *this = r; return *this; diff --git a/src/bitmarkd.cpp b/src/bitmarkd.cpp index 956a902dd6..9a867da2cd 100644 --- a/src/bitmarkd.cpp +++ b/src/bitmarkd.cpp @@ -55,6 +55,8 @@ void DetectShutdownThread(boost::thread_group* threadGroup) // bool AppInit(int argc, char* argv[]) { +======= + //printf("appinit\n"); boost::thread_group threadGroup; boost::thread* detectShutdownThread = NULL; @@ -103,13 +105,14 @@ bool AppInit(int argc, char* argv[]) return false; } - if (mapArgs.count("-v") || mapArgs.count("--version")) - { + if (mapArgs.count("-v") || mapArgs.count("--version")) + { // First part of help message is specific to bitmarkd / RPC client std::string strUsage = _("Bitmark Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n"; - fprintf(stdout, "%s", strUsage.c_str()); - return false; - } + fprintf(stdout, "%s", strUsage.c_str()); + return false; + } + // Command-line RPC bool fCommandLine = false; @@ -182,6 +185,7 @@ bool AppInit(int argc, char* argv[]) int main(int argc, char* argv[]) { + //printf("main"); SetupEnvironment(); bool fRet = false; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7803f640b2..949f9430b5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -22,19 +22,12 @@ using namespace boost::assign; // Hard-Coded (Fixed) Network Nodes unsigned int pnSeed[] = { -// 0xac1f1f0a, // *** inoperative: historical IP with IBM / SoftLayer *** -// 0x253b1359, // *** inoperative: historical IP with IBM / SoftLayer *** -// 0xAE240982, // *** inoperative: historical IP with IBM / SoftLayer *** 0xADFFFC8C, // seed.bitmark.co IP = 173.255.252.140 sam 0x8BA2805C, // eu.bitmark.io IP = 139.162.128.92 frank 0x5E89B1E3, // ge.bitmark.io IP = 94.137.177.227 anton 0x8BA27A8A, // jp.bitmark.io IP = 139.162.122.138 akio 0x2D2141A1, // us.bitmark.io IP = 45.33.65.161 joe -// 0xCC447A12, // tx.bitmark.io IP = 204.68.122.18 tex -// 0xCC447A07, // seed.bitmark.mx IP = 204.68.122.7 jules -// 0xCC447A0B, // one.zmark.org IP = 204.68.122.11 per - 0x8BA2E8F2, // uk.bitmark.one IP = 139.162.232.242 jim - 0x32741C88, // mining.mymarks.io IP = 50.116.28.136 vic + 0x8BA223AA, // sg.bitmark.co IP = 139.162.35.170 ben }; unsigned int pnSeedTest[] = @@ -84,25 +77,25 @@ class CMainParams : public CChainParams { assert(hashGenesisBlock == uint256("0xc1fb746e87e89ae75bdec2ef0639a1f6786744639ce3d0ece1dcf979b79137cb")); assert(genesis.hashMerkleRoot == uint256("0xd4715adf41222fae3d4bf41af30c675bc27228233d0f3cfd4ae0ae1d3e760ba8")); - - // DNS Seeders - Verified 03 08 21 March 8, 2021 - // Domain Sub-Domain Location - vSeeds.push_back(CDNSSeedData("bitmark.guru", "da.bitmark.guru")); // DE Frank - vSeeds.push_back(CDNSSeedData("openmarks.com", "btm.openmarks.com")); // IL eli - vSeeds.push_back(CDNSSeedData("bitmark.one", "shido.bitmark.one")); // JP akio - - vSeeds.push_back(CDNSSeedData("openmarks.com", "dnsseed.openmarks.com")); // DE omar - vSeeds.push_back(CDNSSeedData("zmark.org", "ra.zmark.org")); // CA sam - vSeeds.push_back(CDNSSeedData("chainetics.com", "marks.chainetics.com")); // SG ben - - vSeeds.push_back(CDNSSeedData("bitmark.one", "biji.bitmark.one")); // CA marks - vSeeds.push_back(CDNSSeedData("avalax.com", "marks.avalax.com")); // JP jin - vSeeds.push_back(CDNSSeedData("zmark.org", "shiba.zmark.org")); // NJ j2 - - vSeeds.push_back(CDNSSeedData("zmark.org", "btmk.zmark.org")); // CA zappa - vSeeds.push_back(CDNSSeedData("bitmark.cc", "dnsseed.bitmark.cc")); // NJ joe - vSeeds.push_back(CDNSSeedData("zmark.org", "btm.zmark.org")); // NJ vinny j0 - + + + // DNS Seeders - Verified 03 08 21 March 8, 2021 + // Domain Sub-Domain Location + vSeeds.push_back(CDNSSeedData("bitmark.guru", "da.bitmark.guru")); // DE Frank + vSeeds.push_back(CDNSSeedData("openmarks.com", "btm.openmarks.com")); // IL eli + vSeeds.push_back(CDNSSeedData("bitmark.one", "shido.bitmark.one")); // JP akio + + vSeeds.push_back(CDNSSeedData("openmarks.com", "dnsseed.openmarks.com")); // DE omar + vSeeds.push_back(CDNSSeedData("zmark.org", "ra.zmark.org")); // CA sam + vSeeds.push_back(CDNSSeedData("chainetics.com", "marks.chainetics.com")); // SG ben + + vSeeds.push_back(CDNSSeedData("bitmark.one", "biji.bitmark.one")); // CA marks + vSeeds.push_back(CDNSSeedData("bitmark.cc", "dnsseed.bitmark.cc")); // NJ joe + vSeeds.push_back(CDNSSeedData("zmark.org", "btmk.zmark.org")); // CA zappa + + vSeeds.push_back(CDNSSeedData("zmark.org", "shiba.zmark.org")); // NJ j2 + vSeeds.push_back(CDNSSeedData("avalax.com", "marks.avalax.com")); // JP jin + vSeeds.push_back(CDNSSeedData("zmark.org", "btm.zmark.org")); // NJ vinny j0 base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,85); // b diff --git a/src/chainparams.h b/src/chainparams.h index 11d14b46e3..c2257e109c 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -73,7 +73,24 @@ class CChainParams unsigned int EquihashN() const { return nEquihashN; } unsigned int EquihashK() const { return nEquihashK; } bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; } - + + // Fork2 in suspension (3/21/21) + //int64_t GetFork2Height() const { return nForkHeight2; } + //bool OnFork2(int64_t blockHeight) const { return blockHeight >= nForkHeight2; } + + // CEM Look-Back time frame (from which to find the refrence highest or peak hashrate) Policy is relaxed to ~ 25% of original value. + // CEM v0.1 looks back 365 days. CEM v0.2 looks back only 90 days + // This allow the maximum emission rate to be resumed that much sooner. + // int CEM_WindowLength(int64_t blockHeight) const { return OnFork2(blockHeight) ? 90 : 365; } + // + // CEM is allowed to affect this portion of the epoch nominal block reward. + // CEM v0.1 scales 50% of the max epoch reward. CEM v0.2 scales 80% of the max epoch reward. + // Both versions allow maximum theoretical emission rate if current hashrate is at peak performance, + // but CEM v0.2 has a stronger emission rate reduction if current hashrate is any less than reference peak performance. + // + //int CEM_MaxNativeBlockRewardReduction(int64_t blockHeight) const { return OnFork2(blockHeight) ? 80 : 50; } + + protected: CChainParams() {} diff --git a/src/clientversion.h b/src/clientversion.h index 296a37de0a..a9b3936c41 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -13,10 +13,10 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 9 #define CLIENT_VERSION_REVISION 7 -#define CLIENT_VERSION_BUILD 3 +#define CLIENT_VERSION_BUILD 4 // Set to true for release, false for prerelease (rc: release candidate) or test build -#define CLIENT_VERSION_IS_RELEASE false +#define CLIENT_VERSION_IS_RELEASE true // Copyright year (2009-this) diff --git a/src/crypter.cpp b/src/crypter.cpp index 19c640466a..ccdb9e9d72 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -57,16 +57,16 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector (nCLen); - EVP_CIPHER_CTX ctx; + EVP_CIPHER_CTX *ctx; bool fOk = true; - EVP_CIPHER_CTX_init(&ctx); - if (fOk) fOk = EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); - if (fOk) fOk = EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); - if (fOk) fOk = EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen); - EVP_CIPHER_CTX_cleanup(&ctx); - + ctx = EVP_CIPHER_CTX_new(); + if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_EncryptUpdate(ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); + if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (&vchCiphertext[0])+nCLen, &nFLen); + EVP_CIPHER_CTX_free(ctx); + if (!fOk) return false; vchCiphertext.resize(nCLen + nFLen); @@ -84,15 +84,15 @@ bool CCrypter::Decrypt(const std::vector& vchCiphertext, CKeyingM vchPlaintext = CKeyingMaterial(nPLen); - EVP_CIPHER_CTX ctx; + EVP_CIPHER_CTX *ctx; bool fOk = true; - EVP_CIPHER_CTX_init(&ctx); - if (fOk) fOk = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); - if (fOk) fOk = EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); - if (fOk) fOk = EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen); - EVP_CIPHER_CTX_cleanup(&ctx); + ctx = EVP_CIPHER_CTX_new(); + if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + if (fOk) fOk = EVP_DecryptUpdate(ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); + if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (&vchPlaintext[0])+nPLen, &nFLen); + EVP_CIPHER_CTX_free(ctx); if (!fOk) return false; diff --git a/src/key.cpp b/src/key.cpp index c6eae5547b..6bc2a68f84 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -13,6 +13,15 @@ // anonymous namespace with local implementation code (OpenSSL interaction) namespace { +#if OPENSSL_VERSION_NUMBER < 0x10100000L + void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) + { + if (pr != NULL) + *pr = sig->r; + if (ps != NULL) + *ps = sig->s; + } +#endif // Generate a private key from just the secret parameter int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key) { @@ -71,6 +80,7 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch EC_POINT *Q = NULL; BIGNUM *rr = NULL; BIGNUM *zero = NULL; + BIGNUM *s = 0; int n = 0; int i = recid / 2; @@ -82,7 +92,9 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch x = BN_CTX_get(ctx); if (!BN_copy(x, order)) { ret=-1; goto err; } if (!BN_mul_word(x, i)) { ret=-1; goto err; } - if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; } + ECDSA_SIG_get0(ecsig, (const BIGNUM **)&s, 0); + if (!BN_add(x, x, s)) { ret=-1; goto err; } + // if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; } field = BN_CTX_get(ctx); if (!EC_GROUP_get_curve_GFp(group, field, NULL, NULL, ctx)) { ret=-2; goto err; } if (BN_cmp(x, field) >= 0) { ret=0; goto err; } @@ -103,9 +115,13 @@ int ECDSA_SIG_recover_key_GFp(EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned ch if (!BN_zero(zero)) { ret=-1; goto err; } if (!BN_mod_sub(e, zero, e, order, ctx)) { ret=-1; goto err; } rr = BN_CTX_get(ctx); - if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; } + ECDSA_SIG_get0(ecsig, (const BIGNUM **)&s, 0); + if (!BN_mod_inverse(rr, s, order, ctx)) { ret=-1; goto err; } + // if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; } sor = BN_CTX_get(ctx); - if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; } + ECDSA_SIG_get0(ecsig, 0, (const BIGNUM **)&s); + if (!BN_mod_mul(sor, s, rr, order, ctx)) { ret=-1; goto err; } + // if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; } eor = BN_CTX_get(ctx); if (!BN_mod_mul(eor, e, rr, order, ctx)) { ret=-1; goto err; } if (!EC_POINT_mul(group, Q, eor, R, sor, ctx)) { ret=-2; goto err; } @@ -150,13 +166,15 @@ class CECKey { void SetSecretBytes(const unsigned char vch[32]) { bool ret; - BIGNUM bn; - BN_init(&bn); - ret = BN_bin2bn(vch, 32, &bn); + // BIGNUM bn; + // BN_init(&bn); + BIGNUM *bn; + bn = BN_new(); + ret = BN_bin2bn(vch, 32, bn); assert(ret); - ret = EC_KEY_regenerate_key(pkey, &bn); + ret = EC_KEY_regenerate_key(pkey, bn); assert(ret); - BN_clear_free(&bn); + BN_clear_free(bn); } void GetPrivKey(CPrivKey &privkey, bool fCompressed) { @@ -201,6 +219,7 @@ class CECKey { } bool Sign(const uint256 &hash, std::vector& vchSig) { + BIGNUM *s = 0; vchSig.clear(); ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey); if (sig == NULL) @@ -212,9 +231,10 @@ class CECKey { BIGNUM *halforder = BN_CTX_get(ctx); EC_GROUP_get_order(group, order, ctx); BN_rshift1(halforder, order); - if (BN_cmp(sig->s, halforder) > 0) { + ECDSA_SIG_get0(sig, 0, (const BIGNUM **)&s); + if (BN_cmp(s, halforder) > 0) { // enforce low S values, by negating the value (modulo the order) if above order/2. - BN_sub(sig->s, order, sig->s); + BN_sub(s, order, s); } BN_CTX_end(ctx); BN_CTX_free(ctx); @@ -278,12 +298,15 @@ class CECKey { bool SignCompact(const uint256 &hash, unsigned char *p64, int &rec) { bool fOk = false; + BIGNUM *s = 0; + BIGNUM *r = 0; ECDSA_SIG *sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey); if (sig==NULL) return false; memset(p64, 0, 64); - int nBitsR = BN_num_bits(sig->r); - int nBitsS = BN_num_bits(sig->s); + ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s); + int nBitsR = BN_num_bits(r); + int nBitsS = BN_num_bits(s); if (nBitsR <= 256 && nBitsS <= 256) { CPubKey pubkey; GetPubKey(pubkey, true); @@ -300,8 +323,9 @@ class CECKey { } } assert(fOk); - BN_bn2bin(sig->r,&p64[32-(nBitsR+7)/8]); - BN_bn2bin(sig->s,&p64[64-(nBitsS+7)/8]); + ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s); + BN_bn2bin(r,&p64[32-(nBitsR+7)/8]); + BN_bn2bin(s,&p64[64-(nBitsS+7)/8]); } ECDSA_SIG_free(sig); return fOk; @@ -313,11 +337,14 @@ class CECKey { // (the signature is a valid signature of the given data for that key) bool Recover(const uint256 &hash, const unsigned char *p64, int rec) { + BIGNUM *s = 0; + BIGNUM *r = 0; if (rec<0 || rec>=3) return false; ECDSA_SIG *sig = ECDSA_SIG_new(); - BN_bin2bn(&p64[0], 32, sig->r); - BN_bin2bn(&p64[32], 32, sig->s); + ECDSA_SIG_get0(sig, (const BIGNUM **)&r, (const BIGNUM **)&s); + BN_bin2bn(&p64[0], 32, r); + BN_bin2bn(&p64[32], 32, s); bool ret = ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), rec, 0) == 1; ECDSA_SIG_free(sig); return ret; diff --git a/src/key.h b/src/key.h index 921b1e2e73..5c83876fd1 100644 --- a/src/key.h +++ b/src/key.h @@ -15,6 +15,11 @@ #include #include +// #if OPENSSL_VERSION_NUMBER < 0x10100000L +// #include +// void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps); +// #endif + // secp256k1: // const unsigned int PRIVATE_KEY_SIZE = 279; // const unsigned int PUBLIC_KEY_SIZE = 65; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 6fa22a21a9..e0edac45ba 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -732,6 +732,7 @@ Value submitblock(const Array& params, bool fHelp) return Value::null; } +#ifdef ENABLE_WALLET Value getauxblock(const Array& params, bool fHelp) { if (fHelp || (params.size() != 0 && params.size() != 2)) @@ -882,3 +883,4 @@ Value getauxblock(const Array& params, bool fHelp) return "rejected"; return Value::null; } +#endif diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index 9252744f07..6f5c0eb146 100644 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -20,6 +20,20 @@ #include "json/json_spirit_utils.h" #include "json/json_spirit_writer_template.h" +#include + #include + + // Boost Support for 1.70+ + #if BOOST_VERSION >= 107000 + #define GetIOService(s) ((boost::asio::io_context&)(s).get_executor().context()) + #define GetIOServiceFromPtr(s) ((boost::asio::io_context&)(s->get_executor().context())) // this one + typedef boost::asio::io_context ioContext; + #else + #define GetIOService(s) ((s).get_io_service()) + #define GetIOServiceFromPtr(s) ((s)->get_io_service()) + typedef boost::asio::io_service ioContext; + #endif + // HTTP status codes enum HTTPStatusCode { @@ -104,7 +118,7 @@ class SSLIOStreamDevice : public boost::iostreams::device > accep const bool fUseSSL) { // Accept connection - boost::shared_ptr< AcceptedConnectionImpl > conn(new AcceptedConnectionImpl(acceptor->get_io_service(), context, fUseSSL)); - + boost::shared_ptr< AcceptedConnectionImpl > conn(new AcceptedConnectionImpl(GetIOServiceFromPtr(acceptor), context, fUseSSL)); + acceptor->async_accept( conn->sslStream.lowest_layer(), conn->peer, diff --git a/src/rpcserver.h b/src/rpcserver.h index caff029422..fb4d134ca8 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -19,6 +19,7 @@ #include "json/json_spirit_utils.h" #include "json/json_spirit_writer_template.h" + class CBlockIndex; /* Start RPC threads */ diff --git a/src/version.cpp b/src/version.cpp index 0d8952d77d..2e888778dc 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -12,8 +12,10 @@ // target servers or GUI users specifically. const std::string CLIENT_NAME("Pfennig"); +// https://github.com/bitcoin/bitcoin/issues/4221 +// Standard convention in software release cycles: dev, alpha, beta, rc & stable. // Client version number -#define CLIENT_VERSION_SUFFIX "-beta" +#define CLIENT_VERSION_SUFFIX "-Phi" // The following part of the code determines the CLIENT_BUILD variable. diff --git a/vimver b/vimver index ded9ae80a7..8eae153996 100755 --- a/vimver +++ b/vimver @@ -1,2 +1,6 @@ #!/bin/bash -vim configure.ac src/clientversion.h src/version.h README.md + +echo "set CLIENT_VERSION_IS_RELEASE in Makefile" +read +vim Makefile configure.ac src/clientversion.h src/version.h src/version.cpp README.md +