Skip to content

Commit

Permalink
Merge branch 'SChernykh-patch-1' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fireice-uk committed Jul 18, 2017
2 parents 04dd3bc + 752d1b8 commit 4aecd27
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 47 deletions.
4 changes: 4 additions & 0 deletions cli-miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <stdio.h>
#include <string.h>

#include <time.h>

#ifndef CONF_NO_TLS
#include <openssl/ssl.h>
#include <openssl/err.h>
Expand Down Expand Up @@ -74,6 +76,8 @@ int main(int argc, char *argv[])
OpenSSL_add_all_digests();
#endif

srand(time(0));

const char* sFilename = "config.txt";
bool benchmark_mode = false;

Expand Down
10 changes: 10 additions & 0 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ null,
*/
"nicehash_nonce" : false,

/*
* Manual hardware AES override
*
* Some VMs don't report AES capability correctly. You can set this value to true to enforce hardware AES or
* to false to force disable AES or null to let the miner decide if AES is used.
*
* WARNING: setting this to true on a CPU that doesn't support hardware AES will crash the miner.
*/
"aes_override" : null,

/*
* TLS Settings
* If you need real security, make sure tls_secure_algo is enabled (otherwise MITM attack can downgrade encryption
Expand Down
108 changes: 78 additions & 30 deletions crypto/c_keccak.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ const uint64_t keccakf_rndc[24] =
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
};

const int keccakf_rotc[24] =
{
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
};

const int keccakf_piln[24] =
{
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
};

// update the state with given number of rounds

void keccakf(uint64_t st[25], int rounds)
Expand Down Expand Up @@ -63,26 +51,86 @@ void keccakf(uint64_t st[25], int rounds)

// Rho Pi
t = st[1];
for (i = 0; i < 24; ++i) {
bc[0] = st[keccakf_piln[i]];
st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]);
t = bc[0];
}
st[ 1] = ROTL64(st[ 6], 44);
st[ 6] = ROTL64(st[ 9], 20);
st[ 9] = ROTL64(st[22], 61);
st[22] = ROTL64(st[14], 39);
st[14] = ROTL64(st[20], 18);
st[20] = ROTL64(st[ 2], 62);
st[ 2] = ROTL64(st[12], 43);
st[12] = ROTL64(st[13], 25);
st[13] = ROTL64(st[19], 8);
st[19] = ROTL64(st[23], 56);
st[23] = ROTL64(st[15], 41);
st[15] = ROTL64(st[ 4], 27);
st[ 4] = ROTL64(st[24], 14);
st[24] = ROTL64(st[21], 2);
st[21] = ROTL64(st[ 8], 55);
st[ 8] = ROTL64(st[16], 45);
st[16] = ROTL64(st[ 5], 36);
st[ 5] = ROTL64(st[ 3], 28);
st[ 3] = ROTL64(st[18], 21);
st[18] = ROTL64(st[17], 15);
st[17] = ROTL64(st[11], 10);
st[11] = ROTL64(st[ 7], 6);
st[ 7] = ROTL64(st[10], 3);
st[10] = ROTL64(t, 1);

// Chi
for (j = 0; j < 25; j += 5) {
bc[0] = st[j ];
bc[1] = st[j + 1];
bc[2] = st[j + 2];
bc[3] = st[j + 3];
bc[4] = st[j + 4];
st[j ] ^= (~bc[1]) & bc[2];
st[j + 1] ^= (~bc[2]) & bc[3];
st[j + 2] ^= (~bc[3]) & bc[4];
st[j + 3] ^= (~bc[4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];
}

// unrolled loop, where only last iteration is different
j = 0;
bc[0] = st[j ];
bc[1] = st[j + 1];

st[j ] ^= (~st[j + 1]) & st[j + 2];
st[j + 1] ^= (~st[j + 2]) & st[j + 3];
st[j + 2] ^= (~st[j + 3]) & st[j + 4];
st[j + 3] ^= (~st[j + 4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];

j = 5;
bc[0] = st[j ];
bc[1] = st[j + 1];

st[j ] ^= (~st[j + 1]) & st[j + 2];
st[j + 1] ^= (~st[j + 2]) & st[j + 3];
st[j + 2] ^= (~st[j + 3]) & st[j + 4];
st[j + 3] ^= (~st[j + 4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];

j = 10;
bc[0] = st[j ];
bc[1] = st[j + 1];

st[j ] ^= (~st[j + 1]) & st[j + 2];
st[j + 1] ^= (~st[j + 2]) & st[j + 3];
st[j + 2] ^= (~st[j + 3]) & st[j + 4];
st[j + 3] ^= (~st[j + 4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];

j = 15;
bc[0] = st[j ];
bc[1] = st[j + 1];

st[j ] ^= (~st[j + 1]) & st[j + 2];
st[j + 1] ^= (~st[j + 2]) & st[j + 3];
st[j + 2] ^= (~st[j + 3]) & st[j + 4];
st[j + 3] ^= (~st[j + 4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];

j = 20;
bc[0] = st[j ];
bc[1] = st[j + 1];
bc[2] = st[j + 2];
bc[3] = st[j + 3];
bc[4] = st[j + 4];

st[j ] ^= (~bc[1]) & bc[2];
st[j + 1] ^= (~bc[2]) & bc[3];
st[j + 2] ^= (~bc[3]) & bc[4];
st[j + 3] ^= (~bc[4]) & bc[0];
st[j + 4] ^= (~bc[0]) & bc[1];

// Iota
st[0] ^= keccakf_rndc[round];
}
Expand Down
16 changes: 10 additions & 6 deletions jconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using namespace rapidjson;
/*
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
*/
enum configEnum { aCpuThreadsConf, sUseSlowMem, bNiceHashMode,
enum configEnum { aCpuThreadsConf, sUseSlowMem, bNiceHashMode, bAesOverride,
bTlsMode, bTlsSecureAlgo, sTlsFingerprint, sPoolAddr, sWalletAddr, sPoolPwd,
iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime,
bDaemonMode, sOutputFile, iHttpdPort, bPreferIpv4 };
Expand All @@ -62,6 +62,7 @@ configVal oConfigValues[] = {
{ aCpuThreadsConf, "cpu_threads_conf", kNullType },
{ sUseSlowMem, "use_slow_memory", kStringType },
{ bNiceHashMode, "nicehash_nonce", kTrueType },
{ bAesOverride, "aes_override", kNullType },
{ bTlsMode, "use_tls", kTrueType },
{ bTlsSecureAlgo, "tls_secure_algo", kTrueType },
{ sTlsFingerprint, "tls_fingerprint", kStringType },
Expand Down Expand Up @@ -453,11 +454,14 @@ bool jconf::parse_config(const char* sFilename)

printer::inst()->set_verbose_level(prv->configValues[iVerboseLevel]->GetUint64());

if(!NeedsAutoconf())
{
if(!bHaveAes)
printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates.");
}
if(NeedsAutoconf())
return true;

if(prv->configValues[bAesOverride]->IsBool())
bHaveAes = prv->configValues[bAesOverride]->GetBool();

if(!bHaveAes)
printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates.");

return true;
}
23 changes: 12 additions & 11 deletions socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,34 @@ bool plain_socket::set_hostname(const char* sAddr)
return pCallback->set_socket_error_strerr("CONNECT error: GetAddrInfo: ", err);

addrinfo *ptr = pAddrRoot;
addrinfo *ipv4 = nullptr, *ipv6 = nullptr;
std::vector<addrinfo*> ipv4;
std::vector<addrinfo*> ipv6;

while (ptr != nullptr)
{
if (ptr->ai_family == AF_INET)
ipv4 = ptr;
ipv4.push_back(ptr);
if (ptr->ai_family == AF_INET6)
ipv6 = ptr;
ipv6.push_back(ptr);
ptr = ptr->ai_next;
}

if (ipv4 == nullptr && ipv6 == nullptr)
if (ipv4.empty() && ipv6.empty())
{
freeaddrinfo(pAddrRoot);
pAddrRoot = nullptr;
return pCallback->set_socket_error("CONNECT error: I found some DNS records but no IPv4 or IPv6 addresses.");
}
else if (ipv4 != nullptr && ipv6 == nullptr)
pSockAddr = ipv4;
else if (ipv4 == nullptr && ipv6 != nullptr)
pSockAddr = ipv6;
else if (ipv4 != nullptr && ipv6 != nullptr)
else if (!ipv4.empty() && ipv6.empty())
pSockAddr = ipv4[rand() % ipv4.size()];
else if (ipv4.empty() && !ipv6.empty())
pSockAddr = ipv6[rand() % ipv6.size()];
else if (!ipv4.empty() && !ipv6.empty())
{
if(jconf::inst()->PreferIpv4())
pSockAddr = ipv4;
pSockAddr = ipv4[rand() % ipv4.size()];
else
pSockAddr = ipv6;
pSockAddr = ipv6[rand() % ipv6.size()];
}

hSocket = socket(pSockAddr->ai_family, pSockAddr->ai_socktype, pSockAddr->ai_protocol);
Expand Down

0 comments on commit 4aecd27

Please sign in to comment.