Browse Source

upstream 2.2.4

master 2.2.4-gostd-lite
R4SAS 6 years ago
parent
commit
4cd4c22f8e
  1. 25
      README.txt
  2. 2
      api/websocket.htm
  3. 6
      bignum.cpp
  4. 240
      bignum.hpp
  5. 6
      ccminer.cpp
  6. 12
      ccminer.vcxproj
  7. 602
      compat/bignum_ssl10.hpp
  8. 4
      compat/ccminer-config.h
  9. 4
      configure.ac
  10. 10
      cuda_helper.h
  11. 10
      res/ccminer.rc

25
README.txt

@ -1,5 +1,5 @@
ccminer 2.2.2 (Oct. 2017) "phi and hsr algos" ccminer 2.2.4 (Jan. 2018) "lyra2v2 and keccak improvements"
--------------------------------------------------------------- ---------------------------------------------------------------
*************************************************************** ***************************************************************
@ -80,7 +80,7 @@ its command line interface and options.
blake2s use to mine Nevacoin (Blake2-S 256) blake2s use to mine Nevacoin (Blake2-S 256)
bmw use to mine Midnight bmw use to mine Midnight
cryptolight use to mine AEON cryptonight (MEM/2) cryptolight use to mine AEON cryptonight (MEM/2)
cryptonight use to mine XMR cryptonight cryptonight use to mine XMR cryptonight, Bytecoin, Dash, DigitalNote, etc
c11/flax use to mine Chaincoin and Flax c11/flax use to mine Chaincoin and Flax
decred use to mine Decred 180 bytes Blake256-14 decred use to mine Decred 180 bytes Blake256-14
deep use to mine Deepcoin deep use to mine Deepcoin
@ -89,24 +89,24 @@ its command line interface and options.
fresh use to mine Freshcoin fresh use to mine Freshcoin
fugue256 use to mine Fuguecoin fugue256 use to mine Fuguecoin
groestl use to mine Groestlcoin groestl use to mine Groestlcoin
heavy use to mine Heavycoin
hsr use to mine Hshare hsr use to mine Hshare
jackpot use to mine Sweepcoin jackpot use to mine Sweepcoin
keccak use to mine Maxcoin keccak use to mine Maxcoin
keccakc use to mine CreativeCoin
lbry use to mine LBRY Credits lbry use to mine LBRY Credits
luffa use to mine Joincoin luffa use to mine Joincoin
lyra2 use to mine CryptoCoin lyra2 use to mine CryptoCoin
lyra2v2 use to mine Vertcoin lyra2v2 use to mine Vertcoin
lyra2z use to mine Zerocoin (XZC) lyra2z use to mine Zerocoin (XZC)
mjollnir use to mine Mjollnircoin
myr-gr use to mine Myriad-Groest myr-gr use to mine Myriad-Groest
neoscrypt use to mine FeatherCoin neoscrypt use to mine FeatherCoin, Trezarcoin, Orbitcoin, etc
nist5 use to mine TalkCoin nist5 use to mine TalkCoin
penta use to mine Joincoin / Pentablake penta use to mine Joincoin / Pentablake
phi use to mine LUXCoin phi use to mine LUXCoin
polytimos use to mine Polytimos
quark use to mine Quarkcoin quark use to mine Quarkcoin
qubit use to mine Qubit qubit use to mine Qubit
scrypt use to mine Scrypt coins scrypt use to mine Scrypt coins (Litecoin, Dogecoin, etc)
scrypt:N use to mine Scrypt-N (:10 for 2048 iterations) scrypt:N use to mine Scrypt-N (:10 for 2048 iterations)
scrypt-jane use to mine Chacha coins like Cache and Ultracoin scrypt-jane use to mine Chacha coins like Cache and Ultracoin
s3 use to mine 1coin (ONE) s3 use to mine 1coin (ONE)
@ -123,7 +123,6 @@ its command line interface and options.
x14 use to mine X14Coin x14 use to mine X14Coin
x15 use to mine Halcyon x15 use to mine Halcyon
x17 use to mine X17 x17 use to mine X17
x17 use to mine X17
vanilla use to mine Vanilla (Blake256) vanilla use to mine Vanilla (Blake256)
veltor use to mine VeltorCoin veltor use to mine VeltorCoin
whirlpool use to mine Joincoin whirlpool use to mine Joincoin
@ -140,8 +139,6 @@ its command line interface and options.
--cuda-schedule Set device threads scheduling mode (default: auto) --cuda-schedule Set device threads scheduling mode (default: auto)
-f, --diff-factor Divide difficulty by this factor (default 1.0) -f, --diff-factor Divide difficulty by this factor (default 1.0)
-m, --diff-multiplier Multiply difficulty by this value (default 1.0) -m, --diff-multiplier Multiply difficulty by this value (default 1.0)
--vote=VOTE block reward vote (for HeavyCoin)
--trust-pool trust the max block reward vote (maxvote) sent by the pool
-o, --url=URL URL of mining server -o, --url=URL URL of mining server
-O, --userpass=U:P username:password pair for mining server -O, --userpass=U:P username:password pair for mining server
-u, --user=USERNAME username for mining server -u, --user=USERNAME username for mining server
@ -280,6 +277,16 @@ so we can more efficiently implement new algorithms using the latest hardware
features. features.
>>> RELEASE HISTORY <<< >>> RELEASE HISTORY <<<
Jan. 04th 2017 v2.2.4
Improve lyra2v2
Higher keccak default intensity
Drop SM 2.x support by default, for CUDA 9 and more recent
Dec. 04th 2017 v2.2.3
Polytimos Algo
Handle keccakc variant (with refreshed sha256d merkle)
Optimised keccak for SM5+, based on alexis improvements
Oct. 09th 2017 v2.2.2 Oct. 09th 2017 v2.2.2
Import and clean the hsr algo (x13 + custom hash) Import and clean the hsr algo (x13 + custom hash)
Import and optimise phi algo from LuxCoin repository Import and optimise phi algo from LuxCoin repository

