├── Algo256 ├── blake256_14round.cu ├── blake256_8round.cu ├── cuda_blake256_14round.cu ├── cuda_blake2s.cu ├── cuda_bmw256.cu ├── cuda_cubehash256.cu ├── cuda_groestl256.cu ├── cuda_keccak256.cu ├── cuda_skein256.cu ├── decred.cu └── keccak256.cu ├── LICENSE.txt ├── Makefile.am ├── README.md ├── README.txt ├── algos.h ├── api.cpp ├── api ├── index.php ├── local-sample.php └── websocket.htm ├── autogen.sh ├── bench.cpp ├── bignum.cpp ├── bignum.hpp ├── build.cmd ├── build.sh ├── ccminer.conf ├── ccminer.cpp ├── ccminer.sln ├── ccminer.vcxproj ├── ccminer.vcxproj.filters ├── compat.h ├── compat ├── Makefile.am ├── curl-for-windows │ ├── curl │ │ └── include │ │ │ └── curl │ │ │ ├── curl.h │ │ │ ├── curlbuild.h │ │ │ ├── curlrules.h │ │ │ ├── curlver.h │ │ │ ├── easy.h │ │ │ ├── mprintf.h │ │ │ ├── multi.h │ │ │ ├── stdcheaders.h │ │ │ └── typecheck-gcc.h │ ├── openssl │ │ ├── config │ │ │ └── opensslconf.h │ │ └── openssl │ │ │ ├── crypto │ │ │ ├── opensslconf.h │ │ │ └── sha │ │ │ │ └── sha.h │ │ │ ├── e_os2.h │ │ │ └── include │ │ │ └── openssl │ │ │ ├── bn.h │ │ │ ├── crypto.h │ │ │ ├── e_os2.h │ │ │ ├── opensslconf.h │ │ │ ├── opensslv.h │ │ │ ├── ossl_typ.h │ │ │ ├── safestack.h │ │ │ ├── sha.h │ │ │ ├── stack.h │ │ │ └── symhacks.h │ └── zlib │ │ ├── zconf.h │ │ └── zlib.h ├── getopt │ ├── getopt.h │ └── getopt_long.c ├── gettimeofday.c ├── inttypes.h ├── jansson │ ├── .gitignore │ ├── Makefile.am │ ├── configure.ac │ ├── dump.c │ ├── error.c │ ├── hashtable.c │ ├── hashtable.h │ ├── jansson.h │ ├── jansson_config.h │ ├── jansson_config.h.in │ ├── jansson_private.h │ ├── jansson_private_config.h │ ├── jansson_private_config.h.in │ ├── load.c │ ├── memory.c │ ├── pack_unpack.c │ ├── strbuffer.c │ ├── strbuffer.h │ ├── strconv.c │ ├── utf.c │ ├── utf.h │ ├── util.h │ └── value.c ├── nvapi │ ├── NVAPI.url │ ├── amd64 │ │ └── nvapi64.lib │ ├── nvHLSLExtns.h │ ├── nvHLSLExtnsInternal.h │ ├── nvShaderExtnEnums.h │ ├── nvapi.h │ ├── nvapi_ccminer.h │ ├── nvapi_lite_common.h │ ├── nvapi_lite_d3dext.h │ ├── nvapi_lite_salend.h │ ├── nvapi_lite_salstart.h │ ├── nvapi_lite_sli.h │ ├── nvapi_lite_stereo.h │ ├── nvapi_lite_surround.h │ └── x86 │ │ └── nvapi.lib ├── pthreads │ ├── pthread.h │ ├── sched.h │ ├── x64 │ │ └── pthreadVC2.lib │ └── x86 │ │ ├── pthreadVC2.lib │ │ └── pthreadVC2.libkernel32.lib ├── stdbool.h ├── sys │ └── time.h ├── unistd.h ├── winansi.c └── winansi.h ├── configure.ac ├── configure.sh ├── cpuminer-config.h ├── cpuminer-config.h.in ├── crc32.c ├── cuda.cpp ├── cuda_checkhash.cu ├── cuda_debug.cuh ├── cuda_helper.h ├── cuda_myriadgroestl.cu ├── cuda_myriadgroestl.cu~ ├── cuda_vectors.h ├── elist.h ├── hashlog.cpp ├── lbry ├── cuda_lbry_merged.cu ├── cuda_sha256_lbry.cu ├── cuda_sha512_lbry.cu └── lbry.cu ├── lyra2 ├── Lyra2.c ├── Lyra2.h ├── Sponge.c ├── Sponge.h ├── cuda_lyra2.cu ├── cuda_lyra2_sm5.cuh ├── cuda_lyra2v2.cu ├── lyra2RE.cu └── lyra2REv2.cu ├── miner.h ├── myriadgroestl.cu ├── neoscrypt ├── cuda_neoscrypt.cu ├── neoscrypt-cpu.c ├── neoscrypt.cu └── neoscrypt.h ├── nist5 └── cuda_nist5.cu ├── nvapi.cpp ├── nvml.cpp ├── nvml.h ├── pools.conf ├── pools.cpp ├── quark ├── .cuda_bmw512.cu.swp ├── cuda_bmw512.cu ├── cuda_keccak_skein512.cu ├── cuda_quark.h ├── cuda_quark_blake512.cu ├── cuda_quark_compactionTest.cu ├── cuda_quark_groestl512.cu ├── cuda_quark_jh512.cu ├── cuda_quark_keccak512.cu ├── cuda_quark_skein512.cu ├── cuda_quark_skein512.cu~ ├── groestl_functions_quad.h ├── groestl_transf_quad.h └── quarkcoin.cu ├── qubit ├── qubit.cu ├── qubit_luffa512.cu └── qubit_luffa512.cu~ ├── res ├── ccminer.ico ├── ccminer.rc └── resource.h ├── serialize.hpp ├── sia.cu ├── skein ├── skein.cu ├── skein2.cu └── skein_header.h ├── sph ├── aes_helper.c ├── blake.c ├── blake2b.c ├── blake2b.h ├── blake2s.c ├── blake2s.h ├── bmw.c ├── cubehash.c ├── echo.c ├── fugue.c ├── groestl.c ├── hamsi.c ├── hamsi_helper.c ├── haval.c ├── haval_helper.c ├── jh.c ├── keccak.c ├── luffa.c ├── md_helper.c ├── ripemd.c ├── sha2.c ├── sha256_Y.c ├── sha256_Y.h ├── sha2big.c ├── shabal.c ├── shavite.c ├── simd.c ├── skein.c ├── sph_blake.h ├── sph_bmw.h ├── sph_cubehash.h ├── sph_echo.h ├── sph_fugue.h ├── sph_groestl.h ├── sph_hamsi.h ├── sph_haval.h ├── sph_jh.h ├── sph_keccak.h ├── sph_luffa.h ├── sph_ripemd.h ├── sph_sha2.c ├── sph_sha2.h ├── sph_shabal.h ├── sph_shavite.h ├── sph_simd.h ├── sph_skein.h ├── sph_streebog.h ├── sph_types.h ├── sph_whirlpool.h ├── streebog.c ├── sysendian.h ├── whirlpool.c ├── yescrypt-opt.c ├── yescrypt-simd.c ├── yescrypt.h └── yescryptcommon.c ├── start.sh ├── stats.cpp ├── streebog ├── cuda_keccak_streebog.cu ├── cuda_keccak_streebog.cu~ ├── cuda_streebog.cu ├── sib.cu ├── streebog_arrays.cuh └── veltor.cu ├── sysinfos.cpp ├── test ├── test.c ├── uint256.h ├── util.cpp ├── x11 ├── c11.cu ├── cuda_x11.h ├── cuda_x11_aes.cuh ├── cuda_x11_cubehash512.cu ├── cuda_x11_cubehash_shavite_512.cu ├── cuda_x11_echo.cu ├── cuda_x11_shavite512.cu ├── cuda_x11_simd512.cu ├── cuda_x11_simd512.cu~ ├── cuda_x11_simd512_func.cuh ├── cuda_x11_simd_echo512.cu ├── x11.cu └── x11evo.cu ├── x13 ├── cuda_x13_fugue512.cu ├── cuda_x13_hamsi512.cu ├── cuda_x13_hamsi_fugue512.cu └── x13.cu ├── x14 ├── cuda_x14_shabal512.cu └── x14.cu ├── x15 ├── cuda_whirlpool_tables.cuh ├── cuda_whirlpoolx.cu ├── cuda_x15_whirlpool.cu ├── whirlpool.cu ├── whirlpoolx.cu └── x15.cu ├── x17 ├── cuda_x17_haval256.cu ├── cuda_x17_haval256.cu~ ├── cuda_x17_sha512.cu ├── x17.cu └── x17.cu~ └── yescrypt ├── cuda_yescrypt.cu └── yescrypt.cu /Algo256/keccak256.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * Keccak 256 3 | * 4 | */ 5 | 6 | extern "C" 7 | { 8 | #include "sph/sph_shavite.h" 9 | #include "sph/sph_simd.h" 10 | #include "sph/sph_keccak.h" 11 | 12 | #include "miner.h" 13 | } 14 | 15 | #include "cuda_helper.h" 16 | 17 | extern uint32_t *h_nounce[MAX_GPUS]; 18 | 19 | extern void keccak256_cpu_init(int thr_id); 20 | extern void keccak256_cpu_free(int thr_id); 21 | extern void keccak256_setBlock_80(uint64_t *PaddedMessage80); 22 | extern void keccak256_setOutput(int thr_id); 23 | extern void keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce,const uint2 highTarget); 24 | 25 | // CPU Hash 26 | extern "C" void keccak256_hash(void *state, const void *input) 27 | { 28 | uint32_t _ALIGN(64) hash[16]; 29 | sph_keccak_context ctx_keccak; 30 | 31 | sph_keccak256_init(&ctx_keccak); 32 | sph_keccak256 (&ctx_keccak, input, 80); 33 | sph_keccak256_close(&ctx_keccak, (void*) hash); 34 | 35 | memcpy(state, hash, 32); 36 | } 37 | 38 | static bool init[MAX_GPUS] = { 0 }; 39 | 40 | extern "C" int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done){ 41 | 42 | uint32_t _ALIGN(64) endiandata[20]; 43 | uint32_t *pdata = work->data; 44 | uint32_t *ptarget = work->target; 45 | const uint32_t first_nonce = pdata[19]; 46 | 47 | int dev_id = device_map[thr_id]; 48 | int intensity = (device_sm[dev_id] >= 520) ? 28 : 25; 49 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); 50 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 51 | 52 | if (opt_benchmark) 53 | ptarget[7] = 0x000f; 54 | 55 | // const uint64_t highTarget = *(uint64_t*)&ptarget[6]; 56 | const uint2 highTarget = make_uint2(ptarget[6],ptarget[7]); 57 | if (!init[thr_id]) { 58 | cudaSetDevice(device_map[thr_id]); 59 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 60 | cudaDeviceReset(); 61 | // reduce cpu usage (linux) 62 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 63 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 64 | CUDA_LOG_ERROR(); 65 | } 66 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 67 | keccak256_cpu_init(thr_id); 68 | 69 | init[thr_id] = true; 70 | } 71 | 72 | for (int k=0; k < 20; k++) { 73 | be32enc(&endiandata[k], pdata[k]); 74 | } 75 | 76 | keccak256_setBlock_80((uint64_t*)endiandata); 77 | keccak256_setOutput(thr_id); 78 | int rc = 0; 79 | do { 80 | keccak256_cpu_hash_80(thr_id, throughput, pdata[19],highTarget); 81 | if (h_nounce[thr_id][0] != UINT32_MAX && bench_algo < 0) 82 | { 83 | uint32_t _ALIGN(64) vhash64[8]; 84 | be32enc(&endiandata[19], h_nounce[thr_id][0]); 85 | keccak256_hash(vhash64, endiandata); 86 | 87 | if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) { 88 | *hashes_done = pdata[19] - first_nonce + throughput; 89 | work_set_target_ratio(work, vhash64); 90 | pdata[19] = h_nounce[thr_id][0]; 91 | rc = 1; 92 | if(h_nounce[thr_id][1]!=UINT32_MAX){ 93 | // if(!opt_quiet) 94 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce %08x !", h_nounce[thr_id][1]); 95 | be32enc(&endiandata[19], h_nounce[thr_id][1]); 96 | keccak256_hash(vhash64, endiandata); 97 | pdata[21] = h_nounce[thr_id][1]; 98 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]) { 99 | work_set_target_ratio(work, vhash64); 100 | xchg(pdata[19], pdata[21]); 101 | } 102 | rc = 2; 103 | } 104 | return rc; 105 | } 106 | else{ 107 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_nounce[thr_id][0]); 108 | keccak256_setOutput(thr_id); 109 | } 110 | } 111 | 112 | pdata[19] += throughput; 113 | 114 | } while (!work_restart[thr_id].restart && ((uint64_t)max_nonce > ((uint64_t)(pdata[19]) + (uint64_t)throughput))); 115 | 116 | *hashes_done = pdata[19] - first_nonce; 117 | 118 | return rc; 119 | 120 | } 121 | 122 | // cleanup 123 | extern "C" void free_keccak256(int thr_id) 124 | { 125 | if (!init[thr_id]) 126 | return; 127 | 128 | cudaThreadSynchronize(); 129 | 130 | keccak256_cpu_free(thr_id); 131 | 132 | cudaDeviceSynchronize(); 133 | init[thr_id] = false; 134 | } 135 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # allow to use Host cuda functions in C/C++ 2 | DEF_INCLUDES = @CUDA_INCLUDES@ 3 | 4 | if WANT_JANSSON 5 | JANSSON_INCLUDES= -I$(top_srcdir)/compat/jansson 6 | else 7 | JANSSON_INCLUDES= 8 | endif 9 | 10 | EXTRA_DIST = autogen.sh README.md README.txt LICENSE.txt \ 11 | ccminer.sln ccminer.vcxproj ccminer.vcxproj.filters \ 12 | compat/gettimeofday.c compat/getopt/getopt_long.c cpuminer-config.h.in 13 | 14 | SUBDIRS = compat 15 | 16 | bin_PROGRAMS = ccminer 17 | 18 | ccminer_SOURCES = elist.h miner.h compat.h \ 19 | compat/inttypes.h compat/stdbool.h compat/unistd.h \ 20 | compat/sys/time.h compat/getopt/getopt.h \ 21 | crc32.c \ 22 | ccminer.cpp pools.cpp util.cpp bench.cpp bignum.cpp \ 23 | api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \ 24 | Algo256/decred.cu \ 25 | Algo256/blake256_8round.cu Algo256/blake256_14round.cu Algo256/cuda_blake256_14round.cu \ 26 | Algo256/cuda_keccak256.cu Algo256/keccak256.cu \ 27 | Algo256/cuda_skein256.cu \ 28 | Algo256/cuda_groestl256.cu \ 29 | Algo256/cuda_bmw256.cu \ 30 | Algo256/cuda_blake2s.cu \ 31 | Algo256/cuda_cubehash256.cu \ 32 | lyra2/Lyra2.c lyra2/Sponge.c lyra2/lyra2RE.cu lyra2/cuda_lyra2.cu lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \ 33 | cuda_checkhash.cu \ 34 | sph/blake.c sph/keccak.c sph/shavite.c sph/simd.c sph/groestl.c\ 35 | sph/sha2.c sph/cubehash.c sph/skein.c sph/bmw.c sph/jh.c \ 36 | sph/echo.c sph/luffa.c sph/fugue.c sph/hamsi.c \ 37 | sph/whirlpool.c sph/shabal.c sph/sha2big.c sph/haval.c sph/ripemd.c sph/sph_sha2.c \ 38 | sph/streebog.c \ 39 | sph/blake2b.c \ 40 | neoscrypt/neoscrypt-cpu.c neoscrypt/cuda_neoscrypt.cu \ 41 | neoscrypt/neoscrypt.cu \ 42 | skein/skein.cu skein/skein2.cu \ 43 | nist5/cuda_nist5.cu \ 44 | quark/cuda_keccak_skein512.cu \ 45 | quark/cuda_quark_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_quark_skein512.cu \ 46 | quark/cuda_bmw512.cu quark/cuda_quark_keccak512.cu quark/cuda_quark_compactionTest.cu \ 47 | quark/quarkcoin.cu \ 48 | qubit/qubit_luffa512.cu \ 49 | qubit/qubit.cu \ 50 | x11/cuda_x11_cubehash_shavite_512.cu \ 51 | x11/cuda_x11_simd_echo512.cu \ 52 | x11/cuda_x11_cubehash512.cu x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \ 53 | x11/x11.cu x11/x11evo.cu x11/c11.cu \ 54 | streebog/cuda_streebog.cu streebog/cuda_keccak_streebog.cu \ 55 | streebog/sib.cu streebog/veltor.cu \ 56 | x13/cuda_x13_hamsi_fugue512.cu \ 57 | x13/cuda_x13_fugue512.cu x13/cuda_x13_hamsi512.cu \ 58 | x13/x13.cu \ 59 | x14/cuda_x14_shabal512.cu \ 60 | x14/x14.cu \ 61 | x15/cuda_x15_whirlpool.cu \ 62 | x15/x15.cu \ 63 | x15/whirlpool.cu \ 64 | x17/cuda_x17_haval256.cu x17/cuda_x17_sha512.cu \ 65 | x17/x17.cu \ 66 | lbry/cuda_sha256_lbry.cu lbry/cuda_sha512_lbry.cu \ 67 | lbry/cuda_lbry_merged.cu \ 68 | lbry/lbry.cu \ 69 | sia.cu \ 70 | cuda_myriadgroestl.cu \ 71 | myriadgroestl.cu 72 | 73 | if HAVE_NVML 74 | nvml_defs = -DUSE_WRAPNVML 75 | nvml_libs = -ldl 76 | endif 77 | 78 | if HAVE_WINDOWS 79 | ccminer_SOURCES += compat/winansi.c 80 | endif 81 | 82 | ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@ 83 | ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @PCILIB@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs) 84 | ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @PCIFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs) 85 | 86 | nvcc_ARCH = -gencode=arch=compute_52,code=\"sm_52,compute_52\" 87 | nvcc_ARCH += -gencode=arch=compute_50,code=\"sm_50,compute_50\" 88 | #nvcc_ARCH = -gencode=arch=compute_35,code=\"sm_35,compute_35\" 89 | #nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\" 90 | #nvcc_ARCH += -gencode=arch=compute_20,code=\"sm_21,compute_20\" 91 | 92 | nvcc_FLAGS = $(nvcc_ARCH) @CUDA_INCLUDES@ -I. @CUDA_CFLAGS@ 93 | nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v" -lineinfo 94 | 95 | # we're now targeting all major compute architectures within one binary. 96 | .cu.o: 97 | $(NVCC) $(nvcc_FLAGS) --maxrregcount=128 -o $@ -c $< 98 | 99 | streebog/cuda_streebog.o : streebog/cuda_streebog.cu 100 | $(NVCC) $(nvcc_FLAGS) --maxrregcount=72 -o $@ -c $< 101 | 102 | x11/cuda_x11_simd_echo512.o: x11/cuda_x11_simd_echo512.cu 103 | $(NVCC) $(nvcc_FLAGS) --maxrregcount=72 -o $@ -c $< 104 | 105 | x15/cuda_x15_whirlpool.o: x15/cuda_x15_whirlpool.cu 106 | $(NVCC) $(nvcc_FLAGS) --maxrregcount=72 -o $@ -c $< 107 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ccminer 2 | ======= 3 | 4 | Based on Christian Buchner's & Christian H.'s CUDA project, no more active on github recently. 5 | 6 | Fork by tpruvot@github with X14,X15,X17,Blake256,BlakeCoin,Lyra2RE,Skein,ZR5 and others, check the [README.txt](README.txt) 7 | 8 | Tpruvot BTC donation address: 1AJdfCpLWPNoAMDfHF1wD5y8VgKSSTHxPo 9 | [![tip for next commit](https://tip4commit.com/projects/927.svg)](https://tip4commit.com/github/tpruvot/ccminer) 10 | 11 | A part of the recent algos were originally wrote by [djm34](https://github.com/djm34). 12 | 13 | This variant was tested and built on Linux (ubuntu server 14.04) and VStudio 2013 on Windows 7. 14 | 15 | Note that the x86 releases are generally faster than x64 ones on Windows. 16 | 17 | About source code dependencies 18 | ------------------------------ 19 | 20 | This project requires some libraries to be built : 21 | 22 | - OpenSSL (prebuilt for win) 23 | 24 | - Curl (prebuilt for win) 25 | 26 | - pthreads (prebuilt for win) 27 | 28 | The tree now contains recent prebuilt openssl and curl .lib for both x86 and x64 platforms (windows). 29 | 30 | To rebuild them, you need to clone this repository and its submodules : 31 | git clone https://github.com/peters/curl-for-windows.git compat/curl-for-windows 32 | 33 | On Linux, you can use the helper ./build.sh (edit it if required) 34 | 35 | There is also an old [Tutorial for windows](http://cudamining.co.uk/url/tutorials/id/3) on [CudaMining](http://cudamining.co.uk) website. 36 | 37 | -------------------------------------------------------------------------------- /algos.h: -------------------------------------------------------------------------------- 1 | #ifndef ALGOS_H 2 | #define ALGOS_H 3 | 4 | #include 5 | #include "compat.h" 6 | 7 | enum sha_algos { 8 | ALGO_BLAKE, 9 | ALGO_DECRED, 10 | ALGO_VCASH, 11 | ALGO_BLAKECOIN, 12 | ALGO_BLAKE2S, 13 | // ALGO_WHIRLPOOLX, 14 | ALGO_KECCAK, 15 | ALGO_LYRA2, 16 | ALGO_LYRA2v2, 17 | ALGO_SKEIN, 18 | ALGO_SKEIN2, 19 | ALGO_NIST5, 20 | ALGO_QUARK, 21 | ALGO_QUBIT, 22 | ALGO_WHIRLPOOL, 23 | ALGO_X11, 24 | ALGO_X11EVO, 25 | ALGO_C11, 26 | ALGO_SIB, 27 | ALGO_X13, 28 | ALGO_X14, 29 | ALGO_X15, 30 | ALGO_X17, 31 | ALGO_LBRY, 32 | ALGO_NEOSCRYPT, 33 | ALGO_SIA, 34 | ALGO_MYR_GR, 35 | ALGO_VELTOR, 36 | // ALGO_YESCRYPT, 37 | ALGO_AUTO, 38 | ALGO_COUNT 39 | }; 40 | 41 | extern volatile enum sha_algos opt_algo; 42 | 43 | static const char *algo_names[] = { 44 | "blake", 45 | "decred", 46 | "vcash", 47 | "blakecoin", 48 | "blake2s", 49 | // "whirlpoolx", 50 | "keccak", 51 | "lyra2", 52 | "lyra2v2", 53 | "skein", 54 | "skein2", 55 | "nist5", 56 | "quark", 57 | "qubit", 58 | "whirlpool", 59 | "x11", 60 | "x11evo", 61 | "c11", 62 | "sib", 63 | "x13", 64 | "x14", 65 | "x15", 66 | "xevan", 67 | "lbry", 68 | "neoscrypt", 69 | "sia", 70 | "myr-gr", 71 | "veltor", 72 | // "yescrypt", 73 | "auto", /* reserved for multi algo */ 74 | "" 75 | }; 76 | 77 | // string to int/enum 78 | static inline int algo_to_int(char* arg) 79 | { 80 | int i; 81 | 82 | for (i = 0; i < ALGO_COUNT; i++) { 83 | if (algo_names[i] && !strcasecmp(arg, algo_names[i])) { 84 | return i; 85 | } 86 | } 87 | 88 | if (i == ALGO_COUNT) { 89 | // some aliases... 90 | if (!strcasecmp("all", arg)) 91 | i = ALGO_AUTO; 92 | else if (!strcasecmp("flax", arg)) 93 | i = ALGO_C11; 94 | else if (!strcasecmp("lyra2re", arg)) 95 | i = ALGO_LYRA2; 96 | else if (!strcasecmp("lyra2rev2", arg)) 97 | i = ALGO_LYRA2v2; 98 | else if (!strcasecmp("thorsriddle", arg)) 99 | i = ALGO_VELTOR; 100 | else if (!strcasecmp("whirl", arg)) 101 | i = ALGO_WHIRLPOOL; 102 | else 103 | i = -1; 104 | } 105 | 106 | return i; 107 | } 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /api/local-sample.php: -------------------------------------------------------------------------------- 1 | 0) { 27 | $err = socket_last_error($socket); 28 | echo "."; 29 | if ($timeout > 1 && ($err == 115 || $err == 114)) { 30 | $timeout--; 31 | usleep(50); 32 | $res = socket_connect($socket, API_HOST, $port); 33 | continue; 34 | } 35 | $error = socket_strerror($err); 36 | $msg = "socket connect($port) failed"; 37 | echo "ERR: $msg '$error'\n"; 38 | socket_close($socket); 39 | return NULL; 40 | } 41 | 42 | socket_set_block($socket); 43 | 44 | return $socket; 45 | } 46 | 47 | function readsockline($socket) 48 | { 49 | $line = ''; 50 | while (true) { 51 | $byte = socket_read($socket, 1); 52 | if ($byte === false || $byte === '') 53 | break; 54 | if ($byte === "\0") 55 | break; 56 | $line .= $byte; 57 | } 58 | return $line; 59 | } 60 | 61 | 62 | function request($cmd) 63 | { 64 | $socket = getsock(API_PORT); 65 | if ($socket == null) 66 | return NULL; 67 | 68 | socket_write($socket, $cmd, strlen($cmd)); 69 | $line = readsockline($socket); 70 | socket_close($socket); 71 | 72 | if (strlen($line) == 0) { 73 | echo "WARN: '$cmd' returned nothing\n"; 74 | return $line; 75 | } 76 | 77 | echo "$cmd returned '$line'\n"; 78 | 79 | $data = array(); 80 | 81 | $objs = explode('|', $line); 82 | foreach ($objs as $obj) 83 | { 84 | if (strlen($obj) > 0) 85 | { 86 | $items = explode(';', $obj); 87 | $item = $items[0]; 88 | $id = explode('=', $items[0], 2); 89 | if (count($id) == 1) 90 | $name = $id[0]; 91 | else 92 | $name = $id[0].$id[1]; 93 | 94 | if (strlen($name) == 0) 95 | $name = 'null'; 96 | 97 | if (isset($data[$name])) { 98 | $num = 1; 99 | while (isset($data[$name.$num])) 100 | $num++; 101 | $name .= $num; 102 | } 103 | 104 | $counter = 0; 105 | foreach ($items as $item) 106 | { 107 | $id = explode('=', $item, 2); 108 | if (count($id) == 2) 109 | $data[$name][$id[0]] = $id[1]; 110 | else 111 | $data[$name][$counter] = $id[0]; 112 | 113 | $counter++; 114 | } 115 | 116 | } 117 | } 118 | if ($cmd == 'summary') 119 | return array_pop($data); 120 | else 121 | return $data; 122 | } 123 | 124 | ob_start(); 125 | 126 | error_reporting(0); 127 | 128 | $summary = request('summary'); 129 | $threads = request('threads'); 130 | $pool = request('pool'); 131 | 132 | ob_end_clean(); /* swap to debug */ 133 | //echo ob_get_clean()."\n"; 134 | 135 | header("Content-Type: application/json"); 136 | echo json_encode(compact('summary', 'threads', 'pool'))."\n"; 137 | ?> 138 | -------------------------------------------------------------------------------- /api/websocket.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | aclocal && autoheader && automake --add-missing --gnu --copy && autoconf 2 | -------------------------------------------------------------------------------- /bench.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Made to benchmark and test algo switch 3 | * 4 | * 2015 - tpruvot@github 5 | */ 6 | 7 | #include 8 | 9 | #include "miner.h" 10 | #include "algos.h" 11 | 12 | int bench_algo = -1; 13 | 14 | static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 }; 15 | static uint32_t algo_throughput[MAX_GPUS][ALGO_COUNT] = { 0 }; 16 | static int algo_mem_used[MAX_GPUS][ALGO_COUNT] = { 0 }; 17 | static int device_mem_free[MAX_GPUS] = { 0 }; 18 | 19 | static pthread_barrier_t miner_barr; 20 | static pthread_barrier_t algo_barr; 21 | static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER; 22 | 23 | extern double thr_hashrates[MAX_GPUS]; 24 | 25 | void bench_init(int threads) 26 | { 27 | bench_algo = opt_algo = (enum sha_algos) 0; /* first */ 28 | applog(LOG_BLUE, "Starting benchmark mode with %s", algo_names[opt_algo]); 29 | pthread_barrier_init(&miner_barr, NULL, threads); 30 | pthread_barrier_init(&algo_barr, NULL, threads); 31 | // required for usage of first algo. 32 | for (int n=0; n < opt_n_threads; n++) { 33 | device_mem_free[n] = cuda_available_memory(n); 34 | } 35 | } 36 | 37 | void bench_free() 38 | { 39 | pthread_barrier_destroy(&miner_barr); 40 | pthread_barrier_destroy(&algo_barr); 41 | } 42 | 43 | // required to switch algos 44 | void algo_free_all(int thr_id){ 45 | // only initialized algos will be freed 46 | free_blake256_8round(thr_id); 47 | free_blake256_14round(thr_id); 48 | free_decred(thr_id); 49 | free_blake2s(thr_id); 50 | free_keccak256(thr_id); 51 | free_lyra2(thr_id); 52 | free_lyra2v2(thr_id); 53 | // free_whirlx(thr_id); 54 | free_skeincoin(thr_id); 55 | free_skein2(thr_id); 56 | free_nist5(thr_id); 57 | free_quark(thr_id); 58 | free_qubit(thr_id); 59 | free_x11(thr_id); 60 | free_x11evo(thr_id); 61 | free_c11(thr_id); 62 | free_sib(thr_id); 63 | free_x13(thr_id); 64 | free_x14(thr_id); 65 | free_x15(thr_id); 66 | free_x17(thr_id); 67 | free_lbry(thr_id); 68 | free_neoscrypt(thr_id); 69 | free_myriad(thr_id); 70 | free_sia(thr_id); 71 | free_veltor(thr_id); 72 | // free_yescrypt(thr_id); 73 | } 74 | 75 | // benchmark all algos (called once per mining thread) 76 | bool bench_algo_switch_next(int thr_id) 77 | { 78 | int algo = (int) opt_algo; 79 | int prev_algo = algo; 80 | int dev_id = device_map[thr_id % MAX_GPUS]; 81 | int mfree, mused; 82 | // doesnt seems enough to prevent device slow down 83 | // after some algo switchs 84 | bool need_reset = (gpu_threads == 1); 85 | 86 | algo++; 87 | 88 | // Skip yescrypt 89 | // if(algo == ALGO_YESCRYPT){ 90 | // algo++; 91 | // } 92 | 93 | // free current algo memory and track mem usage 94 | mused = cuda_available_memory(thr_id); 95 | algo_free_all(thr_id); 96 | CUDA_LOG_ERROR(); 97 | 98 | // device can take some time to free 99 | mfree = cuda_available_memory(thr_id); 100 | if (device_mem_free[thr_id] > mfree) { 101 | sleep(1); 102 | mfree = cuda_available_memory(thr_id); 103 | } 104 | 105 | // we need to wait completion on all cards before the switch 106 | if (opt_n_threads > 1) { 107 | pthread_barrier_wait(&miner_barr); 108 | } 109 | 110 | char rate[32] = { 0 }; 111 | double hashrate = stats_get_speed(thr_id, thr_hashrates[thr_id]); 112 | format_hashrate(hashrate, rate); 113 | gpulog(LOG_NOTICE, thr_id, "%s hashrate = %s", algo_names[prev_algo], rate); 114 | 115 | // ensure memory leak is still real after the barrier 116 | if (device_mem_free[thr_id] > mfree) { 117 | mfree = cuda_available_memory(thr_id); 118 | } 119 | 120 | // check if there is memory leak 121 | if (device_mem_free[thr_id] - mfree > 1) { 122 | gpulog(LOG_WARNING, thr_id, "possible %d MB memory leak in %s! %d MB free", 123 | (device_mem_free[thr_id] - mfree), algo_names[prev_algo], mfree); 124 | cuda_reset_device(thr_id, NULL); // force to free the leak 125 | need_reset = false; 126 | mfree = cuda_available_memory(thr_id); 127 | } 128 | // store used memory per algo 129 | algo_mem_used[thr_id][opt_algo] = device_mem_free[thr_id] - mused; 130 | device_mem_free[thr_id] = mfree; 131 | 132 | // store to dump a table per gpu later 133 | algo_hashrates[thr_id][prev_algo] = hashrate; 134 | 135 | // wait the other threads to display logs correctly 136 | if (opt_n_threads > 1) { 137 | pthread_barrier_wait(&algo_barr); 138 | } 139 | 140 | if (algo == ALGO_AUTO) 141 | return false; // all algos done 142 | 143 | // mutex primary used for the stats purge 144 | pthread_mutex_lock(&bench_lock); 145 | stats_purge_all(); 146 | 147 | opt_algo = (enum sha_algos) algo; 148 | global_hashrate = 0; 149 | thr_hashrates[thr_id] = 0; // reset for minmax64 150 | pthread_mutex_unlock(&bench_lock); 151 | 152 | if (need_reset) 153 | cuda_reset_device(thr_id, NULL); 154 | 155 | if (thr_id == 0) 156 | applog(LOG_BLUE, "Benchmark algo %s...", algo_names[algo]); 157 | 158 | return true; 159 | } 160 | 161 | void bench_set_throughput(int thr_id, uint32_t throughput) 162 | { 163 | algo_throughput[thr_id][opt_algo] = throughput; 164 | } 165 | 166 | void bench_display_results() 167 | { 168 | for (int n=0; n < opt_n_threads; n++) 169 | { 170 | int dev_id = device_map[n]; 171 | applog(LOG_BLUE, "Benchmark results for GPU #%d - %s:", dev_id, device_name[dev_id]); 172 | for (int i=0; i < ALGO_COUNT-1; i++) { 173 | double rate = algo_hashrates[n][i]; 174 | if (rate == 0.0) continue; 175 | applog(LOG_INFO, "%12s : %12.1f kH/s, %5d MB, %8u thr.", algo_names[i], 176 | rate / 1024., algo_mem_used[n][i], algo_throughput[n][i]); 177 | } 178 | } 179 | } 180 | 181 | -------------------------------------------------------------------------------- /bignum.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Wrapper to OpenSSL BIGNUM used by net diff (nBits) 3 | */ 4 | 5 | #include 6 | 7 | #include "uint256.h" 8 | #include "bignum.hpp" 9 | 10 | #include "miner.h" // hex2bin 11 | 12 | extern "C" double bn_convert_nbits(const uint32_t nBits) 13 | { 14 | uint256 bn = CBigNum().SetCompact(nBits).getuint256(); 15 | return bn.getdouble(); 16 | } 17 | 18 | // copy the big number to 32-bytes uchar 19 | extern "C" void bn_nbits_to_uchar(const uint32_t nBits, unsigned char *target) 20 | { 21 | char buff[65]; 22 | uint256 bn = CBigNum().SetCompact(nBits).getuint256(); 23 | 24 | snprintf(buff, 65, "%s\n", bn.ToString().c_str()); buff[64] = '\0'; 25 | hex2bin(target, buff, 32); 26 | } 27 | 28 | // unused, but should allow more than 256bits targets 29 | #if 0 30 | extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target) 31 | { 32 | double dhash; 33 | 34 | if (!opt_showdiff) 35 | return 0.0; 36 | 37 | CBigNum h(0), t(0); 38 | std::vector vch(32); 39 | 40 | memcpy(&vch[0], (void*) target, 32); 41 | t.setvch(vch); 42 | memcpy(&vch[0], (void*) hash, 32); 43 | h.setvch(vch); 44 | 45 | dhash = h.getuint256().getdouble(); 46 | if (dhash > 0.) 47 | return t.getuint256().getdouble() / dhash; 48 | else 49 | return dhash; 50 | } 51 | #endif 52 | 53 | // new method to save all nonce(s) share diff/ratio 54 | extern "C" void bn_set_target_ratio(struct work* work, uint32_t* hash, int nonce) 55 | { 56 | bn_store_hash_target_ratio(hash, work->target, work, nonce); 57 | } 58 | 59 | // compute the diff ratio between a found hash and the target 60 | extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target) 61 | { 62 | uint256 h, t; 63 | double dhash; 64 | 65 | memcpy(&t, (void*) target, 32); 66 | memcpy(&h, (void*) hash, 32); 67 | 68 | dhash = h.getdouble(); 69 | if (dhash > 0.) 70 | return t.getdouble() / dhash; 71 | else 72 | return dhash; 73 | } 74 | 75 | // store ratio in work struct 76 | extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work, int nonce) 77 | { 78 | // only if the option is enabled (to reduce cpu usage) 79 | work->shareratio[nonce] = bn_hash_target_ratio(hash, target); 80 | work->sharediff[nonce] = work->targetdiff * work->shareratio[0]; 81 | } 82 | 83 | extern "C" void work_set_target_ratio(struct work* work, uint32_t* hash) 84 | { 85 | bn_store_hash_target_ratio(hash, work->target, work,0); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | REM COMMAND LINE MS BUILD 2 | REM Note: /m:2 = 2 threads, but for host code only... 3 | 4 | msbuild ccminer.vcxproj /m /p:Configuration=Release 5 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Simple script to create the Makefile and build 4 | 5 | # export PATH="$PATH:/usr/local/cuda/bin/" 6 | 7 | make distclean || echo clean 8 | 9 | rm -f Makefile.in 10 | rm -f config.status 11 | ./autogen.sh || echo done 12 | 13 | # CFLAGS="-O2" ./configure 14 | ./configure.sh 15 | 16 | make -j 6 17 | -------------------------------------------------------------------------------- /ccminer.conf: -------------------------------------------------------------------------------- 1 | { 2 | "_comment1" : "Possible keys are the long options (ccminer --help)", 3 | "_comment2" : "todo: support /* comments */", 4 | 5 | "algo" : "blake", 6 | "intensity": 19, 7 | 8 | "api-bind": "127.0.0.1:4068", 9 | "statsavg": 20, 10 | 11 | "quiet" : false, 12 | "debug" : false, 13 | "protocol" : false, 14 | "cpu-priority" : 3, 15 | 16 | "url" : "stratum+tcp://stratum.eu.miners-pool.eu:8421", 17 | "user" : "ShGCAFrspnLDo414EzUyJm4k5Qr2Kkrmvh", 18 | "pass" : "x" 19 | } 20 | -------------------------------------------------------------------------------- /ccminer.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 2013 3 | VisualStudioVersion = 12.0.30723.0 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ccminer", "ccminer.vcxproj", "{36DC07F9-A4A6-4877-A146-1B960083CF6F}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|Win32 = Debug|Win32 10 | Debug|x64 = Debug|x64 11 | Release|Win32 = Release|Win32 12 | Release|x64 = Release|x64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.ActiveCfg = Debug|Win32 16 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.Build.0 = Debug|Win32 17 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.ActiveCfg = Debug|x64 18 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.Build.0 = Debug|x64 19 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.ActiveCfg = Release|Win32 20 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.Build.0 = Release|Win32 21 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.ActiveCfg = Release|x64 22 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.Build.0 = Release|x64 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | #include 8 | 9 | #define localtime_r(src, dst) localtime_s(dst, src) 10 | 11 | static __inline void sleep(int secs) 12 | { 13 | Sleep(secs * 1000); 14 | } 15 | 16 | enum { 17 | PRIO_PROCESS = 0, 18 | }; 19 | 20 | extern int opt_priority; 21 | 22 | static __inline int setpriority(int which, int who, int prio) 23 | { 24 | switch (opt_priority) { 25 | case 5: 26 | prio = THREAD_PRIORITY_TIME_CRITICAL; 27 | break; 28 | case 4: 29 | prio = THREAD_PRIORITY_HIGHEST; 30 | break; 31 | case 3: 32 | prio = THREAD_PRIORITY_ABOVE_NORMAL; 33 | break; 34 | case 2: 35 | prio = THREAD_PRIORITY_NORMAL; 36 | break; 37 | case 1: 38 | prio = THREAD_PRIORITY_BELOW_NORMAL; 39 | break; 40 | case 0: 41 | default: 42 | prio = THREAD_PRIORITY_IDLE; 43 | } 44 | return -!SetThreadPriority(GetCurrentThread(), prio); 45 | } 46 | 47 | #ifdef _MSC_VER 48 | #define snprintf(...) _snprintf(__VA_ARGS__) 49 | #define strdup(...) _strdup(__VA_ARGS__) 50 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) 51 | #define strcasecmp(x,y) _stricmp(x,y) 52 | typedef int ssize_t; 53 | 54 | __inline int msver(void) { 55 | switch (_MSC_VER) { 56 | case 1500: return 2008; 57 | case 1600: return 2010; 58 | case 1700: return 2012; 59 | case 1800: return 2013; 60 | case 1900: return 2015; 61 | default: return (_MSC_VER/100); 62 | } 63 | } 64 | 65 | #include 66 | static __inline char * dirname(char *file) { 67 | char buffer[_MAX_PATH] = { 0 }; 68 | char drive[_MAX_DRIVE]; 69 | char dir[_MAX_DIR]; 70 | char fname[_MAX_FNAME]; 71 | char ext[_MAX_EXT]; 72 | _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); 73 | sprintf(buffer, "%s%s", drive, dir); 74 | return strdup(buffer); 75 | } 76 | #endif 77 | 78 | #endif /* WIN32 */ 79 | 80 | #ifdef _MSC_VER 81 | # define __func__ __FUNCTION__ 82 | # define __thread __declspec(thread) 83 | # define _ALIGN(x) __declspec(align(x)) 84 | #else 85 | # define _ALIGN(x) __attribute__ ((aligned(x))) 86 | /* dirname() for linux/mingw */ 87 | #include 88 | #endif 89 | 90 | #ifndef WIN32 91 | #define MAX_PATH PATH_MAX 92 | #endif 93 | 94 | #endif /* __COMPAT_H__ */ 95 | -------------------------------------------------------------------------------- /compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/curlver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLVER_H 2 | #define __CURL_CURLVER_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* This header file contains nothing but libcurl version info, generated by 26 | a script at release-time. This was made its own header file in 7.11.2 */ 27 | 28 | /* This is the global package copyright */ 29 | #define LIBCURL_COPYRIGHT "1996 - 2014 Daniel Stenberg, ." 30 | 31 | /* This is the version number of the libcurl package from which this header 32 | file origins: */ 33 | #define LIBCURL_VERSION "7.38.0" 34 | 35 | /* The numeric version number is also available "in parts" by using these 36 | defines: */ 37 | #define LIBCURL_VERSION_MAJOR 7 38 | #define LIBCURL_VERSION_MINOR 38 39 | #define LIBCURL_VERSION_PATCH 0 40 | 41 | /* This is the numeric version of the libcurl version number, meant for easier 42 | parsing and comparions by programs. The LIBCURL_VERSION_NUM define will 43 | always follow this syntax: 44 | 45 | 0xXXYYZZ 46 | 47 | Where XX, YY and ZZ are the main version, release and patch numbers in 48 | hexadecimal (using 8 bits each). All three numbers are always represented 49 | using two digits. 1.2 would appear as "0x010200" while version 9.11.7 50 | appears as "0x090b07". 51 | 52 | This 6-digit (24 bits) hexadecimal number does not show pre-release number, 53 | and it is always a greater number in a more recent release. It makes 54 | comparisons with greater than and less than work. 55 | */ 56 | #define LIBCURL_VERSION_NUM 0x072600 57 | 58 | /* 59 | * This is the date and time when the full source package was created. The 60 | * timestamp is not stored in git, as the timestamp is properly set in the 61 | * tarballs by the maketgz script. 62 | * 63 | * The format of the date should follow this template: 64 | * 65 | * "Mon Feb 12 11:35:33 UTC 2007" 66 | */ 67 | #define LIBCURL_TIMESTAMP "Mon Nov 03 12:00:00 UTC 2014" 68 | 69 | #endif /* __CURL_CURLVER_H */ 70 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/easy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_EASY_H 2 | #define __CURL_EASY_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | CURL_EXTERN CURL *curl_easy_init(void); 29 | CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); 30 | CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); 31 | CURL_EXTERN void curl_easy_cleanup(CURL *curl); 32 | 33 | /* 34 | * NAME curl_easy_getinfo() 35 | * 36 | * DESCRIPTION 37 | * 38 | * Request internal information from the curl session with this function. The 39 | * third argument MUST be a pointer to a long, a pointer to a char * or a 40 | * pointer to a double (as the documentation describes elsewhere). The data 41 | * pointed to will be filled in accordingly and can be relied upon only if the 42 | * function returns CURLE_OK. This function is intended to get used *AFTER* a 43 | * performed transfer, all results from this function are undefined until the 44 | * transfer is completed. 45 | */ 46 | CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); 47 | 48 | 49 | /* 50 | * NAME curl_easy_duphandle() 51 | * 52 | * DESCRIPTION 53 | * 54 | * Creates a new curl session handle with the same options set for the handle 55 | * passed in. Duplicating a handle could only be a matter of cloning data and 56 | * options, internal state info and things like persistent connections cannot 57 | * be transferred. It is useful in multithreaded applications when you can run 58 | * curl_easy_duphandle() for each new thread to avoid a series of identical 59 | * curl_easy_setopt() invokes in every thread. 60 | */ 61 | CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl); 62 | 63 | /* 64 | * NAME curl_easy_reset() 65 | * 66 | * DESCRIPTION 67 | * 68 | * Re-initializes a CURL handle to the default values. This puts back the 69 | * handle to the same state as it was in when it was just created. 70 | * 71 | * It does keep: live connections, the Session ID cache, the DNS cache and the 72 | * cookies. 73 | */ 74 | CURL_EXTERN void curl_easy_reset(CURL *curl); 75 | 76 | /* 77 | * NAME curl_easy_recv() 78 | * 79 | * DESCRIPTION 80 | * 81 | * Receives data from the connected socket. Use after successful 82 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 83 | */ 84 | CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, 85 | size_t *n); 86 | 87 | /* 88 | * NAME curl_easy_send() 89 | * 90 | * DESCRIPTION 91 | * 92 | * Sends data over the connected socket. Use after successful 93 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 94 | */ 95 | CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, 96 | size_t buflen, size_t *n); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MPRINTF_H 2 | #define __CURL_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | #include /* needed for FILE */ 27 | 28 | #include "curl.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | CURL_EXTERN int curl_mprintf(const char *format, ...); 35 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 36 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 37 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, 38 | const char *format, ...); 39 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 40 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 42 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, 43 | const char *format, va_list args); 44 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 45 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 46 | 47 | #ifdef _MPRINTF_REPLACE 48 | # undef printf 49 | # undef fprintf 50 | # undef sprintf 51 | # undef vsprintf 52 | # undef snprintf 53 | # undef vprintf 54 | # undef vfprintf 55 | # undef vsnprintf 56 | # undef aprintf 57 | # undef vaprintf 58 | # define printf curl_mprintf 59 | # define fprintf curl_mfprintf 60 | #ifdef CURLDEBUG 61 | /* When built with CURLDEBUG we define away the sprintf functions since we 62 | don't want internal code to be using them */ 63 | # define sprintf sprintf_was_used 64 | # define vsprintf vsprintf_was_used 65 | #else 66 | # define sprintf curl_msprintf 67 | # define vsprintf curl_mvsprintf 68 | #endif 69 | # define snprintf curl_msnprintf 70 | # define vprintf curl_mvprintf 71 | # define vfprintf curl_mvfprintf 72 | # define vsnprintf curl_mvsnprintf 73 | # define aprintf curl_maprintf 74 | # define vaprintf curl_mvaprintf 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __CURL_MPRINTF_H */ 82 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDC_HEADERS_H 2 | #define __STDC_HEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | size_t fread (void *, size_t, size_t, FILE *); 28 | size_t fwrite (const void *, size_t, size_t, FILE *); 29 | 30 | int strcasecmp(const char *, const char *); 31 | int strncasecmp(const char *, const char *, size_t); 32 | 33 | #endif /* __STDC_HEADERS_H */ 34 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/crypto/opensslconf.h: -------------------------------------------------------------------------------- 1 | #include "../../config/opensslconf.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/e_os2.h: -------------------------------------------------------------------------------- 1 | #include "../../e_os2.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | #include "../../crypto/opensslconf.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/opensslv.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_OPENSSLV_H 2 | #define HEADER_OPENSSLV_H 3 | 4 | /* Numeric release version identifier: 5 | * MNNFFPPS: major minor fix patch status 6 | * The status nibble has one of the values 0 for development, 1 to e for betas 7 | * 1 to 14, and f for release. The patch level is exactly that. 8 | * For example: 9 | * 0.9.3-dev 0x00903000 10 | * 0.9.3-beta1 0x00903001 11 | * 0.9.3-beta2-dev 0x00903002 12 | * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) 13 | * 0.9.3 0x0090300f 14 | * 0.9.3a 0x0090301f 15 | * 0.9.4 0x0090400f 16 | * 1.2.3z 0x102031af 17 | * 18 | * For continuity reasons (because 0.9.5 is already out, and is coded 19 | * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level 20 | * part is slightly different, by setting the highest bit. This means 21 | * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start 22 | * with 0x0090600S... 23 | * 24 | * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) 25 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for 26 | * major minor fix final patch/beta) 27 | */ 28 | #define OPENSSL_VERSION_NUMBER 0x1000109fL 29 | #ifdef OPENSSL_FIPS 30 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1i-fips 6 Aug 2014" 31 | #else 32 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1i 6 Aug 2014" 33 | #endif 34 | #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 35 | 36 | 37 | /* The macros below are to be used for shared library (.so, .dll, ...) 38 | * versioning. That kind of versioning works a bit differently between 39 | * operating systems. The most usual scheme is to set a major and a minor 40 | * number, and have the runtime loader check that the major number is equal 41 | * to what it was at application link time, while the minor number has to 42 | * be greater or equal to what it was at application link time. With this 43 | * scheme, the version number is usually part of the file name, like this: 44 | * 45 | * libcrypto.so.0.9 46 | * 47 | * Some unixen also make a softlink with the major verson number only: 48 | * 49 | * libcrypto.so.0 50 | * 51 | * On Tru64 and IRIX 6.x it works a little bit differently. There, the 52 | * shared library version is stored in the file, and is actually a series 53 | * of versions, separated by colons. The rightmost version present in the 54 | * library when linking an application is stored in the application to be 55 | * matched at run time. When the application is run, a check is done to 56 | * see if the library version stored in the application matches any of the 57 | * versions in the version string of the library itself. 58 | * This version string can be constructed in any way, depending on what 59 | * kind of matching is desired. However, to implement the same scheme as 60 | * the one used in the other unixen, all compatible versions, from lowest 61 | * to highest, should be part of the string. Consecutive builds would 62 | * give the following versions strings: 63 | * 64 | * 3.0 65 | * 3.0:3.1 66 | * 3.0:3.1:3.2 67 | * 4.0 68 | * 4.0:4.1 69 | * 70 | * Notice how version 4 is completely incompatible with version, and 71 | * therefore give the breach you can see. 72 | * 73 | * There may be other schemes as well that I haven't yet discovered. 74 | * 75 | * So, here's the way it works here: first of all, the library version 76 | * number doesn't need at all to match the overall OpenSSL version. 77 | * However, it's nice and more understandable if it actually does. 78 | * The current library version is stored in the macro SHLIB_VERSION_NUMBER, 79 | * which is just a piece of text in the format "M.m.e" (Major, minor, edit). 80 | * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, 81 | * we need to keep a history of version numbers, which is done in the 82 | * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and 83 | * should only keep the versions that are binary compatible with the current. 84 | */ 85 | #define SHLIB_VERSION_HISTORY "" 86 | #define SHLIB_VERSION_NUMBER "1.0.0" 87 | 88 | 89 | #endif /* HEADER_OPENSSLV_H */ 90 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/sha.h: -------------------------------------------------------------------------------- 1 | #include "../../crypto/sha/sha.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/stack.h: -------------------------------------------------------------------------------- 1 | /* crypto/stack/stack.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_STACK_H 60 | #define HEADER_STACK_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | typedef struct stack_st 67 | { 68 | int num; 69 | char **data; 70 | int sorted; 71 | 72 | int num_alloc; 73 | int (*comp)(const void *, const void *); 74 | } _STACK; /* Use STACK_OF(...) instead */ 75 | 76 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) 77 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) 78 | 79 | int sk_num(const _STACK *); 80 | void *sk_value(const _STACK *, int); 81 | 82 | void *sk_set(_STACK *, int, void *); 83 | 84 | _STACK *sk_new(int (*cmp)(const void *, const void *)); 85 | _STACK *sk_new_null(void); 86 | void sk_free(_STACK *); 87 | void sk_pop_free(_STACK *st, void (*func)(void *)); 88 | int sk_insert(_STACK *sk, void *data, int where); 89 | void *sk_delete(_STACK *st, int loc); 90 | void *sk_delete_ptr(_STACK *st, void *p); 91 | int sk_find(_STACK *st, void *data); 92 | int sk_find_ex(_STACK *st, void *data); 93 | int sk_push(_STACK *st, void *data); 94 | int sk_unshift(_STACK *st, void *data); 95 | void *sk_shift(_STACK *st); 96 | void *sk_pop(_STACK *st); 97 | void sk_zero(_STACK *st); 98 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) 99 | (const void *, const void *); 100 | _STACK *sk_dup(_STACK *st); 101 | void sk_sort(_STACK *st); 102 | int sk_is_sorted(const _STACK *st); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /compat/getopt/getopt.h: -------------------------------------------------------------------------------- 1 | /* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ 2 | /* $OpenBSD: getopt.h,v 1.1 2002/12/03 20:24:29 millert Exp $ */ 3 | /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 4 | 5 | /*- 6 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 7 | * All rights reserved. 8 | * 9 | * This code is derived from software contributed to The NetBSD Foundation 10 | * by Dieter Baron and Thomas Klausner. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the NetBSD 23 | * Foundation, Inc. and its contributors. 24 | * 4. Neither the name of The NetBSD Foundation nor the names of its 25 | * contributors may be used to endorse or promote products derived 26 | * from this software without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef _GETOPT_H_ 42 | #define _GETOPT_H_ 43 | 44 | #if 0 45 | #include 46 | #endif 47 | 48 | /* 49 | * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 50 | */ 51 | #define no_argument 0 52 | #define required_argument 1 53 | #define optional_argument 2 54 | 55 | struct option { 56 | /* name of long option */ 57 | const char *name; 58 | /* 59 | * one of no_argument, required_argument, and optional_argument: 60 | * whether option takes an argument 61 | */ 62 | int has_arg; 63 | /* if not NULL, set *flag to val when option found */ 64 | int *flag; 65 | /* if flag not NULL, value to set *flag to; else return value */ 66 | int val; 67 | }; 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | int getopt_long(int, char * const *, const char *, 74 | const struct option *, int *); 75 | int getopt_long_only(int, char * const *, const char *, 76 | const struct option *, int *); 77 | #ifndef _GETOPT_DEFINED 78 | #define _GETOPT_DEFINED 79 | int getopt(int, char * const *, const char *); 80 | int getsubopt(char **, char * const *, char **); 81 | 82 | extern char *optarg; /* getopt(3) external variables */ 83 | extern int opterr; 84 | extern int optind; 85 | extern int optopt; 86 | extern int optreset; 87 | extern char *suboptarg; /* getsubopt(3) external variable */ 88 | #endif /* _GETOPT_DEFINED */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | #endif /* !_GETOPT_H_ */ 94 | -------------------------------------------------------------------------------- /compat/gettimeofday.c: -------------------------------------------------------------------------------- 1 | #include < time.h > 2 | #include //I've ommited this line. 3 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 4 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 5 | #else 6 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 7 | #endif 8 | 9 | struct timezone 10 | { 11 | int tz_minuteswest; /* minutes W of Greenwich */ 12 | int tz_dsttime; /* type of dst correction */ 13 | }; 14 | 15 | int gettimeofday(struct timeval *tv, struct timezone *tz) 16 | { 17 | FILETIME ft; 18 | unsigned __int64 tmpres = 0; 19 | static int tzflag; 20 | 21 | if (NULL != tv) 22 | { 23 | GetSystemTimeAsFileTime(&ft); 24 | 25 | tmpres |= ft.dwHighDateTime; 26 | tmpres <<= 32; 27 | tmpres |= ft.dwLowDateTime; 28 | 29 | /*converting file time to unix epoch*/ 30 | tmpres /= 10; /*convert into microseconds*/ 31 | tmpres -= DELTA_EPOCH_IN_MICROSECS; 32 | tv->tv_sec = (long)(tmpres / 1000000UL); 33 | tv->tv_usec = (long)(tmpres % 1000000UL); 34 | } 35 | 36 | if (NULL != tz) 37 | { 38 | if (!tzflag) 39 | { 40 | _tzset(); 41 | tzflag++; 42 | } 43 | tz->tz_minuteswest = _timezone / 60; 44 | tz->tz_dsttime = _daylight; 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | void usleep(__int64 waitTime) 51 | { 52 | if (waitTime > 0) 53 | { 54 | if (waitTime > 100) 55 | { 56 | // use a waitable timer for larger intervals > 0.1ms 57 | 58 | HANDLE timer; 59 | LARGE_INTEGER ft; 60 | 61 | ft.QuadPart = -(10*waitTime); // Convert to 100 nanosecond interval, negative value indicates relative time 62 | 63 | timer = CreateWaitableTimer(NULL, TRUE, NULL); 64 | SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 65 | WaitForSingleObject(timer, INFINITE); 66 | CloseHandle(timer); 67 | } 68 | else 69 | { 70 | // use a polling loop for short intervals <= 100ms 71 | 72 | LARGE_INTEGER perfCnt, start, now; 73 | __int64 elapsed; 74 | 75 | QueryPerformanceFrequency(&perfCnt); 76 | QueryPerformanceCounter(&start); 77 | do { 78 | QueryPerformanceCounter((LARGE_INTEGER*) &now); 79 | elapsed = (__int64)((now.QuadPart - start.QuadPart) / (float)perfCnt.QuadPart * 1000 * 1000); 80 | } while ( elapsed < waitTime ); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /compat/inttypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /compat/jansson/.gitignore: -------------------------------------------------------------------------------- 1 | *.h.in~ 2 | libtool 3 | libjansson.a 4 | -------------------------------------------------------------------------------- /compat/jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_LIBRARIES = libjansson.a 3 | 4 | libjansson_a_SOURCES = \ 5 | jansson_private_config.h \ 6 | dump.c \ 7 | error.c \ 8 | hashtable.c hashtable.h \ 9 | jansson.h \ 10 | jansson_config.h \ 11 | jansson_private.h \ 12 | load.c \ 13 | memory.c \ 14 | pack_unpack.c \ 15 | strbuffer.c strbuffer.h \ 16 | strconv.c \ 17 | utf.c utf.h \ 18 | util.h \ 19 | value.c 20 | 21 | -------------------------------------------------------------------------------- /compat/jansson/configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.60]) 2 | AC_INIT([jansson], [2.6], [petri@digip.org]) 3 | 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | 6 | AM_INIT_AUTOMAKE([1.10 foreign]) 7 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 8 | 9 | AC_CONFIG_SRCDIR([value.c]) 10 | AC_CONFIG_HEADERS([jansson_private_config.h]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CC 14 | AC_PROG_LIBTOOL 15 | AM_CONDITIONAL([GCC], [test x$GCC = xyes]) 16 | 17 | # Checks for libraries. 18 | 19 | # Checks for header files. 20 | AC_CHECK_HEADERS([endian.h fcntl.h locale.h sched.h unistd.h sys/param.h sys/stat.h sys/time.h sys/types.h]) 21 | 22 | # Checks for typedefs, structures, and compiler characteristics. 23 | AC_TYPE_INT32_T 24 | AC_TYPE_UINT32_T 25 | AC_TYPE_LONG_LONG_INT 26 | 27 | AC_C_INLINE 28 | case $ac_cv_c_inline in 29 | yes) json_inline=inline;; 30 | no) json_inline=;; 31 | *) json_inline=$ac_cv_c_inline;; 32 | esac 33 | AC_SUBST([json_inline]) 34 | 35 | # Checks for library functions. 36 | AC_CHECK_FUNCS([close getpid gettimeofday localeconv open read sched_yield strtoll]) 37 | 38 | AC_MSG_CHECKING([for gcc __sync builtins]) 39 | have_sync_builtins=no 40 | AC_TRY_LINK( 41 | [], [unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1);], 42 | [have_sync_builtins=yes], 43 | ) 44 | if test "x$have_sync_builtins" = "xyes"; then 45 | AC_DEFINE([HAVE_SYNC_BUILTINS], [1], 46 | [Define to 1 if gcc's __sync builtins are available]) 47 | fi 48 | AC_MSG_RESULT([$have_sync_builtins]) 49 | 50 | AC_MSG_CHECKING([for gcc __atomic builtins]) 51 | have_atomic_builtins=no 52 | AC_TRY_LINK( 53 | [], [char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_ACQ_REL); __atomic_load_n(&v, __ATOMIC_ACQUIRE);], 54 | [have_atomic_builtins=yes], 55 | ) 56 | if test "x$have_atomic_builtins" = "xyes"; then 57 | AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1], 58 | [Define to 1 if gcc's __atomic builtins are available]) 59 | fi 60 | AC_MSG_RESULT([$have_atomic_builtins]) 61 | 62 | case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in 63 | yesyes) json_have_long_long=1;; 64 | *) json_have_long_long=0;; 65 | esac 66 | AC_SUBST([json_have_long_long]) 67 | 68 | case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in 69 | yesyes) json_have_localeconv=1;; 70 | *) json_have_localeconv=0;; 71 | esac 72 | AC_SUBST([json_have_localeconv]) 73 | 74 | # Features 75 | AC_ARG_ENABLE([urandom], 76 | [AS_HELP_STRING([--disable-urandom], 77 | [Don't use /dev/urandom to seed the hash function])], 78 | [use_urandom=$enableval], [use_urandom=yes]) 79 | 80 | if test "x$use_urandom" = xyes; then 81 | AC_DEFINE([USE_URANDOM], [1], 82 | [Define to 1 if /dev/urandom should be used for seeding the hash function]) 83 | fi 84 | 85 | AC_ARG_ENABLE([windows-cryptoapi], 86 | [AS_HELP_STRING([--disable-windows-cryptoapi], 87 | [Don't use CryptGenRandom to seed the hash function])], 88 | [use_windows_cryptoapi=$enableval], [use_windows_cryptoapi=yes]) 89 | 90 | if test "x$use_windows_cryptoapi" = xyes; then 91 | AC_DEFINE([USE_WINDOWS_CRYPTOAPI], [1], 92 | [Define to 1 if CryptGenRandom should be used for seeding the hash function]) 93 | fi 94 | 95 | AC_CONFIG_FILES([ 96 | Makefile 97 | ]) 98 | AC_OUTPUT 99 | -------------------------------------------------------------------------------- /compat/jansson/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "jansson_private.h" 3 | 4 | void jsonp_error_init(json_error_t *error, const char *source) 5 | { 6 | if(error) 7 | { 8 | error->text[0] = '\0'; 9 | error->line = -1; 10 | error->column = -1; 11 | error->position = 0; 12 | if(source) 13 | jsonp_error_set_source(error, source); 14 | else 15 | error->source[0] = '\0'; 16 | } 17 | } 18 | 19 | void jsonp_error_set_source(json_error_t *error, const char *source) 20 | { 21 | size_t length; 22 | 23 | if(!error || !source) 24 | return; 25 | 26 | length = strlen(source); 27 | if(length < JSON_ERROR_SOURCE_LENGTH) 28 | strcpy(error->source, source); 29 | else { 30 | size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; 31 | strcpy(error->source, "..."); 32 | strcpy(error->source + 3, source + extra); 33 | } 34 | } 35 | 36 | void jsonp_error_set(json_error_t *error, int line, int column, 37 | size_t position, const char *msg, ...) 38 | { 39 | va_list ap; 40 | 41 | va_start(ap, msg); 42 | jsonp_error_vset(error, line, column, position, msg, ap); 43 | va_end(ap); 44 | } 45 | 46 | void jsonp_error_vset(json_error_t *error, int line, int column, 47 | size_t position, const char *msg, va_list ap) 48 | { 49 | if(!error) 50 | return; 51 | 52 | if(error->text[0] != '\0') { 53 | /* error already set */ 54 | return; 55 | } 56 | 57 | error->line = line; 58 | error->column = column; 59 | error->position = position; 60 | 61 | vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); 62 | error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; 63 | } 64 | -------------------------------------------------------------------------------- /compat/jansson/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * This library is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef HASHTABLE_H 9 | #define HASHTABLE_H 10 | 11 | struct hashtable_list { 12 | struct hashtable_list *prev; 13 | struct hashtable_list *next; 14 | }; 15 | 16 | /* "pair" may be a bit confusing a name, but think of it as a 17 | key-value pair. In this case, it just encodes some extra data, 18 | too */ 19 | struct hashtable_pair { 20 | size_t hash; 21 | struct hashtable_list list; 22 | json_t *value; 23 | size_t serial; 24 | char key[1]; 25 | }; 26 | 27 | struct hashtable_bucket { 28 | struct hashtable_list *first; 29 | struct hashtable_list *last; 30 | }; 31 | 32 | typedef struct hashtable { 33 | size_t size; 34 | struct hashtable_bucket *buckets; 35 | size_t num_buckets; /* index to primes[] */ 36 | struct hashtable_list list; 37 | } hashtable_t; 38 | 39 | 40 | #define hashtable_key_to_iter(key_) \ 41 | (&(container_of(key_, struct hashtable_pair, key)->list)) 42 | 43 | /** 44 | * hashtable_init - Initialize a hashtable object 45 | * 46 | * @hashtable: The (statically allocated) hashtable object 47 | * 48 | * Initializes a statically allocated hashtable object. The object 49 | * should be cleared with hashtable_close when it's no longer used. 50 | * 51 | * Returns 0 on success, -1 on error (out of memory). 52 | */ 53 | int hashtable_init(hashtable_t *hashtable); 54 | 55 | /** 56 | * hashtable_close - Release all resources used by a hashtable object 57 | * 58 | * @hashtable: The hashtable 59 | * 60 | * Destroys a statically allocated hashtable object. 61 | */ 62 | void hashtable_close(hashtable_t *hashtable); 63 | 64 | /** 65 | * hashtable_set - Add/modify value in hashtable 66 | * 67 | * @hashtable: The hashtable object 68 | * @key: The key 69 | * @serial: For addition order of keys 70 | * @value: The value 71 | * 72 | * If a value with the given key already exists, its value is replaced 73 | * with the new value. Value is "stealed" in the sense that hashtable 74 | * doesn't increment its refcount but decreases the refcount when the 75 | * value is no longer needed. 76 | * 77 | * Returns 0 on success, -1 on failure (out of memory). 78 | */ 79 | int hashtable_set(hashtable_t *hashtable, 80 | const char *key, size_t serial, 81 | json_t *value); 82 | 83 | /** 84 | * hashtable_get - Get a value associated with a key 85 | * 86 | * @hashtable: The hashtable object 87 | * @key: The key 88 | * 89 | * Returns value if it is found, or NULL otherwise. 90 | */ 91 | void *hashtable_get(hashtable_t *hashtable, const char *key); 92 | 93 | /** 94 | * hashtable_del - Remove a value from the hashtable 95 | * 96 | * @hashtable: The hashtable object 97 | * @key: The key 98 | * 99 | * Returns 0 on success, or -1 if the key was not found. 100 | */ 101 | int hashtable_del(hashtable_t *hashtable, const char *key); 102 | 103 | /** 104 | * hashtable_clear - Clear hashtable 105 | * 106 | * @hashtable: The hashtable object 107 | * 108 | * Removes all items from the hashtable. 109 | */ 110 | void hashtable_clear(hashtable_t *hashtable); 111 | 112 | /** 113 | * hashtable_iter - Iterate over hashtable 114 | * 115 | * @hashtable: The hashtable object 116 | * 117 | * Returns an opaque iterator to the first element in the hashtable. 118 | * The iterator should be passed to hashtable_iter_* functions. 119 | * The hashtable items are not iterated over in any particular order. 120 | * 121 | * There's no need to free the iterator in any way. The iterator is 122 | * valid as long as the item that is referenced by the iterator is not 123 | * deleted. Other values may be added or deleted. In particular, 124 | * hashtable_iter_next() may be called on an iterator, and after that 125 | * the key/value pair pointed by the old iterator may be deleted. 126 | */ 127 | void *hashtable_iter(hashtable_t *hashtable); 128 | 129 | /** 130 | * hashtable_iter_at - Return an iterator at a specific key 131 | * 132 | * @hashtable: The hashtable object 133 | * @key: The key that the iterator should point to 134 | * 135 | * Like hashtable_iter() but returns an iterator pointing to a 136 | * specific key. 137 | */ 138 | void *hashtable_iter_at(hashtable_t *hashtable, const char *key); 139 | 140 | /** 141 | * hashtable_iter_next - Advance an iterator 142 | * 143 | * @hashtable: The hashtable object 144 | * @iter: The iterator 145 | * 146 | * Returns a new iterator pointing to the next element in the 147 | * hashtable or NULL if the whole hastable has been iterated over. 148 | */ 149 | void *hashtable_iter_next(hashtable_t *hashtable, void *iter); 150 | 151 | /** 152 | * hashtable_iter_key - Retrieve the key pointed by an iterator 153 | * 154 | * @iter: The iterator 155 | */ 156 | void *hashtable_iter_key(void *iter); 157 | 158 | /** 159 | * hashtable_iter_serial - Retrieve the serial number pointed to by an iterator 160 | * 161 | * @iter: The iterator 162 | */ 163 | size_t hashtable_iter_serial(void *iter); 164 | 165 | /** 166 | * hashtable_iter_value - Retrieve the value pointed by an iterator 167 | * 168 | * @iter: The iterator 169 | */ 170 | void *hashtable_iter_value(void *iter); 171 | 172 | /** 173 | * hashtable_iter_set - Set the value pointed by an iterator 174 | * 175 | * @iter: The iterator 176 | * @value: The value to set 177 | */ 178 | void hashtable_iter_set(void *iter, json_t *value); 179 | 180 | #endif 181 | -------------------------------------------------------------------------------- /compat/jansson/jansson_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | * 7 | * 8 | * This file specifies a part of the site-specific configuration for 9 | * Jansson, namely those things that affect the public API in 10 | * jansson.h. 11 | * 12 | * The configure script copies this file to jansson_config.h and 13 | * replaces @var@ substitutions by values that fit your system. If you 14 | * cannot run the configure script, you can do the value substitution 15 | * by hand. 16 | */ 17 | 18 | #ifndef JANSSON_CONFIG_H 19 | #define JANSSON_CONFIG_H 20 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 21 | defined to `inline', otherwise empty. In C++, the inline is always 22 | supported. */ 23 | 24 | #ifdef _MSC_VER 25 | #define inline __inline 26 | #if !defined(HAVE_STRUCT_TIMESPEC) && _MSC_VER >= 1900 27 | #define HAVE_STRUCT_TIMESPEC 28 | #endif 29 | #endif 30 | 31 | #ifdef __cplusplus 32 | #define JSON_INLINE inline 33 | #else 34 | #define JSON_INLINE inline 35 | #endif 36 | 37 | /* If your compiler supports the `long long` type and the strtoll() 38 | library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, 39 | otherwise to 0. */ 40 | #define JSON_INTEGER_IS_LONG_LONG 1 41 | 42 | /* If locale.h and localeconv() are available, define to 1, 43 | otherwise to 0. */ 44 | #define JSON_HAVE_LOCALECONV 1 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /compat/jansson/jansson_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2014 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | * 7 | * 8 | * This file specifies a part of the site-specific configuration for 9 | * Jansson, namely those things that affect the public API in 10 | * jansson.h. 11 | * 12 | * The configure script copies this file to jansson_config.h and 13 | * replaces @var@ substitutions by values that fit your system. If you 14 | * cannot run the configure script, you can do the value substitution 15 | * by hand. 16 | */ 17 | 18 | #ifndef JANSSON_CONFIG_H 19 | #define JANSSON_CONFIG_H 20 | 21 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 22 | defined to `inline', otherwise empty. In C++, the inline is always 23 | supported. */ 24 | #ifdef __cplusplus 25 | #define JSON_INLINE inline 26 | #else 27 | #define JSON_INLINE @json_inline@ 28 | #endif 29 | 30 | /* If your compiler supports the `long long` type and the strtoll() 31 | library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, 32 | otherwise to 0. */ 33 | #define JSON_INTEGER_IS_LONG_LONG @json_have_long_long@ 34 | 35 | /* If locale.h and localeconv() are available, define to 1, 36 | otherwise to 0. */ 37 | #define JSON_HAVE_LOCALECONV @json_have_localeconv@ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include 12 | #include "jansson.h" 13 | #include "hashtable.h" 14 | #include "strbuffer.h" 15 | 16 | #define container_of(ptr_, type_, member_) \ 17 | ((type_ *)((char *)ptr_ - offsetof(type_, member_))) 18 | 19 | /* On some platforms, max() may already be defined */ 20 | #ifndef max 21 | #define max(a, b) ((a) > (b) ? (a) : (b)) 22 | #endif 23 | 24 | /* va_copy is a C99 feature. In C89 implementations, it's sometimes 25 | available as __va_copy. If not, memcpy() should do the trick. */ 26 | #ifndef va_copy 27 | #ifdef __va_copy 28 | #define va_copy __va_copy 29 | #else 30 | #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) 31 | #endif 32 | #endif 33 | 34 | typedef struct { 35 | json_t json; 36 | hashtable_t hashtable; 37 | size_t serial; 38 | int visited; 39 | } json_object_t; 40 | 41 | typedef struct { 42 | json_t json; 43 | size_t size; 44 | size_t entries; 45 | json_t **table; 46 | int visited; 47 | } json_array_t; 48 | 49 | typedef struct { 50 | json_t json; 51 | char *value; 52 | } json_string_t; 53 | 54 | typedef struct { 55 | json_t json; 56 | double value; 57 | } json_real_t; 58 | 59 | typedef struct { 60 | json_t json; 61 | json_int_t value; 62 | } json_integer_t; 63 | 64 | #define json_to_object(json_) container_of(json_, json_object_t, json) 65 | #define json_to_array(json_) container_of(json_, json_array_t, json) 66 | #define json_to_string(json_) container_of(json_, json_string_t, json) 67 | #define json_to_real(json_) container_of(json_, json_real_t, json) 68 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 69 | 70 | void jsonp_error_init(json_error_t *error, const char *source); 71 | void jsonp_error_set_source(json_error_t *error, const char *source); 72 | void jsonp_error_set(json_error_t *error, int line, int column, 73 | size_t position, const char *msg, ...); 74 | void jsonp_error_vset(json_error_t *error, int line, int column, 75 | size_t position, const char *msg, va_list ap); 76 | 77 | /* Locale independent string<->double conversions */ 78 | int jsonp_strtod(strbuffer_t *strbuffer, double *out); 79 | int jsonp_dtostr(char *buffer, size_t size, double value); 80 | 81 | /* Wrappers for custom memory functions */ 82 | void* jsonp_malloc(size_t size); 83 | void jsonp_free(void *ptr); 84 | char *jsonp_strndup(const char *str, size_t length); 85 | char *jsonp_strdup(const char *str); 86 | 87 | /* Windows compatibility */ 88 | #ifdef _WIN32 89 | #define snprintf _snprintf 90 | #define vsnprintf _vsnprintf 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private_config.h: -------------------------------------------------------------------------------- 1 | /* jansson_private_config.h. Generated from jansson_private_config.h.in by configure. */ 2 | /* jansson_private_config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if gcc's __atomic builtins are available */ 5 | /* #undef HAVE_ATOMIC_BUILTINS */ 6 | 7 | /* Define to 1 if you have the `close' function. */ 8 | #define HAVE_CLOSE 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_DLFCN_H */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | /* #undef HAVE_ENDIAN_H */ 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_FCNTL_H 1 18 | 19 | /* Define to 1 if you have the `getpid' function. */ 20 | #define HAVE_GETPID 1 21 | 22 | /* Define to 1 if you have the `gettimeofday' function. */ 23 | #define HAVE_GETTIMEOFDAY 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `localeconv' function. */ 29 | #define HAVE_LOCALECONV 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_LOCALE_H 1 33 | 34 | /* Define to 1 if the system has the type `long long int'. */ 35 | #define HAVE_LONG_LONG_INT 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_MEMORY_H 1 39 | 40 | /* Define to 1 if you have the `open' function. */ 41 | #define HAVE_OPEN 1 42 | 43 | /* Define to 1 if you have the `read' function. */ 44 | #define HAVE_READ 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SCHED_H 1 48 | 49 | /* Define to 1 if you have the `sched_yield' function. */ 50 | /* #undef HAVE_SCHED_YIELD */ 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_STDINT_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_STDLIB_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_STRINGS_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_STRING_H 1 63 | 64 | /* Define to 1 if you have the `strtoll' function. */ 65 | #define HAVE_STRTOLL 1 66 | 67 | /* Define to 1 if gcc's __sync builtins are available */ 68 | #define HAVE_SYNC_BUILTINS 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_SYS_PARAM_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_SYS_STAT_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_SYS_TIME_H 1 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SYS_TYPES_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_UNISTD_H 1 84 | 85 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 86 | */ 87 | #define LT_OBJDIR ".libs/" 88 | 89 | /* Name of package */ 90 | #define PACKAGE "jansson" 91 | 92 | /* Define to the address where bug reports for this package should be sent. */ 93 | #define PACKAGE_BUGREPORT "petri@digip.org" 94 | 95 | /* Define to the full name of this package. */ 96 | #define PACKAGE_NAME "jansson" 97 | 98 | /* Define to the full name and version of this package. */ 99 | #define PACKAGE_STRING "jansson 2.6" 100 | 101 | /* Define to the one symbol short name of this package. */ 102 | #define PACKAGE_TARNAME "jansson" 103 | 104 | /* Define to the home page for this package. */ 105 | #define PACKAGE_URL "" 106 | 107 | /* Define to the version of this package. */ 108 | #define PACKAGE_VERSION "2.6" 109 | 110 | /* Define to 1 if you have the ANSI C header files. */ 111 | #define STDC_HEADERS 1 112 | 113 | /* Define to 1 if /dev/urandom should be used for seeding the hash function */ 114 | #define USE_URANDOM 1 115 | 116 | /* Define to 1 if CryptGenRandom should be used for seeding the hash function 117 | */ 118 | #define USE_WINDOWS_CRYPTOAPI 1 119 | 120 | /* Version number of package */ 121 | #define VERSION "2.6" 122 | 123 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 124 | , or is not used. If the typedef were allowed, the 125 | #define below would cause a syntax error. */ 126 | /* #undef _UINT32_T */ 127 | 128 | /* Define to `__inline__' or `__inline' if that's what the C compiler 129 | calls it, or to nothing if 'inline' is not supported under any name. */ 130 | #ifndef __cplusplus 131 | /* #undef inline */ 132 | #endif 133 | 134 | /* Define to the type of a signed integer type of width exactly 32 bits if 135 | such a type exists and the standard includes do not define it. */ 136 | /* #undef int32_t */ 137 | 138 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 139 | such a type exists and the standard includes do not define it. */ 140 | /* #undef uint32_t */ 141 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private_config.h.in: -------------------------------------------------------------------------------- 1 | /* jansson_private_config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if gcc's __atomic builtins are available */ 4 | #undef HAVE_ATOMIC_BUILTINS 5 | 6 | /* Define to 1 if you have the `close' function. */ 7 | #undef HAVE_CLOSE 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_DLFCN_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_ENDIAN_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_FCNTL_H 17 | 18 | /* Define to 1 if you have the `getpid' function. */ 19 | #undef HAVE_GETPID 20 | 21 | /* Define to 1 if you have the `gettimeofday' function. */ 22 | #undef HAVE_GETTIMEOFDAY 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_INTTYPES_H 26 | 27 | /* Define to 1 if you have the `localeconv' function. */ 28 | #undef HAVE_LOCALECONV 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_LOCALE_H 32 | 33 | /* Define to 1 if the system has the type `long long int'. */ 34 | #undef HAVE_LONG_LONG_INT 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_MEMORY_H 38 | 39 | /* Define to 1 if you have the `open' function. */ 40 | #undef HAVE_OPEN 41 | 42 | /* Define to 1 if you have the `read' function. */ 43 | #undef HAVE_READ 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_SCHED_H 47 | 48 | /* Define to 1 if you have the `sched_yield' function. */ 49 | #undef HAVE_SCHED_YIELD 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_STDINT_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_STDLIB_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_STRINGS_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_STRING_H 62 | 63 | /* Define to 1 if you have the `strtoll' function. */ 64 | #undef HAVE_STRTOLL 65 | 66 | /* Define to 1 if gcc's __sync builtins are available */ 67 | #undef HAVE_SYNC_BUILTINS 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_SYS_PARAM_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_SYS_STAT_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_SYS_TIME_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_SYS_TYPES_H 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #undef HAVE_UNISTD_H 83 | 84 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 85 | */ 86 | #undef LT_OBJDIR 87 | 88 | /* Name of package */ 89 | #undef PACKAGE 90 | 91 | /* Define to the address where bug reports for this package should be sent. */ 92 | #undef PACKAGE_BUGREPORT 93 | 94 | /* Define to the full name of this package. */ 95 | #undef PACKAGE_NAME 96 | 97 | /* Define to the full name and version of this package. */ 98 | #undef PACKAGE_STRING 99 | 100 | /* Define to the one symbol short name of this package. */ 101 | #undef PACKAGE_TARNAME 102 | 103 | /* Define to the home page for this package. */ 104 | #undef PACKAGE_URL 105 | 106 | /* Define to the version of this package. */ 107 | #undef PACKAGE_VERSION 108 | 109 | /* Define to 1 if you have the ANSI C header files. */ 110 | #undef STDC_HEADERS 111 | 112 | /* Define to 1 if /dev/urandom should be used for seeding the hash function */ 113 | #undef USE_URANDOM 114 | 115 | /* Define to 1 if CryptGenRandom should be used for seeding the hash function 116 | */ 117 | #undef USE_WINDOWS_CRYPTOAPI 118 | 119 | /* Version number of package */ 120 | #undef VERSION 121 | 122 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 123 | , or is not used. If the typedef were allowed, the 124 | #define below would cause a syntax error. */ 125 | #undef _UINT32_T 126 | 127 | /* Define to `__inline__' or `__inline' if that's what the C compiler 128 | calls it, or to nothing if 'inline' is not supported under any name. */ 129 | #ifndef __cplusplus 130 | #undef inline 131 | #endif 132 | 133 | /* Define to the type of a signed integer type of width exactly 32 bits if 134 | such a type exists and the standard includes do not define it. */ 135 | #undef int32_t 136 | 137 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 138 | such a type exists and the standard includes do not define it. */ 139 | #undef uint32_t 140 | -------------------------------------------------------------------------------- /compat/jansson/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * Copyright (c) 2011-2012 Basile Starynkevitch 4 | * 5 | * Jansson is free software; you can redistribute it and/or modify it 6 | * under the terms of the MIT license. See LICENSE for details. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include "jansson.h" 13 | #include "jansson_private.h" 14 | 15 | /* memory function pointers */ 16 | static json_malloc_t do_malloc = malloc; 17 | static json_free_t do_free = free; 18 | 19 | void *jsonp_malloc(size_t size) 20 | { 21 | if(!size) 22 | return NULL; 23 | 24 | return (*do_malloc)(size); 25 | } 26 | 27 | void jsonp_free(void *ptr) 28 | { 29 | if(!ptr) 30 | return; 31 | 32 | (*do_free)(ptr); 33 | } 34 | 35 | char *jsonp_strdup(const char *str) 36 | { 37 | char *new_str; 38 | size_t len; 39 | 40 | len = strlen(str); 41 | if(len == (size_t)-1) 42 | return NULL; 43 | 44 | new_str = jsonp_malloc(len + 1); 45 | if(!new_str) 46 | return NULL; 47 | 48 | memcpy(new_str, str, len + 1); 49 | return new_str; 50 | } 51 | 52 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) 53 | { 54 | do_malloc = malloc_fn; 55 | do_free = free_fn; 56 | } 57 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef _GNU_SOURCE 9 | #define _GNU_SOURCE 10 | #endif 11 | 12 | #include 13 | #include 14 | #include "jansson_private.h" 15 | #include "strbuffer.h" 16 | 17 | #define STRBUFFER_MIN_SIZE 16 18 | #define STRBUFFER_FACTOR 2 19 | #define STRBUFFER_SIZE_MAX ((size_t)-1) 20 | 21 | int strbuffer_init(strbuffer_t *strbuff) 22 | { 23 | strbuff->size = STRBUFFER_MIN_SIZE; 24 | strbuff->length = 0; 25 | 26 | strbuff->value = jsonp_malloc(strbuff->size); 27 | if(!strbuff->value) 28 | return -1; 29 | 30 | /* initialize to empty */ 31 | strbuff->value[0] = '\0'; 32 | return 0; 33 | } 34 | 35 | void strbuffer_close(strbuffer_t *strbuff) 36 | { 37 | if(strbuff->value) 38 | jsonp_free(strbuff->value); 39 | 40 | strbuff->size = 0; 41 | strbuff->length = 0; 42 | strbuff->value = NULL; 43 | } 44 | 45 | void strbuffer_clear(strbuffer_t *strbuff) 46 | { 47 | strbuff->length = 0; 48 | strbuff->value[0] = '\0'; 49 | } 50 | 51 | const char *strbuffer_value(const strbuffer_t *strbuff) 52 | { 53 | return strbuff->value; 54 | } 55 | 56 | char *strbuffer_steal_value(strbuffer_t *strbuff) 57 | { 58 | char *result = strbuff->value; 59 | strbuff->value = NULL; 60 | return result; 61 | } 62 | 63 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 64 | { 65 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 66 | } 67 | 68 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 69 | { 70 | return strbuffer_append_bytes(strbuff, &byte, 1); 71 | } 72 | 73 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) 74 | { 75 | if(size >= strbuff->size - strbuff->length) 76 | { 77 | size_t new_size; 78 | char *new_value; 79 | 80 | /* avoid integer overflow */ 81 | if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR 82 | || size > STRBUFFER_SIZE_MAX - 1 83 | || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) 84 | return -1; 85 | 86 | new_size = max(strbuff->size * STRBUFFER_FACTOR, 87 | strbuff->length + size + 1); 88 | 89 | new_value = jsonp_malloc(new_size); 90 | if(!new_value) 91 | return -1; 92 | 93 | memcpy(new_value, strbuff->value, strbuff->length); 94 | 95 | jsonp_free(strbuff->value); 96 | strbuff->value = new_value; 97 | strbuff->size = new_size; 98 | } 99 | 100 | memcpy(strbuff->value + strbuff->length, data, size); 101 | strbuff->length += size; 102 | strbuff->value[strbuff->length] = '\0'; 103 | 104 | return 0; 105 | } 106 | 107 | char strbuffer_pop(strbuffer_t *strbuff) 108 | { 109 | if(strbuff->length > 0) { 110 | char c = strbuff->value[--strbuff->length]; 111 | strbuff->value[strbuff->length] = '\0'; 112 | return c; 113 | } 114 | else 115 | return '\0'; 116 | } 117 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | size_t length; /* bytes used */ 14 | size_t size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | 24 | /* Steal the value and close the strbuffer */ 25 | char *strbuffer_steal_value(strbuffer_t *strbuff); 26 | 27 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 28 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 29 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); 30 | 31 | char strbuffer_pop(strbuffer_t *strbuff); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /compat/jansson/strconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "jansson_private.h" 6 | #include "strbuffer.h" 7 | 8 | /* need jansson_private_config.h to get the correct snprintf */ 9 | #ifdef HAVE_CONFIG_H 10 | #include "jansson_private_config.h" 11 | #endif 12 | 13 | #if JSON_HAVE_LOCALECONV 14 | #include 15 | 16 | /* 17 | - This code assumes that the decimal separator is exactly one 18 | character. 19 | 20 | - If setlocale() is called by another thread between the call to 21 | localeconv() and the call to sprintf() or strtod(), the result may 22 | be wrong. setlocale() is not thread-safe and should not be used 23 | this way. Multi-threaded programs should use uselocale() instead. 24 | */ 25 | 26 | static void to_locale(strbuffer_t *strbuffer) 27 | { 28 | const char *point; 29 | char *pos; 30 | 31 | point = localeconv()->decimal_point; 32 | if(*point == '.') { 33 | /* No conversion needed */ 34 | return; 35 | } 36 | 37 | pos = strchr(strbuffer->value, '.'); 38 | if(pos) 39 | *pos = *point; 40 | } 41 | 42 | static void from_locale(char *buffer) 43 | { 44 | const char *point; 45 | char *pos; 46 | 47 | point = localeconv()->decimal_point; 48 | if(*point == '.') { 49 | /* No conversion needed */ 50 | return; 51 | } 52 | 53 | pos = strchr(buffer, *point); 54 | if(pos) 55 | *pos = '.'; 56 | } 57 | #endif 58 | 59 | int jsonp_strtod(strbuffer_t *strbuffer, double *out) 60 | { 61 | double value; 62 | char *end; 63 | 64 | #if JSON_HAVE_LOCALECONV 65 | to_locale(strbuffer); 66 | #endif 67 | 68 | errno = 0; 69 | value = strtod(strbuffer->value, &end); 70 | assert(end == strbuffer->value + strbuffer->length); 71 | 72 | if(errno == ERANGE && value != 0) { 73 | /* Overflow */ 74 | return -1; 75 | } 76 | 77 | *out = value; 78 | return 0; 79 | } 80 | 81 | int jsonp_dtostr(char *buffer, size_t size, double value) 82 | { 83 | int ret; 84 | char *start, *end; 85 | size_t length; 86 | 87 | ret = snprintf(buffer, size, "%.17g", value); 88 | if(ret < 0) 89 | return -1; 90 | 91 | length = (size_t)ret; 92 | if(length >= size) 93 | return -1; 94 | 95 | #if JSON_HAVE_LOCALECONV 96 | from_locale(buffer); 97 | #endif 98 | 99 | /* Make sure there's a dot or 'e' in the output. Otherwise 100 | a real is converted to an integer when decoding */ 101 | if(strchr(buffer, '.') == NULL && 102 | strchr(buffer, 'e') == NULL) 103 | { 104 | if(length + 3 >= size) { 105 | /* No space to append ".0" */ 106 | return -1; 107 | } 108 | buffer[length] = '.'; 109 | buffer[length + 1] = '0'; 110 | buffer[length + 2] = '\0'; 111 | length += 2; 112 | } 113 | 114 | /* Remove leading '+' from positive exponent. Also remove leading 115 | zeros from exponents (added by some printf() implementations) */ 116 | start = strchr(buffer, 'e'); 117 | if(start) { 118 | start++; 119 | end = start + 1; 120 | 121 | if(*start == '-') 122 | start++; 123 | 124 | while(*end == '0') 125 | end++; 126 | 127 | if(end != start) { 128 | memmove(start, end, length - (size_t)(end - buffer)); 129 | length -= (size_t)(end - start); 130 | } 131 | } 132 | 133 | return (int)length; 134 | } 135 | -------------------------------------------------------------------------------- /compat/jansson/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "utf.h" 10 | 11 | int utf8_encode(int32_t codepoint, char *buffer, int *size) 12 | { 13 | if(codepoint < 0) 14 | return -1; 15 | else if(codepoint < 0x80) 16 | { 17 | buffer[0] = (char)codepoint; 18 | *size = 1; 19 | } 20 | else if(codepoint < 0x800) 21 | { 22 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); 23 | buffer[1] = 0x80 + ((codepoint & 0x03F)); 24 | *size = 2; 25 | } 26 | else if(codepoint < 0x10000) 27 | { 28 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); 29 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); 30 | buffer[2] = 0x80 + ((codepoint & 0x003F)); 31 | *size = 3; 32 | } 33 | else if(codepoint <= 0x10FFFF) 34 | { 35 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); 36 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); 37 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); 38 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); 39 | *size = 4; 40 | } 41 | else 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int utf8_check_first(char byte) 48 | { 49 | unsigned char u = (unsigned char)byte; 50 | 51 | if(u < 0x80) 52 | return 1; 53 | 54 | if(0x80 <= u && u <= 0xBF) { 55 | /* second, third or fourth byte of a multi-byte 56 | sequence, i.e. a "continuation byte" */ 57 | return 0; 58 | } 59 | else if(u == 0xC0 || u == 0xC1) { 60 | /* overlong encoding of an ASCII byte */ 61 | return 0; 62 | } 63 | else if(0xC2 <= u && u <= 0xDF) { 64 | /* 2-byte sequence */ 65 | return 2; 66 | } 67 | 68 | else if(0xE0 <= u && u <= 0xEF) { 69 | /* 3-byte sequence */ 70 | return 3; 71 | } 72 | else if(0xF0 <= u && u <= 0xF4) { 73 | /* 4-byte sequence */ 74 | return 4; 75 | } 76 | else { /* u >= 0xF5 */ 77 | /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid 78 | UTF-8 */ 79 | return 0; 80 | } 81 | } 82 | 83 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint) 84 | { 85 | int i; 86 | int32_t value = 0; 87 | unsigned char u = (unsigned char)buffer[0]; 88 | 89 | if(size == 2) 90 | { 91 | value = u & 0x1F; 92 | } 93 | else if(size == 3) 94 | { 95 | value = u & 0xF; 96 | } 97 | else if(size == 4) 98 | { 99 | value = u & 0x7; 100 | } 101 | else 102 | return 0; 103 | 104 | for(i = 1; i < size; i++) 105 | { 106 | u = (unsigned char)buffer[i]; 107 | 108 | if(u < 0x80 || u > 0xBF) { 109 | /* not a continuation byte */ 110 | return 0; 111 | } 112 | 113 | value = (value << 6) + (u & 0x3F); 114 | } 115 | 116 | if(value > 0x10FFFF) { 117 | /* not in Unicode range */ 118 | return 0; 119 | } 120 | 121 | else if(0xD800 <= value && value <= 0xDFFF) { 122 | /* invalid code point (UTF-16 surrogate halves) */ 123 | return 0; 124 | } 125 | 126 | else if((size == 2 && value < 0x80) || 127 | (size == 3 && value < 0x800) || 128 | (size == 4 && value < 0x10000)) { 129 | /* overlong encoding */ 130 | return 0; 131 | } 132 | 133 | if(codepoint) 134 | *codepoint = value; 135 | 136 | return 1; 137 | } 138 | 139 | const char *utf8_iterate(const char *buffer, int32_t *codepoint) 140 | { 141 | int count; 142 | int32_t value; 143 | 144 | if(!*buffer) 145 | return buffer; 146 | 147 | count = utf8_check_first(buffer[0]); 148 | if(count <= 0) 149 | return NULL; 150 | 151 | if(count == 1) 152 | value = (unsigned char)buffer[0]; 153 | else 154 | { 155 | if(!utf8_check_full(buffer, count, &value)) 156 | return NULL; 157 | } 158 | 159 | if(codepoint) 160 | *codepoint = value; 161 | 162 | return buffer + count; 163 | } 164 | 165 | int utf8_check_string(const char *string, int length) 166 | { 167 | int i; 168 | 169 | if(length == -1) 170 | length = strlen(string); 171 | 172 | for(i = 0; i < length; i++) 173 | { 174 | int count = utf8_check_first(string[i]); 175 | if(count == 0) 176 | return 0; 177 | else if(count > 1) 178 | { 179 | if(i + count > length) 180 | return 0; 181 | 182 | if(!utf8_check_full(&string[i], count, NULL)) 183 | return 0; 184 | 185 | i += count - 1; 186 | } 187 | } 188 | 189 | return 1; 190 | } 191 | -------------------------------------------------------------------------------- /compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #ifdef HAVE_CONFIG_H 12 | #include "jansson_private_config.h" 13 | 14 | #ifdef HAVE_INTTYPES_H 15 | /* inttypes.h includes stdint.h in a standard environment, so there's 16 | no need to include stdint.h separately. If inttypes.h doesn't define 17 | int32_t, it's defined in config.h. */ 18 | #include 19 | #endif /* HAVE_INTTYPES_H */ 20 | 21 | #else /* !HAVE_CONFIG_H */ 22 | #ifdef _WIN32 23 | typedef int int32_t; 24 | #else /* !_WIN32 */ 25 | /* Assume a standard environment */ 26 | #include 27 | #endif /* _WIN32 */ 28 | 29 | #endif /* HAVE_CONFIG_H */ 30 | 31 | int utf8_encode(int codepoint, char *buffer, int *size); 32 | 33 | int utf8_check_first(char byte); 34 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 35 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 36 | 37 | int utf8_check_string(const char *string, int length); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /compat/jansson/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTIL_H 9 | #define UTIL_H 10 | 11 | #ifndef max 12 | #define max(a, b) ((a) > (b) ? (a) : (b)) 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /compat/nvapi/NVAPI.url: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=https://developer.nvidia.com/nvapi 3 | -------------------------------------------------------------------------------- /compat/nvapi/amd64/nvapi64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/amd64/nvapi64.lib -------------------------------------------------------------------------------- /compat/nvapi/nvShaderExtnEnums.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | ////////////////////////// NVIDIA SHADER EXTENSIONS //////////////////////////// 3 | //////////////////////////////////////////////////////////////////////////////// 4 | 5 | // This file can be included both from HLSL shader code as well as C++ code. 6 | // The app should call NvAPI_D3D_IsNvShaderExtnOpCodeSupported() to 7 | // check for support for every nv shader extension opcode it plans to use 8 | 9 | 10 | 11 | //----------------------------------------------------------------------------// 12 | //---------------------------- NV Shader Extn Version -----------------------// 13 | //----------------------------------------------------------------------------// 14 | #define NV_SHADER_EXTN_VERSION 1 15 | 16 | //----------------------------------------------------------------------------// 17 | //---------------------------- Misc constants --------------------------------// 18 | //----------------------------------------------------------------------------// 19 | #define NV_WARP_SIZE 32 20 | 21 | 22 | //----------------------------------------------------------------------------// 23 | //---------------------------- opCode constants ------------------------------// 24 | //----------------------------------------------------------------------------// 25 | 26 | 27 | #define NV_EXTN_OP_SHFL 1 28 | #define NV_EXTN_OP_SHFL_UP 2 29 | #define NV_EXTN_OP_SHFL_DOWN 3 30 | #define NV_EXTN_OP_SHFL_XOR 4 31 | 32 | #define NV_EXTN_OP_VOTE_ALL 5 33 | #define NV_EXTN_OP_VOTE_ANY 6 34 | #define NV_EXTN_OP_VOTE_BALLOT 7 35 | 36 | #define NV_EXTN_OP_GET_LANE_ID 8 37 | #define NV_EXTN_OP_FP16_ATOMIC 12 38 | #define NV_EXTN_OP_FP32_ATOMIC 13 39 | -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_common.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_d3dext.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_d3dext.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_salend.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_salend.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_salstart.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_salstart.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_sli.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_sli.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_stereo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_stereo.h -------------------------------------------------------------------------------- /compat/nvapi/nvapi_lite_surround.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/nvapi_lite_surround.h -------------------------------------------------------------------------------- /compat/nvapi/x86/nvapi.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/nvapi/x86/nvapi.lib -------------------------------------------------------------------------------- /compat/pthreads/sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Module: sched.h 3 | * 4 | * Purpose: 5 | * Provides an implementation of POSIX realtime extensions 6 | * as defined in 7 | * 8 | * POSIX 1003.1b-1993 (POSIX.1b) 9 | * 10 | * -------------------------------------------------------------------------- 11 | * 12 | * Pthreads-win32 - POSIX Threads Library for Win32 13 | * Copyright(C) 1998 John E. Bossom 14 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 15 | * 16 | * Contact Email: rpj@callisto.canberra.edu.au 17 | * 18 | * The current list of contributors is contained 19 | * in the file CONTRIBUTORS included with the source 20 | * code distribution. The list can also be seen at the 21 | * following World Wide Web location: 22 | * http://sources.redhat.com/pthreads-win32/contributors.html 23 | * 24 | * This library is free software; you can redistribute it and/or 25 | * modify it under the terms of the GNU Lesser General Public 26 | * License as published by the Free Software Foundation; either 27 | * version 2 of the License, or (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | * Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public 35 | * License along with this library in the file COPYING.LIB; 36 | * if not, write to the Free Software Foundation, Inc., 37 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 38 | */ 39 | #if !defined(_SCHED_H) 40 | #define _SCHED_H 41 | 42 | #undef PTW32_SCHED_LEVEL 43 | 44 | #if defined(_POSIX_SOURCE) 45 | #define PTW32_SCHED_LEVEL 0 46 | /* Early POSIX */ 47 | #endif 48 | 49 | #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309 50 | #undef PTW32_SCHED_LEVEL 51 | #define PTW32_SCHED_LEVEL 1 52 | /* Include 1b, 1c and 1d */ 53 | #endif 54 | 55 | #if defined(INCLUDE_NP) 56 | #undef PTW32_SCHED_LEVEL 57 | #define PTW32_SCHED_LEVEL 2 58 | /* Include Non-Portable extensions */ 59 | #endif 60 | 61 | #define PTW32_SCHED_LEVEL_MAX 3 62 | 63 | #if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_SCHED_LEVEL) 64 | #define PTW32_SCHED_LEVEL PTW32_SCHED_LEVEL_MAX 65 | /* Include everything */ 66 | #endif 67 | 68 | 69 | #if defined(__GNUC__) && !defined(__declspec) 70 | # error Please upgrade your GNU compiler to one that supports __declspec. 71 | #endif 72 | 73 | /* 74 | * When building the library, you should define PTW32_BUILD so that 75 | * the variables/functions are exported correctly. When using the library, 76 | * do NOT define PTW32_BUILD, and then the variables/functions will 77 | * be imported correctly. 78 | */ 79 | #if !defined(PTW32_STATIC_LIB) 80 | # if defined(PTW32_BUILD) 81 | # define PTW32_DLLPORT __declspec (dllexport) 82 | # else 83 | # define PTW32_DLLPORT __declspec (dllimport) 84 | # endif 85 | #else 86 | # define PTW32_DLLPORT 87 | #endif 88 | 89 | /* 90 | * This is a duplicate of what is in the autoconf config.h, 91 | * which is only used when building the pthread-win32 libraries. 92 | */ 93 | 94 | #if !defined(PTW32_CONFIG_H) 95 | # if defined(WINCE) 96 | # define NEED_ERRNO 97 | # define NEED_SEM 98 | # endif 99 | # if defined(__MINGW64__) 100 | # define HAVE_STRUCT_TIMESPEC 101 | # define HAVE_MODE_T 102 | # elif defined(_UWIN) || defined(__MINGW32__) 103 | # define HAVE_MODE_T 104 | # endif 105 | #endif 106 | 107 | /* 108 | * 109 | */ 110 | 111 | #if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX 112 | #if defined(NEED_ERRNO) 113 | #include "need_errno.h" 114 | #else 115 | #include 116 | #endif 117 | #endif /* PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX */ 118 | 119 | #if (defined(__MINGW64__) || defined(__MINGW32__)) || defined(_UWIN) 120 | # if PTW32_SCHED_LEVEL >= PTW32_SCHED_LEVEL_MAX 121 | /* For pid_t */ 122 | # include 123 | /* Required by Unix 98 */ 124 | # include 125 | # else 126 | typedef int pid_t; 127 | # endif 128 | #else 129 | typedef int pid_t; 130 | #endif 131 | 132 | /* Thread scheduling policies */ 133 | 134 | enum { 135 | SCHED_OTHER = 0, 136 | SCHED_FIFO, 137 | SCHED_RR, 138 | SCHED_MIN = SCHED_OTHER, 139 | SCHED_MAX = SCHED_RR 140 | }; 141 | 142 | struct sched_param { 143 | int sched_priority; 144 | }; 145 | 146 | #if defined(__cplusplus) 147 | extern "C" 148 | { 149 | #endif /* __cplusplus */ 150 | 151 | PTW32_DLLPORT int __cdecl sched_yield (void); 152 | 153 | PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy); 154 | 155 | PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy); 156 | 157 | PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy); 158 | 159 | PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid); 160 | 161 | /* 162 | * Note that this macro returns ENOTSUP rather than 163 | * ENOSYS as might be expected. However, returning ENOSYS 164 | * should mean that sched_get_priority_{min,max} are 165 | * not implemented as well as sched_rr_get_interval. 166 | * This is not the case, since we just don't support 167 | * round-robin scheduling. Therefore I have chosen to 168 | * return the same value as sched_setscheduler when 169 | * SCHED_RR is passed to it. 170 | */ 171 | #define sched_rr_get_interval(_pid, _interval) \ 172 | ( errno = ENOTSUP, (int) -1 ) 173 | 174 | 175 | #if defined(__cplusplus) 176 | } /* End of extern "C" */ 177 | #endif /* __cplusplus */ 178 | 179 | #undef PTW32_SCHED_LEVEL 180 | #undef PTW32_SCHED_LEVEL_MAX 181 | 182 | #endif /* !_SCHED_H */ 183 | 184 | -------------------------------------------------------------------------------- /compat/pthreads/x64/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/pthreads/x64/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/pthreads/x86/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/pthreads/x86/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/pthreads/x86/pthreadVC2.libkernel32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/compat/pthreads/x86/pthreadVC2.libkernel32.lib -------------------------------------------------------------------------------- /compat/stdbool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define false 0 4 | #define true 1 5 | 6 | #define bool int 7 | -------------------------------------------------------------------------------- /compat/sys/time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef __cplusplus 3 | extern "C" 4 | { 5 | #endif 6 | int gettimeofday(struct timeval *tv, struct timezone *tz); 7 | void usleep(__int64 usec); 8 | #ifdef __cplusplus 9 | } 10 | #endif 11 | typedef __int64 useconds_t; 12 | -------------------------------------------------------------------------------- /compat/unistd.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "getopt/getopt.h" -------------------------------------------------------------------------------- /compat/winansi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ANSI emulation wrappers 3 | */ 4 | #ifdef WIN32 5 | #include 6 | #include 7 | #include 8 | 9 | #define isatty(fd) _isatty(fd) 10 | #define fileno(fd) _fileno(fd) 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | int winansi_fputs(const char *str, FILE *stream); 16 | int winansi_printf(const char *format, ...); 17 | int winansi_fprintf(FILE *stream, const char *format, ...); 18 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #undef fputs 24 | #undef fprintf 25 | #undef vfprintf 26 | 27 | #define fputs winansi_fputs 28 | #define printf winansi_printf 29 | #define fprintf winansi_fprintf 30 | #define vfprintf winansi_vfprintf 31 | 32 | #endif -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([ccminer], [krnlx-xevan], [], [ccminer], [https://github.com/alexis78/ccminer]) 2 | 3 | AC_PREREQ([2.59c]) 4 | AC_CANONICAL_SYSTEM 5 | AC_CONFIG_SRCDIR([ccminer.cpp]) 6 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 7 | AC_CONFIG_HEADERS([cpuminer-config.h]) 8 | 9 | dnl Make sure anyone changing configure.ac/Makefile.am has a clue 10 | AM_MAINTAINER_MODE 11 | 12 | dnl Checks for programs 13 | AC_PROG_CC_C99 14 | AC_PROG_GCC_TRADITIONAL 15 | AM_PROG_CC_C_O 16 | AM_PROG_AS 17 | AC_PROG_RANLIB 18 | AC_PROG_CXX 19 | AC_OPENMP 20 | 21 | dnl Checks for header files 22 | AC_HEADER_STDC 23 | AC_CHECK_HEADERS([sys/endian.h sys/param.h syslog.h]) 24 | # sys/sysctl.h requires sys/types.h on FreeBSD 25 | # sys/sysctl.h requires sys/param.h on OpenBSD 26 | AC_CHECK_HEADERS([sys/sysctl.h], [], [], 27 | [#include 28 | #ifdef HAVE_SYS_PARAM_H 29 | #include 30 | #endif 31 | ]) 32 | 33 | AC_CHECK_DECLS([be32dec, le32dec, be32enc, le32enc], [], [], 34 | [AC_INCLUDES_DEFAULT 35 | #ifdef HAVE_SYS_ENDIAN_H 36 | #include 37 | #endif 38 | ]) 39 | 40 | AC_FUNC_ALLOCA 41 | AC_CHECK_FUNCS([getopt_long]) 42 | 43 | case $target in 44 | i*86-*-*) 45 | have_x86=true 46 | ;; 47 | x86_64-*-*) 48 | have_x86=true 49 | have_x86_64=true 50 | ;; 51 | amd64-*-*) 52 | have_x86=true 53 | have_x86_64=true 54 | ;; 55 | esac 56 | 57 | PTHREAD_FLAGS="-pthread" 58 | WS2_LIBS="" 59 | 60 | case $target in 61 | *-*-mingw*) 62 | have_win32=true 63 | PTHREAD_FLAGS="" 64 | WS2_LIBS="-lws2_32" 65 | ;; 66 | esac 67 | 68 | AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) 69 | AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread", 70 | AC_CHECK_LIB([pthreadGC2], [pthread_create], PTHREAD_LIBS="-lpthreadGC2", 71 | AC_CHECK_LIB([pthreadGC1], [pthread_create], PTHREAD_LIBS="-lpthreadGC1", 72 | AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC" 73 | )))) 74 | 75 | AC_CHECK_LIB([z],[gzopen], [], []) 76 | AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])]) 77 | AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])]) 78 | 79 | # libpci-dev (to get vendor name) 80 | PCILIB=""; PCIFLAGS="" 81 | AC_CHECK_LIB([pci],[pci_alloc], PCILIB="-lpci"; PCIFLAGS="-DHAVE_PCIDEV", []) 82 | AC_SUBST(PCILIB) 83 | AC_SUBST(PCIFLAGS) 84 | 85 | AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) 86 | AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) 87 | AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue]) 88 | AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) 89 | 90 | if test x$request_jansson = xtrue 91 | then 92 | JANSSON_LIBS="compat/jansson/libjansson.a" 93 | else 94 | JANSSON_LIBS=-ljansson 95 | fi 96 | 97 | LIBCURL_CHECK_CONFIG(, 7.15.2, , 98 | [AC_MSG_ERROR([Missing required libcurl >= 7.15.2])]) 99 | 100 | AC_SUBST(JANSSON_LIBS) 101 | AC_SUBST(PTHREAD_FLAGS) 102 | AC_SUBST(PTHREAD_LIBS) 103 | AC_SUBST(WS2_LIBS) 104 | 105 | AC_CONFIG_FILES([ 106 | Makefile 107 | compat/Makefile 108 | compat/jansson/Makefile 109 | ]) 110 | 111 | dnl find out what version we are running 112 | ARCH=`uname -m` 113 | if [[ $ARCH == "x86_64" ]]; 114 | then 115 | SUFFIX="64" 116 | else 117 | SUFFIX="" 118 | fi 119 | 120 | dnl Setup CUDA paths 121 | AC_ARG_WITH([cuda], 122 | [ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]]) 123 | 124 | AC_ARG_WITH([nvml], 125 | [ --with-nvml=PATH prefix where libnvml is installed [default=/usr/lib]]) 126 | 127 | AM_CONDITIONAL([HAVE_NVML], [test -n "$with_nvml"]) 128 | 129 | NVCC="nvcc" 130 | 131 | if test -n "$with_cuda" ; then 132 | CUDA_INCLUDES="-I$with_cuda/include" 133 | CUDA_LIBS="-lcudart" 134 | CUDA_LDFLAGS="-L$with_cuda/lib$SUFFIX" 135 | if test -x "$with_cuda/bin/nvcc" ; then 136 | NVCC="$with_cuda/bin/nvcc" 137 | fi 138 | else 139 | CUDA_INCLUDES="-I/usr/local/cuda/include" 140 | CUDA_LIBS="-lcudart -static-libstdc++" 141 | CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX" 142 | fi 143 | 144 | if test -n "$with_nvml" ; then 145 | NVML_LIBPATH=$with_nvml 146 | CUDA_LDFLAGS="$CUDA_LDFLAGS -ldl" 147 | fi 148 | AC_SUBST(NVML_LIBPATH) 149 | 150 | AC_SUBST(CUDA_CFLAGS) 151 | AC_SUBST(CUDA_INCLUDES) 152 | AC_SUBST(CUDA_LIBS) 153 | AC_SUBST(CUDA_LDFLAGS) 154 | AC_SUBST(NVCC) 155 | 156 | AC_SUBST(OPENMP_CFLAGS) 157 | 158 | AC_OUTPUT 159 | -------------------------------------------------------------------------------- /configure.sh: -------------------------------------------------------------------------------- 1 | # possible additional CUDA_CFLAGS 2 | #-gencode=arch=compute_52,code=\"sm_52,compute_52\" 3 | #-gencode=arch=compute_50,code=\"sm_50,compute_50\" 4 | #-gencode=arch=compute_35,code=\"sm_35,compute_35\" 5 | #-gencode=arch=compute_30,code=\"sm_30,compute_30\" 6 | 7 | #--ptxas-options=\"-v -dlcm=cg\"" 8 | 9 | extracflags="-march=native -D_REENTRANT -falign-functions=16 -falign-jumps=16 -falign-labels=16" 10 | 11 | CUDA_CFLAGS="-O3 -lineno -Xcompiler -Wall -D_FORCE_INLINES" ./configure CXXFLAGS="-O3 $extracflags" --with-cuda=/usr/local/cuda-7.5 --with-nvml=libnvidia-ml.so 12 | 13 | -------------------------------------------------------------------------------- /cpuminer-config.h.in: -------------------------------------------------------------------------------- 1 | /* cpuminer-config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 4 | systems. This function is required for `alloca.c' support on those systems. 5 | */ 6 | #undef CRAY_STACKSEG_END 7 | 8 | /* Define to 1 if using `alloca.c'. */ 9 | #undef C_ALLOCA 10 | 11 | /* Define to 1 if you have `alloca', as a function or macro. */ 12 | #undef HAVE_ALLOCA 13 | 14 | /* Define to 1 if you have and it should be used (not on Ultrix). 15 | */ 16 | #undef HAVE_ALLOCA_H 17 | 18 | /* Define to 1 if you have the declaration of `be32dec', and to 0 if you 19 | don't. */ 20 | #undef HAVE_DECL_BE32DEC 21 | 22 | /* Define to 1 if you have the declaration of `be32enc', and to 0 if you 23 | don't. */ 24 | #undef HAVE_DECL_BE32ENC 25 | 26 | /* Define to 1 if you have the declaration of `le32dec', and to 0 if you 27 | don't. */ 28 | #undef HAVE_DECL_LE32DEC 29 | 30 | /* Define to 1 if you have the declaration of `le32enc', and to 0 if you 31 | don't. */ 32 | #undef HAVE_DECL_LE32ENC 33 | 34 | /* Define to 1 if you have the `getopt_long' function. */ 35 | #undef HAVE_GETOPT_LONG 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #undef HAVE_INTTYPES_H 39 | 40 | /* Define to 1 if you have the `crypto' library (-lcrypto). */ 41 | #undef HAVE_LIBCRYPTO 42 | 43 | /* Define to 1 if you have a functional curl library. */ 44 | #undef HAVE_LIBCURL 45 | 46 | /* Define to 1 if you have the `ssl' library (-lssl). */ 47 | #undef HAVE_LIBSSL 48 | 49 | /* Define to 1 if you have the `z' library (-lz). */ 50 | #undef HAVE_LIBZ 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #undef HAVE_MEMORY_H 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_STDINT_H 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #undef HAVE_STDLIB_H 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #undef HAVE_STRINGS_H 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #undef HAVE_STRING_H 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #undef HAVE_SYSLOG_H 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #undef HAVE_SYS_ENDIAN_H 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #undef HAVE_SYS_PARAM_H 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #undef HAVE_SYS_STAT_H 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #undef HAVE_SYS_SYSCTL_H 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #undef HAVE_SYS_TYPES_H 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #undef HAVE_UNISTD_H 87 | 88 | /* Defined if libcurl supports AsynchDNS */ 89 | #undef LIBCURL_FEATURE_ASYNCHDNS 90 | 91 | /* Defined if libcurl supports IDN */ 92 | #undef LIBCURL_FEATURE_IDN 93 | 94 | /* Defined if libcurl supports IPv6 */ 95 | #undef LIBCURL_FEATURE_IPV6 96 | 97 | /* Defined if libcurl supports KRB4 */ 98 | #undef LIBCURL_FEATURE_KRB4 99 | 100 | /* Defined if libcurl supports libz */ 101 | #undef LIBCURL_FEATURE_LIBZ 102 | 103 | /* Defined if libcurl supports NTLM */ 104 | #undef LIBCURL_FEATURE_NTLM 105 | 106 | /* Defined if libcurl supports SSL */ 107 | #undef LIBCURL_FEATURE_SSL 108 | 109 | /* Defined if libcurl supports SSPI */ 110 | #undef LIBCURL_FEATURE_SSPI 111 | 112 | /* Defined if libcurl supports DICT */ 113 | #undef LIBCURL_PROTOCOL_DICT 114 | 115 | /* Defined if libcurl supports FILE */ 116 | #undef LIBCURL_PROTOCOL_FILE 117 | 118 | /* Defined if libcurl supports FTP */ 119 | #undef LIBCURL_PROTOCOL_FTP 120 | 121 | /* Defined if libcurl supports FTPS */ 122 | #undef LIBCURL_PROTOCOL_FTPS 123 | 124 | /* Defined if libcurl supports HTTP */ 125 | #undef LIBCURL_PROTOCOL_HTTP 126 | 127 | /* Defined if libcurl supports HTTPS */ 128 | #undef LIBCURL_PROTOCOL_HTTPS 129 | 130 | /* Defined if libcurl supports IMAP */ 131 | #undef LIBCURL_PROTOCOL_IMAP 132 | 133 | /* Defined if libcurl supports LDAP */ 134 | #undef LIBCURL_PROTOCOL_LDAP 135 | 136 | /* Defined if libcurl supports POP3 */ 137 | #undef LIBCURL_PROTOCOL_POP3 138 | 139 | /* Defined if libcurl supports RTSP */ 140 | #undef LIBCURL_PROTOCOL_RTSP 141 | 142 | /* Defined if libcurl supports SMTP */ 143 | #undef LIBCURL_PROTOCOL_SMTP 144 | 145 | /* Defined if libcurl supports TELNET */ 146 | #undef LIBCURL_PROTOCOL_TELNET 147 | 148 | /* Defined if libcurl supports TFTP */ 149 | #undef LIBCURL_PROTOCOL_TFTP 150 | 151 | /* Name of package */ 152 | #undef PACKAGE 153 | 154 | /* Define to the address where bug reports for this package should be sent. */ 155 | #undef PACKAGE_BUGREPORT 156 | 157 | /* Define to the full name of this package. */ 158 | #undef PACKAGE_NAME 159 | 160 | /* Define to the full name and version of this package. */ 161 | #undef PACKAGE_STRING 162 | 163 | /* Define to the one symbol short name of this package. */ 164 | #undef PACKAGE_TARNAME 165 | 166 | /* Define to the home page for this package. */ 167 | #undef PACKAGE_URL 168 | 169 | /* Define to the version of this package. */ 170 | #undef PACKAGE_VERSION 171 | 172 | /* If using the C implementation of alloca, define if you know the 173 | direction of stack growth for your system; otherwise it will be 174 | automatically deduced at runtime. 175 | STACK_DIRECTION > 0 => grows toward higher addresses 176 | STACK_DIRECTION < 0 => grows toward lower addresses 177 | STACK_DIRECTION = 0 => direction of growth unknown */ 178 | #undef STACK_DIRECTION 179 | 180 | /* Define to 1 if you have the ANSI C header files. */ 181 | #undef STDC_HEADERS 182 | 183 | /* Version number of package */ 184 | #undef VERSION 185 | 186 | /* Define curl_free() as free() if our version of curl lacks curl_free. */ 187 | #undef curl_free 188 | 189 | /* Define to `unsigned int' if does not define. */ 190 | #undef size_t 191 | -------------------------------------------------------------------------------- /crc32.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or 3 | * code or tables extracted from it, as desired without restriction. 4 | * 5 | * First, the polynomial itself and its table of feedback terms. The 6 | * polynomial is 7 | * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 8 | * 9 | * Note that we take it "backwards" and put the highest-order term in 10 | * the lowest-order bit. The X^32 term is "implied"; the LSB is the 11 | * X^31 term, etc. The X^0 term (usually shown as "+1") results in 12 | * the MSB being 1 13 | * 14 | * Note that the usual hardware shift register implementation, which 15 | * is what we're using (we're merely optimizing it by doing eight-bit 16 | * chunks at a time) shifts bits into the lowest-order term. In our 17 | * implementation, that means shifting towards the right. Why do we 18 | * do it this way? Because the calculated CRC must be transmitted in 19 | * order from highest-order term to lowest-order term. UARTs transmit 20 | * characters in order from LSB to MSB. By storing the CRC this way 21 | * we hand it to the UART in the order low-byte to high-byte; the UART 22 | * sends each low-bit to hight-bit; and the result is transmission bit 23 | * by bit from highest- to lowest-order term without requiring any bit 24 | * shuffling on our part. Reception works similarly 25 | * 26 | * The feedback terms table consists of 256, 32-bit entries. Notes 27 | * 28 | * The table can be generated at runtime if desired; code to do so 29 | * is shown later. It might not be obvious, but the feedback 30 | * terms simply represent the results of eight shift/xor opera 31 | * tions for all combinations of data and CRC register values 32 | * 33 | * The values must be right-shifted by eight bits by the "updcrc 34 | * logic; the shift must be unsigned (bring in zeroes). On some 35 | * hardware you could probably optimize the shift in assembler by 36 | * using byte-swap instructions 37 | * polynomial $edb88320 38 | * 39 | * 40 | * CRC32 code derived from work by Gary S. Brown. 41 | */ 42 | 43 | #include 44 | #include 45 | 46 | static uint32_t crc32_tab[] = { 47 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 48 | 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 49 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 50 | 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 51 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 52 | 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 53 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 54 | 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 55 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 56 | 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 57 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 58 | 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 59 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 60 | 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 61 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 62 | 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 63 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 64 | 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 65 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 66 | 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 67 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 68 | 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 69 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 70 | 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 71 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 72 | 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 73 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 74 | 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 75 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 76 | 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 77 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 78 | 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 79 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 80 | 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 81 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 82 | 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 83 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 84 | 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 85 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 86 | 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 87 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 88 | 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 89 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 90 | }; 91 | 92 | /* Real CRC32 Function */ 93 | extern uint32_t crc32(uint32_t crc, const void *buf, size_t size) 94 | { 95 | const uint8_t *p; 96 | 97 | p = buf; 98 | crc = crc ^ ~0U; 99 | 100 | while (size--) 101 | crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 102 | 103 | return crc ^ ~0U; 104 | } 105 | 106 | /* CRC32 Function simplified for ccminer */ 107 | extern uint32_t crc32_u32t(const uint32_t *buf, size_t size) 108 | { 109 | const uint8_t *p; 110 | uint32_t crc = 0; 111 | 112 | p = (uint8_t *) buf; 113 | crc = crc ^ ~0U; 114 | 115 | while (size--) 116 | crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); 117 | 118 | return crc ^ ~0U; 119 | } 120 | -------------------------------------------------------------------------------- /cuda_debug.cuh: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper to trace gpu computed data with --cputest 3 | * 4 | * Sample usage in an algo scan cuda unit : 5 | * 6 | * #define _DEBUG 7 | * #define _DEBUG_PREFIX "x11-" 8 | * #include "cuda_debug.cuh" 9 | * 10 | * TRACE64("luffa", d_hash); 11 | * or 12 | * TRACE("luffa") 13 | * 14 | * Dont forget to link the scan function in util.cpp (do_gpu_tests) 15 | * 16 | */ 17 | 18 | #include 19 | //#include "cuda_helper.h" 20 | 21 | #ifndef _DEBUG_PREFIX 22 | #define _DEBUG_PREFIX "" 23 | #endif 24 | 25 | #ifdef _DEBUG 26 | #define TRACE64(algo, d_buf) { \ 27 | if (max_nonce == 1 && pdata[19] <= 1 && !opt_benchmark) { \ 28 | uint32_t oft = 0; \ 29 | uint32_t* debugbuf = NULL; \ 30 | cudaMallocHost(&debugbuf, 16*sizeof(uint32_t)); \ 31 | cudaMemcpy(debugbuf, d_buf[thr_id] + oft, 16*sizeof(uint32_t), cudaMemcpyDeviceToHost); \ 32 | printf(_DEBUG_PREFIX "%s %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", \ 33 | algo, \ 34 | swab32(debugbuf[0]), swab32(debugbuf[1]), swab32(debugbuf[2]), swab32(debugbuf[3]), \ 35 | swab32(debugbuf[4]), swab32(debugbuf[5]), swab32(debugbuf[6]), swab32(debugbuf[7]), \ 36 | swab32(debugbuf[8]), swab32(debugbuf[9]), swab32(debugbuf[10]),swab32(debugbuf[11]), \ 37 | swab32(debugbuf[12]),swab32(debugbuf[13]),swab32(debugbuf[14]),swab32(debugbuf[15])); \ 38 | cudaFreeHost(debugbuf); \ 39 | } \ 40 | } 41 | #else 42 | #define TRACE64(algo, d_buf) {} 43 | #endif 44 | 45 | // simplified default 46 | #define TRACE(algo) TRACE64(algo, d_hash) 47 | 48 | -------------------------------------------------------------------------------- /cuda_helper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/cuda_helper.h -------------------------------------------------------------------------------- /lyra2/Lyra2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Header file for the Lyra2 Password Hashing Scheme (PHS). 3 | * 4 | * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014. 5 | * 6 | * This software is hereby placed in the public domain. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 9 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 12 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 15 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 16 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 17 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 18 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | #ifndef LYRA2_H_ 21 | #define LYRA2_H_ 22 | 23 | #include 24 | 25 | typedef unsigned char byte; 26 | 27 | //Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED) 28 | #define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t) 29 | #define BLOCK_LEN_BLAKE2_SAFE_BYTES (BLOCK_LEN_BLAKE2_SAFE_INT64 * 8) //same as above, in bytes 30 | 31 | 32 | #ifdef BLOCK_LEN_BITS 33 | #define BLOCK_LEN_INT64 (BLOCK_LEN_BITS/64) //Block length: 768 bits (=96 bytes, =12 uint64_t) 34 | #define BLOCK_LEN_BYTES (BLOCK_LEN_BITS/8) //Block length, in bytes 35 | #else //default block lenght: 768 bits 36 | #define BLOCK_LEN_INT64 12 //Block length: 768 bits (=96 bytes, =12 uint64_t) 37 | #define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes 38 | #endif 39 | 40 | int LYRA2(void *K, int64_t kLen, const void *pwd, int32_t pwdlen, const void *salt, int32_t saltlen, int64_t timeCost, const int16_t nRows, const int16_t nCols); 41 | 42 | #endif /* LYRA2_H_ */ 43 | -------------------------------------------------------------------------------- /lyra2/Sponge.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Header file for Blake2b's internal permutation in the form of a sponge. 3 | * This code is based on the original Blake2b's implementation provided by 4 | * Samuel Neves (https://blake2.net/) 5 | * 6 | * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014. 7 | * 8 | * This software is hereby placed in the public domain. 9 | * 10 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 11 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 12 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 14 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 16 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 17 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 18 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 19 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 20 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | #ifndef SPONGE_H_ 23 | #define SPONGE_H_ 24 | 25 | #include 26 | 27 | /* Blake2b IV Array */ 28 | static const uint64_t blake2b_IV[8] = 29 | { 30 | 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 31 | 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 32 | 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 33 | 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL 34 | }; 35 | 36 | /* Blake2b's rotation */ 37 | static __inline uint64_t rotr64(const uint64_t w, const unsigned c) { 38 | #ifdef _MSC_VER 39 | return _rotr64(w, c); 40 | #else 41 | return ( w >> c ) | ( w << ( 64 - c ) ); 42 | #endif 43 | } 44 | 45 | /* Blake2b's G function */ 46 | #define G(r,i,a,b,c,d) do { \ 47 | a = a + b; \ 48 | d = rotr64(d ^ a, 32); \ 49 | c = c + d; \ 50 | b = rotr64(b ^ c, 24); \ 51 | a = a + b; \ 52 | d = rotr64(d ^ a, 16); \ 53 | c = c + d; \ 54 | b = rotr64(b ^ c, 63); \ 55 | } while(0) 56 | 57 | 58 | /*One Round of the Blake2b's compression function*/ 59 | #define ROUND_LYRA(r) \ 60 | G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ 61 | G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ 62 | G(r,2,v[ 2],v[ 6],v[10],v[14]); \ 63 | G(r,3,v[ 3],v[ 7],v[11],v[15]); \ 64 | G(r,4,v[ 0],v[ 5],v[10],v[15]); \ 65 | G(r,5,v[ 1],v[ 6],v[11],v[12]); \ 66 | G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ 67 | G(r,7,v[ 3],v[ 4],v[ 9],v[14]); 68 | 69 | //---- Housekeeping 70 | void initState(uint64_t state[/*16*/]); 71 | 72 | //---- Squeezes 73 | void squeeze(uint64_t *state, unsigned char *out, unsigned int len); 74 | void reducedSqueezeRow0(uint64_t* state, uint64_t* row, const uint32_t nCols); 75 | 76 | //---- Absorbs 77 | void absorbBlock(uint64_t *state, const uint64_t *in); 78 | void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in); 79 | 80 | //---- Duplexes 81 | void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, const uint32_t nCols); 82 | void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols); 83 | void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols); 84 | 85 | //---- Misc 86 | void printArray(unsigned char *array, unsigned int size, char *name); 87 | 88 | #endif /* SPONGE_H_ */ 89 | -------------------------------------------------------------------------------- /myriadgroestl.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sph/sph_groestl.h" 7 | 8 | #include "miner.h" 9 | #include "cuda_helper.h" 10 | 11 | #define NBN 2 12 | //#define NPT 2 13 | 14 | static uint32_t *d_resNonce[MAX_GPUS]; 15 | static uint32_t *h_resNonce[MAX_GPUS]; 16 | 17 | void myriadgroestl_cpu_init(int thr_id, uint32_t threads); 18 | void myriadgroestl_cpu_free(int thr_id); 19 | void myriadgroestl_cpu_setBlock(int thr_id, void *data); 20 | void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_resNounce, const uint64_t target); 21 | 22 | void myriadhash(void *state, const void *input) 23 | { 24 | uint32_t _ALIGN(64) hash[16]; 25 | sph_groestl512_context ctx_groestl; 26 | SHA256_CTX sha256; 27 | 28 | sph_groestl512_init(&ctx_groestl); 29 | sph_groestl512(&ctx_groestl, input, 80); 30 | sph_groestl512_close(&ctx_groestl, hash); 31 | 32 | SHA256_Init(&sha256); 33 | SHA256_Update(&sha256,(unsigned char *)hash, 64); 34 | SHA256_Final((unsigned char *)hash, &sha256); 35 | 36 | memcpy(state, hash, 32); 37 | } 38 | 39 | static bool init[MAX_GPUS] = { 0 }; 40 | 41 | int scanhash_myriad(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done) 42 | { 43 | uint32_t _ALIGN(64) endiandata[32]; 44 | uint32_t *pdata = work->data; 45 | uint32_t *ptarget = work->target; 46 | uint32_t first_nonce = pdata[19]; 47 | int dev_id = device_map[thr_id]; 48 | int intensity = 23;//(device_sm[dev_id] >= 600) ? 20 : 18; 49 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); 50 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 51 | 52 | if (opt_benchmark) 53 | ptarget[7] = 0x00000000; 54 | 55 | // init 56 | if(!init[thr_id]) 57 | { 58 | cudaSetDevice(dev_id); 59 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 60 | cudaDeviceReset(); 61 | // reduce cpu usage 62 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 63 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 64 | CUDA_LOG_ERROR(); 65 | } 66 | 67 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 68 | 69 | myriadgroestl_cpu_init(thr_id, throughput); 70 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 71 | CUDA_SAFE_CALL(cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t))); 72 | 73 | init[thr_id] = true; 74 | } 75 | 76 | for (int k=0; k < 20; k++) 77 | be32enc(&endiandata[k], pdata[k]); 78 | 79 | myriadgroestl_cpu_setBlock(thr_id, endiandata); 80 | 81 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 82 | int rc = 0; 83 | do { 84 | myriadgroestl_cpu_hash(thr_id, throughput, pdata[19], d_resNonce[thr_id], *(uint64_t*)&ptarget[6]); 85 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 86 | 87 | if (h_resNonce[thr_id][0] != UINT32_MAX){ 88 | uint32_t _ALIGN(64) vhash64[8]; 89 | endiandata[19] = swab32(h_resNonce[thr_id][0]); 90 | myriadhash(vhash64, endiandata); 91 | if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) { 92 | *hashes_done = pdata[19] - first_nonce + throughput + 1; 93 | rc = 1; 94 | work_set_target_ratio(work, vhash64); 95 | pdata[19] = h_resNonce[thr_id][0]; 96 | work->nonces[0] = pdata[19]; 97 | if (h_resNonce[thr_id][1] != UINT32_MAX) { 98 | // if(!opt_quiet) 99 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce: %08x", swab32(h_resNonce[thr_id][1])); 100 | endiandata[19] = swab32(h_resNonce[thr_id][1]); 101 | myriadhash(vhash64, endiandata); 102 | pdata[21] = h_resNonce[thr_id][1]; 103 | work->nonces[1] = pdata[21]; 104 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]){ 105 | work_set_target_ratio(work, vhash64); 106 | xchg(pdata[19],pdata[21]); 107 | xchg(work->nonces[ 0],work->nonces[ 1]); 108 | } 109 | rc=2; 110 | } 111 | return rc; 112 | } else { 113 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]); 114 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 115 | } 116 | } 117 | 118 | pdata[19] += throughput; 119 | } while (!work_restart[thr_id].restart && (uint64_t)max_nonce > (uint64_t)throughput + (uint64_t)pdata[19]); 120 | 121 | *hashes_done = pdata[19] - first_nonce + 1; 122 | 123 | return rc; 124 | } 125 | 126 | // cleanup 127 | void free_myriad(int thr_id){ 128 | 129 | if (!init[thr_id]) 130 | return; 131 | 132 | cudaDeviceSynchronize(); 133 | cudaFreeHost(h_resNonce[thr_id]); 134 | cudaFree(d_resNonce[thr_id]); 135 | 136 | myriadgroestl_cpu_free(thr_id); 137 | init[thr_id] = false; 138 | 139 | cudaDeviceSynchronize(); 140 | } 141 | -------------------------------------------------------------------------------- /neoscrypt/neoscrypt.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "cuda_helper.h" 6 | 7 | #include "neoscrypt.h" 8 | 9 | #define NBN 2 10 | 11 | static uint32_t *d_resNonce[MAX_GPUS]; 12 | static uint32_t *h_resNonce[MAX_GPUS]; 13 | 14 | extern void neoscrypt_setBlockTarget(uint32_t* pdata); 15 | extern void neoscrypt_cpu_init(int thr_id, uint32_t threads); 16 | extern void neoscrypt_free(int thr_id); 17 | extern void neoscrypt_cpu_hash_k4(bool stratum, int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *result,const uint32_t target7); 18 | 19 | static bool init[MAX_GPUS] = { 0 }; 20 | 21 | int scanhash_neoscrypt(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done){ 22 | 23 | uint32_t _ALIGN(64) endiandata[20]; 24 | uint32_t *pdata = work->data; 25 | uint32_t *ptarget = work->target; 26 | const uint32_t first_nonce = pdata[19]; 27 | 28 | int dev_id = device_map[thr_id]; 29 | int intensity = 14; 30 | 31 | if (strstr(device_name[dev_id], "GTX 10")) intensity = 16; 32 | 33 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); 34 | 35 | if (strstr(device_name[dev_id], "GTX 9")) throughput = 45312; 36 | 37 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 38 | 39 | api_set_throughput(thr_id, throughput); 40 | 41 | if (opt_benchmark) 42 | ptarget[7] = 0x00ff; 43 | 44 | if(!init[thr_id]){ 45 | cudaSetDevice(dev_id); 46 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 47 | cudaDeviceReset(); 48 | // reduce cpu usage 49 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 50 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 51 | cudaGetLastError(); // reset errors if device is not "reset" 52 | } 53 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 54 | 55 | neoscrypt_cpu_init(thr_id, throughput); 56 | 57 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 58 | h_resNonce[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t)); 59 | if(h_resNonce[thr_id] == NULL){ 60 | gpulog(LOG_ERR,thr_id,"Host memory allocation failed"); 61 | exit(EXIT_FAILURE); 62 | } 63 | 64 | CUDA_LOG_ERROR(); 65 | init[thr_id] = true; 66 | } 67 | 68 | if (have_stratum) { 69 | for (int k = 0; k < 20; k++) 70 | be32enc(&endiandata[k], pdata[k]); 71 | } else { 72 | for (int k = 0; k < 20; k++) 73 | endiandata[k] = pdata[k]; 74 | } 75 | 76 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 77 | 78 | neoscrypt_setBlockTarget(endiandata); 79 | 80 | int rc = 0; 81 | 82 | do{ 83 | neoscrypt_cpu_hash_k4(have_stratum, thr_id, throughput, pdata[19], d_resNonce[thr_id], ptarget[7]); 84 | 85 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 86 | if(h_resNonce[thr_id][0] != UINT32_MAX){ 87 | uint32_t vhash[8]; 88 | if(have_stratum) 89 | be32enc(&endiandata[19], h_resNonce[thr_id][0]); 90 | else 91 | endiandata[19] = h_resNonce[thr_id][0]; 92 | neoscrypt((uchar*)vhash,(uchar*)endiandata, 0x80000620); 93 | if(vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)){ 94 | *hashes_done = pdata[19] - first_nonce + throughput; 95 | work_set_target_ratio(work, vhash); 96 | pdata[19] = h_resNonce[thr_id][0]; 97 | rc = 1; 98 | if(h_resNonce[thr_id][1] != UINT32_MAX){ 99 | // if(!opt_quiet) 100 | // gpulog(LOG_BLUE,dev_id,"Found second nonce %08x !", h_resNonce[thr_id][1]); 101 | if(have_stratum) 102 | be32enc(&endiandata[19], h_resNonce[thr_id][1]); 103 | else 104 | endiandata[19] = h_resNonce[thr_id][1]; 105 | neoscrypt((uchar*)vhash,(uchar*)endiandata, 0x80000620); 106 | pdata[21] = h_resNonce[thr_id][1]; 107 | if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio[0]){ 108 | work_set_target_ratio(work, vhash); 109 | xchg(pdata[19],pdata[21]); 110 | } 111 | rc = 2; 112 | } 113 | return rc; 114 | } 115 | else{ 116 | if(vhash[7] != ptarget[7]) 117 | applog(LOG_WARNING, "GPU #%d: Nonce $%08X does not validate on CPU!", device_map[thr_id], h_resNonce[thr_id][0]); 118 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 119 | } 120 | } 121 | pdata[19] += throughput; 122 | } while(!work_restart[thr_id].restart && ((uint64_t)max_nonce > ((uint64_t)(pdata[19]) + (uint64_t)throughput))); 123 | *hashes_done = pdata[19] - first_nonce; 124 | return rc; 125 | } 126 | 127 | // cleanup 128 | void free_neoscrypt(int thr_id) 129 | { 130 | if (!init[thr_id]) 131 | return; 132 | 133 | cudaDeviceSynchronize(); 134 | 135 | free(h_resNonce[thr_id]); 136 | cudaFree(d_resNonce[thr_id]); 137 | 138 | neoscrypt_free(thr_id); 139 | init[thr_id] = false; 140 | 141 | cudaDeviceSynchronize(); 142 | } 143 | -------------------------------------------------------------------------------- /neoscrypt/neoscrypt.h: -------------------------------------------------------------------------------- 1 | #if (__cplusplus) 2 | extern "C" { 3 | #endif 4 | 5 | void neoscrypt(unsigned char *output, const unsigned char *input, unsigned int profile); 6 | 7 | #if (__cplusplus) 8 | } 9 | #else 10 | 11 | #define SCRYPT_BLOCK_SIZE 64 12 | #define SCRYPT_HASH_BLOCK_SIZE 64 13 | #define SCRYPT_HASH_DIGEST_SIZE 32 14 | 15 | typedef uint8_t hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 16 | 17 | #define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b))) 18 | #define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b))) 19 | 20 | #define U8TO32_BE(p) \ 21 | (((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \ 22 | ((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]))) 23 | 24 | #define U32TO8_BE(p, v) \ 25 | (p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \ 26 | (p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) ); 27 | 28 | #define U64TO8_BE(p, v) \ 29 | U32TO8_BE((p), (uint32_t)((v) >> 32)); \ 30 | U32TO8_BE((p) + 4, (uint32_t)((v) )); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /nist5/cuda_nist5.cu: -------------------------------------------------------------------------------- 1 | extern "C" 2 | { 3 | #include "sph/sph_blake.h" 4 | #include "sph/sph_groestl.h" 5 | #include "sph/sph_skein.h" 6 | #include "sph/sph_jh.h" 7 | #include "sph/sph_keccak.h" 8 | } 9 | 10 | #include "miner.h" 11 | 12 | #include "cuda_helper.h" 13 | 14 | #include "quark/cuda_quark.h" 15 | 16 | 17 | static uint32_t *d_hash[MAX_GPUS]; 18 | #define NBN 2 19 | 20 | /* 8 adapters max */ 21 | static uint32_t *d_resNonce[MAX_GPUS]; 22 | static uint32_t *h_resNonce[MAX_GPUS]; 23 | 24 | // Original nist5hash Funktion aus einem miner Quelltext 25 | extern "C" void nist5hash(void *state, const void *input) 26 | { 27 | sph_blake512_context ctx_blake; 28 | sph_groestl512_context ctx_groestl; 29 | sph_jh512_context ctx_jh; 30 | sph_keccak512_context ctx_keccak; 31 | sph_skein512_context ctx_skein; 32 | 33 | uint8_t hash[64]; 34 | 35 | sph_blake512_init(&ctx_blake); 36 | sph_blake512 (&ctx_blake, input, 80); 37 | sph_blake512_close(&ctx_blake, (void*) hash); 38 | 39 | sph_groestl512_init(&ctx_groestl); 40 | sph_groestl512 (&ctx_groestl, (const void*) hash, 64); 41 | sph_groestl512_close(&ctx_groestl, (void*) hash); 42 | 43 | sph_jh512_init(&ctx_jh); 44 | sph_jh512 (&ctx_jh, (const void*) hash, 64); 45 | sph_jh512_close(&ctx_jh, (void*) hash); 46 | 47 | sph_keccak512_init(&ctx_keccak); 48 | sph_keccak512 (&ctx_keccak, (const void*) hash, 64); 49 | sph_keccak512_close(&ctx_keccak, (void*) hash); 50 | 51 | sph_skein512_init(&ctx_skein); 52 | sph_skein512 (&ctx_skein, (const void*) hash, 64); 53 | sph_skein512_close(&ctx_skein, (void*) hash); 54 | 55 | memcpy(state, hash, 32); 56 | } 57 | 58 | static bool init[MAX_GPUS] = { 0 }; 59 | 60 | extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done){ 61 | 62 | int dev_id = device_map[thr_id]; 63 | 64 | uint32_t _ALIGN(64) endiandata[20]; 65 | uint32_t *pdata = work->data; 66 | uint32_t *ptarget = work->target; 67 | const uint32_t first_nonce = pdata[19]; 68 | 69 | uint32_t throughput = cuda_default_throughput(thr_id, 1 << 21); // 256*256*16 70 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 71 | 72 | if (opt_benchmark) 73 | ((uint32_t*)ptarget)[7] = 0x00FF; 74 | 75 | const uint64_t highTarget = *(uint64_t*)&ptarget[6]; 76 | 77 | if (!init[thr_id]) 78 | { 79 | cudaSetDevice(device_map[thr_id]); 80 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 81 | cudaDeviceReset(); 82 | // reduce cpu usage 83 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 84 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 85 | CUDA_LOG_ERROR(); 86 | } 87 | 88 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 89 | 90 | CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 8 * sizeof(uint64_t) * throughput)); 91 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 92 | h_resNonce[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t)); 93 | if(h_resNonce[thr_id] == NULL){ 94 | gpulog(LOG_ERR,thr_id,"Host memory allocation failed"); 95 | exit(EXIT_FAILURE); 96 | } 97 | init[thr_id] = true; 98 | } 99 | 100 | for (int k=0; k < 20; k++) 101 | be32enc(&endiandata[k], pdata[k]); 102 | 103 | quark_blake512_cpu_setBlock_80(thr_id, endiandata); 104 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 105 | int rc = 0; 106 | do { 107 | // Hash with CUDA 108 | quark_blake512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); 109 | quark_groestl512_cpu_hash_64(thr_id, throughput, NULL, d_hash[thr_id]); 110 | quark_jh512_cpu_hash_64(thr_id, throughput, NULL, d_hash[thr_id]); 111 | quark_keccak_skein512_cpu_hash_64_final(thr_id, throughput, NULL, d_hash[thr_id],d_resNonce[thr_id],highTarget); 112 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 113 | 114 | if (h_resNonce[thr_id][0] != UINT32_MAX){ 115 | const uint32_t Htarg = ptarget[7]; 116 | const uint32_t startNounce = pdata[19]; 117 | uint32_t vhash64[8]; 118 | be32enc(&endiandata[19], startNounce+h_resNonce[thr_id][0]); 119 | nist5hash(vhash64, endiandata); 120 | if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) { 121 | rc = 1; 122 | *hashes_done = pdata[19] - first_nonce + throughput; 123 | work_set_target_ratio(work, vhash64); 124 | pdata[19] =startNounce + h_resNonce[thr_id][0]; 125 | if (h_resNonce[thr_id][1] != UINT32_MAX) { 126 | be32enc(&endiandata[19], startNounce+h_resNonce[thr_id][1]); 127 | nist5hash(vhash64, endiandata); 128 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]) 129 | work_set_target_ratio(work, vhash64); 130 | pdata[21] = startNounce+h_resNonce[thr_id][1]; 131 | rc=2; 132 | } 133 | return rc; 134 | } 135 | else { 136 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]); 137 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 138 | } 139 | } 140 | pdata[19] += throughput; 141 | } while (!work_restart[thr_id].restart && (uint64_t)max_nonce > (uint64_t)throughput + (uint64_t)pdata[19]); 142 | 143 | *hashes_done = pdata[19] - first_nonce; 144 | return 0; 145 | } 146 | 147 | // ressources cleanup 148 | extern "C" void free_nist5(int thr_id){ 149 | if (!init[thr_id]) 150 | return; 151 | 152 | cudaDeviceSynchronize(); 153 | 154 | free(h_resNonce[thr_id]); 155 | cudaFree(d_resNonce[thr_id]); 156 | cudaFree(d_hash[thr_id]); 157 | 158 | // blake512_cpu_free(thr_id); 159 | 160 | init[thr_id] = false; 161 | 162 | cudaDeviceSynchronize(); 163 | } 164 | -------------------------------------------------------------------------------- /pools.conf: -------------------------------------------------------------------------------- 1 | { 2 | "_note": "Sample rotation of 2 pools", 3 | 4 | "pools":[{ 5 | "name": "Longpoll sample", 6 | "url": "http://ziftr.suprnova.cc:9991", 7 | "user": "tpruvot.win", 8 | "pass": "x", 9 | "max-diff": 0.0, 10 | "scantime": 40, 11 | "time-limit": 180, 12 | "disabled": false 13 | }, 14 | { 15 | "name": "Stratum sample", 16 | "url": "stratum+tcp://zrc-stratum.suprnova.cc:2257", 17 | "user": "tpruvot.elite", 18 | "pass": "x", 19 | "time-limit": 300 20 | }], 21 | 22 | "algo" : "zr5", 23 | 24 | "timeout": 60, 25 | 26 | "api-bind" : "0.0.0.0", 27 | "api-remote" : true, 28 | 29 | "no-gbt": true 30 | } 31 | -------------------------------------------------------------------------------- /quark/.cuda_bmw512.cu.swp: -------------------------------------------------------------------------------- 1 | b0nano 2.5.3Ujkrnlrig22quark/cuda_bmw512.cu -------------------------------------------------------------------------------- /quark/cuda_quark.h: -------------------------------------------------------------------------------- 1 | #include "cuda_helper.h" 2 | 3 | /* commonly used cuda quark kernels prototypes */ 4 | 5 | extern void quark_blake512_cpu_setBlock_80(int thr_id, uint32_t *pdata); 6 | extern void quark_blake512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash); 7 | extern void quark_blake512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 8 | 9 | extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 10 | extern void quark_bmw512_cpu_hash_64_quark(int thr_id, uint32_t threads, uint32_t *d_hash); 11 | 12 | extern void blake512_bmw512_cpu_setBlock_80(int thr_id, uint32_t *endiandata); 13 | extern void quark_blake512_bmw512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash); 14 | 15 | extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 16 | extern void quark_groestl512_sm20_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 17 | 18 | extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 19 | 20 | extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 21 | extern void quark_keccak512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash, uint64_t target, uint32_t *d_resNonce); 22 | 23 | extern void quark_keccak_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 24 | extern void quark_keccak_skein512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash,uint32_t *d_resNonce,const uint64_t highTarget); 25 | 26 | extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash); 27 | extern void quark_jh512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t *d_hash, uint64_t target, uint32_t *d_resNonce); 28 | extern void quark_jh512_4way_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_nonceVector, uint32_t* d_hash); 29 | 30 | extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads); 31 | extern void quark_compactTest_cpu_free(int thr_id); 32 | extern void quark_compactTest_cpu_hash_64(int thr_id,uint32_t threads,uint32_t *inpHashes,uint32_t *d_validNonceTable,uint32_t *d_nonces1,uint32_t *nrm1,uint32_t *d_nonces2,uint32_t *nrm2); 33 | extern void quark_compactTest_single_false_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *inpHashes, uint32_t *d_validNonceTable,uint32_t *d_nonces1, uint32_t *nrm1); 34 | 35 | -------------------------------------------------------------------------------- /quark/groestl_transf_quad.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | #define merge8(z,x,y,b)\ 4 | z=__byte_perm(x, y, b); \ 5 | 6 | #define SWAP8(x,y)\ 7 | x=__byte_perm(x, y, 0x5410); \ 8 | y=__byte_perm(y, x, 0x5410); 9 | 10 | #define SWAP4(x,y)\ 11 | t = 0xf0f0f0f0 & (x ^ (y<<4)); \ 12 | x^= t; \ 13 | y^= t>>4; 14 | 15 | #define SWAP2(x,y)\ 16 | t = 0xcccccccc & (x ^ (y<<2)); \ 17 | x^= t; \ 18 | y^= t>>2; 19 | 20 | #define SWAP1(x,y)\ 21 | t = 0xaaaaaaaa & (x ^ (y<<1)); \ 22 | x^= t; \ 23 | y^= t>>1; 24 | 25 | __device__ 26 | static void to_bitslice_quad(uint32_t *const __restrict__ input, uint32_t *const __restrict__ output){ 27 | 28 | uint32_t other[8]; 29 | uint32_t t; 30 | 31 | uint32_t perm = (threadIdx.x & 1) ? 0x7362 : 0x5140; 32 | const uint32_t n = threadIdx.x & 3; 33 | 34 | #pragma unroll 8 35 | for (uint32_t i = 0; i < 8; i++) 36 | { 37 | input[i] = __shfl(input[i], (n ^ (3 * ((n == 1) || (n == 2)))&3), 4); 38 | other[i] = __shfl(input[i], (threadIdx.x + 1) & 3, 4); 39 | input[i] = __shfl(input[i], threadIdx.x & 2, 4); 40 | other[i] = __shfl(other[i], threadIdx.x & 2, 4); 41 | } 42 | 43 | merge8(output[0], input[0], input[4], perm); 44 | merge8(output[1], other[0], other[4], perm); 45 | merge8(output[2], input[1], input[5], perm); 46 | merge8(output[3], other[1], other[5], perm); 47 | merge8(output[4], input[2], input[6], perm); 48 | merge8(output[5], other[2], other[6], perm); 49 | merge8(output[6], input[3], input[7], perm); 50 | merge8(output[7], other[3], other[7], perm); 51 | 52 | SWAP1(output[0], output[1]); 53 | SWAP1(output[2], output[3]); 54 | SWAP1(output[4], output[5]); 55 | SWAP1(output[6], output[7]); 56 | 57 | SWAP2(output[0], output[2]); 58 | SWAP2(output[1], output[3]); 59 | SWAP2(output[4], output[6]); 60 | SWAP2(output[5], output[7]); 61 | 62 | SWAP4(output[0], output[4]); 63 | SWAP4(output[1], output[5]); 64 | SWAP4(output[2], output[6]); 65 | SWAP4(output[3], output[7]); 66 | } 67 | */ 68 | 69 | /* File included in quark/groestl (quark/jha,nist5/X11+) and groest/myriad coins for SM 3+ */ 70 | 71 | #define merge8(z,x,y)\ 72 | z=__byte_perm(x, y, 0x5140); \ 73 | 74 | #define SWAP8(x,y)\ 75 | x=__byte_perm(x, y, 0x5410); \ 76 | y=__byte_perm(x, y, 0x7632); 77 | 78 | #define SWAP4(x,y)\ 79 | t = (y<<4); \ 80 | t = (x ^ t); \ 81 | t = 0xf0f0f0f0UL & t; \ 82 | x = (x ^ t); \ 83 | t= t>>4;\ 84 | y= y ^ t; 85 | 86 | #define SWAP2(x,y)\ 87 | t = (y<<2); \ 88 | t = (x ^ t); \ 89 | t = 0xccccccccUL & t; \ 90 | x = (x ^ t); \ 91 | t= t>>2;\ 92 | y= y ^ t; 93 | 94 | #define SWAP1(x,y)\ 95 | t = (y+y); \ 96 | t = (x ^ t); \ 97 | t = 0xaaaaaaaaUL & t; \ 98 | x = (x ^ t); \ 99 | t= t>>1;\ 100 | y= y ^ t; 101 | 102 | 103 | __device__ __forceinline__ 104 | void to_bitslice_quad(uint32_t *const __restrict__ input, uint32_t *const __restrict__ output) 105 | { 106 | uint32_t other[8]; 107 | uint32_t d[8]; 108 | uint32_t t; 109 | const unsigned int n = threadIdx.x & 3; 110 | 111 | #pragma unroll 112 | for (int i = 0; i < 8; i++) { 113 | input[i] = __shfl((int)input[i], n ^ (3*(n >=1 && n <=2)), 4); 114 | other[i] = __shfl((int)input[i], (threadIdx.x + 1) & 3, 4); 115 | input[i] = __shfl((int)input[i], threadIdx.x & 2, 4); 116 | other[i] = __shfl((int)other[i], threadIdx.x & 2, 4); 117 | if (threadIdx.x & 1) { 118 | input[i] = __byte_perm(input[i], 0, 0x1032); 119 | other[i] = __byte_perm(other[i], 0, 0x1032); 120 | } 121 | } 122 | 123 | merge8(d[0], input[0], input[4]); 124 | merge8(d[1], other[0], other[4]); 125 | merge8(d[2], input[1], input[5]); 126 | merge8(d[3], other[1], other[5]); 127 | merge8(d[4], input[2], input[6]); 128 | merge8(d[5], other[2], other[6]); 129 | merge8(d[6], input[3], input[7]); 130 | merge8(d[7], other[3], other[7]); 131 | 132 | SWAP1(d[0], d[1]); 133 | SWAP1(d[2], d[3]); 134 | SWAP1(d[4], d[5]); 135 | SWAP1(d[6], d[7]); 136 | 137 | SWAP2(d[0], d[2]); 138 | SWAP2(d[1], d[3]); 139 | SWAP2(d[4], d[6]); 140 | SWAP2(d[5], d[7]); 141 | 142 | SWAP4(d[0], d[4]); 143 | SWAP4(d[1], d[5]); 144 | SWAP4(d[2], d[6]); 145 | SWAP4(d[3], d[7]); 146 | 147 | output[0] = d[0]; 148 | output[1] = d[1]; 149 | output[2] = d[2]; 150 | output[3] = d[3]; 151 | output[4] = d[4]; 152 | output[5] = d[5]; 153 | output[6] = d[6]; 154 | output[7] = d[7]; 155 | } 156 | 157 | 158 | __device__ 159 | static void from_bitslice_quad52(const uint32_t *const __restrict__ input, uint32_t *const __restrict__ output) 160 | { 161 | uint32_t t; 162 | const uint32_t perm = 0x7531;//(threadIdx.x & 1) ? 0x3175 : 0x7531; 163 | 164 | output[0] = __byte_perm(input[0], input[4], perm); 165 | output[2] = __byte_perm(input[1], input[5], perm); 166 | output[8] = __byte_perm(input[2], input[6], perm); 167 | output[10] = __byte_perm(input[3], input[7], perm); 168 | 169 | SWAP1(output[0], output[2]); 170 | SWAP1(output[8], output[10]); 171 | SWAP2(output[0], output[8]); 172 | SWAP2(output[2], output[10]); 173 | 174 | t = __byte_perm(output[0], output[8], 0x5410); 175 | output[8] = __byte_perm(output[0], output[8], 0x7632); 176 | output[0] = t; 177 | 178 | t = __byte_perm(output[2], output[10], 0x5410); 179 | output[10] = __byte_perm(output[2], output[10], 0x7632); 180 | output[2] = t; 181 | 182 | SWAP4(output[0], output[8]); 183 | SWAP4(output[2], output[10]); 184 | 185 | if (threadIdx.x & 1) 186 | { 187 | output[4] = __byte_perm(output[0], 0, 0x3232); 188 | output[0] = __byte_perm(output[0], 0, 0x1032); 189 | 190 | output[6] = __byte_perm(output[2], 0, 0x3232); 191 | output[2] = __byte_perm(output[2], 0, 0x1032); 192 | 193 | output[12] = __byte_perm(output[8], 0, 0x3232); 194 | output[8] = __byte_perm(output[8], 0, 0x1032); 195 | 196 | output[14] = __byte_perm(output[10], 0, 0x3232); 197 | output[10] = __byte_perm(output[10], 0, 0x1032); 198 | } 199 | else 200 | { 201 | output[4] = output[0]; 202 | output[6] = output[2]; 203 | output[12] = output[8]; 204 | output[14] = output[10]; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /qubit/qubit.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * qubit algorithm 3 | * 4 | */ 5 | extern "C" { 6 | #include "sph/sph_luffa.h" 7 | #include "sph/sph_cubehash.h" 8 | #include "sph/sph_shavite.h" 9 | #include "sph/sph_simd.h" 10 | #include "sph/sph_echo.h" 11 | } 12 | 13 | #include "miner.h" 14 | 15 | #include "cuda_helper.h" 16 | #include "x11/cuda_x11.h" 17 | 18 | #define NBN 2 19 | 20 | static uint32_t *d_resNonce[MAX_GPUS]; 21 | static uint32_t *h_resNonce[MAX_GPUS]; 22 | 23 | static uint32_t *d_hash[MAX_GPUS]; 24 | 25 | extern void qubit_luffa512_cpu_setBlock_80(void *pdata); 26 | extern void qubit_luffa512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash); 27 | 28 | extern "C" void qubithash(void *state, const void *input) 29 | { 30 | uint8_t _ALIGN(128) hash[64]; 31 | 32 | // luffa1-cubehash2-shavite3-simd4-echo5 33 | 34 | sph_luffa512_context ctx_luffa; 35 | sph_cubehash512_context ctx_cubehash; 36 | sph_shavite512_context ctx_shavite; 37 | sph_simd512_context ctx_simd; 38 | sph_echo512_context ctx_echo; 39 | 40 | sph_luffa512_init(&ctx_luffa); 41 | sph_luffa512 (&ctx_luffa, input, 80); 42 | sph_luffa512_close(&ctx_luffa, (void*) hash); 43 | 44 | sph_cubehash512_init(&ctx_cubehash); 45 | sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64); 46 | sph_cubehash512_close(&ctx_cubehash, (void*) hash); 47 | 48 | sph_shavite512_init(&ctx_shavite); 49 | sph_shavite512 (&ctx_shavite, (const void*) hash, 64); 50 | sph_shavite512_close(&ctx_shavite, (void*) hash); 51 | 52 | sph_simd512_init(&ctx_simd); 53 | sph_simd512 (&ctx_simd, (const void*) hash, 64); 54 | sph_simd512_close(&ctx_simd, (void*) hash); 55 | 56 | sph_echo512_init(&ctx_echo); 57 | sph_echo512 (&ctx_echo, (const void*) hash, 64); 58 | sph_echo512_close(&ctx_echo, (void*) hash); 59 | 60 | memcpy(state, hash, 32); 61 | } 62 | 63 | static bool init[MAX_GPUS] = { 0 }; 64 | 65 | extern "C" int scanhash_qubit(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done){ 66 | 67 | int dev_id = device_map[thr_id]; 68 | 69 | uint32_t _ALIGN(64) endiandata[20]; 70 | uint32_t *pdata = work->data; 71 | uint32_t *ptarget = work->target; 72 | const uint32_t first_nonce = pdata[19]; 73 | uint32_t intensity = (device_sm[dev_id] <= 500) ? 20 : 21; 74 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); // 256*256*8 75 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 76 | 77 | if (opt_benchmark) 78 | ptarget[7] = 0x007f; 79 | 80 | if (!init[thr_id]) 81 | { 82 | cudaSetDevice(device_map[thr_id]); 83 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 84 | cudaDeviceReset(); 85 | // reduce cpu usage 86 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 87 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 88 | CUDA_LOG_ERROR(); 89 | } 90 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 91 | 92 | x11_simd_echo_512_cpu_init(thr_id, throughput); 93 | 94 | CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 8 * sizeof(uint64_t) * throughput)); 95 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 96 | h_resNonce[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t)); 97 | if(h_resNonce[thr_id] == NULL){ 98 | gpulog(LOG_ERR,thr_id,"Host memory allocation failed"); 99 | exit(EXIT_FAILURE); 100 | } 101 | 102 | init[thr_id] = true; 103 | } 104 | 105 | for (int k=0; k < 20; k++) 106 | be32enc(&endiandata[k], pdata[k]); 107 | 108 | qubit_luffa512_cpu_setBlock_80((void*)endiandata); 109 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 110 | do { 111 | // Hash with CUDA 112 | qubit_luffa512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); 113 | x11_cubehash_shavite512_cpu_hash_64(thr_id, throughput, d_hash[thr_id]); 114 | x11_simd_echo512_cpu_hash_64_final(thr_id, throughput, d_hash[thr_id], d_resNonce[thr_id], *(uint64_t*)&ptarget[6]); 115 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 116 | 117 | if (h_resNonce[thr_id][0] != UINT32_MAX){ 118 | const uint32_t Htarg = ptarget[7]; 119 | const uint32_t startNounce = pdata[19]; 120 | uint32_t vhash64[8]; 121 | be32enc(&endiandata[19], startNounce + h_resNonce[thr_id][0]); 122 | qubithash(vhash64, endiandata); 123 | 124 | if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) { 125 | int res = 1; 126 | *hashes_done = pdata[19] - first_nonce + throughput; 127 | work_set_target_ratio(work, vhash64); 128 | pdata[19] = startNounce + h_resNonce[thr_id][0]; 129 | if (h_resNonce[thr_id][1] != UINT32_MAX) { 130 | // if (!opt_quiet) 131 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce %08x ",h_resNonce[thr_id][1]); 132 | 133 | be32enc(&endiandata[19], startNounce+h_resNonce[thr_id][1]); 134 | qubithash(vhash64, endiandata); 135 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]) 136 | work_set_target_ratio(work, vhash64); 137 | pdata[21] = startNounce+h_resNonce[thr_id][1]; 138 | res++; 139 | } 140 | return res; 141 | } 142 | else { 143 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]); 144 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 145 | } 146 | } 147 | 148 | pdata[19] += throughput; 149 | } while (!work_restart[thr_id].restart && (uint64_t)max_nonce > (uint64_t)throughput + pdata[19]); 150 | 151 | *hashes_done = pdata[19] - first_nonce; 152 | return 0; 153 | } 154 | 155 | // cleanup 156 | extern "C" void free_qubit(int thr_id) 157 | { 158 | if (!init[thr_id]) 159 | return; 160 | 161 | cudaDeviceSynchronize(); 162 | 163 | free(h_resNonce[thr_id]); 164 | cudaFree(d_resNonce[thr_id]); 165 | cudaFree(d_hash[thr_id]); 166 | 167 | x11_simd_echo_512_cpu_free(thr_id); 168 | 169 | init[thr_id] = false; 170 | 171 | cudaDeviceSynchronize(); 172 | } 173 | -------------------------------------------------------------------------------- /res/ccminer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/res/ccminer.ico -------------------------------------------------------------------------------- /res/ccminer.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/res/ccminer.rc -------------------------------------------------------------------------------- /res/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/res/resource.h -------------------------------------------------------------------------------- /sph/blake2b.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef __BLAKE2B_H__ 3 | #define __BLAKE2B_H__ 4 | 5 | #include 6 | #include 7 | 8 | #if defined(_MSC_VER) 9 | #include 10 | #define inline __inline 11 | #define ALIGN(x) __declspec(align(x)) 12 | #else 13 | #define ALIGN(x) __attribute__((aligned(x))) 14 | #endif 15 | 16 | #if defined(_MSC_VER) || defined(__x86_64__) || defined(__x86__) 17 | #define NATIVE_LITTLE_ENDIAN 18 | #endif 19 | 20 | // state context 21 | ALIGN(64) typedef struct { 22 | uint8_t b[128]; // input buffer 23 | uint64_t h[8]; // chained state 24 | uint64_t t[2]; // total number of bytes 25 | size_t c; // pointer for b[] 26 | size_t outlen; // digest size 27 | } blake2b_ctx; 28 | 29 | #if defined(__cplusplus) 30 | extern "C" { 31 | #endif 32 | 33 | int blake2b_init(blake2b_ctx *ctx, size_t outlen, const void *key, size_t keylen); 34 | void blake2b_update(blake2b_ctx *ctx, const void *in, size_t inlen); 35 | void blake2b_final(blake2b_ctx *ctx, void *out); 36 | 37 | #if defined(__cplusplus) 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /sph/blake2s.h: -------------------------------------------------------------------------------- 1 | /** 2 | * BLAKE2 reference source code package - reference C implementations 3 | * 4 | * Written in 2012 by Samuel Neves 5 | * 6 | * To the extent possible under law, the author(s) have dedicated all copyright 7 | * and related and neighboring rights to this software to the public domain 8 | * worldwide. This software is distributed without any warranty. 9 | * 10 | * You should have received a copy of the CC0 Public Domain Dedication along with 11 | * this software. If not, see . 12 | */ 13 | #pragma once 14 | #ifndef __BLAKE2_H__ 15 | #define __BLAKE2_H__ 16 | 17 | #include 18 | #include 19 | 20 | #if defined(_MSC_VER) 21 | #include 22 | #define inline __inline 23 | #define ALIGN(x) __declspec(align(x)) 24 | #else 25 | #define ALIGN(x) __attribute__((aligned(x))) 26 | #endif 27 | 28 | /* blake2-impl.h */ 29 | 30 | static inline uint32_t load32(const void *src) 31 | { 32 | #if defined(NATIVE_LITTLE_ENDIAN) 33 | return *(uint32_t *)(src); 34 | #else 35 | const uint8_t *p = (uint8_t *)src; 36 | uint32_t w = *p++; 37 | w |= (uint32_t)(*p++) << 8; 38 | w |= (uint32_t)(*p++) << 16; 39 | w |= (uint32_t)(*p++) << 24; 40 | return w; 41 | #endif 42 | } 43 | 44 | static inline void store32(void *dst, uint32_t w) 45 | { 46 | #if defined(NATIVE_LITTLE_ENDIAN) 47 | *(uint32_t *)(dst) = w; 48 | #else 49 | uint8_t *p = (uint8_t *)dst; 50 | *p++ = (uint8_t)w; w >>= 8; 51 | *p++ = (uint8_t)w; w >>= 8; 52 | *p++ = (uint8_t)w; w >>= 8; 53 | *p++ = (uint8_t)w; 54 | #endif 55 | } 56 | 57 | static inline uint64_t load48(const void *src) 58 | { 59 | const uint8_t *p = (const uint8_t *)src; 60 | uint64_t w = *p++; 61 | w |= (uint64_t)(*p++) << 8; 62 | w |= (uint64_t)(*p++) << 16; 63 | w |= (uint64_t)(*p++) << 24; 64 | w |= (uint64_t)(*p++) << 32; 65 | w |= (uint64_t)(*p++) << 40; 66 | return w; 67 | } 68 | 69 | static inline void store48(void *dst, uint64_t w) 70 | { 71 | uint8_t *p = (uint8_t *)dst; 72 | *p++ = (uint8_t)w; w >>= 8; 73 | *p++ = (uint8_t)w; w >>= 8; 74 | *p++ = (uint8_t)w; w >>= 8; 75 | *p++ = (uint8_t)w; w >>= 8; 76 | *p++ = (uint8_t)w; w >>= 8; 77 | *p++ = (uint8_t)w; 78 | } 79 | 80 | /* prevents compiler optimizing out memset() */ 81 | static inline void secure_zero_memory(void *v, size_t n) 82 | { 83 | volatile uint8_t *p = ( volatile uint8_t * )v; 84 | 85 | while( n-- ) *p++ = 0; 86 | } 87 | 88 | /* blake2.h */ 89 | 90 | #if defined(__cplusplus) 91 | extern "C" { 92 | #endif 93 | 94 | enum blake2s_constant 95 | { 96 | BLAKE2S_BLOCKBYTES = 64, 97 | BLAKE2S_OUTBYTES = 32, 98 | BLAKE2S_KEYBYTES = 32, 99 | BLAKE2S_SALTBYTES = 8, 100 | BLAKE2S_PERSONALBYTES = 8 101 | }; 102 | 103 | #pragma pack(push, 1) 104 | typedef struct __blake2s_param 105 | { 106 | uint8_t digest_length; // 1 107 | uint8_t key_length; // 2 108 | uint8_t fanout; // 3 109 | uint8_t depth; // 4 110 | uint32_t leaf_length; // 8 111 | uint8_t node_offset[6];// 14 112 | uint8_t node_depth; // 15 113 | uint8_t inner_length; // 16 114 | // uint8_t reserved[0]; 115 | uint8_t salt[BLAKE2S_SALTBYTES]; // 24 116 | uint8_t personal[BLAKE2S_PERSONALBYTES]; // 32 117 | } blake2s_param; 118 | 119 | ALIGN( 64 ) typedef struct __blake2s_state 120 | { 121 | uint32_t h[8]; 122 | uint32_t t[2]; 123 | uint32_t f[2]; 124 | uint8_t buf[2 * BLAKE2S_BLOCKBYTES]; 125 | size_t buflen; 126 | uint8_t last_node; 127 | } blake2s_state ; 128 | #pragma pack(pop) 129 | 130 | int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] ); 131 | 132 | // Streaming API 133 | int blake2s_init( blake2s_state *S, const uint8_t outlen ); 134 | int blake2s_init_key( blake2s_state *S, const uint8_t outlen, const void *key, const uint8_t keylen ); 135 | int blake2s_init_param( blake2s_state *S, const blake2s_param *P ); 136 | int blake2s_update( blake2s_state *S, const uint8_t *in, uint64_t inlen ); 137 | int blake2s_final( blake2s_state *S, uint8_t *out, uint8_t outlen ); 138 | 139 | // Simple API 140 | int blake2s( uint8_t *out, const void *in, const void *key, const uint8_t outlen, const uint64_t inlen, uint8_t keylen ); 141 | 142 | // Direct Hash Mining Helpers 143 | #define blake2s_salt32(out, in, inlen, key32) blake2s(out, in, key32, 32, inlen, 32) /* neoscrypt */ 144 | #define blake2s_simple(out, in, inlen) blake2s(out, in, NULL, 32, inlen, 0) 145 | 146 | #if defined(__cplusplus) 147 | } 148 | #endif 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /sph/haval_helper.c: -------------------------------------------------------------------------------- 1 | /* $Id: haval_helper.c 218 2010-06-08 17:06:34Z tp $ */ 2 | /* 3 | * Helper code, included (three times !) by HAVAL implementation. 4 | * 5 | * TODO: try to merge this with md_helper.c. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @author Thomas Pornin 33 | */ 34 | 35 | #undef SPH_XCAT 36 | #define SPH_XCAT(a, b) SPH_XCAT_(a, b) 37 | #undef SPH_XCAT_ 38 | #define SPH_XCAT_(a, b) a ## b 39 | 40 | static void 41 | #ifdef SPH_UPTR 42 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short) 43 | #else 44 | SPH_XCAT(haval, PASSES) 45 | #endif 46 | (sph_haval_context *sc, const void *data, size_t len) 47 | { 48 | unsigned current; 49 | 50 | #if SPH_64 51 | current = (unsigned)sc->count & 127U; 52 | #else 53 | current = (unsigned)sc->count_low & 127U; 54 | #endif 55 | while (len > 0) { 56 | unsigned clen; 57 | #if !SPH_64 58 | sph_u32 clow, clow2; 59 | #endif 60 | 61 | clen = 128U - current; 62 | if (clen > len) 63 | clen = len; 64 | memcpy(sc->buf + current, data, clen); 65 | data = (const unsigned char *)data + clen; 66 | current += clen; 67 | len -= clen; 68 | if (current == 128U) { 69 | DSTATE; 70 | IN_PREPARE(sc->buf); 71 | RSTATE; 72 | SPH_XCAT(CORE, PASSES)(INW); 73 | WSTATE; 74 | current = 0; 75 | } 76 | #if SPH_64 77 | sc->count += clen; 78 | #else 79 | clow = sc->count_low; 80 | clow2 = SPH_T32(clow + clen); 81 | sc->count_low = clow2; 82 | if (clow2 < clow) 83 | sc->count_high ++; 84 | #endif 85 | } 86 | } 87 | 88 | #ifdef SPH_UPTR 89 | static void 90 | SPH_XCAT(haval, PASSES)(sph_haval_context *sc, const void *data, size_t len) 91 | { 92 | unsigned current; 93 | size_t orig_len; 94 | #if !SPH_64 95 | sph_u32 clow, clow2; 96 | #endif 97 | DSTATE; 98 | 99 | if (len < 256U) { 100 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 101 | return; 102 | } 103 | #if SPH_64 104 | current = (unsigned)sc->count & 127U; 105 | #else 106 | current = (unsigned)sc->count_low & 127U; 107 | #endif 108 | if (current > 0) { 109 | unsigned clen; 110 | clen = 128U - current; 111 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, clen); 112 | data = (const unsigned char *)data + clen; 113 | len -= clen; 114 | } 115 | #if !SPH_UNALIGNED 116 | if (((SPH_UPTR)data & 3U) != 0) { 117 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 118 | return; 119 | } 120 | #endif 121 | orig_len = len; 122 | RSTATE; 123 | while (len >= 128U) { 124 | IN_PREPARE(data); 125 | SPH_XCAT(CORE, PASSES)(INW); 126 | data = (const unsigned char *)data + 128U; 127 | len -= 128U; 128 | } 129 | WSTATE; 130 | if (len > 0) 131 | memcpy(sc->buf, data, len); 132 | #if SPH_64 133 | sc->count += (sph_u64)orig_len; 134 | #else 135 | clow = sc->count_low; 136 | clow2 = SPH_T32(clow + orig_len); 137 | sc->count_low = clow2; 138 | if (clow2 < clow) 139 | sc->count_high ++; 140 | orig_len >>= 12; 141 | orig_len >>= 10; 142 | orig_len >>= 10; 143 | sc->count_high += orig_len; 144 | #endif 145 | } 146 | #endif 147 | 148 | static void 149 | SPH_XCAT(SPH_XCAT(haval, PASSES), _close)(sph_haval_context *sc,unsigned ub, unsigned n, void *dst){ 150 | unsigned current; 151 | DSTATE; 152 | 153 | #if SPH_64 154 | current = (unsigned)sc->count & 127U; 155 | #else 156 | current = (unsigned)sc->count_low & 127U; 157 | #endif 158 | sc->buf[current ++] = (0x01 << n) | ((ub & 0xFF) >> (8 - n)); 159 | RSTATE; 160 | if (current > 118U) { 161 | memset(sc->buf + current, 0, 128U - current); 162 | 163 | do { 164 | IN_PREPARE(sc->buf); 165 | SPH_XCAT(CORE, PASSES)(INW); 166 | } while (0); 167 | current = 0; 168 | } 169 | memset(sc->buf + current, 0, 118U - current); 170 | sc->buf[118] = 0x01 | (PASSES << 3); 171 | sc->buf[119] = sc->olen << 3; 172 | #if SPH_64 173 | sph_enc64le_aligned(sc->buf + 120, SPH_T64(sc->count << 3)); 174 | #else 175 | sph_enc32le_aligned(sc->buf + 120, SPH_T32(sc->count_low << 3)); 176 | sph_enc32le_aligned(sc->buf + 124, 177 | SPH_T32((sc->count_high << 3) | (sc->count_low >> 29))); 178 | #endif 179 | 180 | do { 181 | IN_PREPARE(sc->buf); 182 | SPH_XCAT(CORE, PASSES)(INW); 183 | } while (0); 184 | WSTATE; 185 | 186 | haval_out(sc, dst); 187 | haval_init(sc, sc->olen, sc->passes); 188 | } 189 | -------------------------------------------------------------------------------- /sph/sha256_Y.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2005,2007,2009 Colin Percival 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: src/lib/libmd/sha256_Y.h,v 1.2 2006/01/17 15:35:56 phk Exp $ 27 | */ 28 | 29 | #ifndef _SHA256_H_ 30 | #define _SHA256_H_ 31 | 32 | #include 33 | 34 | #include 35 | 36 | typedef struct SHA256Context { 37 | uint32_t state[8]; 38 | uint32_t count[2]; 39 | unsigned char buf[64]; 40 | } SHA256_CTX_Y; 41 | 42 | typedef struct HMAC_SHA256Context { 43 | SHA256_CTX_Y ictx; 44 | SHA256_CTX_Y octx; 45 | } HMAC_SHA256_CTX_Y; 46 | 47 | void SHA256_Init_Y(SHA256_CTX_Y *); 48 | void SHA256_Update_Y(SHA256_CTX_Y *, const void *, size_t); 49 | void SHA256_Final_Y(unsigned char [32], SHA256_CTX_Y *); 50 | void HMAC_SHA256_Init_Y(HMAC_SHA256_CTX_Y *, const void *, size_t); 51 | void HMAC_SHA256_Update_Y(HMAC_SHA256_CTX_Y *, const void *, size_t); 52 | void HMAC_SHA256_Final_Y(unsigned char [32], HMAC_SHA256_CTX_Y *); 53 | 54 | /** 55 | * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): 56 | * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and 57 | * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). 58 | */ 59 | void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, 60 | uint64_t, uint8_t *, size_t); 61 | 62 | 63 | #endif /* !_SHA256_H_ */ 64 | -------------------------------------------------------------------------------- /sph/sph_fugue.h: -------------------------------------------------------------------------------- 1 | #ifndef SPH_FUGUE_H__ 2 | #define SPH_FUGUE_H__ 3 | 4 | #include 5 | #include "sph_types.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif 10 | 11 | #define SPH_SIZE_fugue224 224 12 | 13 | #define SPH_SIZE_fugue256 256 14 | 15 | #define SPH_SIZE_fugue384 384 16 | 17 | #define SPH_SIZE_fugue512 512 18 | 19 | typedef struct { 20 | #ifndef DOXYGEN_IGNORE 21 | sph_u32 partial; 22 | unsigned partial_len; 23 | unsigned round_shift; 24 | sph_u32 S[36]; 25 | #if SPH_64 26 | sph_u64 bit_count; 27 | #else 28 | sph_u32 bit_count_high, bit_count_low; 29 | #endif 30 | #endif 31 | } sph_fugue_context; 32 | 33 | typedef sph_fugue_context sph_fugue224_context; 34 | 35 | typedef sph_fugue_context sph_fugue256_context; 36 | 37 | typedef sph_fugue_context sph_fugue384_context; 38 | 39 | typedef sph_fugue_context sph_fugue512_context; 40 | 41 | void sph_fugue224_init(void *cc); 42 | 43 | void sph_fugue224(void *cc, const void *data, size_t len); 44 | 45 | void sph_fugue224_close(void *cc, void *dst); 46 | 47 | void sph_fugue224_addbits_and_close( 48 | void *cc, unsigned ub, unsigned n, void *dst); 49 | 50 | void sph_fugue256_init(void *cc); 51 | 52 | void sph_fugue256(void *cc, const void *data, size_t len); 53 | 54 | void sph_fugue256_close(void *cc, void *dst); 55 | 56 | void sph_fugue256_addbits_and_close( 57 | void *cc, unsigned ub, unsigned n, void *dst); 58 | 59 | void sph_fugue384_init(void *cc); 60 | 61 | void sph_fugue384(void *cc, const void *data, size_t len); 62 | 63 | void sph_fugue384_close(void *cc, void *dst); 64 | 65 | void sph_fugue384_addbits_and_close( 66 | void *cc, unsigned ub, unsigned n, void *dst); 67 | 68 | void sph_fugue512_init(void *cc); 69 | 70 | void sph_fugue512(void *cc, const void *data, size_t len); 71 | 72 | void sph_fugue512_close(void *cc, void *dst); 73 | 74 | void sph_fugue512_addbits_and_close( 75 | void *cc, unsigned ub, unsigned n, void *dst); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /sph/sysendian.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2007-2009 Colin Percival 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | #ifndef _SYSENDIAN_H_ 30 | #define _SYSENDIAN_H_ 31 | 32 | /* If we don't have be64enc, the we have isn't usable. */ 33 | #if !HAVE_DECL_BE64ENC 34 | #undef HAVE_SYS_ENDIAN_H 35 | #endif 36 | 37 | #ifdef HAVE_SYS_ENDIAN_H 38 | 39 | #include 40 | 41 | #else 42 | 43 | #include 44 | 45 | #if !HAVE_DECL_LE32DEC 46 | static uint32_t le32dec(const void *pp) 47 | { 48 | const uint8_t *p = (uint8_t const *)pp; 49 | return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + 50 | ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); 51 | } 52 | #endif 53 | 54 | #if !HAVE_DECL_BE32ENC 55 | static void be32enc(void *pp, uint32_t x) 56 | { 57 | uint8_t *p = (uint8_t *)pp; 58 | p[3] = x & 0xff; 59 | p[2] = (x >> 8) & 0xff; 60 | p[1] = (x >> 16) & 0xff; 61 | p[0] = (x >> 24) & 0xff; 62 | } 63 | #endif 64 | 65 | #if !HAVE_DECL_BE32DEC 66 | static uint32_t be32dec(const void *pp) 67 | { 68 | const uint8_t *p = (uint8_t const *)pp; 69 | return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + 70 | ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); 71 | } 72 | #endif 73 | 74 | #if !HAVE_DECL_LE32ENC 75 | static void le32enc(void *pp, uint32_t x) 76 | { 77 | uint8_t *p = (uint8_t *)pp; 78 | p[0] = x & 0xff; 79 | p[1] = (x >> 8) & 0xff; 80 | p[2] = (x >> 16) & 0xff; 81 | p[3] = (x >> 24) & 0xff; 82 | } 83 | #endif 84 | 85 | static uint64_t 86 | be64dec(const void *pp) 87 | { 88 | const uint8_t *p = (uint8_t const *)pp; 89 | 90 | return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) + 91 | ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) + 92 | ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) + 93 | ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56)); 94 | } 95 | 96 | static void 97 | be64enc(void *pp, uint64_t x) 98 | { 99 | uint8_t * p = (uint8_t *)pp; 100 | 101 | p[7] = x & 0xff; 102 | p[6] = (x >> 8) & 0xff; 103 | p[5] = (x >> 16) & 0xff; 104 | p[4] = (x >> 24) & 0xff; 105 | p[3] = (x >> 32) & 0xff; 106 | p[2] = (x >> 40) & 0xff; 107 | p[1] = (x >> 48) & 0xff; 108 | p[0] = (x >> 56) & 0xff; 109 | } 110 | 111 | 112 | 113 | static uint64_t 114 | le64dec(const void *pp) 115 | { 116 | const uint8_t *p = (uint8_t const *)pp; 117 | 118 | return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) + 119 | ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) + 120 | ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) + 121 | ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56)); 122 | } 123 | 124 | static void 125 | le64enc(void *pp, uint64_t x) 126 | { 127 | uint8_t * p = (uint8_t *)pp; 128 | 129 | p[0] = x & 0xff; 130 | p[1] = (x >> 8) & 0xff; 131 | p[2] = (x >> 16) & 0xff; 132 | p[3] = (x >> 24) & 0xff; 133 | p[4] = (x >> 32) & 0xff; 134 | p[5] = (x >> 40) & 0xff; 135 | p[6] = (x >> 48) & 0xff; 136 | p[7] = (x >> 56) & 0xff; 137 | } 138 | #endif /* !HAVE_SYS_ENDIAN_H */ 139 | 140 | #endif /* !_SYSENDIAN_H_ */ 141 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | #USE THIS STARTUP SCRIPT TO AUTOMATICALLY MINE THE MOST PROFITABLE COIN IN ZPOOL UNDER LINUX 4 | 5 | while : 6 | do 7 | 8 | ./ccminer -r 0 -a quark --url stratum+tcp://mine.zpool.ca:4033 -u 13VDy6uNHnoChvR8mW68KJqorBVG93eK5p -p quark,skein,lyra2v2,nist5 --show-diff 9 | ./ccminer -r 0 -a skein --url stratum+tcp://mine.zpool.ca:4933 -u 13VDy6uNHnoChvR8mW68KJqorBVG93eK5p -p quark,skein,lyra2v2,nist5 --show-diff -d 0,1 -i 28,26 10 | ./ccminer -r 0 -a lyra2v2 --url stratum+tcp://mine.zpool.ca:4533 -u 13VDy6uNHnoChvR8mW68KJqorBVG93eK5p -p quark,skein,lyra2v2,nist5 --show-diff -i 21 11 | ./ccminer -r 0 -a nist5 --url stratum+tcp://mine.zpool.ca:3833 -u 13VDy6uNHnoChvR8mW68KJqorBVG93eK5p -p quark,skein,lyra2v2,nist5 --show-diff -d 0,1 -i 21,19 12 | 13 | sleep 5 14 | done 15 | -------------------------------------------------------------------------------- /stats.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Stats place holder 3 | * 4 | * Note: this source is C++ (requires std::map) 5 | * 6 | * tpruvot@github 2014 7 | */ 8 | #include 9 | #include 10 | #include 11 | 12 | #include "miner.h" 13 | 14 | static std::map tlastscans; 15 | static uint64_t uid = 0; 16 | 17 | #define STATS_AVG_SAMPLES 30 18 | #define STATS_PURGE_TIMEOUT 120*60 /* 120 mn */ 19 | 20 | extern uint64_t global_hashrate; 21 | extern int opt_statsavg; 22 | 23 | /** 24 | * Store speed per thread 25 | */ 26 | void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8_t found, uint32_t height) 27 | { 28 | const uint64_t key = uid++; 29 | stats_data data; 30 | // to enough hashes to give right stats 31 | if (hashcount < 1000 || hashrate < 0.01) 32 | return; 33 | 34 | // first hash rates are often erroneous 35 | //if (uid < opt_n_threads * 2) 36 | // return; 37 | 38 | memset(&data, 0, sizeof(data)); 39 | data.uid = (uint32_t) uid; 40 | data.gpu_id = (uint8_t) device_map[thr_id]; 41 | data.thr_id = (uint8_t) thr_id; 42 | data.tm_stat = (uint32_t) time(NULL); 43 | data.height = height; 44 | data.npool = (uint8_t) cur_pooln; 45 | data.pool_type = pools[cur_pooln].type; 46 | data.hashcount = hashcount; 47 | data.hashfound = found; 48 | data.hashrate = hashrate; 49 | data.difficulty = net_diff ? net_diff : stratum_diff; 50 | if (opt_n_threads == 1 && global_hashrate && uid > 10) { 51 | // prevent stats on too high vardiff (erroneous rates) 52 | double ratio = (hashrate / (1.0 * global_hashrate)); 53 | if (ratio < 0.4 || ratio > 1.6) 54 | data.ignored = 1; 55 | } 56 | tlastscans[key] = data; 57 | } 58 | 59 | /** 60 | * Get the computed average speed 61 | * @param thr_id int (-1 for all threads) 62 | */ 63 | double stats_get_speed(int thr_id, double def_speed) 64 | { 65 | double speed = 0.0; 66 | int records = 0; 67 | 68 | std::map::reverse_iterator i = tlastscans.rbegin(); 69 | while (i != tlastscans.rend() && records < opt_statsavg) { 70 | if (!i->second.ignored) 71 | if (thr_id == -1 || i->second.thr_id == thr_id) { 72 | if (i->second.hashcount > 1000) { 73 | speed += i->second.hashrate; 74 | records++; 75 | // applog(LOG_BLUE, "%d %x %.1f", thr_id, i->second.thr_id, i->second.hashrate); 76 | } 77 | } 78 | ++i; 79 | } 80 | 81 | if (records) 82 | speed /= (double)(records); 83 | else 84 | speed = def_speed; 85 | 86 | if (thr_id == -1) 87 | speed *= (double)(opt_n_threads); 88 | 89 | return speed; 90 | } 91 | 92 | /** 93 | * Get the gpu average speed 94 | * @param gpu_id int (-1 for all threads) 95 | */ 96 | double stats_get_gpu_speed(int gpu_id) 97 | { 98 | double speed = 0.0; 99 | 100 | for (int thr_id=0; thr_id::reverse_iterator i = tlastscans.rbegin(); 117 | while (i != tlastscans.rend() && records < max_records) { 118 | if (!i->second.ignored) 119 | if (thr_id == -1 || i->second.thr_id == thr_id) { 120 | memcpy(&data[records], &(i->second), sizeof(struct stats_data)); 121 | records++; 122 | } 123 | ++i; 124 | } 125 | return records; 126 | } 127 | 128 | /** 129 | * Remove old entries to reduce memory usage 130 | */ 131 | void stats_purge_old(void) 132 | { 133 | int deleted = 0; 134 | uint32_t now = (uint32_t) time(NULL); 135 | uint32_t sz = (uint32_t) tlastscans.size(); 136 | std::map::iterator i = tlastscans.begin(); 137 | while (i != tlastscans.end()) { 138 | if (i->second.ignored || (now - i->second.tm_stat) > STATS_PURGE_TIMEOUT) { 139 | deleted++; 140 | tlastscans.erase(i++); 141 | } 142 | else ++i; 143 | } 144 | if (opt_debug && deleted) { 145 | applog(LOG_DEBUG, "stats: %d/%d records purged", deleted, sz); 146 | } 147 | } 148 | 149 | /** 150 | * Reset the cache 151 | */ 152 | void stats_purge_all(void) 153 | { 154 | tlastscans.clear(); 155 | } 156 | 157 | /** 158 | * API meminfo 159 | */ 160 | void stats_getmeminfo(uint64_t *mem, uint32_t *records) 161 | { 162 | (*records) = (uint32_t) tlastscans.size(); 163 | (*mem) = (*records) * sizeof(stats_data); 164 | } 165 | -------------------------------------------------------------------------------- /streebog/veltor.cu: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include "sph/sph_skein.h" 3 | #include "sph/sph_shavite.h" 4 | #include "sph/sph_shabal.h" 5 | #include "sph/sph_streebog.h" 6 | } 7 | 8 | #include "miner.h" 9 | #include "cuda_helper.h" 10 | #include "x11/cuda_x11.h" 11 | 12 | extern void streebog_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_hash,uint32_t* d_resNonce); 13 | extern void streebog_set_target(const uint32_t* ptarget); 14 | extern void x14_shabal512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 15 | 16 | extern void skein512_cpu_setBlock_80(void *pdata); 17 | extern void skein512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash); 18 | 19 | #include 20 | #include 21 | 22 | #define NBN 2 23 | static uint32_t *d_hash[MAX_GPUS]; 24 | static uint32_t *d_resNonce[MAX_GPUS]; 25 | static uint32_t *h_resNonce[MAX_GPUS]; 26 | 27 | // veltorcoin CPU Hash 28 | extern "C" void veltorhash(void *output, const void *input) 29 | { 30 | unsigned char _ALIGN(128) hash[128] = { 0 }; 31 | 32 | sph_skein512_context ctx_skein; 33 | sph_gost512_context ctx_gost; 34 | sph_shabal512_context ctx_shabal; 35 | sph_shavite512_context ctx_shavite; 36 | 37 | sph_skein512_init(&ctx_skein); 38 | sph_skein512 (&ctx_skein, input, 80); 39 | sph_skein512_close(&ctx_skein, (void*) hash); 40 | 41 | sph_shavite512_init(&ctx_shavite); 42 | sph_shavite512 (&ctx_shavite, (const void*) hash, 64); 43 | sph_shavite512_close(&ctx_shavite, (void*) hash); 44 | 45 | sph_shabal512_init(&ctx_shabal); 46 | sph_shabal512 (&ctx_shabal, (const void*) hash, 64); 47 | sph_shabal512_close(&ctx_shabal, (void*) hash); 48 | 49 | sph_gost512_init(&ctx_gost); 50 | sph_gost512(&ctx_gost, (const void*) hash, 64); 51 | sph_gost512_close(&ctx_gost, (void*) hash); 52 | 53 | memcpy(output, hash, 32); 54 | } 55 | 56 | static bool init[MAX_GPUS] = { 0 }; 57 | 58 | extern "C" int scanhash_veltor(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done){ 59 | 60 | int dev_id = device_map[thr_id]; 61 | 62 | uint32_t *pdata = work->data; 63 | uint32_t *ptarget = work->target; 64 | const uint32_t first_nonce = pdata[19]; 65 | int intensity = (device_sm[device_map[thr_id]] > 500) ? 24 : 22; 66 | // int intensity = is_windows() ? 14 : 16; 67 | if (strstr(device_name[dev_id], "GTX 9")) intensity = 24; 68 | if (strstr(device_name[dev_id], "GTX 10")) intensity = 25; 69 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); // 19=256*256*8; 70 | //if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 71 | 72 | if (opt_benchmark) 73 | ptarget[7] = 0xf; 74 | 75 | if (!init[thr_id]) 76 | { 77 | cudaSetDevice(device_map[thr_id]); 78 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 79 | cudaDeviceReset(); 80 | // reduce cpu usage 81 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 82 | // cudaDeviceSetSharedMemConfig(cudaSharedMemBankSizeEightByte); 83 | CUDA_LOG_ERROR(); 84 | } 85 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 86 | 87 | CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 8 * sizeof(uint64_t) * throughput)); 88 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 89 | h_resNonce[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t)); 90 | if(h_resNonce[thr_id] == NULL){ 91 | gpulog(LOG_ERR,thr_id,"Host memory allocation failed"); 92 | exit(EXIT_FAILURE); 93 | } 94 | 95 | init[thr_id] = true; 96 | } 97 | 98 | uint32_t endiandata[20]; 99 | for (int k=0; k < 20; k++) 100 | be32enc(&endiandata[k], pdata[k]); 101 | 102 | skein512_cpu_setBlock_80(endiandata); 103 | 104 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 105 | streebog_set_target(ptarget); 106 | 107 | do { 108 | skein512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); 109 | x11_shavite512_cpu_hash_64(thr_id, throughput, d_hash[thr_id]); 110 | x14_shabal512_cpu_hash_64(thr_id, throughput, d_hash[thr_id]); 111 | streebog_cpu_hash_64_final(thr_id, throughput, d_hash[thr_id], d_resNonce[thr_id]); 112 | 113 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 114 | 115 | if (h_resNonce[thr_id][0] != UINT32_MAX){ 116 | const uint32_t Htarg = ptarget[7]; 117 | const uint32_t startNounce = pdata[19]; 118 | uint32_t vhash64[8]; 119 | be32enc(&endiandata[19], startNounce + h_resNonce[thr_id][0]); 120 | veltorhash(vhash64, endiandata); 121 | 122 | if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) { 123 | int res = 1; 124 | *hashes_done = pdata[19] - first_nonce + throughput; 125 | work_set_target_ratio(work, vhash64); 126 | pdata[19] = startNounce + h_resNonce[thr_id][0]; 127 | if (h_resNonce[thr_id][1] != UINT32_MAX) { 128 | pdata[21] = startNounce+h_resNonce[thr_id][1]; 129 | // if(!opt_quiet) 130 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce: %08x", pdata[21]); 131 | be32enc(&endiandata[19], startNounce+h_resNonce[thr_id][1]); 132 | veltorhash(vhash64, endiandata); 133 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]){ 134 | work_set_target_ratio(work, vhash64); 135 | xchg(pdata[19],pdata[21]); 136 | } 137 | 138 | res++; 139 | } 140 | return res; 141 | } 142 | else { 143 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]); 144 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 145 | } 146 | } 147 | 148 | pdata[19] += throughput; 149 | } while (!work_restart[thr_id].restart && ((uint64_t)max_nonce > (uint64_t)throughput + pdata[19])); 150 | 151 | *hashes_done = pdata[19] - first_nonce; 152 | 153 | return 0; 154 | } 155 | 156 | // cleanup 157 | extern "C" void free_veltor(int thr_id) 158 | { 159 | if (!init[thr_id]) 160 | return; 161 | 162 | cudaDeviceSynchronize(); 163 | 164 | free(h_resNonce[thr_id]); 165 | cudaFree(d_resNonce[thr_id]); 166 | cudaFree(d_hash[thr_id]); 167 | init[thr_id] = false; 168 | 169 | cudaDeviceSynchronize(); 170 | } 171 | -------------------------------------------------------------------------------- /sysinfos.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit to read cpu informations 3 | * 4 | * TODO: WMI implementation for windows 5 | * 6 | * tpruvot 2014 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "miner.h" 15 | 16 | #ifndef WIN32 17 | 18 | #define HWMON_PATH \ 19 | "/sys/class/hwmon/hwmon1/device/temp1_input" 20 | #define HWMON_ALT \ 21 | "/sys/class/hwmon/hwmon0/temp1_input" 22 | 23 | static double linux_cputemp(int core) 24 | { 25 | double tc = 0.0; 26 | FILE *fd = fopen(HWMON_PATH, "r"); 27 | uint32_t val = 0; 28 | 29 | if (!fd) 30 | fd = fopen(HWMON_ALT, "r"); 31 | 32 | if (!fd) 33 | return tc; 34 | 35 | if (fscanf(fd, "%d", &val)) 36 | tc = (double)val / 1000.0; 37 | 38 | fclose(fd); 39 | return tc; 40 | } 41 | 42 | #define CPUFREQ_PATH \ 43 | "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq" 44 | static uint32_t linux_cpufreq(int core) 45 | { 46 | FILE *fd = fopen(CPUFREQ_PATH, "r"); 47 | uint32_t freq = 0; 48 | 49 | if (!fd) 50 | return freq; 51 | 52 | if (!fscanf(fd, "%d", &freq)) 53 | return freq; 54 | 55 | return freq; 56 | } 57 | 58 | #else /* WIN32 */ 59 | 60 | static float win32_cputemp(int core) 61 | { 62 | // todo 63 | return 0.0; 64 | } 65 | 66 | #endif /* !WIN32 */ 67 | 68 | 69 | /* exports */ 70 | 71 | 72 | float cpu_temp(int core) 73 | { 74 | #ifdef WIN32 75 | return win32_cputemp(core); 76 | #else 77 | return (float) linux_cputemp(core); 78 | #endif 79 | } 80 | 81 | uint32_t cpu_clock(int core) 82 | { 83 | #ifdef WIN32 84 | return 0; 85 | #else 86 | return linux_cpufreq(core); 87 | #endif 88 | } 89 | 90 | int cpu_fanpercent() 91 | { 92 | return 0; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krnlx/ccminer-xevan/7d41d49b92db27b9ab80270adaa92f6b06d1ef78/test -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | //unsigned long long x = 0x002000000000000UL; 3 | 4 | unsigned long long x = 0x0002000000000000UL; 5 | unsigned int *y= (unsigned int *)&x; 6 | printf("%x %x\n",y[0],y[1]); 7 | } 8 | -------------------------------------------------------------------------------- /x11/cuda_x11.h: -------------------------------------------------------------------------------- 1 | #include "quark/cuda_quark.h" 2 | 3 | extern void x11_luffa512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 4 | extern void x11_cubehash512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 5 | extern void x11_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 6 | 7 | extern void x11_cubehash_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 8 | 9 | extern void x11_simd512_cpu_init(int thr_id, uint32_t threads); 10 | extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 11 | extern void x11_simd512_cpu_free(int thr_id); 12 | 13 | extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads,uint32_t *d_hash); 14 | extern void x11_echo512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_hash, uint32_t *d_resNonce, const uint64_t target); 15 | 16 | extern void x11_simd_echo_512_cpu_init(int thr_id, uint32_t threads); 17 | extern void x11_simd_echo512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t *d_hash, uint32_t *d_resNonce, const uint64_t target); 18 | extern void x11_simd_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash); 19 | extern void x11_simd_echo_512_cpu_free(int thr_id); 20 | 21 | -------------------------------------------------------------------------------- /x15/whirlpool.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * whirlpool routine (djm) 3 | */ 4 | extern "C" 5 | { 6 | #include "sph/sph_whirlpool.h" 7 | } 8 | #include "miner.h" 9 | #include "cuda_helper.h" 10 | 11 | #define NBN 2 12 | 13 | // Memory for the hash functions 14 | static uint32_t *d_resNonce[MAX_GPUS]; 15 | static uint32_t *h_resNonce[MAX_GPUS]; 16 | 17 | extern void x15_whirlpool_cpu_init(int thr_id, uint32_t threads, int mode); 18 | extern void x15_whirlpool_cpu_free(int thr_id); 19 | 20 | extern void whirlpool512_setBlock_80(void *pdata, const void *ptarget); 21 | extern void whirlpool512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_resNonce, const uint64_t target); 22 | 23 | // CPU Hash function 24 | extern "C" void wcoinhash(void *state, const void *input) 25 | { 26 | sph_whirlpool_context ctx_whirlpool; 27 | 28 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 29 | #define hashB hash+64 30 | 31 | memset(hash, 0, sizeof hash); 32 | 33 | sph_whirlpool1_init(&ctx_whirlpool); 34 | sph_whirlpool1(&ctx_whirlpool, input, 80); 35 | sph_whirlpool1_close(&ctx_whirlpool, hash); 36 | 37 | sph_whirlpool1_init(&ctx_whirlpool); 38 | sph_whirlpool1(&ctx_whirlpool, hash, 64); 39 | sph_whirlpool1_close(&ctx_whirlpool, hashB); 40 | 41 | sph_whirlpool1_init(&ctx_whirlpool); 42 | sph_whirlpool1(&ctx_whirlpool, hashB, 64); 43 | sph_whirlpool1_close(&ctx_whirlpool, hash); 44 | 45 | sph_whirlpool1_init(&ctx_whirlpool); 46 | sph_whirlpool1(&ctx_whirlpool, hash, 64); 47 | sph_whirlpool1_close(&ctx_whirlpool, hash); 48 | 49 | memcpy(state, hash, 32); 50 | } 51 | 52 | static bool init[MAX_GPUS] = { 0 }; 53 | 54 | extern "C" int scanhash_whirl(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done) 55 | { 56 | 57 | int dev_id = device_map[thr_id]; 58 | 59 | uint32_t endiandata[20]; 60 | uint32_t* pdata = work->data; 61 | uint32_t* ptarget = work->target; 62 | const uint32_t first_nonce = pdata[19]; 63 | 64 | uint32_t default_throughput; 65 | if(device_sm[dev_id]<=500) default_throughput = 1<<22; 66 | else if(device_sm[dev_id]<=520) default_throughput = 1<<25; 67 | else if((device_sm[dev_id]<=520) && is_windows()) default_throughput = 1<<24; 68 | else if(device_sm[dev_id]>520) default_throughput = 1<<25; 69 | uint32_t throughput = cuda_default_throughput(thr_id, default_throughput); // 19=256*256*8; 70 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 71 | 72 | if (opt_benchmark) 73 | ((uint32_t*)ptarget)[7] = 0x0000ff; 74 | 75 | if (!init[thr_id]) { 76 | cudaSetDevice(device_map[thr_id]); 77 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 78 | // reduce cpu usage 79 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 80 | CUDA_LOG_ERROR(); 81 | } 82 | 83 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 84 | 85 | x15_whirlpool_cpu_init(thr_id, throughput, 1 /* old whirlpool */); 86 | 87 | // CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput)); 88 | CUDA_SAFE_CALL(cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t))); 89 | h_resNonce[thr_id] = (uint32_t*) malloc(NBN * sizeof(uint32_t)); 90 | if(h_resNonce[thr_id] == NULL){ 91 | gpulog(LOG_ERR,thr_id,"Host memory allocation failed"); 92 | exit(EXIT_FAILURE); 93 | } 94 | init[thr_id] = true; 95 | } 96 | 97 | for (int k=0; k < 20; k++) { 98 | be32enc(&endiandata[k], pdata[k]); 99 | } 100 | 101 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 102 | whirlpool512_setBlock_80((void*)endiandata, ptarget); 103 | do { 104 | whirlpool512_cpu_hash_80(thr_id, throughput, pdata[19], d_resNonce[thr_id], *(uint64_t*)&ptarget[ 6]); 105 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 106 | 107 | if (h_resNonce[thr_id][0] != UINT32_MAX){ 108 | const uint32_t Htarg = ptarget[7]; 109 | const uint32_t startNounce = pdata[19]; 110 | uint32_t vhash64[8]; 111 | be32enc(&endiandata[19], startNounce + h_resNonce[thr_id][0]); 112 | wcoinhash(vhash64, endiandata); 113 | 114 | if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) { 115 | int res = 1; 116 | *hashes_done = pdata[19] - first_nonce + throughput; 117 | work_set_target_ratio(work, vhash64); 118 | pdata[19] = startNounce + h_resNonce[thr_id][0]; 119 | if (h_resNonce[thr_id][1] != UINT32_MAX) { 120 | pdata[21] = startNounce+h_resNonce[thr_id][1]; 121 | // if(!opt_quiet) 122 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce: %08x", pdata[21]); 123 | be32enc(&endiandata[19], pdata[21]); 124 | wcoinhash(vhash64, endiandata); 125 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio[0]){ 126 | work_set_target_ratio(work, vhash64); 127 | xchg(pdata[19],pdata[21]); 128 | } 129 | res++; 130 | } 131 | return res; 132 | }else { 133 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", h_resNonce[thr_id][0]); 134 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 135 | } 136 | } 137 | 138 | pdata[19] += throughput; 139 | 140 | } while (!work_restart[thr_id].restart && ((uint64_t)max_nonce > (uint64_t)throughput + pdata[19])); 141 | 142 | *hashes_done = pdata[19] - first_nonce; 143 | return 0; 144 | } 145 | 146 | // cleanup 147 | extern "C" void free_whirl(int thr_id) 148 | { 149 | if (!init[thr_id]) 150 | return; 151 | 152 | cudaDeviceSynchronize(); 153 | 154 | x15_whirlpool_cpu_free(thr_id); 155 | init[thr_id] = false; 156 | 157 | cudaDeviceSynchronize(); 158 | } 159 | 160 | -------------------------------------------------------------------------------- /x15/whirlpoolx.cu: -------------------------------------------------------------------------------- 1 | /* 2 | * whirlpool routine (djm) 3 | * whirlpoolx routine (provos alexis, tpruvot) 4 | */ 5 | extern "C" { 6 | #include "sph/sph_whirlpool.h" 7 | } 8 | 9 | #include "miner.h" 10 | #include "cuda_helper.h" 11 | 12 | static uint32_t *d_hash[MAX_GPUS] = { 0 }; 13 | 14 | extern void whirlpoolx_cpu_free(int thr_id); 15 | extern void whirlpoolx_cpu_init(int thr_id, int threads); 16 | extern void whirlpoolx_setBlock_precompute(void *pdata, const void *ptarget,int thr_id); 17 | extern uint32_t cpu_whirlpoolx(int thr_id, uint32_t threads, uint32_t startNounce); 18 | extern void whirlpoolx_precompute(int thr_id); 19 | // CPU Hash function 20 | extern "C" void whirlxHash(void *state, const void *input) 21 | { 22 | sph_whirlpool_context ctx_whirlpool; 23 | 24 | unsigned char hash[64]; 25 | unsigned char hash_xored[32]; 26 | 27 | sph_whirlpool_init(&ctx_whirlpool); 28 | sph_whirlpool(&ctx_whirlpool, input, 80); 29 | sph_whirlpool_close(&ctx_whirlpool, hash); 30 | 31 | // compress the 48 first bytes of the hash to 32 32 | for (int i = 0; i < 32; i++) { 33 | hash_xored[i] = hash[i] ^ hash[i + 16]; 34 | } 35 | memcpy(state, hash_xored, 32); 36 | } 37 | 38 | static bool init[MAX_GPUS] = { 0 }; 39 | 40 | extern "C" int scanhash_whirlpoolx(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done) 41 | { 42 | uint32_t *pdata = work->data; 43 | uint32_t *ptarget = work->target; 44 | const uint32_t first_nonce = pdata[19]; 45 | uint32_t endiandata[20]; 46 | int intensity = is_windows() ? 20 : 22; 47 | uint32_t throughput = cuda_default_throughput(thr_id, 1U << intensity); 48 | if (init[thr_id]) throughput = min(throughput, max_nonce - first_nonce); 49 | 50 | if (opt_benchmark) 51 | ptarget[7] = 0x000f; 52 | 53 | if (!init[thr_id]) { 54 | cudaSetDevice(device_map[thr_id]); 55 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 56 | cudaDeviceReset(); 57 | // reduce cpu usage 58 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 59 | CUDA_LOG_ERROR(); 60 | } 61 | 62 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 63 | 64 | CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], (size_t) 64 * throughput), -1); 65 | 66 | whirlpoolx_cpu_init(thr_id, throughput); 67 | 68 | init[thr_id] = true; 69 | } 70 | 71 | for (int k=0; k < 20; k++) { 72 | be32enc(&endiandata[k], pdata[k]); 73 | } 74 | 75 | whirlpoolx_setBlock_precompute((void*)endiandata, ptarget,thr_id); 76 | 77 | do { 78 | uint32_t foundNonce = cpu_whirlpoolx(thr_id, throughput, pdata[19]); 79 | 80 | *(hashes_done) = pdata[19] - first_nonce + throughput; 81 | 82 | if (foundNonce != UINT32_MAX && bench_algo < 0) 83 | { 84 | const uint32_t Htarg = ptarget[7]; 85 | uint32_t vhash64[8]; 86 | be32enc(&endiandata[19], foundNonce); 87 | whirlxHash(vhash64, endiandata); 88 | 89 | if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) { 90 | work_set_target_ratio(work, vhash64); 91 | pdata[19] = foundNonce; 92 | return 1; 93 | } else { 94 | gpulog(LOG_WARNING, thr_id, "result for %08x does not validate on CPU!", foundNonce); 95 | } 96 | } 97 | 98 | if ((uint64_t)throughput + pdata[19] >= max_nonce) { 99 | pdata[19] = max_nonce; 100 | break; 101 | } 102 | 103 | pdata[19] += throughput; 104 | 105 | } while (!work_restart[thr_id].restart); 106 | 107 | *(hashes_done) = pdata[19] - first_nonce; 108 | 109 | return 0; 110 | } 111 | 112 | // cleanup 113 | extern "C" void free_whirlx(int thr_id) 114 | { 115 | if (!init[thr_id]) 116 | return; 117 | 118 | cudaThreadSynchronize(); 119 | 120 | cudaFree(d_hash[thr_id]); 121 | 122 | whirlpoolx_cpu_free(thr_id); 123 | init[thr_id] = false; 124 | 125 | cudaDeviceSynchronize(); 126 | } 127 | -------------------------------------------------------------------------------- /yescrypt/yescrypt.cu: -------------------------------------------------------------------------------- 1 | 2 | extern "C" 3 | { 4 | #include "sph/yescrypt.h" 5 | } 6 | 7 | #include "cuda_helper.h" 8 | #include "miner.h" 9 | 10 | #define NBN 2 11 | 12 | static uint32_t *d_resNonce[MAX_GPUS]; 13 | static uint32_t *h_resNonce[MAX_GPUS]; 14 | 15 | extern void yescrypt_setBlockTarget(uint32_t * data, const void *ptarget); 16 | extern void yescrypt_cpu_init(int thr_id, int threads); 17 | extern void yescrypt_free(int thr_id); 18 | extern void yescrypt_cpu_hash_k4(int thr_id, int threads, uint32_t startNounce, uint32_t* resNonce); 19 | 20 | 21 | static bool init[MAX_GPUS] = { 0 }; 22 | 23 | int scanhash_yescrypt(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done){ 24 | 25 | int dev_id = device_map[thr_id]; 26 | 27 | uint32_t _ALIGN(64) endiandata[20]; 28 | uint32_t *pdata = work->data; 29 | uint32_t *ptarget = work->target; 30 | const uint32_t first_nonce = pdata[19]; 31 | 32 | if (opt_benchmark) 33 | ((uint32_t*)ptarget)[7] = 0x0000ff; 34 | 35 | int coef = 16; 36 | if (device_sm[device_map[thr_id]] == 500) coef = 6; 37 | if (device_sm[device_map[thr_id]] == 350) coef = 2; 38 | 39 | const int throughput = 64*coef; 40 | 41 | if (!init[thr_id]) 42 | { 43 | cudaSetDevice(device_map[thr_id]); 44 | if (opt_cudaschedule == -1 && gpu_threads == 1) { 45 | cudaDeviceReset(); 46 | // reduce cpu usage 47 | cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); 48 | cudaDeviceSetCacheConfig(cudaFuncCachePreferL1); 49 | } 50 | gpulog(LOG_INFO,thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); 51 | 52 | yescrypt_cpu_init(thr_id, throughput); 53 | 54 | cudaMalloc(&d_resNonce[thr_id], NBN * sizeof(uint32_t)); 55 | cudaMallocHost(&h_resNonce[thr_id], NBN * sizeof(uint32_t)); 56 | 57 | init[thr_id] = true; 58 | } 59 | 60 | for (int k = 0; k < 20; k++) 61 | be32enc(&endiandata[k], ((uint32_t*)pdata)[k]); 62 | 63 | yescrypt_setBlockTarget(pdata,ptarget); 64 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 65 | int rc = 0; 66 | do { 67 | yescrypt_cpu_hash_k4(thr_id, throughput, pdata[19], d_resNonce[thr_id]); 68 | cudaMemcpy(h_resNonce[thr_id], d_resNonce[thr_id], NBN*sizeof(uint32_t), cudaMemcpyDeviceToHost); 69 | if(h_resNonce[thr_id][0] != UINT32_MAX){ 70 | uint32_t vhash64[8]; 71 | be32enc(&endiandata[19], h_resNonce[thr_id][0]); 72 | yescrypt_hash((uchar*) endiandata, (uchar*)vhash64); 73 | 74 | if ( (vhash64[7] <= ptarget[7]) && fulltest(vhash64, ptarget)) { 75 | *hashes_done = pdata[19] - first_nonce + throughput; 76 | pdata[19] = h_resNonce[thr_id][0]; 77 | rc = 1; 78 | 79 | if(h_resNonce[thr_id][1] != UINT32_MAX){ 80 | // if(!opt_quiet) 81 | // gpulog(LOG_BLUE,dev_id,"Found 2nd nonce: %08x", h_resNonce[thr_id][1]); 82 | endiandata[19] = h_resNonce[thr_id][1]; 83 | yescrypt_hash((uchar*)endiandata, (uchar*)vhash64); 84 | pdata[21] = h_resNonce[thr_id][1]; 85 | if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio){ 86 | work_set_target_ratio(work, vhash64); 87 | xchg(pdata[19],pdata[21]); 88 | } 89 | rc = 2; 90 | } 91 | return rc; 92 | } else { 93 | gpulog(LOG_INFO,dev_id, "Result for nonce $%08X does not validate on CPU!", h_resNonce[thr_id]); 94 | cudaMemset(d_resNonce[thr_id], 0xff, NBN*sizeof(uint32_t)); 95 | } 96 | } 97 | pdata[19] += throughput; 98 | }while(!work_restart[thr_id].restart && ((uint64_t)max_nonce > ((uint64_t)(pdata[19]) + (uint64_t)throughput))); 99 | *hashes_done = pdata[19] - first_nonce + 1; 100 | return rc; 101 | } 102 | 103 | // cleanup 104 | void free_yescrypt(int thr_id) 105 | { 106 | if (!init[thr_id]) 107 | return; 108 | 109 | cudaDeviceSynchronize(); 110 | 111 | cudaFreeHost(h_resNonce[thr_id]); 112 | cudaFree(d_resNonce[thr_id]); 113 | 114 | yescrypt_free(thr_id); 115 | init[thr_id] = false; 116 | 117 | cudaDeviceSynchronize(); 118 | } 119 | --------------------------------------------------------------------------------