diff --git a/fastcpu/.gitignore b/fastcpu/.gitignore new file mode 100644 index 0000000..ce68fe8 --- /dev/null +++ b/fastcpu/.gitignore @@ -0,0 +1,3 @@ +*.o +*.so +*~ diff --git a/fastcpu/Makefile b/fastcpu/Makefile new file mode 100644 index 0000000..e8a2db1 --- /dev/null +++ b/fastcpu/Makefile @@ -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 + diff --git a/fastcpu/bitmsghash.cpp b/fastcpu/bitmsghash.cpp index b2eb40f..ede2c9d 100644 --- a/fastcpu/bitmsghash.cpp +++ b/fastcpu/bitmsghash.cpp @@ -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; @@ -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}; @@ -59,7 +67,7 @@ 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; @@ -67,9 +75,9 @@ extern "C" __declspec(dllexport) unsigned long long BitmessagePOW(unsigned char # 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 @@ -85,4 +93,4 @@ extern "C" __declspec(dllexport) unsigned long long BitmessagePOW(unsigned char # endif free(threads); return successval; -} \ No newline at end of file +} diff --git a/fastcpu/proofofwork.py b/fastcpu/proofofwork.py index 717c374..9bab66c 100644 --- a/fastcpu/proofofwork.py +++ b/fastcpu/proofofwork.py @@ -8,7 +8,7 @@ import ctypes -bitmsglib = 'BitMsgHash.so' +bitmsglib = './bitmsghash.so' if "win32" == sys.platform: bitmsglib = 'BitMsgHash.dll' bso = ctypes.CDLL(bitmsglib)