2
api/websocket.htm

@ -1,7 +1,7 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<head> <head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script>
</head> </head>

6
bignum.cpp

@ -5,7 +5,13 @@
#include <stdio.h> #include <stdio.h>
#include "uint256.h" #include "uint256.h"
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include "compat/bignum_ssl10.hpp"
#else
#include "bignum.hpp" #include "bignum.hpp"
#endif
#include "miner.h" // hex2bin #include "miner.h" // hex2bin

240
bignum.hpp

@ -9,20 +9,13 @@
#define PROTOCOL_VERSION 70001 #define PROTOCOL_VERSION 70001
#endif #endif
#include <map>
#include <limits>
#include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
#include "uint256.h"
#include <openssl/bn.h> #include <openssl/bn.h>
#include "serialize.hpp" #include "serialize.hpp"
using namespace std;
/** Errors thrown by the bignum class */ /** Errors thrown by the bignum class */
class bignum_error : public std::runtime_error class bignum_error : public std::runtime_error
{ {
@ -60,75 +53,90 @@ public:
/** C++ wrapper for BIGNUM (OpenSSL bignum) */ /** C++ wrapper for BIGNUM (OpenSSL bignum) */
class CBigNum : public BIGNUM class CBigNum
{ {
private:
BIGNUM *self = NULL;
void init()
{
if (self)
BN_clear_free(self);
self = BN_new();
if (!self)
throw bignum_error("CBigNum::init(): BN_new() returned NULL");
}
public: public:
BIGNUM *get() { return self; }
const BIGNUM *getc() const { return self; }
CBigNum() CBigNum()
{ {
BN_init(this); init();
} }
CBigNum(const CBigNum& b) CBigNum(const CBigNum& b)
{ {
BN_init(this); init();
if (!BN_copy(this, &b)) if (!BN_copy(self, b.getc()))
{ {
BN_clear_free(this); BN_clear_free(self);
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
} }
} }
CBigNum& operator=(const CBigNum& b) CBigNum& operator=(const CBigNum& b)
{ {
if (!BN_copy(this, &b)) if (!BN_copy(self, b.getc()))
throw bignum_error("CBigNum::operator= : BN_copy failed"); throw bignum_error("CBigNum::operator= : BN_copy failed");
return (*this); return (*this);
} }
~CBigNum() ~CBigNum()
{ {
BN_clear_free(this); BN_clear_free(self);
} }
//CBigNum(char n) is not portable. Use 'signed char' or 'unsigned char'. //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(signed char n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(short n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } CBigNum(short n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } CBigNum(int n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(long n) { BN_init(this); if (n >= 0) setulong(n); else setint64(n); } CBigNum(long n) { init(); if (n >= 0) setulong(n); else setint64(n); }
CBigNum(int64 n) { BN_init(this); setint64(n); } CBigNum(int64 n) { init(); setint64(n); }
CBigNum(unsigned char n) { BN_init(this); setulong(n); } CBigNum(unsigned char n) { init(); setulong(n); }
CBigNum(unsigned short n) { BN_init(this); setulong(n); } CBigNum(unsigned short n) { init(); setulong(n); }
CBigNum(unsigned int n) { BN_init(this); setulong(n); } CBigNum(unsigned int n) { init(); setulong(n); }
CBigNum(unsigned long n) { BN_init(this); setulong(n); } CBigNum(unsigned long n) { init(); setulong(n); }
CBigNum(uint64 n) { BN_init(this); setuint64(n); } CBigNum(uint64 n) { init(); setuint64(n); }
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); } explicit CBigNum(uint256 n) { init(); setuint256(n); }
explicit CBigNum(const std::vector<unsigned char>& vch) explicit CBigNum(const std::vector<unsigned char>& vch)
{ {
BN_init(this); init();
setvch(vch); setvch(vch);
} }
void setulong(unsigned long n) void setulong(unsigned long n)
{ {
if (!BN_set_word(this, n)) if (!BN_set_word(self, n))
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed"); throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
} }
unsigned long getulong() const unsigned long getulong() const
{ {
return (unsigned long) BN_get_word(this); return BN_get_word(self);
} }
unsigned int getuint() const unsigned int getuint() const
{ {
return (unsigned int) BN_get_word(this); return BN_get_word(self);
} }
int getint() const int getint() const
{ {
unsigned long n = (unsigned long) BN_get_word(this); unsigned long n = BN_get_word(self);
if (!BN_is_negative(this)) if (!BN_is_negative(self))
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n); return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
else else
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n); return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
@ -141,11 +149,9 @@ public:
bool fNegative; bool fNegative;
uint64 n; uint64 n;
if (sn < 0LL) if (sn < (int64)0)
{ {
// Since the minimum signed integer cannot be represented as positive so long as its type is signed, // Since the minimum signed integer cannot be represented as positive so long as its type is signed, and it's not well-defined what happens if you make it unsigned before negating it, we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
// and it's not well-defined what happens if you make it unsigned before negating it,
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
n = -(sn + 1); n = -(sn + 1);
++n; ++n;
fNegative = true; fNegative = true;
@ -171,12 +177,27 @@ public:
} }
*p++ = c; *p++ = c;
} }
unsigned int nSize = (unsigned int) (p - (pch + 4)); unsigned int nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff; pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff; pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff; pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff; pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this); BN_mpi2bn(pch, p - pch, self);
}
uint64 getuint64()
{
unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(self, &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 n) void setuint64(uint64 n)
@ -198,12 +219,12 @@ public:
} }
*p++ = c; *p++ = c;
} }
unsigned int nSize = (unsigned int) (p - (pch + 4)); unsigned int nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff; pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff; pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff; pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff; pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this); BN_mpi2bn(pch, p - pch, self);
} }
void setuint256(uint256 n) void setuint256(uint256 n)
@ -226,33 +247,34 @@ public:
} }
*p++ = c; *p++ = c;
} }
unsigned int nSize = (unsigned int) (p - (pch + 4)); unsigned int nSize = p - (pch + 4);
pch[0] = (nSize >> 24) & 0xff; pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff; pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff; pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize >> 0) & 0xff; pch[3] = (nSize >> 0) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this); BN_mpi2bn(pch, p - pch, self);
} }
uint256 getuint256() const uint256 getuint256()
{ {
unsigned int nSize = BN_bn2mpi(this, NULL); unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize < 4) if (nSize < 4)
return 0; return 0;
std::vector<unsigned char> vch(nSize); std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]); BN_bn2mpi(self, &vch[0]);
if (vch.size() > 4) if (vch.size() > 4)
vch[4] &= 0x7f; vch[4] &= 0x7f;
uint256 n = 0; uint256 n = 0;
for (unsigned int i = 0, j = (unsigned int) vch.size()-1; i < sizeof(n) && j >= 4; i++, j--) for (unsigned int i = 0, j = vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
((unsigned char*)&n)[i] = vch[j]; ((unsigned char*)&n)[i] = vch[j];
return n; return n;
} }
void setvch(const std::vector<unsigned char>& vch) void setvch(const std::vector<unsigned char>& vch)
{ {
std::vector<unsigned char> vch2(vch.size() + 4); std::vector<unsigned char> vch2(vch.size() + 4);
unsigned int nSize = (unsigned int) vch.size(); unsigned int nSize = vch.size();
// BIGNUM's byte stream format expects 4 bytes of // BIGNUM's byte stream format expects 4 bytes of
// big endian size data info at the front // big endian size data info at the front
vch2[0] = (nSize >> 24) & 0xff; vch2[0] = (nSize >> 24) & 0xff;
@ -261,83 +283,43 @@ public:
vch2[3] = (nSize >> 0) & 0xff; vch2[3] = (nSize >> 0) & 0xff;
// swap data to big endian // swap data to big endian
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4); reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
BN_mpi2bn(&vch2[0], (int) vch2.size(), this); BN_mpi2bn(&vch2[0], vch2.size(), self);
} }
std::vector<unsigned char> getvch() const std::vector<unsigned char> getvch() const
{ {
unsigned int nSize = BN_bn2mpi(this, NULL); unsigned int nSize = BN_bn2mpi(self, NULL);
if (nSize <= 4) if (nSize <= 4)
return std::vector<unsigned char>(); return std::vector<unsigned char>();
std::vector<unsigned char> vch(nSize); std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]); BN_bn2mpi(self, &vch[0]);
vch.erase(vch.begin(), vch.begin() + 4); vch.erase(vch.begin(), vch.begin() + 4);
reverse(vch.begin(), vch.end()); reverse(vch.begin(), vch.end());
return vch; return vch;
} }
// The "compact" format is a representation of a whole
// number N using an unsigned 32bit number similar to a
// floating point format.
// The most significant 8 bits are the unsigned exponent of base 256.
// This exponent can be thought of as "number of bytes of N".
// The lower 23 bits are the mantissa.
// Bit number 24 (0x800000) represents the sign of N.
// N = (-1^sign) * mantissa * 256^(exponent-3)
//
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
// MPI uses the most significant bit of the first byte as sign.
// Thus 0x1234560000 is compact (0x05123456)
// and 0xc0de000000 is compact (0x0600c0de)
// (0x05c0de00) would be -0x40de000000
//
// Bitcoin only uses this "compact" format for encoding difficulty
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
//
// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
CBigNum& SetCompact(unsigned int nCompact) CBigNum& SetCompact(unsigned int nCompact)
{ {
unsigned int nSize = nCompact >> 24; unsigned int nSize = nCompact >> 24;
bool fNegative =(nCompact & 0x00800000) != 0; std::vector<unsigned char> vch(4 + nSize);
unsigned int nWord = nCompact & 0x007fffff; vch[3] = nSize;
if (nSize <= 3) if (nSize >= 1) vch[4] = (nCompact >> 16) & 0xff;
{ if (nSize >= 2) vch[5] = (nCompact >> 8) & 0xff;
nWord >>= 8*(3-nSize); if (nSize >= 3) vch[6] = (nCompact >> 0) & 0xff;
BN_set_word(this, nWord); BN_mpi2bn(&vch[0], vch.size(), self);
}
else
{
BN_set_word(this, nWord);
BN_lshift(this, this, 8*(nSize-3));
}
BN_set_negative(this, fNegative);
return *this; return *this;
} }
unsigned int GetCompact() const unsigned int GetCompact() const
{ {
unsigned int nSize = BN_num_bytes(this); unsigned int nSize = BN_bn2mpi(self, NULL);
unsigned int nCompact = 0; std::vector<unsigned char> vch(nSize);
if (nSize <= 3) nSize -= 4;
nCompact = (unsigned int) BN_get_word(this) << 8*(3-nSize); BN_bn2mpi(self, &vch[0]);
else unsigned int nCompact = nSize << 24;
{ if (nSize >= 1) nCompact |= (vch[4] << 16);
CBigNum bn; if (nSize >= 2) nCompact |= (vch[5] << 8);
BN_rshift(&bn, this, 8*(nSize-3)); if (nSize >= 3) nCompact |= (vch[6] << 0);
nCompact = (unsigned int) BN_get_word(&bn);
}
// The 0x00800000 bit denotes the sign.
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
if (nCompact & 0x00800000)
{
nCompact >>= 8;
nSize++;
}
nCompact |= nSize << 24;
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
return nCompact; return nCompact;
} }
@ -378,20 +360,20 @@ public:
CBigNum bn0 = 0; CBigNum bn0 = 0;
std::string str; std::string str;
CBigNum bn = *this; CBigNum bn = *this;
BN_set_negative(&bn, false); BN_set_negative(bn.get(), false);
CBigNum dv; CBigNum dv;
CBigNum rem; CBigNum rem;
if (BN_cmp(&bn, &bn0) == 0) if (BN_cmp(bn.getc(), bn0.getc()) == 0)
return "0"; return "0";
while (BN_cmp(&bn, &bn0) > 0) while (BN_cmp(bn.getc(), bn0.getc()) > 0)
{ {
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx)) if (!BN_div(dv.get(), rem.get(), bn.getc(), bnBase.getc(), pctx))
throw bignum_error("CBigNum::ToString() : BN_div failed"); throw bignum_error("CBigNum::ToString() : BN_div failed");
bn = dv; bn = dv;
unsigned int c = rem.getulong(); unsigned int c = rem.getulong();
str += "0123456789abcdef"[c]; str += "0123456789abcdef"[c];
} }
if (BN_is_negative(this)) if (BN_is_negative(self))
str += "-"; str += "-";
reverse(str.begin(), str.end()); reverse(str.begin(), str.end());
return str; return str;
@ -424,12 +406,12 @@ public:
bool operator!() const bool operator!() const
{ {
return BN_is_zero(this); return BN_is_zero(self);
} }
CBigNum& operator+=(const CBigNum& b) CBigNum& operator+=(const CBigNum& b)
{ {
if (!BN_add(this, this, &b)) if (!BN_add(self, self, b.getc()))
throw bignum_error("CBigNum::operator+= : BN_add failed"); throw bignum_error("CBigNum::operator+= : BN_add failed");
return *this; return *this;
} }
@ -443,7 +425,7 @@ public:
CBigNum& operator*=(const CBigNum& b) CBigNum& operator*=(const CBigNum& b)
{ {
CAutoBN_CTX pctx; CAutoBN_CTX pctx;
if (!BN_mul(this, this, &b, pctx)) if (!BN_mul(self, self, b.getc(), pctx))
throw bignum_error("CBigNum::operator*= : BN_mul failed"); throw bignum_error("CBigNum::operator*= : BN_mul failed");
return *this; return *this;
} }
@ -462,7 +444,7 @@ public:
CBigNum& operator<<=(unsigned int shift) CBigNum& operator<<=(unsigned int shift)
{ {
if (!BN_lshift(this, this, shift)) if (!BN_lshift(self, self, shift))
throw bignum_error("CBigNum:operator<<= : BN_lshift failed"); throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
return *this; return *this;
} }
@ -473,13 +455,13 @@ public:
// if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL // if built on ubuntu 9.04 or 9.10, probably depends on version of OpenSSL
CBigNum a = 1; CBigNum a = 1;
a <<= shift; a <<= shift;
if (BN_cmp(&a, this) > 0) if (BN_cmp(a.getc(), self) > 0)
{ {
*this = 0; *this = 0;
return *this; return *this;
} }
if (!BN_rshift(this, this, shift)) if (!BN_rshift(self, self, shift))
throw bignum_error("CBigNum:operator>>= : BN_rshift failed"); throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
return *this; return *this;
} }
@ -488,7 +470,7 @@ public:
CBigNum& operator++() CBigNum& operator++()
{ {
// prefix operator // prefix operator
if (!BN_add(this, this, BN_value_one())) if (!BN_add(self, self, BN_value_one()))
throw bignum_error("CBigNum::operator++ : BN_add failed"); throw bignum_error("CBigNum::operator++ : BN_add failed");
return *this; return *this;
} }
@ -505,7 +487,7 @@ public:
{ {
// prefix operator // prefix operator
CBigNum r; CBigNum r;
if (!BN_sub(&r, this, BN_value_one())) if (!BN_sub(r.get(), self, BN_value_one()))
throw bignum_error("CBigNum::operator-- : BN_sub failed"); throw bignum_error("CBigNum::operator-- : BN_sub failed");
*this = r; *this = r;
return *this; return *this;
@ -530,7 +512,7 @@ public:
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b) inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
{ {
CBigNum r; CBigNum r;
if (!BN_add(&r, &a, &b)) if (!BN_add(r.get(), a.getc(), b.getc()))
throw bignum_error("CBigNum::operator+ : BN_add failed"); throw bignum_error("CBigNum::operator+ : BN_add failed");
return r; return r;
} }
@ -538,7 +520,7 @@ inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b) inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
{ {
CBigNum r; CBigNum r;
if (!BN_sub(&r, &a, &b)) if (!BN_sub(r.get(), a.getc(), b.getc()))
throw bignum_error("CBigNum::operator- : BN_sub failed"); throw bignum_error("CBigNum::operator- : BN_sub failed");
return r; return r;
} }
@ -546,7 +528,7 @@ inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator-(const CBigNum& a) inline const CBigNum operator-(const CBigNum& a)
{ {
CBigNum r(a); CBigNum r(a);
BN_set_negative(&r, !BN_is_negative(&r)); BN_set_negative(r.get(), !BN_is_negative(r.getc()));
return r; return r;
} }
@ -554,7 +536,7 @@ inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
{ {
CAutoBN_CTX pctx; CAutoBN_CTX pctx;
CBigNum r; CBigNum r;
if (!BN_mul(&r, &a, &b, pctx)) if (!BN_mul(r.get(), a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator* : BN_mul failed"); throw bignum_error("CBigNum::operator* : BN_mul failed");
return r; return r;
} }
@ -563,7 +545,7 @@ inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
{ {
CAutoBN_CTX pctx; CAutoBN_CTX pctx;
CBigNum r; CBigNum r;
if (!BN_div(&r, NULL, &a, &b, pctx)) if (!BN_div(r.get(), NULL, a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator/ : BN_div failed"); throw bignum_error("CBigNum::operator/ : BN_div failed");
return r; return r;
} }
@ -572,7 +554,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
{ {
CAutoBN_CTX pctx; CAutoBN_CTX pctx;
CBigNum r; CBigNum r;
if (!BN_mod(&r, &a, &b, pctx)) if (!BN_mod(r.get(), a.getc(), b.getc(), pctx))
throw bignum_error("CBigNum::operator% : BN_div failed"); throw bignum_error("CBigNum::operator% : BN_div failed");
return r; return r;
} }
@ -580,7 +562,7 @@ inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift) inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
{ {
CBigNum r; CBigNum r;
if (!BN_lshift(&r, &a, shift)) if (!BN_lshift(r.get(), a.getc(), shift))
throw bignum_error("CBigNum:operator<< : BN_lshift failed"); throw bignum_error("CBigNum:operator<< : BN_lshift failed");
return r; return r;
} }
@ -592,11 +574,11 @@ inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
return r; return r;
} }
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); } inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) == 0); }
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); } inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) != 0); }
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); } inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) <= 0); }
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); } inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); } inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); } inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(a.getc(), b.getc()) > 0); }
#endif #endif

