Skip to content

Fastcpu on unix #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fastcpu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*~
11 changes: 11 additions & 0 deletions fastcpu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all: bitmsghash.so

bitmsghash.so: bitmsghash.o
g++ -shared -L/usr/lib -lssl -lcrypto -o bitmsghash.so bitmsghash.o

bitmsghash.o:
g++ -fpic -c bitmsghash.cpp

clean:
rm *.o *.so

18 changes: 13 additions & 5 deletions fastcpu/bitmsghash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
#define HASH_SIZE 64
#define BUFLEN 16384

#if defined(__GNUC__)
#define EXPORT __attribute__ ((__visibility__("default")))
#define UINT intptr_t
#elif defined(WIN32)
#define EXPORT __declspec(dllexport)
#define UINT unsigned int
#endif

#define ntohll(x) ( ( (uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) | ntohl( ((unsigned int)(x >> 32)) ) )

unsigned long long max_val;
Expand All @@ -30,7 +38,7 @@ DWORD WINAPI threadfunc(LPVOID lpParameter) {
DWORD incamt = (DWORD)lpParameter;
#else
void * threadfunc(void* param) {
unsigned int incamt = (unsigned int)param;
UINT incamt = (UINT)param;
#endif
SHA512_CTX sha;
unsigned char buf[HASH_SIZE+sizeof(uint64_t)] = {0};
Expand Down Expand Up @@ -59,17 +67,17 @@ void * threadfunc(void* param) {
return NULL;
}

extern "C" __declspec(dllexport) unsigned long long BitmessagePOW(unsigned char * starthash, unsigned long long target)
extern "C" EXPORT unsigned long long BitmessagePOW(unsigned char * starthash, unsigned long long target)
{
successval = 0;
max_val = target;
initialHash = (unsigned char *) starthash;
# ifdef WIN32
HANDLE* threads = (HANDLE*)calloc(sizeof(HANDLE), numthreads);
# else
pthread_t* threads = calloc(sizeof(pthread_t), numthreads);
pthread_t* threads = (pthread_t*)calloc(sizeof(pthread_t), numthreads);
# endif
for (int i = 0; i < numthreads; i++) {
for (UINT i = 0; i < numthreads; i++) {
# ifdef WIN32
threads[i] = CreateThread(NULL, 0, threadfunc, (LPVOID)i, 0, NULL);
# else
Expand All @@ -85,4 +93,4 @@ extern "C" __declspec(dllexport) unsigned long long BitmessagePOW(unsigned char
# endif
free(threads);
return successval;
}
}
2 changes: 1 addition & 1 deletion fastcpu/proofofwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import ctypes

bitmsglib = 'BitMsgHash.so'
bitmsglib = './bitmsghash.so'
if "win32" == sys.platform:
bitmsglib = 'BitMsgHash.dll'
bso = ctypes.CDLL(bitmsglib)
Expand Down