Deleted old module
This commit is contained in:
parent
c22c5c2208
commit
a398354700
20
checkdeps.py
20
checkdeps.py
|
@ -88,25 +88,7 @@ def testCompiler():
|
||||||
# silent, we can't test without setuptools
|
# silent, we can't test without setuptools
|
||||||
return True
|
return True
|
||||||
|
|
||||||
bitmsghash = Extension(
|
return True
|
||||||
'bitmsghash',
|
|
||||||
sources=['src/bitmsghash/bitmsghash.cpp'],
|
|
||||||
libraries=['pthread', 'crypto'],
|
|
||||||
)
|
|
||||||
|
|
||||||
dist = Distribution()
|
|
||||||
dist.ext_modules = [bitmsghash]
|
|
||||||
cmd = build_ext(dist)
|
|
||||||
cmd.initialize_options()
|
|
||||||
cmd.finalize_options()
|
|
||||||
cmd.force = True
|
|
||||||
try:
|
|
||||||
cmd.run()
|
|
||||||
except CompileError:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
fullPath = os.path.join(cmd.build_lib, cmd.get_ext_filename("bitmsghash"))
|
|
||||||
return os.path.isfile(fullPath)
|
|
||||||
|
|
||||||
|
|
||||||
prereqs = detectPrereqs()
|
prereqs = detectPrereqs()
|
||||||
|
|
|
@ -52,8 +52,6 @@ else:
|
||||||
arch=64
|
arch=64
|
||||||
|
|
||||||
a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'),
|
a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'),
|
||||||
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'),
|
|
||||||
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
|
|
||||||
("workprover/fastsolver/libfastsolver-{}.dll".format(arch), os.path.join(srcPath, "workprover/fastsolver/libfastsolver-{}.dll".format(arch)), "BINARY"),
|
("workprover/fastsolver/libfastsolver-{}.dll".format(arch), os.path.join(srcPath, "workprover/fastsolver/libfastsolver-{}.dll".format(arch)), "BINARY"),
|
||||||
("workprover/gpusolver.cl", os.path.join(srcPath, "workprover/gpusolver.cl"), "BINARY"),
|
("workprover/gpusolver.cl", os.path.join(srcPath, "workprover/gpusolver.cl"), "BINARY"),
|
||||||
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
|
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
|
||||||
|
|
9
setup.py
9
setup.py
|
@ -50,12 +50,6 @@ if __name__ == "__main__":
|
||||||
with open(os.path.join(here, 'README.md')) as f:
|
with open(os.path.join(here, 'README.md')) as f:
|
||||||
README = f.read()
|
README = f.read()
|
||||||
|
|
||||||
bitmsghash = Extension(
|
|
||||||
'pybitmessage.bitmsghash.bitmsghash',
|
|
||||||
sources=['src/bitmsghash/bitmsghash.cpp'],
|
|
||||||
libraries=['pthread', 'crypto'],
|
|
||||||
)
|
|
||||||
|
|
||||||
installRequires = []
|
installRequires = []
|
||||||
packages = [
|
packages = [
|
||||||
'pybitmessage',
|
'pybitmessage',
|
||||||
|
@ -110,7 +104,7 @@ if __name__ == "__main__":
|
||||||
packages=packages,
|
packages=packages,
|
||||||
package_data={'': [
|
package_data={'': [
|
||||||
'bitmessageqt/*.ui', 'translations/*.ts', 'translations/*.qm',
|
'bitmessageqt/*.ui', 'translations/*.ts', 'translations/*.qm',
|
||||||
'bitmsghash/*.cl', 'workprover/*.cl', 'workprover/fastsolver/*',
|
'workprover/*.cl', 'workprover/fastsolver/*',
|
||||||
'sslkeys/*.pem',
|
'sslkeys/*.pem',
|
||||||
'images/*.png', 'images/*.ico', 'images/*.icns'
|
'images/*.png', 'images/*.ico', 'images/*.icns'
|
||||||
]},
|
]},
|
||||||
|
@ -122,7 +116,6 @@ if __name__ == "__main__":
|
||||||
('share/icons/hicolor/24x24/apps/',
|
('share/icons/hicolor/24x24/apps/',
|
||||||
['desktop/icons/24x24/pybitmessage.png'])
|
['desktop/icons/24x24/pybitmessage.png'])
|
||||||
],
|
],
|
||||||
ext_modules=[bitmsghash],
|
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
entry_points={
|
entry_points={
|
||||||
'bitmessage.gui.menu': [
|
'bitmessage.gui.menu': [
|
||||||
|
|
|
@ -44,9 +44,6 @@ from debug import logger
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
|
||||||
# Helper Functions
|
|
||||||
import proofofwork
|
|
||||||
|
|
||||||
str_chan = '[chan]'
|
str_chan = '[chan]'
|
||||||
|
|
||||||
queuedRawObjects = {}
|
queuedRawObjects = {}
|
||||||
|
|
|
@ -36,7 +36,6 @@ from helper_ackPayload import genAckPayload
|
||||||
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
|
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
|
||||||
import helper_search
|
import helper_search
|
||||||
import l10n
|
import l10n
|
||||||
import openclpow
|
|
||||||
from utils import str_broadcast_subscribers, avatarize
|
from utils import str_broadcast_subscribers, avatarize
|
||||||
from account import (
|
from account import (
|
||||||
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
|
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
|
||||||
|
@ -46,7 +45,6 @@ from network.stats import pendingDownload, pendingUpload
|
||||||
from uisignaler import UISignaler
|
from uisignaler import UISignaler
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import paths
|
import paths
|
||||||
from proofofwork import getPowType
|
|
||||||
import queues
|
import queues
|
||||||
import shutdown
|
import shutdown
|
||||||
import state
|
import state
|
||||||
|
@ -2888,7 +2886,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
waitForSync = False
|
waitForSync = False
|
||||||
|
|
||||||
# C PoW currently doesn't support interrupting and OpenCL is untested
|
# C PoW currently doesn't support interrupting and OpenCL is untested
|
||||||
if getPowType() == "python" and (self.POWTasksCount > 0 or pendingUpload() > 0):
|
if self.POWTasksCount > 0 or pendingUpload() > 0:
|
||||||
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Proof of work pending"),
|
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Proof of work pending"),
|
||||||
_translate("MainWindow", "%n object(s) pending proof of work", None, QtCore.QCoreApplication.CodecForTr, self.POWTasksCount) + ", " +
|
_translate("MainWindow", "%n object(s) pending proof of work", None, QtCore.QCoreApplication.CodecForTr, self.POWTasksCount) + ", " +
|
||||||
_translate("MainWindow", "%n object(s) waiting to be distributed", None, QtCore.QCoreApplication.CodecForTr, pendingUpload()) + "\n\n" +
|
_translate("MainWindow", "%n object(s) waiting to be distributed", None, QtCore.QCoreApplication.CodecForTr, pendingUpload()) + "\n\n" +
|
||||||
|
|
|
@ -11,14 +11,13 @@ import defaults
|
||||||
from foldertree import AccountMixin
|
from foldertree import AccountMixin
|
||||||
from helper_sql import *
|
from helper_sql import *
|
||||||
from l10n import getTranslationLanguage
|
from l10n import getTranslationLanguage
|
||||||
from openclpow import openclAvailable, openclEnabled
|
|
||||||
import paths
|
import paths
|
||||||
import proofofwork
|
|
||||||
from pyelliptic.openssl import OpenSSL
|
from pyelliptic.openssl import OpenSSL
|
||||||
import queues
|
import queues
|
||||||
import network.stats
|
import network.stats
|
||||||
import state
|
import state
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
import singleworker
|
||||||
|
|
||||||
# this is BM support address going to Peter Surda
|
# this is BM support address going to Peter Surda
|
||||||
OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK'
|
OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK'
|
||||||
|
@ -113,10 +112,10 @@ def createSupportMessage(myapp):
|
||||||
if paths.frozen:
|
if paths.frozen:
|
||||||
frozen = paths.frozen
|
frozen = paths.frozen
|
||||||
portablemode = "True" if state.appdata == paths.lookupExeFolder() else "False"
|
portablemode = "True" if state.appdata == paths.lookupExeFolder() else "False"
|
||||||
cpow = "True" if proofofwork.bmpow else "False"
|
cpow = "True" if "fast" in singleworker.workProver.availableSolvers else "False"
|
||||||
openclpow = str(
|
openclpow = str(
|
||||||
BMConfigParser().safeGet('bitmessagesettings', 'opencl')
|
BMConfigParser().safeGet('bitmessagesettings', 'opencl')
|
||||||
) if openclEnabled() else "None"
|
) if BMConfigParser().safeGetBoolean("bitmessagesettings", "powsolver") == "gpu" else "None"
|
||||||
locale = getTranslationLanguage()
|
locale = getTranslationLanguage()
|
||||||
socks = BMConfigParser().safeGet(
|
socks = BMConfigParser().safeGet(
|
||||||
'bitmessagesettings', 'socksproxytype', "N/A")
|
'bitmessagesettings', 'socksproxytype', "N/A")
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
UNAME_S := $(shell uname -s)
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
|
||||||
CCFLAGS += -I/usr/local/Cellar/openssl/1.0.2d_1/include
|
|
||||||
LDFLAGS += -L/usr/local/Cellar/openssl/1.0.2d_1/lib
|
|
||||||
else ifeq ($(UNAME_S),MINGW32_NT-6.1)
|
|
||||||
CCFLAGS += -IC:\OpenSSL-1.0.2j-mingw\include -D_WIN32 -march=native
|
|
||||||
LDFLAGS += -static-libgcc -LC:\OpenSSL-1.0.2j-mingw\lib -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
|
|
||||||
else
|
|
||||||
LDFLAGS += -lpthread -o bitmsghash.so
|
|
||||||
endif
|
|
||||||
|
|
||||||
all: bitmsghash.so
|
|
||||||
|
|
||||||
powtest:
|
|
||||||
./testpow.py
|
|
||||||
|
|
||||||
bitmsghash.so: bitmsghash.o
|
|
||||||
${CXX} bitmsghash.o -shared -fPIC -lcrypto $(LDFLAGS)
|
|
||||||
|
|
||||||
bitmsghash.o:
|
|
||||||
${CXX} -Wall -O3 -march=native -fPIC $(CCFLAGS) -c bitmsghash.cpp
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f bitmsghash.o bitmsghash.so bitmsghash*.dll
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
all: bitmsghash.so
|
|
||||||
|
|
||||||
powtest:
|
|
||||||
./testpow.py
|
|
||||||
|
|
||||||
bitmsghash.so: bitmsghash.o
|
|
||||||
${CXX} bitmsghash.o -shared -fPIC -lpthread -lcrypto $(LDFLAGS) -o bitmsghash.so
|
|
||||||
|
|
||||||
bitmsghash.o:
|
|
||||||
${CXX} -Wall -O3 -march=native -fPIC $(CCFLAGS) -c bitmsghash.cpp
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f bitmsghash.o bitmsghash.so
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
all:
|
|
||||||
cl /I C:\OpenSSL-1.0.2j\include /INCREMENTAL bitmsghash.cpp /MT /link /DLL /OUT:bitmsghash32.dll /LIBPATH:C:\OpenSSL-1.0.2j\lib\ libeay32.lib ws2_32.lib
|
|
|
@ -1,276 +0,0 @@
|
||||||
/*
|
|
||||||
* This is based on the John The Ripper SHA512 code, modified for double SHA512 and for use as a miner in Bitmessage.
|
|
||||||
* This software is originally Copyright (c) 2012 Myrice <qqlddg at gmail dot com>
|
|
||||||
* and it is hereby released to the general public under the following terms:
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are permitted.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef cl_khr_byte_addressable_store
|
|
||||||
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : disable
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define uint8_t unsigned char
|
|
||||||
#define uint32_t unsigned int
|
|
||||||
#define uint64_t unsigned long
|
|
||||||
#define SALT_SIZE 0
|
|
||||||
|
|
||||||
#define BINARY_SIZE 8
|
|
||||||
#define FULL_BINARY_SIZE 64
|
|
||||||
|
|
||||||
|
|
||||||
#define PLAINTEXT_LENGTH 72
|
|
||||||
|
|
||||||
#define CIPHERTEXT_LENGTH 128
|
|
||||||
|
|
||||||
|
|
||||||
/// Warning: This version of SWAP64(n) is slow and avoid bugs on AMD GPUs(7970)
|
|
||||||
// #define SWAP64(n) as_ulong(as_uchar8(n).s76543210)
|
|
||||||
|
|
||||||
#define SWAP64(n) \
|
|
||||||
(((n) << 56) \
|
|
||||||
| (((n) & 0xff00) << 40) \
|
|
||||||
| (((n) & 0xff0000) << 24) \
|
|
||||||
| (((n) & 0xff000000) << 8) \
|
|
||||||
| (((n) >> 8) & 0xff000000) \
|
|
||||||
| (((n) >> 24) & 0xff0000) \
|
|
||||||
| (((n) >> 40) & 0xff00) \
|
|
||||||
| ((n) >> 56))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define rol(x,n) ((x << n) | (x >> (64-n)))
|
|
||||||
#define ror(x,n) ((x >> n) | (x << (64-n)))
|
|
||||||
#define Ch(x,y,z) ((x & y) ^ ( (~x) & z))
|
|
||||||
#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
|
|
||||||
#define Sigma0(x) ((ror(x,28)) ^ (ror(x,34)) ^ (ror(x,39)))
|
|
||||||
#define Sigma1(x) ((ror(x,14)) ^ (ror(x,18)) ^ (ror(x,41)))
|
|
||||||
#define sigma0(x) ((ror(x,1)) ^ (ror(x,8)) ^(x>>7))
|
|
||||||
#define sigma1(x) ((ror(x,19)) ^ (ror(x,61)) ^(x>>6))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct { // notice memory align problem
|
|
||||||
uint64_t H[8];
|
|
||||||
uint32_t buffer[32]; //1024 bits
|
|
||||||
uint32_t buflen;
|
|
||||||
} sha512_ctx;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint64_t target;
|
|
||||||
char v[PLAINTEXT_LENGTH+1];
|
|
||||||
} sha512_key;
|
|
||||||
|
|
||||||
|
|
||||||
/* Macros for reading/writing chars from int32's */
|
|
||||||
#define PUTCHAR(buf, index, val) (buf)[(index)>>2] = ((buf)[(index)>>2] & ~(0xffU << (((index) & 3) << 3))) + ((val) << (((index) & 3) << 3))
|
|
||||||
|
|
||||||
|
|
||||||
__constant uint64_t k[] = {
|
|
||||||
0x428a2f98d728ae22UL, 0x7137449123ef65cdUL, 0xb5c0fbcfec4d3b2fUL,
|
|
||||||
0xe9b5dba58189dbbcUL,
|
|
||||||
0x3956c25bf348b538UL, 0x59f111f1b605d019UL, 0x923f82a4af194f9bUL,
|
|
||||||
0xab1c5ed5da6d8118UL,
|
|
||||||
0xd807aa98a3030242UL, 0x12835b0145706fbeUL, 0x243185be4ee4b28cUL,
|
|
||||||
0x550c7dc3d5ffb4e2UL,
|
|
||||||
0x72be5d74f27b896fUL, 0x80deb1fe3b1696b1UL, 0x9bdc06a725c71235UL,
|
|
||||||
0xc19bf174cf692694UL,
|
|
||||||
0xe49b69c19ef14ad2UL, 0xefbe4786384f25e3UL, 0x0fc19dc68b8cd5b5UL,
|
|
||||||
0x240ca1cc77ac9c65UL,
|
|
||||||
0x2de92c6f592b0275UL, 0x4a7484aa6ea6e483UL, 0x5cb0a9dcbd41fbd4UL,
|
|
||||||
0x76f988da831153b5UL,
|
|
||||||
0x983e5152ee66dfabUL, 0xa831c66d2db43210UL, 0xb00327c898fb213fUL,
|
|
||||||
0xbf597fc7beef0ee4UL,
|
|
||||||
0xc6e00bf33da88fc2UL, 0xd5a79147930aa725UL, 0x06ca6351e003826fUL,
|
|
||||||
0x142929670a0e6e70UL,
|
|
||||||
0x27b70a8546d22ffcUL, 0x2e1b21385c26c926UL, 0x4d2c6dfc5ac42aedUL,
|
|
||||||
0x53380d139d95b3dfUL,
|
|
||||||
0x650a73548baf63deUL, 0x766a0abb3c77b2a8UL, 0x81c2c92e47edaee6UL,
|
|
||||||
0x92722c851482353bUL,
|
|
||||||
0xa2bfe8a14cf10364UL, 0xa81a664bbc423001UL, 0xc24b8b70d0f89791UL,
|
|
||||||
0xc76c51a30654be30UL,
|
|
||||||
0xd192e819d6ef5218UL, 0xd69906245565a910UL, 0xf40e35855771202aUL,
|
|
||||||
0x106aa07032bbd1b8UL,
|
|
||||||
0x19a4c116b8d2d0c8UL, 0x1e376c085141ab53UL, 0x2748774cdf8eeb99UL,
|
|
||||||
0x34b0bcb5e19b48a8UL,
|
|
||||||
0x391c0cb3c5c95a63UL, 0x4ed8aa4ae3418acbUL, 0x5b9cca4f7763e373UL,
|
|
||||||
0x682e6ff3d6b2b8a3UL,
|
|
||||||
0x748f82ee5defb2fcUL, 0x78a5636f43172f60UL, 0x84c87814a1f0ab72UL,
|
|
||||||
0x8cc702081a6439ecUL,
|
|
||||||
0x90befffa23631e28UL, 0xa4506cebde82bde9UL, 0xbef9a3f7b2c67915UL,
|
|
||||||
0xc67178f2e372532bUL,
|
|
||||||
0xca273eceea26619cUL, 0xd186b8c721c0c207UL, 0xeada7dd6cde0eb1eUL,
|
|
||||||
0xf57d4f7fee6ed178UL,
|
|
||||||
0x06f067aa72176fbaUL, 0x0a637dc5a2c898a6UL, 0x113f9804bef90daeUL,
|
|
||||||
0x1b710b35131c471bUL,
|
|
||||||
0x28db77f523047d84UL, 0x32caab7b40c72493UL, 0x3c9ebe0a15c9bebcUL,
|
|
||||||
0x431d67c49c100d4cUL,
|
|
||||||
0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL, 0x5fcb6fab3ad6faecUL,
|
|
||||||
0x6c44198c4a475817UL,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void setup_ctx(sha512_ctx* ctx, const char * password, uint8_t pass_len)
|
|
||||||
{
|
|
||||||
uint32_t* b32 = ctx->buffer;
|
|
||||||
|
|
||||||
//set password to buffer
|
|
||||||
for (uint32_t i = 0; i < pass_len; i++) {
|
|
||||||
PUTCHAR(b32,i,password[i]);
|
|
||||||
}
|
|
||||||
ctx->buflen = pass_len;
|
|
||||||
|
|
||||||
//append 1 to ctx buffer
|
|
||||||
uint32_t length = ctx->buflen;
|
|
||||||
PUTCHAR(b32, length, 0x80);
|
|
||||||
while((++length & 3) != 0) {
|
|
||||||
PUTCHAR(b32, length, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t* buffer32 = b32+(length>>2);
|
|
||||||
for(uint32_t i = length; i < 128; i+=4) {// append 0 to 128
|
|
||||||
*buffer32++=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//append length to buffer
|
|
||||||
uint64_t *buffer64 = (uint64_t *)ctx->buffer;
|
|
||||||
buffer64[15] = SWAP64(((uint64_t) ctx->buflen) * 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint64_t sha512(char* password)
|
|
||||||
{
|
|
||||||
__private sha512_ctx ctx;
|
|
||||||
setup_ctx(&ctx, password, 72);
|
|
||||||
// sha512 main`
|
|
||||||
int i;
|
|
||||||
|
|
||||||
uint64_t a = 0x6a09e667f3bcc908UL;
|
|
||||||
uint64_t b = 0xbb67ae8584caa73bUL;
|
|
||||||
uint64_t c = 0x3c6ef372fe94f82bUL;
|
|
||||||
uint64_t d = 0xa54ff53a5f1d36f1UL;
|
|
||||||
uint64_t e = 0x510e527fade682d1UL;
|
|
||||||
uint64_t f = 0x9b05688c2b3e6c1fUL;
|
|
||||||
uint64_t g = 0x1f83d9abfb41bd6bUL;
|
|
||||||
uint64_t h = 0x5be0cd19137e2179UL;
|
|
||||||
|
|
||||||
__private uint64_t w[16];
|
|
||||||
|
|
||||||
uint64_t *data = (uint64_t *) ctx.buffer;
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
w[i] = SWAP64(data[i]);
|
|
||||||
|
|
||||||
uint64_t t1, t2;
|
|
||||||
for (i = 0; i < 16; i++) {
|
|
||||||
t1 = k[i] + w[i] + h + Sigma1(e) + Ch(e, f, g);
|
|
||||||
t2 = Maj(a, b, c) + Sigma0(a);
|
|
||||||
|
|
||||||
h = g;
|
|
||||||
g = f;
|
|
||||||
f = e;
|
|
||||||
e = d + t1;
|
|
||||||
d = c;
|
|
||||||
c = b;
|
|
||||||
b = a;
|
|
||||||
a = t1 + t2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 16; i < 80; i++) {
|
|
||||||
|
|
||||||
w[i & 15] =sigma1(w[(i - 2) & 15]) + sigma0(w[(i - 15) & 15]) + w[(i -16) & 15] + w[(i - 7) & 15];
|
|
||||||
t1 = k[i] + w[i & 15] + h + Sigma1(e) + Ch(e, f, g);
|
|
||||||
t2 = Maj(a, b, c) + Sigma0(a);
|
|
||||||
|
|
||||||
h = g;
|
|
||||||
g = f;
|
|
||||||
f = e;
|
|
||||||
e = d + t1;
|
|
||||||
d = c;
|
|
||||||
c = b;
|
|
||||||
b = a;
|
|
||||||
a = t1 + t2;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t finalhash[8];
|
|
||||||
|
|
||||||
finalhash[0] = SWAP64(a + 0x6a09e667f3bcc908UL);
|
|
||||||
finalhash[1] = SWAP64(b + 0xbb67ae8584caa73bUL);
|
|
||||||
finalhash[2] = SWAP64(c + 0x3c6ef372fe94f82bUL);
|
|
||||||
finalhash[3] = SWAP64(d + 0xa54ff53a5f1d36f1UL);
|
|
||||||
finalhash[4] = SWAP64(e + 0x510e527fade682d1UL);
|
|
||||||
finalhash[5] = SWAP64(f + 0x9b05688c2b3e6c1fUL);
|
|
||||||
finalhash[6] = SWAP64(g + 0x1f83d9abfb41bd6bUL);
|
|
||||||
finalhash[7] = SWAP64(h + 0x5be0cd19137e2179UL);
|
|
||||||
|
|
||||||
setup_ctx(&ctx, (char*) finalhash, 64);
|
|
||||||
|
|
||||||
a = 0x6a09e667f3bcc908UL;
|
|
||||||
b = 0xbb67ae8584caa73bUL;
|
|
||||||
c = 0x3c6ef372fe94f82bUL;
|
|
||||||
d = 0xa54ff53a5f1d36f1UL;
|
|
||||||
e = 0x510e527fade682d1UL;
|
|
||||||
f = 0x9b05688c2b3e6c1fUL;
|
|
||||||
g = 0x1f83d9abfb41bd6bUL;
|
|
||||||
h = 0x5be0cd19137e2179UL;
|
|
||||||
|
|
||||||
data = (uint64_t *) ctx.buffer;
|
|
||||||
//((uint64_t*)ctx.buffer)[8] = SWAP64((uint64_t)0x80);
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
w[i] = SWAP64(data[i]);
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++) {
|
|
||||||
t1 = k[i] + w[i] + h + Sigma1(e) + Ch(e, f, g);
|
|
||||||
t2 = Maj(a, b, c) + Sigma0(a);
|
|
||||||
|
|
||||||
h = g;
|
|
||||||
g = f;
|
|
||||||
f = e;
|
|
||||||
e = d + t1;
|
|
||||||
d = c;
|
|
||||||
c = b;
|
|
||||||
b = a;
|
|
||||||
a = t1 + t2;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 16; i < 80; i++) {
|
|
||||||
|
|
||||||
w[i & 15] =sigma1(w[(i - 2) & 15]) + sigma0(w[(i - 15) & 15]) + w[(i -16) & 15] + w[(i - 7) & 15];
|
|
||||||
t1 = k[i] + w[i & 15] + h + Sigma1(e) + Ch(e, f, g);
|
|
||||||
t2 = Maj(a, b, c) + Sigma0(a);
|
|
||||||
|
|
||||||
h = g;
|
|
||||||
g = f;
|
|
||||||
f = e;
|
|
||||||
e = d + t1;
|
|
||||||
d = c;
|
|
||||||
c = b;
|
|
||||||
b = a;
|
|
||||||
a = t1 + t2;
|
|
||||||
}
|
|
||||||
return SWAP64(a + 0x6a09e667f3bcc908UL);
|
|
||||||
}
|
|
||||||
|
|
||||||
__kernel void kernel_sha512(__global const sha512_key *password,__global uint64_t *hash, uint64_t start)
|
|
||||||
{
|
|
||||||
uint64_t idx = get_global_id(0);
|
|
||||||
if (idx == 0 && start == 0) {
|
|
||||||
*hash = 0;
|
|
||||||
}
|
|
||||||
uint64_t winval;
|
|
||||||
|
|
||||||
uint64_t junk[9];
|
|
||||||
|
|
||||||
__global uint64_t * source = (__global uint64_t*) password->v;
|
|
||||||
for (int i = 1; i < 9; i++) {
|
|
||||||
junk[i] = source[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
junk[0] = SWAP64(idx + (start));
|
|
||||||
|
|
||||||
winval = sha512((char*)junk);
|
|
||||||
if (SWAP64(winval) < password->target) {
|
|
||||||
*hash = SWAP64(junk[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,165 +0,0 @@
|
||||||
// bitmessage cracker, build with g++ or MSVS to a shared library, use included python code for usage under bitmessage
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include "Winsock.h"
|
|
||||||
#include "Windows.h"
|
|
||||||
#define uint64_t unsigned __int64
|
|
||||||
#else
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#endif
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined (__DragonFly__) || defined (__OpenBSD__) || defined (__NetBSD__)
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "openssl/sha.h"
|
|
||||||
|
|
||||||
#define HASH_SIZE 64
|
|
||||||
#define BUFLEN 16384
|
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
|
||||||
#define EXPORT __attribute__ ((__visibility__("default")))
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
#define EXPORT __declspec(dllexport)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
|
||||||
#define ntohll(x) ( ( (uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) | ntohl( ((unsigned int)(x >> 32)) ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned long long max_val;
|
|
||||||
unsigned char *initialHash;
|
|
||||||
unsigned long long successval = 0;
|
|
||||||
unsigned int numthreads = 0;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
DWORD WINAPI threadfunc(LPVOID param) {
|
|
||||||
#else
|
|
||||||
void * threadfunc(void* param) {
|
|
||||||
#endif
|
|
||||||
unsigned int incamt = *((unsigned int*)param);
|
|
||||||
SHA512_CTX sha;
|
|
||||||
unsigned char buf[HASH_SIZE + sizeof(uint64_t)] = { 0 };
|
|
||||||
unsigned char output[HASH_SIZE] = { 0 };
|
|
||||||
|
|
||||||
memcpy(buf + sizeof(uint64_t), initialHash, HASH_SIZE);
|
|
||||||
|
|
||||||
unsigned long long tmpnonce = incamt;
|
|
||||||
unsigned long long * nonce = (unsigned long long *)buf;
|
|
||||||
unsigned long long * hash = (unsigned long long *)output;
|
|
||||||
while (successval == 0) {
|
|
||||||
tmpnonce += numthreads;
|
|
||||||
|
|
||||||
(*nonce) = ntohll(tmpnonce); /* increment nonce */
|
|
||||||
SHA512_Init(&sha);
|
|
||||||
SHA512_Update(&sha, buf, HASH_SIZE + sizeof(uint64_t));
|
|
||||||
SHA512_Final(output, &sha);
|
|
||||||
SHA512_Init(&sha);
|
|
||||||
SHA512_Update(&sha, output, HASH_SIZE);
|
|
||||||
SHA512_Final(output, &sha);
|
|
||||||
|
|
||||||
if (ntohll(*hash) < max_val) {
|
|
||||||
successval = tmpnonce;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef _WIN32
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void getnumthreads()
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
DWORD_PTR dwProcessAffinity, dwSystemAffinity;
|
|
||||||
#elif __linux__
|
|
||||||
cpu_set_t dwProcessAffinity;
|
|
||||||
#elif __OpenBSD__
|
|
||||||
int mib[2], core_count = 0;
|
|
||||||
int dwProcessAffinity = 0;
|
|
||||||
size_t len2;
|
|
||||||
#else
|
|
||||||
int dwProcessAffinity = 0;
|
|
||||||
int32_t core_count = 0;
|
|
||||||
#endif
|
|
||||||
size_t len = sizeof(dwProcessAffinity);
|
|
||||||
if (numthreads > 0)
|
|
||||||
return;
|
|
||||||
#ifdef _WIN32
|
|
||||||
GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinity, &dwSystemAffinity);
|
|
||||||
#elif __linux__
|
|
||||||
sched_getaffinity(0, len, &dwProcessAffinity);
|
|
||||||
#elif __OpenBSD__
|
|
||||||
len2 = sizeof(core_count);
|
|
||||||
mib[0] = CTL_HW;
|
|
||||||
mib[1] = HW_NCPU;
|
|
||||||
if (sysctl(mib, 2, &core_count, &len2, 0, 0) == 0)
|
|
||||||
numthreads = core_count;
|
|
||||||
#else
|
|
||||||
if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0) == 0)
|
|
||||||
numthreads = core_count;
|
|
||||||
else if (sysctlbyname("hw.ncpu", &core_count, &len, 0, 0) == 0)
|
|
||||||
numthreads = core_count;
|
|
||||||
#endif
|
|
||||||
for (unsigned int i = 0; i < len * 8; i++)
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
if (dwProcessAffinity & (1i64 << i))
|
|
||||||
#else // CYGWIN/MINGW
|
|
||||||
if (dwProcessAffinity & (1ULL << i))
|
|
||||||
#endif
|
|
||||||
#elif defined __linux__
|
|
||||||
if (CPU_ISSET(i, &dwProcessAffinity))
|
|
||||||
#else
|
|
||||||
if (dwProcessAffinity & (1 << i))
|
|
||||||
#endif
|
|
||||||
numthreads++;
|
|
||||||
if (numthreads == 0) // something failed
|
|
||||||
numthreads = 1;
|
|
||||||
printf("Number of threads: %i\n", (int)numthreads);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, unsigned long long target)
|
|
||||||
{
|
|
||||||
successval = 0;
|
|
||||||
max_val = target;
|
|
||||||
getnumthreads();
|
|
||||||
initialHash = (unsigned char *)starthash;
|
|
||||||
# ifdef _WIN32
|
|
||||||
HANDLE* threads = (HANDLE*)calloc(sizeof(HANDLE), numthreads);
|
|
||||||
# else
|
|
||||||
pthread_t* threads = (pthread_t*)calloc(sizeof(pthread_t), numthreads);
|
|
||||||
struct sched_param schparam;
|
|
||||||
schparam.sched_priority = 0;
|
|
||||||
# endif
|
|
||||||
unsigned int *threaddata = (unsigned int *)calloc(sizeof(unsigned int), numthreads);
|
|
||||||
for (unsigned int i = 0; i < numthreads; i++) {
|
|
||||||
threaddata[i] = i;
|
|
||||||
# ifdef _WIN32
|
|
||||||
threads[i] = CreateThread(NULL, 0, threadfunc, (LPVOID)&threaddata[i], 0, NULL);
|
|
||||||
SetThreadPriority(threads[i], THREAD_PRIORITY_IDLE);
|
|
||||||
# else
|
|
||||||
pthread_create(&threads[i], NULL, threadfunc, (void*)&threaddata[i]);
|
|
||||||
# ifdef __linux__
|
|
||||||
pthread_setschedparam(threads[i], SCHED_IDLE, &schparam);
|
|
||||||
# else
|
|
||||||
pthread_setschedparam(threads[i], SCHED_RR, &schparam);
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
# ifdef _WIN32
|
|
||||||
WaitForMultipleObjects(numthreads, threads, TRUE, INFINITE);
|
|
||||||
# else
|
|
||||||
for (unsigned int i = 0; i < numthreads; i++) {
|
|
||||||
pthread_join(threads[i], NULL);
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
free(threads);
|
|
||||||
free(threaddata);
|
|
||||||
return successval;
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ mainscript = ["bitmessagemain.py"]
|
||||||
|
|
||||||
DATA_FILES = [
|
DATA_FILES = [
|
||||||
('', ['sslkeys', 'images']),
|
('', ['sslkeys', 'images']),
|
||||||
('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']),
|
|
||||||
("workprover", ["gpusolver.cl"]),
|
("workprover", ["gpusolver.cl"]),
|
||||||
("workprover/fastsolver", ["libfastsolver.so"]),
|
("workprover/fastsolver", ["libfastsolver.so"]),
|
||||||
('translations', glob('translations/*.qm')),
|
('translations', glob('translations/*.qm')),
|
||||||
|
|
112
src/openclpow.py
112
src/openclpow.py
|
@ -1,112 +0,0 @@
|
||||||
#!/usr/bin/env python2.7
|
|
||||||
from struct import pack, unpack
|
|
||||||
import time
|
|
||||||
import hashlib
|
|
||||||
import random
|
|
||||||
import os
|
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
|
||||||
import paths
|
|
||||||
from state import shutdown
|
|
||||||
from debug import logger
|
|
||||||
|
|
||||||
libAvailable = True
|
|
||||||
ctx = False
|
|
||||||
queue = False
|
|
||||||
program = False
|
|
||||||
gpus = []
|
|
||||||
enabledGpus = []
|
|
||||||
vendors = []
|
|
||||||
hash_dt = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
import pyopencl as cl
|
|
||||||
import numpy
|
|
||||||
except ImportError:
|
|
||||||
libAvailable = False
|
|
||||||
|
|
||||||
|
|
||||||
def initCL():
|
|
||||||
global ctx, queue, program, hash_dt, libAvailable
|
|
||||||
if libAvailable is False:
|
|
||||||
return
|
|
||||||
del enabledGpus[:]
|
|
||||||
del vendors[:]
|
|
||||||
del gpus[:]
|
|
||||||
ctx = False
|
|
||||||
try:
|
|
||||||
hash_dt = numpy.dtype([('target', numpy.uint64), ('v', numpy.str_, 73)])
|
|
||||||
try:
|
|
||||||
for platform in cl.get_platforms():
|
|
||||||
gpus.extend(platform.get_devices(device_type=cl.device_type.GPU))
|
|
||||||
if BMConfigParser().safeGet("bitmessagesettings", "opencl") == platform.vendor:
|
|
||||||
enabledGpus.extend(platform.get_devices(device_type=cl.device_type.GPU))
|
|
||||||
if platform.vendor not in vendors:
|
|
||||||
vendors.append(platform.vendor)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
if (len(enabledGpus) > 0):
|
|
||||||
ctx = cl.Context(devices=enabledGpus)
|
|
||||||
queue = cl.CommandQueue(ctx)
|
|
||||||
f = open(os.path.join(paths.codePath(), "bitmsghash", 'bitmsghash.cl'), 'r')
|
|
||||||
fstr = ''.join(f.readlines())
|
|
||||||
program = cl.Program(ctx, fstr).build(options="")
|
|
||||||
logger.info("Loaded OpenCL kernel")
|
|
||||||
else:
|
|
||||||
logger.info("No OpenCL GPUs found")
|
|
||||||
del enabledGpus[:]
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("OpenCL fail: ", exc_info=True)
|
|
||||||
del enabledGpus[:]
|
|
||||||
|
|
||||||
def openclAvailable():
|
|
||||||
return (len(gpus) > 0)
|
|
||||||
|
|
||||||
def openclEnabled():
|
|
||||||
return (len(enabledGpus) > 0)
|
|
||||||
|
|
||||||
def do_opencl_pow(hash, target):
|
|
||||||
output = numpy.zeros(1, dtype=[('v', numpy.uint64, 1)])
|
|
||||||
if (len(enabledGpus) == 0):
|
|
||||||
return output[0][0]
|
|
||||||
|
|
||||||
data = numpy.zeros(1, dtype=hash_dt, order='C')
|
|
||||||
data[0]['v'] = ("0000000000000000" + hash).decode("hex")
|
|
||||||
data[0]['target'] = target
|
|
||||||
|
|
||||||
hash_buf = cl.Buffer(ctx, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=data)
|
|
||||||
dest_buf = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, output.nbytes)
|
|
||||||
|
|
||||||
kernel = program.kernel_sha512
|
|
||||||
worksize = kernel.get_work_group_info(cl.kernel_work_group_info.WORK_GROUP_SIZE, enabledGpus[0])
|
|
||||||
|
|
||||||
kernel.set_arg(0, hash_buf)
|
|
||||||
kernel.set_arg(1, dest_buf)
|
|
||||||
|
|
||||||
start = time.time()
|
|
||||||
progress = 0
|
|
||||||
globamt = worksize*2000
|
|
||||||
|
|
||||||
while output[0][0] == 0 and shutdown == 0:
|
|
||||||
kernel.set_arg(2, pack("<Q", progress))
|
|
||||||
cl.enqueue_nd_range_kernel(queue, kernel, (globamt,), (worksize,))
|
|
||||||
cl.enqueue_read_buffer(queue, dest_buf, output)
|
|
||||||
queue.finish()
|
|
||||||
progress += globamt
|
|
||||||
sofar = time.time() - start
|
|
||||||
# logger.debug("Working for %.3fs, %.2f Mh/s", sofar, (progress / sofar) / 1000000)
|
|
||||||
if shutdown != 0:
|
|
||||||
raise Exception ("Interrupted")
|
|
||||||
taken = time.time() - start
|
|
||||||
# logger.debug("Took %d tries.", progress)
|
|
||||||
return output[0][0]
|
|
||||||
|
|
||||||
#initCL()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
target = 54227212183L
|
|
||||||
initialHash = "3758f55b5a8d902fd3597e4ce6a2d3f23daff735f65d9698c270987f4e67ad590b93f3ffeba0ef2fd08a8dc2f87b68ae5a0dc819ab57f22ad2c4c9c8618a43b3".decode("hex")
|
|
||||||
nonce = do_opencl_pow(initialHash.encode("hex"), target)
|
|
||||||
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
|
|
||||||
print "{} - value {} < {}".format(nonce, trialValue, target)
|
|
||||||
|
|
|
@ -1,295 +0,0 @@
|
||||||
#import shared
|
|
||||||
#import time
|
|
||||||
#from multiprocessing import Pool, cpu_count
|
|
||||||
import hashlib
|
|
||||||
from struct import unpack, pack
|
|
||||||
from subprocess import call
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from bmconfigparser import BMConfigParser
|
|
||||||
from debug import logger
|
|
||||||
import paths
|
|
||||||
import openclpow
|
|
||||||
import queues
|
|
||||||
import tr
|
|
||||||
import os
|
|
||||||
import ctypes
|
|
||||||
|
|
||||||
import state
|
|
||||||
|
|
||||||
bitmsglib = 'bitmsghash.so'
|
|
||||||
|
|
||||||
bmpow = None
|
|
||||||
|
|
||||||
def _set_idle():
|
|
||||||
if 'linux' in sys.platform:
|
|
||||||
os.nice(20)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
sys.getwindowsversion()
|
|
||||||
import win32api,win32process,win32con # @UnresolvedImport
|
|
||||||
pid = win32api.GetCurrentProcessId()
|
|
||||||
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
|
|
||||||
win32process.SetPriorityClass(handle, win32process.IDLE_PRIORITY_CLASS)
|
|
||||||
except:
|
|
||||||
#Windows 64-bit
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _pool_worker(nonce, initialHash, target, pool_size):
|
|
||||||
_set_idle()
|
|
||||||
trialValue = float('inf')
|
|
||||||
while trialValue > target:
|
|
||||||
nonce += pool_size
|
|
||||||
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
|
|
||||||
return [trialValue, nonce]
|
|
||||||
|
|
||||||
def _doSafePoW(target, initialHash):
|
|
||||||
logger.debug("Safe PoW start")
|
|
||||||
nonce = 0
|
|
||||||
trialValue = float('inf')
|
|
||||||
while trialValue > target and state.shutdown == 0:
|
|
||||||
nonce += 1
|
|
||||||
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
|
|
||||||
if state.shutdown != 0:
|
|
||||||
raise StopIteration("Interrupted")
|
|
||||||
logger.debug("Safe PoW done")
|
|
||||||
return [trialValue, nonce]
|
|
||||||
|
|
||||||
def _doFastPoW(target, initialHash):
|
|
||||||
logger.debug("Fast PoW start")
|
|
||||||
from multiprocessing import Pool, cpu_count
|
|
||||||
try:
|
|
||||||
pool_size = cpu_count()
|
|
||||||
except:
|
|
||||||
pool_size = 4
|
|
||||||
try:
|
|
||||||
maxCores = BMConfigParser().getint('bitmessagesettings', 'maxcores')
|
|
||||||
except:
|
|
||||||
maxCores = 99999
|
|
||||||
if pool_size > maxCores:
|
|
||||||
pool_size = maxCores
|
|
||||||
|
|
||||||
pool = Pool(processes=pool_size)
|
|
||||||
result = []
|
|
||||||
for i in range(pool_size):
|
|
||||||
result.append(pool.apply_async(_pool_worker, args=(i, initialHash, target, pool_size)))
|
|
||||||
|
|
||||||
while True:
|
|
||||||
if state.shutdown > 0:
|
|
||||||
try:
|
|
||||||
pool.terminate()
|
|
||||||
pool.join()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
raise StopIteration("Interrupted")
|
|
||||||
for i in range(pool_size):
|
|
||||||
if result[i].ready():
|
|
||||||
try:
|
|
||||||
result[i].successful()
|
|
||||||
except AssertionError:
|
|
||||||
pool.terminate()
|
|
||||||
pool.join()
|
|
||||||
raise StopIteration("Interrupted")
|
|
||||||
result = result[i].get()
|
|
||||||
pool.terminate()
|
|
||||||
pool.join()
|
|
||||||
logger.debug("Fast PoW done")
|
|
||||||
return result[0], result[1]
|
|
||||||
time.sleep(0.2)
|
|
||||||
|
|
||||||
def _doCPoW(target, initialHash):
|
|
||||||
h = initialHash
|
|
||||||
m = target
|
|
||||||
out_h = ctypes.pointer(ctypes.create_string_buffer(h, 64))
|
|
||||||
out_m = ctypes.c_ulonglong(m)
|
|
||||||
logger.debug("C PoW start")
|
|
||||||
nonce = bmpow(out_h, out_m)
|
|
||||||
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
|
|
||||||
if state.shutdown != 0:
|
|
||||||
raise StopIteration("Interrupted")
|
|
||||||
logger.debug("C PoW done")
|
|
||||||
return [trialValue, nonce]
|
|
||||||
|
|
||||||
def _doGPUPoW(target, initialHash):
|
|
||||||
logger.debug("GPU PoW start")
|
|
||||||
nonce = openclpow.do_opencl_pow(initialHash.encode("hex"), target)
|
|
||||||
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
|
|
||||||
#print "{} - value {} < {}".format(nonce, trialValue, target)
|
|
||||||
if trialValue > target:
|
|
||||||
deviceNames = ", ".join(gpu.name for gpu in openclpow.enabledGpus)
|
|
||||||
queues.UISignalQueue.put(('updateStatusBar', (tr._translate("MainWindow",'Your GPU(s) did not calculate correctly, disabling OpenCL. Please report to the developers.'), 1)))
|
|
||||||
logger.error("Your GPUs (%s) did not calculate correctly, disabling OpenCL. Please report to the developers.", deviceNames)
|
|
||||||
openclpow.enabledGpus = []
|
|
||||||
raise Exception("GPU did not calculate correctly.")
|
|
||||||
if state.shutdown != 0:
|
|
||||||
raise StopIteration("Interrupted")
|
|
||||||
logger.debug("GPU PoW done")
|
|
||||||
return [trialValue, nonce]
|
|
||||||
|
|
||||||
def estimate(difficulty, format = False):
|
|
||||||
ret = difficulty / 10
|
|
||||||
if ret < 1:
|
|
||||||
ret = 1
|
|
||||||
if format:
|
|
||||||
out = str(int(ret)) + " seconds"
|
|
||||||
if ret > 60:
|
|
||||||
ret /= 60
|
|
||||||
out = str(int(ret)) + " minutes"
|
|
||||||
if ret > 60:
|
|
||||||
ret /= 60
|
|
||||||
out = str(int(ret)) + " hours"
|
|
||||||
if ret > 24:
|
|
||||||
ret /= 24
|
|
||||||
out = str(int(ret)) + " days"
|
|
||||||
if ret > 7:
|
|
||||||
out = str(int(ret)) + " weeks"
|
|
||||||
if ret > 31:
|
|
||||||
out = str(int(ret)) + " months"
|
|
||||||
if ret > 366:
|
|
||||||
ret /= 366
|
|
||||||
out = str(int(ret)) + " years"
|
|
||||||
else:
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def getPowType():
|
|
||||||
if openclpow.openclEnabled():
|
|
||||||
return "OpenCL"
|
|
||||||
if bmpow:
|
|
||||||
return "C"
|
|
||||||
return "python"
|
|
||||||
|
|
||||||
def notifyBuild(tried=False):
|
|
||||||
if bmpow:
|
|
||||||
queues.UISignalQueue.put(('updateStatusBar', (tr._translate("proofofwork", "C PoW module built successfully."), 1)))
|
|
||||||
elif tried:
|
|
||||||
queues.UISignalQueue.put(('updateStatusBar', (tr._translate("proofofwork", "Failed to build C PoW module. Please build it manually."), 1)))
|
|
||||||
else:
|
|
||||||
queues.UISignalQueue.put(('updateStatusBar', (tr._translate("proofofwork", "C PoW module unavailable. Please build it."), 1)))
|
|
||||||
|
|
||||||
def buildCPoW():
|
|
||||||
if bmpow is not None:
|
|
||||||
return
|
|
||||||
if paths.frozen is not None:
|
|
||||||
notifyBuild(False)
|
|
||||||
return
|
|
||||||
if sys.platform in ["win32", "win64"]:
|
|
||||||
notifyBuild(False)
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
if "bsd" in sys.platform:
|
|
||||||
# BSD make
|
|
||||||
call(["make", "-C", os.path.join(paths.codePath(), "bitmsghash"), '-f', 'Makefile.bsd'])
|
|
||||||
else:
|
|
||||||
# GNU make
|
|
||||||
call(["make", "-C", os.path.join(paths.codePath(), "bitmsghash")])
|
|
||||||
if os.path.exists(os.path.join(paths.codePath(), "bitmsghash", "bitmsghash.so")):
|
|
||||||
init()
|
|
||||||
notifyBuild(True)
|
|
||||||
else:
|
|
||||||
notifyBuild(True)
|
|
||||||
except:
|
|
||||||
notifyBuild(True)
|
|
||||||
|
|
||||||
def run(target, initialHash):
|
|
||||||
if state.shutdown != 0:
|
|
||||||
raise
|
|
||||||
target = int(target)
|
|
||||||
if openclpow.openclEnabled():
|
|
||||||
# trialvalue1, nonce1 = _doGPUPoW(target, initialHash)
|
|
||||||
# trialvalue, nonce = _doFastPoW(target, initialHash)
|
|
||||||
# print "GPU: %s, %s" % (trialvalue1, nonce1)
|
|
||||||
# print "Fast: %s, %s" % (trialvalue, nonce)
|
|
||||||
# return [trialvalue, nonce]
|
|
||||||
try:
|
|
||||||
return _doGPUPoW(target, initialHash)
|
|
||||||
except StopIteration:
|
|
||||||
raise
|
|
||||||
except:
|
|
||||||
pass # fallback
|
|
||||||
if bmpow:
|
|
||||||
try:
|
|
||||||
return _doCPoW(target, initialHash)
|
|
||||||
except StopIteration:
|
|
||||||
raise
|
|
||||||
except:
|
|
||||||
pass # fallback
|
|
||||||
if paths.frozen == "macosx_app" or not paths.frozen:
|
|
||||||
# on my (Peter Surda) Windows 10, Windows Defender
|
|
||||||
# does not like this and fights with PyBitmessage
|
|
||||||
# over CPU, resulting in very slow PoW
|
|
||||||
# added on 2015-11-29: multiprocesing.freeze_support() doesn't help
|
|
||||||
try:
|
|
||||||
return _doFastPoW(target, initialHash)
|
|
||||||
except StopIteration:
|
|
||||||
logger.error("Fast PoW got StopIteration")
|
|
||||||
raise
|
|
||||||
except:
|
|
||||||
logger.error("Fast PoW got exception:", exc_info=True)
|
|
||||||
pass #fallback
|
|
||||||
try:
|
|
||||||
return _doSafePoW(target, initialHash)
|
|
||||||
except StopIteration:
|
|
||||||
raise
|
|
||||||
except:
|
|
||||||
pass #fallback
|
|
||||||
|
|
||||||
def resetPoW():
|
|
||||||
openclpow.initCL()
|
|
||||||
|
|
||||||
# init
|
|
||||||
def init():
|
|
||||||
global bitmsglib, bso, bmpow
|
|
||||||
|
|
||||||
openclpow.initCL()
|
|
||||||
|
|
||||||
if "win32" == sys.platform:
|
|
||||||
if ctypes.sizeof(ctypes.c_voidp) == 4:
|
|
||||||
bitmsglib = 'bitmsghash32.dll'
|
|
||||||
else:
|
|
||||||
bitmsglib = 'bitmsghash64.dll'
|
|
||||||
try:
|
|
||||||
# MSVS
|
|
||||||
bso = ctypes.WinDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
|
||||||
logger.info("Loaded C PoW DLL (stdcall) %s", bitmsglib)
|
|
||||||
bmpow = bso.BitmessagePOW
|
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
|
||||||
_doCPoW(2**63, "")
|
|
||||||
logger.info("Successfully tested C PoW DLL (stdcall) %s", bitmsglib)
|
|
||||||
except:
|
|
||||||
logger.error("C PoW test fail.", exc_info=True)
|
|
||||||
try:
|
|
||||||
# MinGW
|
|
||||||
bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
|
||||||
logger.info("Loaded C PoW DLL (cdecl) %s", bitmsglib)
|
|
||||||
bmpow = bso.BitmessagePOW
|
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
|
||||||
_doCPoW(2**63, "")
|
|
||||||
logger.info("Successfully tested C PoW DLL (cdecl) %s", bitmsglib)
|
|
||||||
except:
|
|
||||||
logger.error("C PoW test fail.", exc_info=True)
|
|
||||||
bso = None
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
bso = ctypes.CDLL(os.path.join(paths.codePath(), "bitmsghash", bitmsglib))
|
|
||||||
except OSError:
|
|
||||||
import glob
|
|
||||||
try:
|
|
||||||
bso = ctypes.CDLL(glob.glob(os.path.join(
|
|
||||||
paths.codePath(), "bitmsghash", "bitmsghash*.so"
|
|
||||||
))[0])
|
|
||||||
except (OSError, IndexError):
|
|
||||||
bso = None
|
|
||||||
except:
|
|
||||||
bso = None
|
|
||||||
else:
|
|
||||||
logger.info("Loaded C PoW DLL %s", bitmsglib)
|
|
||||||
if bso:
|
|
||||||
try:
|
|
||||||
bmpow = bso.BitmessagePOW
|
|
||||||
bmpow.restype = ctypes.c_ulonglong
|
|
||||||
except:
|
|
||||||
bmpow = None
|
|
||||||
else:
|
|
||||||
bmpow = None
|
|
||||||
if bmpow is None:
|
|
||||||
buildCPoW()
|
|
Loading…
Reference in New Issue
Block a user