6
ccminer.cpp

@ -3208,6 +3208,8 @@ int main(int argc, char *argv[])
} }
// Prevent windows to sleep while mining // Prevent windows to sleep while mining
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
// Enable windows high precision timer
timeBeginPeriod(1);
#endif #endif
if (opt_affinity != -1) { if (opt_affinity != -1) {
if (!opt_quiet) if (!opt_quiet)
@ -3401,10 +3403,6 @@ int main(int argc, char *argv[])
opt_n_threads, opt_n_threads > 1 ? "s":"", opt_n_threads, opt_n_threads > 1 ? "s":"",
algo_names[opt_algo]); algo_names[opt_algo]);
#ifdef WIN32
timeBeginPeriod(1); // enable high timer precision (similar to Google Chrome Trick)
#endif
/* main loop - simply wait for workio thread to exit */ /* main loop - simply wait for workio thread to exit */
pthread_join(thr_info[work_thr_id].pth, NULL); pthread_join(thr_info[work_thr_id].pth, NULL);

12
ccminer.vcxproj

@ -39,7 +39,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 8.0.props" /> <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@ -155,10 +155,10 @@
<MaxRegCount>80</MaxRegCount> <MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV> <PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep> <Keep>true</Keep>
<!--CodeGeneration>compute_20,sm_21;compute_30,sm_30;compute_35,sm_35</CodeGeneration--> <!--CodeGeneration>compute_30,sm_30;compute_35,sm_35</CodeGeneration-->
<!--CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration--> <!--CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration-->
<!--CodeGeneration>compute_61,sm_61</CodeGeneration--> <!--CodeGeneration>compute_61,sm_61</CodeGeneration-->
<CodeGeneration>compute_20,sm_21;compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61</CodeGeneration> <CodeGeneration>compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61</CodeGeneration>
<AdditionalOptions>--ptxas-options="-O2" --Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>--ptxas-options="-O2" --Wno-deprecated-gpu-targets %(AdditionalOptions)</AdditionalOptions>
<Optimization>O3</Optimization> <Optimization>O3</Optimization>
</CudaCompile> </CudaCompile>
@ -202,10 +202,10 @@
<MaxRegCount>80</MaxRegCount> <MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV> <PtxAsOptionV>true</PtxAsOptionV>
<Keep>true</Keep> <Keep>true</Keep>
<!--CodeGeneration>compute_20,sm_21;compute_30,sm_30;compute_35,sm_35</CodeGeneration--> <!--CodeGeneration>compute_30,sm_30;compute_35,sm_35</CodeGeneration-->
<!--CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration--> <!--CodeGeneration>compute_50,sm_50;compute_52,sm_52</CodeGeneration-->
<!--CodeGeneration>compute_61,sm_61</CodeGeneration--> <!--CodeGeneration>compute_61,sm_61</CodeGeneration-->
<CodeGeneration>compute_20,sm_21;compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61</CodeGeneration> <CodeGeneration>compute_30,sm_30;compute_35,sm_35;compute_50,sm_50;compute_52,sm_52;compute_61,sm_61</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include</Include> <Include>$(NVTOOLSEXT_PATH)\include</Include>
<Optimization>O3</Optimization> <Optimization>O3</Optimization>
<TargetMachinePlatform>64</TargetMachinePlatform> <TargetMachinePlatform>64</TargetMachinePlatform>
@ -300,7 +300,7 @@
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 8.0.targets" /> <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 9.0.targets" />
</ImportGroup> </ImportGroup>
<!-- Copy the required dlls --> <!-- Copy the required dlls -->
<Target Name="AfterBuild"> <Target Name="AfterBuild">

602
compat/bignum_ssl10.hpp

@ -0,0 +1,602 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BIGNUM_H
#define BITCOIN_BIGNUM_H
#ifndef PROTOCOL_VERSION
#define PROTOCOL_VERSION 70001
#endif
#include <map>
#include <limits>
#include <algorithm>
#include <stdexcept>
#include <vector>
#include "uint256.h"
#include <openssl/bn.h>
#include "serialize.hpp"
using namespace std;
/** Errors thrown by the bignum class */
class bignum_error : public std::runtime_error
{
public:
explicit bignum_error(const std::string& str) : std::runtime_error(str) {}
};
/** RAII encapsulated BN_CTX (OpenSSL bignum context) */
class CAutoBN_CTX
{
protected:
BN_CTX* pctx;
BN_CTX* operator=(BN_CTX* pnew) { return pctx = pnew; }
public:
CAutoBN_CTX()
{
pctx = BN_CTX_new();
if (pctx == NULL)
throw bignum_error("CAutoBN_CTX : BN_CTX_new() returned NULL");
}
~CAutoBN_CTX()
{
if (pctx != NULL)
BN_CTX_free(pctx);
}
operator BN_CTX*() { return pctx; }
BN_CTX& operator*() { return *pctx; }
BN_CTX** operator&() { return &pctx; }
bool operator!() { return (pctx == NULL); }
};
/** C++ wrapper for BIGNUM (OpenSSL bignum) */
class CBigNum : public BIGNUM
{
public:
CBigNum()
{
BN_init(this);
}
CBigNum(const CBigNum& b)
{
BN_init(this);
if (!BN_copy(this, &b))
{
BN_clear_free(this);
throw bignum_error("CBigNum::CBigNum(const CBigNum&) : BN_copy failed");
}
}
CBigNum& operator=(const CBigNum& b)
{
if (!BN_copy(this, &b))
throw bignum_error("CBigNum::operator= : BN_copy failed");
return (*this);
}
~CBigNum()
{
BN_clear_free(this);
}
//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(int64 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(uint64 n) { BN_init(this); setuint64(n); }
explicit CBigNum(uint256 n) { BN_init(this); setuint256(n); }
explicit CBigNum(const std::vector<unsigned char>& vch)
{
BN_init(this);
setvch(vch);
}
void setulong(unsigned long n)
{
if (!BN_set_word(this, n))
throw bignum_error("CBigNum conversion from unsigned long : BN_set_word failed");
}
unsigned long getulong() const
{
return (unsigned long) BN_get_word(this);
}
unsigned int getuint() const
{
return (unsigned int) BN_get_word(this);
}
int getint() const
{
unsigned long n = (unsigned long) BN_get_word(this);
if (!BN_is_negative(this))
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : n);
else
return (n > (unsigned long)std::numeric_limits<int>::max() ? std::numeric_limits<int>::min() : -(int)n);
}
void setint64(int64 sn)
{
unsigned char pch[sizeof(sn) + 6];
unsigned char* p = pch + 4;
bool fNegative;
uint64 n;
if (sn < 0LL)
{
// Since the minimum signed integer cannot be represented as positive so long as its type is signed,
// and it's not well-defined what happens if you make it unsigned before negating it,
// we instead increment the negative integer by 1, convert it, then increment the (now positive) unsigned integer by 1 to compensate
n = -(sn + 1);
++n;
fNegative = true;
} else {
n = sn;
fNegative = false;
}
bool fLeadingZeroes = true;
for (int i = 0; i < 8; i++)
{
unsigned char c = (n >> 56) & 0xff;
n <<= 8;
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = (fNegative ? 0x80 : 0);
else if (fNegative)
c |= 0x80;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
void setuint64(uint64 n)
{
unsigned char pch[sizeof(n) + 6];
unsigned char* p = pch + 4;
bool fLeadingZeroes = true;
for (int i = 0; i < 8; i++)
{
unsigned char c = (n >> 56) & 0xff;
n <<= 8;
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = 0;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
void setuint256(uint256 n)
{
unsigned char pch[sizeof(n) + 6];
unsigned char* p = pch + 4;
bool fLeadingZeroes = true;
unsigned char* pbegin = (unsigned char*)&n;
unsigned char* psrc = pbegin + sizeof(n);
while (psrc != pbegin)
{
unsigned char c = *(--psrc);
if (fLeadingZeroes)
{
if (c == 0)
continue;
if (c & 0x80)
*p++ = 0;
fLeadingZeroes = false;
}
*p++ = c;
}
unsigned int nSize = (unsigned int) (p - (pch + 4));
pch[0] = (nSize >> 24) & 0xff;
pch[1] = (nSize >> 16) & 0xff;
pch[2] = (nSize >> 8) & 0xff;
pch[3] = (nSize >> 0) & 0xff;
BN_mpi2bn(pch, (int) (p - pch), this);
}
uint256 getuint256() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
if (nSize < 4)
return 0;
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
if (vch.size() > 4)
vch[4] &= 0x7f;
uint256 n = 0;
for (unsigned int i = 0, j = (unsigned int) vch.size()-1; i < sizeof(n) && j >= 4; i++, j--)
((unsigned char*)&n)[i] = vch[j];
return n;
}
void setvch(const std::vector<unsigned char>& vch)
{
std::vector<unsigned char> vch2(vch.size() + 4);
unsigned int nSize = (unsigned int) vch.size();
// BIGNUM's byte stream format expects 4 bytes of
// big endian size data info at the front
vch2[0] = (nSize >> 24) & 0xff;
vch2[1] = (nSize >> 16) & 0xff;
vch2[2] = (nSize >> 8) & 0xff;
vch2[3] = (nSize >> 0) & 0xff;
// swap data to big endian
reverse_copy(vch.begin(), vch.end(), vch2.begin() + 4);
BN_mpi2bn(&vch2[0], (int) vch2.size(), this);
}
std::vector<unsigned char> getvch() const
{
unsigned int nSize = BN_bn2mpi(this, NULL);
if (nSize <= 4)
return std::vector<unsigned char>();
std::vector<unsigned char> vch(nSize);
BN_bn2mpi(this, &vch[0]);
vch.erase(vch.begin(), vch.begin() + 4);
reverse(vch.begin(), vch.end());
return vch;
}
// The "compact" format is a representation of a whole
// number N using an unsigned 32bit number similar to a
// floating point format.
// The most significant 8 bits are the unsigned exponent of base 256.
// This exponent can be thought of as "number of bytes of N".
// The lower 23 bits are the mantissa.
// Bit number 24 (0x800000) represents the sign of N.
// N = (-1^sign) * mantissa * 256^(exponent-3)
//
// Satoshi's original implementation used BN_bn2mpi() and BN_mpi2bn().
// MPI uses the most significant bit of the first byte as sign.
// Thus 0x1234560000 is compact (0x05123456)
// and 0xc0de000000 is compact (0x0600c0de)
// (0x05c0de00) would be -0x40de000000
//
// Bitcoin only uses this "compact" format for encoding difficulty
// targets, which are unsigned 256bit quantities. Thus, all the
// complexities of the sign bit and using base 256 are probably an
// implementation accident.
//
// This implementation directly uses shifts instead of going
// through an intermediate MPI representation.
CBigNum& SetCompact(unsigned int nCompact)
{
unsigned int nSize = nCompact >> 24;
bool fNegative =(nCompact & 0x00800000) != 0;
unsigned int nWord = nCompact & 0x007fffff;
if (nSize <= 3)
{
nWord >>= 8*(3-nSize);
BN_set_word(this, nWord);
}
else
{
BN_set_word(this, nWord);
BN_lshift(this, this, 8*(nSize-3));
}
BN_set_negative(this, fNegative);
return *this;
}
unsigned int GetCompact() const
{
unsigned int nSize = BN_num_bytes(this);
unsigned int nCompact = 0;
if (nSize <= 3)
nCompact = (unsigned int) BN_get_word(this) << 8*(3-nSize);
else
{
CBigNum bn;
BN_rshift(&bn, this, 8*(nSize-3));
nCompact = (unsigned int) BN_get_word(&bn);
}
// The 0x00800000 bit denotes the sign.
// Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
if (nCompact & 0x00800000)
{
nCompact >>= 8;
nSize++;
}
nCompact |= nSize << 24;
nCompact |= (BN_is_negative(this) ? 0x00800000 : 0);
return nCompact;
}
void SetHex(const std::string& str)
{
// skip 0x
const char* psz = str.c_str();
while (isspace(*psz))
psz++;
bool fNegative = false;
if (*psz == '-')
{
fNegative = true;
psz++;
}
if (psz[0] == '0' && tolower(psz[1]) == 'x')
psz += 2;
while (isspace(*psz))
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;
}
if (fNegative)
*this = 0 - *this;
}
std::string ToString(int nBase=10) const
{
CAutoBN_CTX pctx;
CBigNum bnBase = nBase;
CBigNum bn0 = 0;
std::string str;
CBigNum bn = *this;
BN_set_negative(&bn, false);
CBigNum dv;
CBigNum rem;
if (BN_cmp(&bn, &bn0) == 0)
return "0";
while (BN_cmp(&bn, &bn0) > 0)
{
if (!BN_div(&dv, &rem, &bn, &bnBase, pctx))
throw bignum_error("CBigNum::ToString() : BN_div failed");
bn = dv;
unsigned int c = rem.getulong();
str += "0123456789abcdef"[c];
}
if (BN_is_negative(this))
str += "-";
reverse(str.begin(), str.end());
return str;
}
std::string GetHex() const
{
return ToString(16);
}
unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const
{
return ::GetSerializeSize(getvch(), nType, nVersion);
}
template<typename Stream>
void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const
{
::Serialize(s, getvch(), nType, nVersion);
}
template<typename Stream>
void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION)
{
std::vector<unsigned char> vch;
::Unserialize(s, vch, nType, nVersion);
setvch(vch);
}
bool operator!() const
{
return BN_is_zero(this);
}
CBigNum& operator+=(const CBigNum& b)
{
if (!BN_add(this, this, &b))
throw bignum_error("CBigNum::operator+= : BN_add failed");
return *this;
}
CBigNum& operator-=(const CBigNum& b)
{
*this = *this - b;
return *this;
}
CBigNum& operator*=(const CBigNum& b)
{
CAutoBN_CTX pctx;
if (!BN_mul(this, this, &b, pctx))
throw bignum_error("CBigNum::operator*= : BN_mul failed");
return *this;
}
CBigNum& operator/=(const CBigNum& b)
{
*this = *this / b;
return *this;
}
CBigNum& operator%=(const CBigNum& b)
{
*this = *this % b;
return *this;
}
CBigNum& operator<<=(unsigned int shift)
{
if (!BN_lshift(this, this, shift))
throw bignum_error("CBigNum:operator<<= : BN_lshift failed");
return *this;
}
CBigNum& operator>>=(unsigned int shift)
{
// Note: BN_rshift segfaults on 64-bit if 2^shift is greater than the number
// 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)
{
*this = 0;
return *this;
}
if (!BN_rshift(this, this, shift))
throw bignum_error("CBigNum:operator>>= : BN_rshift failed");
return *this;
}
CBigNum& operator++()
{
// prefix operator
if (!BN_add(this, this, BN_value_one()))
throw bignum_error("CBigNum::operator++ : BN_add failed");
return *this;
}
const CBigNum operator++(int)
{
// postfix operator
const CBigNum ret = *this;
++(*this);
return ret;
}
CBigNum& operator--()
{
// prefix operator
CBigNum r;
if (!BN_sub(&r, this, BN_value_one()))
throw bignum_error("CBigNum::operator-- : BN_sub failed");
*this = r;
return *this;
}
const CBigNum operator--(int)
{
// postfix operator
const CBigNum ret = *this;
--(*this);
return ret;
}
friend inline const CBigNum operator-(const CBigNum& a, const CBigNum& b);
friend inline const CBigNum operator/(const CBigNum& a, const CBigNum& b);
friend inline const CBigNum operator%(const CBigNum& a, const CBigNum& b);
};
inline const CBigNum operator+(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_add(&r, &a, &b))
throw bignum_error("CBigNum::operator+ : BN_add failed");
return r;
}
inline const CBigNum operator-(const CBigNum& a, const CBigNum& b)
{
CBigNum r;
if (!BN_sub(&r, &a, &b))
throw bignum_error("CBigNum::operator- : BN_sub failed");
return r;
}
inline const CBigNum operator-(const CBigNum& a)
{
CBigNum r(a);
BN_set_negative(&r, !BN_is_negative(&r));
return r;
}
inline const CBigNum operator*(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mul(&r, &a, &b, pctx))
throw bignum_error("CBigNum::operator* : BN_mul failed");
return r;
}
inline const CBigNum operator/(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_div(&r, NULL, &a, &b, pctx))
throw bignum_error("CBigNum::operator/ : BN_div failed");
return r;
}
inline const CBigNum operator%(const CBigNum& a, const CBigNum& b)
{
CAutoBN_CTX pctx;
CBigNum r;
if (!BN_mod(&r, &a, &b, pctx))
throw bignum_error("CBigNum::operator% : BN_div failed");
return r;
}
inline const CBigNum operator<<(const CBigNum& a, unsigned int shift)
{
CBigNum r;
if (!BN_lshift(&r, &a, shift))
throw bignum_error("CBigNum:operator<< : BN_lshift failed");
return r;
}
inline const CBigNum operator>>(const CBigNum& a, unsigned int shift)
{
CBigNum r = a;
r >>= shift;
return r;
}
inline bool operator==(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) == 0); }
inline bool operator!=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) != 0); }
inline bool operator<=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) <= 0); }
inline bool operator>=(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) >= 0); }
inline bool operator<(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) < 0); }
inline bool operator>(const CBigNum& a, const CBigNum& b) { return (BN_cmp(&a, &b) > 0); }
#endif

4
compat/ccminer-config.h

@ -161,10 +161,10 @@
#define PACKAGE_NAME "ccminer" #define PACKAGE_NAME "ccminer"
/* Define to the home page for this package. */ /* Define to the home page for this package. */
#define PACKAGE_URL "http://github.com/r4sas/ccminer-gostd-lite" #define PACKAGE_URL "https://github.com/GOSTSec/ccminer-gostd-lite"
/* Define to the version of this package. */ /* Define to the version of this package. */
#define PACKAGE_VERSION "2.2.2-gostd-lite" #define PACKAGE_VERSION "2.2.4-gostd-lite"
/* If using the C implementation of alloca, define if you know the /* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be direction of stack growth for your system; otherwise it will be

4
configure.ac

@ -1,4 +1,4 @@
AC_INIT([ccminer], [2.2.2], [], [ccminer], [http://github.com/tpruvot/ccminer]) AC_INIT([ccminer], [2.2.4-gostd-lite], [], [ccminer], [https://github.com/GOSTSec/ccminer-gostd-lite])
AC_PREREQ([2.59c]) AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM
@ -77,7 +77,7 @@ AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread",
)))) ))))
AC_CHECK_LIB([z],[gzopen], [], []) AC_CHECK_LIB([z],[gzopen], [], [])
AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])]) AC_CHECK_LIB([ssl],[SSL_free], [], [AC_MSG_ERROR([OpenSSL library required])])
AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])]) AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])])
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])

10
cuda_helper.h

@ -669,4 +669,14 @@ static uint2 SHR2(uint2 a, int offset)
#endif #endif
} }
// CUDA 9+ deprecated functions warnings (new mask param)
#if CUDA_VERSION >= 9000 && __CUDA_ARCH__ >= 300
#undef __shfl
#define __shfl(var, srcLane, width) __shfl_sync(0xFFFFFFFFu, var, srcLane, width)
#undef __shfl_up
#define __shfl_up(var, delta, width) __shfl_up_sync(0xFFFFFFFF, var, delta, width)
#undef __any
#define __any(p) __any_sync(0xFFFFFFFFu, p)
#endif
#endif // #ifndef CUDA_HELPER_H #endif // #ifndef CUDA_HELPER_H

10
res/ccminer.rc

@ -60,8 +60,8 @@ IDI_ICON1 ICON "ccminer.ico"
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,2,2,0 FILEVERSION 2,2,4,0
PRODUCTVERSION 2,2,2,0 PRODUCTVERSION 2,2,4,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x21L FILEFLAGS 0x21L
@ -76,10 +76,10 @@ BEGIN
BEGIN BEGIN
BLOCK "040904e4" BLOCK "040904e4"
BEGIN BEGIN
VALUE "FileVersion", "2.2.2" VALUE "FileVersion", "2.2.4"
VALUE "LegalCopyright", "Copyright (C) 2017" VALUE "LegalCopyright", "Copyright (C) 2018"
VALUE "ProductName", "ccminer" VALUE "ProductName", "ccminer"
VALUE "ProductVersion", "2.2.2" VALUE "ProductVersion", "2.2.4"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

Loading…
Cancel
Save