├── .gitignore ├── .travis.yml ├── AUTHORS ├── Android.mk ├── COPYING ├── ChangeLog ├── Dockerfile ├── LICENSE ├── Makefile ├── Makefile.am ├── Makefile.in ├── NEWS ├── README.md ├── RUN-ZCOIN-MTP.cmd ├── algo ├── .dirstamp ├── allium.c ├── axiom.c ├── bastion.c ├── bitcore.c ├── blake.c ├── blake2.c ├── blakecoin.c ├── bmw256.c ├── c11.c ├── cryptolight.c ├── cryptonight.c ├── decred.c ├── drop.c ├── fresh.c ├── groestl.c ├── heavy.c ├── ink.c ├── jha.c ├── keccak.c ├── lbry.c ├── luffa.c ├── lyra2re.c ├── lyra2rev2.c ├── mtp_algo.cpp ├── myr-groestl.c ├── neoscrypt.c ├── nist5.c ├── pentablake.c ├── phi1612.c ├── phi2.c ├── pluck.c ├── quark.c ├── qubit.c ├── s3.c ├── scrypt-jane.c ├── scrypt.c ├── sha2.c ├── sia.c ├── sibcoin.c ├── skein.c ├── skein2.c ├── sonoa.c ├── timetravel.c ├── tribus.c ├── veltor.c ├── x11.c ├── x11evo.c ├── x12.c ├── x13.c ├── x14.c ├── x15.c ├── x16r.c ├── x16s.c ├── x17.c ├── xevan.c ├── yescrypt.c └── zr5.c ├── api.c ├── api ├── index.php ├── local-sample.php └── websocket.htm ├── argon2ref ├── argon2.c ├── argon2.h ├── blake2-impl.h ├── blake2.h ├── blake2b-load-sse2.h ├── blake2b-load-sse41.h ├── blake2b-round.h ├── blake2ba.c ├── blake2bp.c ├── blamka-round-opt.h ├── blamka-round-ref.h ├── core.c ├── core.h ├── encoding.c ├── encoding.h ├── ref.c ├── thread.c └── thread.h ├── asm ├── .dirstamp ├── aesb-x64.S ├── aesb-x86.S ├── neoscrypt_asm.S ├── scrypt-arm.S ├── scrypt-x64.S ├── scrypt-x86.S ├── sha2-arm.S ├── sha2-x64.S └── sha2-x86.S ├── autogen.sh ├── base58.cpp ├── build.sh ├── compat.h ├── compat ├── .gitignore ├── .travis.yml ├── Android.mk ├── CHANGES ├── CMakeLists.txt ├── CleanSpec.mk ├── LICENSE ├── Makefile.am ├── bionic │ └── cpuminer-config.h ├── bos-jansson │ ├── Makefile.am │ ├── bos_deserializer.c │ ├── bos_serializer.c │ ├── bosjansson.def │ ├── bosjansson.h │ ├── configure.ac │ ├── dump.c │ ├── error.c │ ├── hashtable.c │ ├── hashtable.h │ ├── hashtable_seed.c │ ├── jansson_config.h │ ├── jansson_config.h.in │ ├── jansson_config.h.in_old │ ├── jansson_private.h │ ├── jansson_private_config.h │ ├── load.c │ ├── lookup3.h │ ├── memory.c │ ├── pack_unpack.c │ ├── strbuffer.c │ ├── strbuffer.h │ ├── strconv.c │ ├── utf.c │ ├── utf.h │ └── value.c ├── cpuminer-config.h ├── 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 │ │ │ ├── e_os2.h │ │ │ ├── opensslconf.h │ │ │ └── sha.h │ ├── out │ │ └── lib │ │ │ ├── libcryptoMT.lib │ │ │ ├── libcurl.lib │ │ │ ├── libeay32MT.lib │ │ │ ├── libsslMT.lib │ │ │ ├── pthreadVC2.lib │ │ │ ├── ssleay32MT.lib │ │ │ └── zlibstat.lib │ └── zlib │ │ ├── zconf.h │ │ └── zlib.h ├── getopt │ ├── getopt.h │ └── getopt_long.c ├── gettimeofday.c ├── inttypes.h ├── pthreads │ ├── pthread.h │ ├── sched.h │ ├── x64 │ │ └── pthreadVC2.lib │ └── x86 │ │ └── pthreadVC2.lib ├── stdbool.h ├── sys │ └── time.h ├── unistd.h ├── winansi.c └── winansi.h ├── compile ├── config.guess ├── config.status ├── config.sub ├── configure ├── configure.ac ├── cpu-miner.c ├── cpuminer-conf.json ├── cpuminer-config.h.in ├── cpuminer.1 ├── cpuminer.nsi ├── cpuminer.sln ├── cpuminer.vcxproj ├── cpuminer.vcxproj.filters ├── crypto ├── .dirstamp ├── aesb.c ├── blake2b.c ├── blake2b.h ├── blake2s.c ├── blake2s.h ├── c_blake256.c ├── c_blake256.h ├── c_groestl.c ├── c_groestl.h ├── c_jh.c ├── c_jh.h ├── c_keccak.c ├── c_keccak.h ├── c_skein.c ├── c_skein.h ├── groestl_tables.h ├── hash-ops.h ├── hash.c ├── hash.h ├── int-util.h ├── oaes_config.h ├── oaes_lib.c ├── oaes_lib.h └── skein_port.h ├── depcomp ├── elist.h ├── install-sh ├── lyra2 ├── .dirstamp ├── Lyra2.c ├── Lyra2.h ├── Sponge.c └── Sponge.h ├── m4 └── .gitignore ├── merkletree ├── .dirstamp ├── LICENSE ├── README.md ├── byteswap.h ├── definition.h ├── endian.h ├── merkle-tree.cpp ├── merkle-tree.hpp ├── mtp.cpp ├── mtp.h ├── prevector.h └── zeroafterfree.h ├── miner.h ├── mingw64.sh ├── missing ├── nomacro.pl ├── res ├── cpuminer.ico ├── cpuminer.rc ├── cpuminer.svg ├── icon.rc ├── resource.h └── setup.ico ├── scryptjane ├── scrypt-conf.h ├── scrypt-jane-chacha.h ├── scrypt-jane-hash.h ├── scrypt-jane-hash_blake256.h ├── scrypt-jane-hash_blake512.h ├── scrypt-jane-hash_keccak.h ├── scrypt-jane-hash_sha256.h ├── scrypt-jane-hash_sha512.h ├── scrypt-jane-hash_skein512.h ├── scrypt-jane-mix_chacha-avx.h ├── scrypt-jane-mix_chacha-sse2.h ├── scrypt-jane-mix_chacha-ssse3.h ├── scrypt-jane-mix_chacha.h ├── scrypt-jane-mix_salsa-avx.h ├── scrypt-jane-mix_salsa-sse2.h ├── scrypt-jane-mix_salsa.h ├── scrypt-jane-mix_salsa64-avx.h ├── scrypt-jane-mix_salsa64-sse2.h ├── scrypt-jane-mix_salsa64-ssse3.h ├── scrypt-jane-mix_salsa64.h ├── scrypt-jane-pbkdf2.h ├── scrypt-jane-portable-x86.h ├── scrypt-jane-portable.h ├── scrypt-jane-romix-basic.h ├── scrypt-jane-romix-template.h ├── scrypt-jane-romix.h ├── scrypt-jane-salsa.h ├── scrypt-jane-salsa64.h └── scrypt-jane-test-vectors.h ├── sha3 ├── .dirstamp ├── aes_helper.c ├── gost_streebog.c ├── gost_streebog.h ├── haval_helper.c ├── md_helper.c ├── mod_blakecoin.c ├── sph_blake.c ├── sph_blake.h ├── sph_bmw.c ├── sph_bmw.h ├── sph_cubehash.c ├── sph_cubehash.h ├── sph_echo.c ├── sph_echo.h ├── sph_fugue.c ├── sph_fugue.h ├── sph_groestl.c ├── sph_groestl.h ├── sph_hamsi.c ├── sph_hamsi.h ├── sph_hamsi_helper.c ├── sph_haval.c ├── sph_haval.h ├── sph_hefty1.c ├── sph_hefty1.h ├── sph_jh.c ├── sph_jh.h ├── sph_keccak.c ├── sph_keccak.h ├── sph_luffa.c ├── sph_luffa.h ├── sph_ripemd.c ├── sph_ripemd.h ├── sph_sha2.c ├── sph_sha2.h ├── sph_sha2big.c ├── sph_shabal.c ├── sph_shabal.h ├── sph_shavite.c ├── sph_shavite.h ├── sph_simd.c ├── sph_simd.h ├── sph_skein.c ├── sph_skein.h ├── sph_types.h ├── sph_whirlpool.c └── sph_whirlpool.h ├── stamp-h1 ├── sysinfos.c ├── uint256.cpp ├── uint256.h ├── util.c └── yescrypt ├── .dirstamp ├── sha256_Y.c ├── sha256_Y.h ├── sysendian.h ├── yescrypt-best.c ├── yescrypt-common.c ├── yescrypt-opt.c ├── yescrypt-platform.h ├── yescrypt-simd.c └── yescrypt.h /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - gcc 5 | 6 | before_install: 7 | - sudo apt-get update -qq 8 | - sudo apt-get install libcurl4-openssl-dev 9 | 10 | before_script: 11 | - ./autogen.sh 12 | 13 | script: 14 | - ./configure --with-crypto --with-curl 15 | - make 16 | - ./cpuminer --cputest 17 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jeff Garzik 2 | 3 | ArtForz 4 | 5 | pooler 6 | 7 | BlueDragon747 8 | 9 | 1gh 10 | 11 | Neisklar 12 | 13 | prettyhatemachine 14 | 15 | LucasJones 16 | 17 | tpruvot@github 18 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | # Sample Android repo Makefile, used to test arm on the Tegra K1 3 | ################################################################ 4 | 5 | cpuminer-src := $(call my-dir) 6 | 7 | LOCAL_PATH := $(cpuminer-src) 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_MODULE=cpuminer-jansson 11 | LOCAL_MODULE_TAGS=optional 12 | 13 | define all-c-files-under 14 | $(patsubst ./%,%, \ 15 | $(shell cd $(LOCAL_PATH) ; \ 16 | find -L $(1) -name "*.c" -and -not -name ".*") \ 17 | ) 18 | endef 19 | 20 | LOCAL_SRC_FILES := $(call all-c-files-under,compat/jansson) 21 | LOCAL_C_INCLUDES := $(cpuminer-src)/compat/jansson 22 | 23 | include $(BUILD_STATIC_LIBRARY) 24 | 25 | ################################################################ 26 | 27 | 28 | LOCAL_PATH := $(cpuminer-src) 29 | include $(CLEAR_VARS) 30 | 31 | LOCAL_MODULE=cpuminer 32 | LOCAL_MODULE_TAGS=optional 33 | LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES 34 | LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities 35 | LOCAL_MODULE_STEM := $(LOCAL_MODULE) 36 | 37 | LOCAL_C_INCLUDES := $(cpuminer-src)/compat/bionic \ 38 | $(cpuminer-src)/compat/jansson \ 39 | $(TARGET_OUT_INTERMEDIATES)/include/libcurl \ 40 | external/openssl/include \ 41 | 42 | LOCAL_CFLAGS := -std=c99 -Wno-pointer-sign -Wno-missing-field-initializers \ 43 | -Wno-unused-parameter #-DNOASM 44 | LOCAL_CFLAGS += -DVERSION=\"1.3\" 45 | 46 | sph_files:=$(call all-c-files-under,sha3) 47 | 48 | LOCAL_SRC_FILES=\ 49 | cpu-miner.c util.c \ 50 | api.c sysinfos.c \ 51 | $(call all-c-files-under,algo) \ 52 | $(filter-out sha3/md_helper.c,$(sph_files)) \ 53 | $(call all-c-files-under,crypto) \ 54 | $(call all-c-files-under,lyra2) \ 55 | asm/sha2-$(TARGET_ARCH).S \ 56 | asm/scrypt-$(TARGET_ARCH).S \ 57 | asm/neoscrypt_asm.S 58 | 59 | LOCAL_STATIC_LIBRARIES := libm cpuminer-jansson 60 | LOCAL_STATIC_LIBRARIES += libz libcrypto_static 61 | LOCAL_STATIC_LIBRARIES += libssl_static 62 | 63 | # Require curl config changes and an addional 64 | # module definition in external/curl(_static?) 65 | #LOCAL_FORCE_STATIC_EXECUTABLE := true 66 | 67 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) 68 | LOCAL_CFLAGS += -DCURL_STATICLIB # -DHTTP_ONLY 69 | LOCAL_STATIC_LIBRARIES += libcurl_static libc 70 | else 71 | LOCAL_SHARED_LIBRARIES := libssl libcrypto 72 | LOCAL_SHARED_LIBRARIES += libcurl 73 | #LOCAL_STATIC_LIBRARIES += libcurl_static 74 | endif 75 | 76 | include $(BUILD_EXECUTABLE) 77 | 78 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See git repository ('git log') for full changelog. 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Usage: docker build . 2 | # Usage: docker run tpruvot/cpuminer-multi -a xevan --url=stratum+tcp://yiimp.ccminer.org:3739 --user=iGadPnKrdpW3pcdVC3aA77Ku4anrzJyaLG --pass=x 3 | 4 | FROM ubuntu:14.04 5 | MAINTAINER Tanguy Pruvot 6 | 7 | RUN apt-get update -qq 8 | 9 | RUN apt-get install -qy automake autoconf pkg-config libcurl4-openssl-dev libssl-dev libjansson-dev libgmp-dev make g++ git 10 | 11 | RUN git clone https://github.com/tpruvot/cpuminer-multi -b linux 12 | 13 | RUN cd cpuminer-multi && ./build.sh 14 | 15 | WORKDIR /cpuminer-multi 16 | ENTRYPOINT ["./cpuminer"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | cpuminer is available under the terms of the GNU Public License version 2. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /RUN-ZCOIN-MTP.cmd: -------------------------------------------------------------------------------- 1 | 2 | rem x64\Release\cpuminer -a mtp -o http://127.0.0.1:8382 -u djm34 -p password --coinbase-addr aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak -t 1 --no-getwork --protocol-dump 3 | 4 | x64\Release\cpuminer -a mtp -o stratum+tcp://zcoin.mintpond.com:3000 -u aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak.cpuworker -p 0,d=5,verbose,strict -t 6 --cpu-affinity 0xff 5 | 6 | rem x64\Release\cpuminer -a mtp -o stratum+tcp://pool.bibop.net:4000 -u aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak.worker -p c=XZC -t 3 7 | 8 | pause -------------------------------------------------------------------------------- /algo/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/algo/.dirstamp -------------------------------------------------------------------------------- /algo/allium.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Allium algo Implementation 3 | */ 4 | 5 | #include 6 | 7 | #include "sha3/sph_blake.h" 8 | #include "sha3/sph_keccak.h" 9 | #include "sha3/sph_cubehash.h" 10 | #include "sha3/sph_skein.h" 11 | #include "sha3/sph_groestl.h" 12 | 13 | #include "lyra2/Lyra2.h" 14 | 15 | #include "miner.h" 16 | 17 | static char* format_hash(char* buf, uint8_t *hash) 18 | { 19 | int len = 0; 20 | for (int i=0; i < 32; i += 4) { 21 | len += sprintf(buf+len, "%02x%02x%02x%02x ", 22 | hash[i], hash[i+1], hash[i+2], hash[i+3]); 23 | } 24 | return buf; 25 | } 26 | 27 | void allium_hash(void *state, const void *input) 28 | { 29 | uint32_t hashA[8], hashB[8]; 30 | 31 | sph_blake256_context ctx_blake; 32 | sph_keccak256_context ctx_keccak; 33 | sph_skein256_context ctx_skein; 34 | sph_groestl256_context ctx_groestl; 35 | sph_cubehash256_context ctx_cube; 36 | 37 | // sph_blake256_set_rounds(14); 38 | 39 | sph_blake256_init(&ctx_blake); 40 | sph_blake256(&ctx_blake, input, 80); 41 | sph_blake256_close(&ctx_blake, hashA); 42 | 43 | sph_keccak256_init(&ctx_keccak); 44 | sph_keccak256(&ctx_keccak, hashA, 32); 45 | sph_keccak256_close(&ctx_keccak, hashB); 46 | 47 | LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 48 | 49 | sph_cubehash256_init(&ctx_cube); 50 | sph_cubehash256(&ctx_cube, hashA, 32); 51 | sph_cubehash256_close(&ctx_cube, hashB); 52 | 53 | LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 54 | 55 | sph_skein256_init(&ctx_skein); 56 | sph_skein256(&ctx_skein, hashA, 32); 57 | sph_skein256_close(&ctx_skein, hashB); 58 | 59 | sph_groestl256_init(&ctx_groestl); 60 | sph_groestl256(&ctx_groestl, hashB, 32); 61 | sph_groestl256_close(&ctx_groestl, hashA); 62 | 63 | memcpy(state, hashA, 32); 64 | } 65 | 66 | int scanhash_allium(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 67 | { 68 | uint32_t _ALIGN(128) hash[8]; 69 | uint32_t _ALIGN(128) endiandata[20]; 70 | uint32_t *pdata = work->data; 71 | uint32_t *ptarget = work->target; 72 | 73 | const uint32_t Htarg = ptarget[7]; 74 | const uint32_t first_nonce = pdata[19]; 75 | uint32_t n = first_nonce; 76 | 77 | if(opt_benchmark){ 78 | ptarget[7] = 0x00ff; 79 | } 80 | 81 | for (int i=0; i < 19; i++) { 82 | be32enc(&endiandata[i], pdata[i]); 83 | } 84 | 85 | do { 86 | be32enc(&endiandata[19], n); 87 | allium_hash(hash, endiandata); 88 | 89 | if (hash[7] < Htarg && fulltest(hash, ptarget)) { 90 | work_set_target_ratio(work, hash); 91 | *hashes_done = n - first_nonce + 1; 92 | pdata[19] = n; 93 | return 1; 94 | } 95 | n++; 96 | 97 | } while (n < max_nonce && !work_restart[thr_id].restart); 98 | 99 | *hashes_done = n - first_nonce + 1; 100 | pdata[19] = n; 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /algo/axiom.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_shabal.h" 7 | 8 | static __thread uint32_t _ALIGN(128) M[65536][8]; 9 | 10 | void axiomhash(void *output, const void *input) 11 | { 12 | sph_shabal256_context ctx; 13 | const int N = 65536; 14 | 15 | sph_shabal256_init(&ctx); 16 | sph_shabal256(&ctx, input, 80); 17 | sph_shabal256_close(&ctx, M[0]); 18 | 19 | for(int i = 1; i < N; i++) { 20 | //sph_shabal256_init(&ctx); 21 | sph_shabal256(&ctx, M[i-1], 32); 22 | sph_shabal256_close(&ctx, M[i]); 23 | } 24 | 25 | for(int b = 0; b < N; b++) 26 | { 27 | const int p = b > 0 ? b - 1 : 0xFFFF; 28 | const int q = M[p][0] % 0xFFFF; 29 | const int j = (b + q) % N; 30 | 31 | //sph_shabal256_init(&ctx); 32 | #if 0 33 | sph_shabal256(&ctx, M[p], 32); 34 | sph_shabal256(&ctx, M[j], 32); 35 | #else 36 | uint8_t _ALIGN(128) hash[64]; 37 | memcpy(hash, M[p], 32); 38 | memcpy(&hash[32], M[j], 32); 39 | sph_shabal256(&ctx, hash, 64); 40 | #endif 41 | sph_shabal256_close(&ctx, M[b]); 42 | } 43 | memcpy(output, M[N-1], 32); 44 | } 45 | 46 | int scanhash_axiom(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 47 | { 48 | uint32_t _ALIGN(128) hash32[8]; 49 | uint32_t _ALIGN(128) endiandata[20]; 50 | uint32_t *pdata = work->data; 51 | uint32_t *ptarget = work->target; 52 | 53 | const uint32_t Htarg = ptarget[7]; 54 | const uint32_t first_nonce = pdata[19]; 55 | 56 | uint32_t n = first_nonce; 57 | 58 | for (int i=0; i < 19; i++) { 59 | be32enc(&endiandata[i], pdata[i]); 60 | } 61 | 62 | do { 63 | be32enc(&endiandata[19], n); 64 | axiomhash(hash32, endiandata); 65 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 66 | work_set_target_ratio(work, hash32); 67 | *hashes_done = n - first_nonce + 1; 68 | pdata[19] = n; 69 | return true; 70 | } 71 | n++; 72 | 73 | } while (n < max_nonce && !work_restart[thr_id].restart); 74 | 75 | *hashes_done = n - first_nonce + 1; 76 | pdata[19] = n; 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /algo/blake.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include "sha3/sph_blake.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | static __thread sph_blake256_context blake_mid; 10 | static __thread bool ctx_midstate_done = false; 11 | 12 | void blakehash(void *state, const void *input) 13 | { 14 | sph_blake256_context ctx; 15 | 16 | uint8_t *ending = (uint8_t*) input; 17 | ending += 64; 18 | 19 | // do one memcopy to get a fresh context 20 | if (!ctx_midstate_done) { 21 | sph_blake256_init(&blake_mid); 22 | sph_blake256(&blake_mid, input, 64); 23 | ctx_midstate_done = true; 24 | } 25 | memcpy(&ctx, &blake_mid, sizeof(blake_mid)); 26 | 27 | sph_blake256(&ctx, ending, 16); 28 | sph_blake256_close(&ctx, state); 29 | } 30 | 31 | int scanhash_blake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 32 | { 33 | uint32_t _ALIGN(128) hash32[8]; 34 | uint32_t _ALIGN(128) endiandata[20]; 35 | uint32_t *pdata = work->data; 36 | uint32_t *ptarget = work->target; 37 | 38 | const uint32_t first_nonce = pdata[19]; 39 | const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7]; 40 | 41 | uint32_t n = first_nonce; 42 | 43 | ctx_midstate_done = false; 44 | 45 | // we need big endian data... 46 | for (int kk=0; kk < 19; kk++) { 47 | be32enc(&endiandata[kk], pdata[kk]); 48 | } 49 | 50 | #ifdef DEBUG_ALGO 51 | applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]); 52 | #endif 53 | 54 | do { 55 | be32enc(&endiandata[19], n); 56 | blakehash(hash32, endiandata); 57 | 58 | if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) { 59 | work_set_target_ratio(work, hash32); 60 | *hashes_done = n - first_nonce + 1; 61 | return 1; 62 | } 63 | 64 | n++; pdata[19] = n; 65 | 66 | } while (n < max_nonce && !work_restart[thr_id].restart); 67 | 68 | *hashes_done = n - first_nonce + 1; 69 | pdata[19] = n; 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /algo/blake2.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Blake2-S Implementation 3 | * tpruvot@github 2015-2016 4 | */ 5 | 6 | #include "miner.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "crypto/blake2s.h" 12 | 13 | static __thread blake2s_state s_midstate; 14 | static __thread blake2s_state s_ctx; 15 | #define MIDLEN 76 16 | #define A 64 17 | 18 | void blake2s_hash(void *output, const void *input) 19 | { 20 | uint8_t _ALIGN(A) hash[BLAKE2S_OUTBYTES]; 21 | blake2s_state blake2_ctx; 22 | 23 | blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES); 24 | blake2s_update(&blake2_ctx, input, 80); 25 | blake2s_final(&blake2_ctx, hash, BLAKE2S_OUTBYTES); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | static void blake2s_hash_end(uint32_t *output, const uint32_t *input) 31 | { 32 | s_ctx.buflen = MIDLEN; 33 | memcpy(&s_ctx, &s_midstate, 32 + 16 + MIDLEN); 34 | blake2s_update(&s_ctx, (uint8_t*) &input[MIDLEN/4], 80 - MIDLEN); 35 | blake2s_final(&s_ctx, (uint8_t*) output, BLAKE2S_OUTBYTES); 36 | } 37 | 38 | int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 39 | { 40 | uint32_t _ALIGN(A) vhashcpu[8]; 41 | uint32_t _ALIGN(A) endiandata[20]; 42 | uint32_t *pdata = work->data; 43 | uint32_t *ptarget = work->target; 44 | 45 | const uint32_t Htarg = ptarget[7]; 46 | const uint32_t first_nonce = pdata[19]; 47 | 48 | uint32_t n = first_nonce; 49 | 50 | for (int i=0; i < 19; i++) { 51 | be32enc(&endiandata[i], pdata[i]); 52 | } 53 | 54 | // midstate 55 | blake2s_init(&s_midstate, BLAKE2S_OUTBYTES); 56 | blake2s_update(&s_midstate, (uint8_t*) endiandata, MIDLEN); 57 | memcpy(&s_ctx, &s_midstate, sizeof(blake2s_state)); 58 | 59 | do { 60 | be32enc(&endiandata[19], n); 61 | blake2s_hash_end(vhashcpu, endiandata); 62 | 63 | //blake2s_hash(vhashcpu, endiandata); 64 | if (vhashcpu[7] < Htarg && fulltest(vhashcpu, ptarget)) { 65 | work_set_target_ratio(work, vhashcpu); 66 | *hashes_done = n - first_nonce + 1; 67 | pdata[19] = n; 68 | return 1; 69 | } 70 | n++; 71 | 72 | } while (n < max_nonce && !work_restart[thr_id].restart); 73 | 74 | *hashes_done = n - first_nonce + 1; 75 | pdata[19] = n; 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /algo/blakecoin.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #define BLAKE32_ROUNDS 8 4 | #include "sha3/sph_blake.h" 5 | 6 | void blakecoin_init(void *cc); 7 | void blakecoin(void *cc, const void *data, size_t len); 8 | void blakecoin_close(void *cc, void *dst); 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static __thread sph_blake256_context blake_mid; 15 | static __thread bool ctx_midstate_done = false; 16 | 17 | void blakecoinhash(void *state, const void *input) 18 | { 19 | sph_blake256_context ctx; 20 | 21 | uint8_t *ending = (uint8_t*) input; 22 | ending += 64; 23 | 24 | // do one memcopy to get a fresh context 25 | if (!ctx_midstate_done) { 26 | blakecoin_init(&blake_mid); 27 | blakecoin(&blake_mid, input, 64); 28 | ctx_midstate_done = true; 29 | } 30 | memcpy(&ctx, &blake_mid, sizeof(blake_mid)); 31 | 32 | blakecoin(&ctx, ending, 16); 33 | blakecoin_close(&ctx, state); 34 | } 35 | 36 | int scanhash_blakecoin(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 37 | { 38 | uint32_t _ALIGN(128) hash32[8]; 39 | uint32_t _ALIGN(128) endiandata[20]; 40 | uint32_t *pdata = work->data; 41 | uint32_t *ptarget = work->target; 42 | 43 | const uint32_t first_nonce = pdata[19]; 44 | const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7]; 45 | uint32_t n = first_nonce; 46 | 47 | ctx_midstate_done = false; 48 | 49 | // we need big endian data... 50 | for (int kk=0; kk < 19; kk++) { 51 | be32enc(&endiandata[kk], pdata[kk]); 52 | } 53 | 54 | #ifdef DEBUG_ALGO 55 | applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]); 56 | #endif 57 | 58 | do { 59 | be32enc(&endiandata[19], n); 60 | blakecoinhash(hash32, endiandata); 61 | 62 | if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) { 63 | work_set_target_ratio(work, hash32); 64 | *hashes_done = n - first_nonce + 1; 65 | return 1; 66 | } 67 | 68 | n++; pdata[19] = n; 69 | 70 | } while (n < max_nonce && !work_restart[thr_id].restart); 71 | 72 | *hashes_done = n - first_nonce + 1; 73 | pdata[19] = n; 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /algo/bmw256.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_bmw.h" 7 | 8 | void bmwhash(void *output, const void *input) 9 | { 10 | uint32_t hash[16]; 11 | sph_bmw256_context ctx; 12 | 13 | sph_bmw256_init(&ctx); 14 | sph_bmw256(&ctx, input, 80); 15 | sph_bmw256_close(&ctx, hash); 16 | 17 | memcpy(output, hash, 32); 18 | } 19 | 20 | int scanhash_bmw(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 21 | { 22 | uint32_t _ALIGN(128) hash32[8]; 23 | uint32_t _ALIGN(128) endiandata[20]; 24 | uint32_t *pdata = work->data; 25 | uint32_t *ptarget = work->target; 26 | 27 | const uint32_t Htarg = ptarget[7]; 28 | const uint32_t first_nonce = pdata[19]; 29 | 30 | uint32_t n = first_nonce; 31 | 32 | for (int i=0; i < 19; i++) { 33 | be32enc(&endiandata[i], pdata[i]); 34 | }; 35 | 36 | do { 37 | be32enc(&endiandata[19], n); 38 | bmwhash(hash32, endiandata); 39 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 40 | work_set_target_ratio(work, hash32); 41 | *hashes_done = n - first_nonce + 1; 42 | pdata[19] = n; 43 | return 1; 44 | } 45 | n++; 46 | 47 | } while (n < max_nonce && !work_restart[thr_id].restart); 48 | 49 | *hashes_done = n - first_nonce + 1; 50 | pdata[19] = n; 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /algo/c11.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | 20 | 21 | void c11hash(void *output, const void *input) 22 | { 23 | uint32_t _ALIGN(64) hash[16]; 24 | 25 | sph_blake512_context ctx_blake; 26 | sph_bmw512_context ctx_bmw; 27 | sph_groestl512_context ctx_groestl; 28 | sph_skein512_context ctx_skein; 29 | sph_jh512_context ctx_jh; 30 | sph_keccak512_context ctx_keccak; 31 | 32 | sph_luffa512_context ctx_luffa1; 33 | sph_cubehash512_context ctx_cubehash1; 34 | sph_shavite512_context ctx_shavite1; 35 | sph_simd512_context ctx_simd1; 36 | sph_echo512_context ctx_echo1; 37 | 38 | sph_blake512_init(&ctx_blake); 39 | sph_blake512 (&ctx_blake, input, 80); 40 | sph_blake512_close (&ctx_blake, hash); 41 | 42 | sph_bmw512_init(&ctx_bmw); 43 | sph_bmw512 (&ctx_bmw, hash, 64); 44 | sph_bmw512_close(&ctx_bmw, hash); 45 | 46 | sph_groestl512_init(&ctx_groestl); 47 | sph_groestl512 (&ctx_groestl, hash, 64); 48 | sph_groestl512_close(&ctx_groestl, hash); 49 | 50 | sph_jh512_init(&ctx_jh); 51 | sph_jh512 (&ctx_jh, hash, 64); 52 | sph_jh512_close(&ctx_jh, hash); 53 | 54 | sph_keccak512_init(&ctx_keccak); 55 | sph_keccak512 (&ctx_keccak, hash, 64); 56 | sph_keccak512_close(&ctx_keccak, hash); 57 | 58 | sph_skein512_init(&ctx_skein); 59 | sph_skein512 (&ctx_skein, hash, 64); 60 | sph_skein512_close (&ctx_skein, hash); 61 | 62 | sph_luffa512_init (&ctx_luffa1); 63 | sph_luffa512 (&ctx_luffa1, hash, 64); 64 | sph_luffa512_close (&ctx_luffa1, hash); 65 | 66 | sph_cubehash512_init (&ctx_cubehash1); 67 | sph_cubehash512 (&ctx_cubehash1, hash, 64); 68 | sph_cubehash512_close(&ctx_cubehash1, hash); 69 | 70 | sph_shavite512_init (&ctx_shavite1); 71 | sph_shavite512 (&ctx_shavite1, hash, 64); 72 | sph_shavite512_close(&ctx_shavite1, hash); 73 | 74 | sph_simd512_init (&ctx_simd1); 75 | sph_simd512 (&ctx_simd1, hash, 64); 76 | sph_simd512_close(&ctx_simd1, hash); 77 | 78 | sph_echo512_init (&ctx_echo1); 79 | sph_echo512 (&ctx_echo1, hash, 64); 80 | sph_echo512_close(&ctx_echo1, hash); 81 | 82 | memcpy(output, hash, 32); 83 | } 84 | 85 | int scanhash_c11(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 86 | { 87 | uint32_t _ALIGN(128) hash32[8]; 88 | uint32_t _ALIGN(128) endiandata[20]; 89 | uint32_t *pdata = work->data; 90 | uint32_t *ptarget = work->target; 91 | 92 | const uint32_t Htarg = ptarget[7]; 93 | const uint32_t first_nonce = pdata[19]; 94 | uint32_t nonce = first_nonce; 95 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 96 | 97 | if (opt_benchmark) 98 | ptarget[7] = 0x0cff; 99 | 100 | for (int k=0; k < 19; k++) 101 | be32enc(&endiandata[k], pdata[k]); 102 | 103 | do { 104 | be32enc(&endiandata[19], nonce); 105 | c11hash(hash32, endiandata); 106 | 107 | if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) { 108 | work_set_target_ratio(work, hash32); 109 | pdata[19] = nonce; 110 | *hashes_done = pdata[19] - first_nonce; 111 | return 1; 112 | } 113 | nonce++; 114 | 115 | } while (nonce < max_nonce && !(*restart)); 116 | 117 | pdata[19] = nonce; 118 | *hashes_done = pdata[19] - first_nonce + 1; 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /algo/decred.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include "sha3/sph_blake.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | static __thread sph_blake256_context blake_mid; 10 | static __thread bool ctx_midstate_done = false; 11 | 12 | void decred_hash(void *state, const void *input) 13 | { 14 | #define MIDSTATE_LEN 128 15 | sph_blake256_context ctx; 16 | 17 | uint8_t *ending = (uint8_t*) input; 18 | ending += MIDSTATE_LEN; 19 | 20 | if (!ctx_midstate_done) { 21 | sph_blake256_init(&blake_mid); 22 | sph_blake256(&blake_mid, input, MIDSTATE_LEN); 23 | ctx_midstate_done = true; 24 | } 25 | memcpy(&ctx, &blake_mid, sizeof(blake_mid)); 26 | 27 | sph_blake256(&ctx, ending, (180 - MIDSTATE_LEN)); 28 | sph_blake256_close(&ctx, state); 29 | } 30 | 31 | void decred_hash_simple(void *state, const void *input) 32 | { 33 | sph_blake256_context ctx; 34 | sph_blake256_init(&ctx); 35 | sph_blake256(&ctx, input, 180); 36 | sph_blake256_close(&ctx, state); 37 | } 38 | 39 | int scanhash_decred(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 40 | { 41 | uint32_t _ALIGN(128) endiandata[48]; 42 | uint32_t _ALIGN(128) hash32[8]; 43 | uint32_t *pdata = work->data; 44 | uint32_t *ptarget = work->target; 45 | 46 | #define DCR_NONCE_OFT32 35 47 | 48 | const uint32_t first_nonce = pdata[DCR_NONCE_OFT32]; 49 | const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7]; 50 | 51 | uint32_t n = first_nonce; 52 | 53 | ctx_midstate_done = false; 54 | 55 | #if 1 56 | memcpy(endiandata, pdata, 180); 57 | #else 58 | for (int k=0; k < (180/4); k++) 59 | be32enc(&endiandata[k], pdata[k]); 60 | #endif 61 | 62 | #ifdef DEBUG_ALGO 63 | if (!thr_id) applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]); 64 | #endif 65 | 66 | do { 67 | //be32enc(&endiandata[DCR_NONCE_OFT32], n); 68 | endiandata[DCR_NONCE_OFT32] = n; 69 | decred_hash(hash32, endiandata); 70 | 71 | if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) { 72 | work_set_target_ratio(work, hash32); 73 | *hashes_done = n - first_nonce + 1; 74 | #ifdef DEBUG_ALGO 75 | applog(LOG_BLUE, "Nonce : %08x %08x", n, swab32(n)); 76 | applog_hash(ptarget); 77 | applog_compare_hash(hash32, ptarget); 78 | #endif 79 | pdata[DCR_NONCE_OFT32] = n; 80 | return 1; 81 | } 82 | 83 | n++; 84 | 85 | } while (n < max_nonce && !work_restart[thr_id].restart); 86 | 87 | *hashes_done = n - first_nonce + 1; 88 | pdata[DCR_NONCE_OFT32] = n; 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /algo/fresh.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_shavite.h" 9 | #include "sha3/sph_simd.h" 10 | #include "sha3/sph_echo.h" 11 | 12 | //#define DEBUG_ALGO 13 | 14 | extern void freshhash(void* output, const void* input, uint32_t len) 15 | { 16 | unsigned char hash[128]; // uint32_t hashA[16], hashB[16]; 17 | #define hashA hash 18 | #define hashB hash+64 19 | 20 | sph_shavite512_context ctx_shavite; 21 | sph_simd512_context ctx_simd; 22 | sph_echo512_context ctx_echo; 23 | 24 | sph_shavite512_init(&ctx_shavite); 25 | sph_shavite512(&ctx_shavite, input, len); 26 | sph_shavite512_close(&ctx_shavite, hashA); 27 | 28 | sph_simd512_init(&ctx_simd); 29 | sph_simd512(&ctx_simd, hashA, 64); 30 | sph_simd512_close(&ctx_simd, hashB); 31 | 32 | sph_shavite512_init(&ctx_shavite); 33 | sph_shavite512(&ctx_shavite, hashB, 64); 34 | sph_shavite512_close(&ctx_shavite, hashA); 35 | 36 | sph_simd512_init(&ctx_simd); 37 | sph_simd512(&ctx_simd, hashA, 64); 38 | sph_simd512_close(&ctx_simd, hashB); 39 | 40 | sph_echo512_init(&ctx_echo); 41 | sph_echo512(&ctx_echo, hashB, 64); 42 | sph_echo512_close(&ctx_echo, hashA); 43 | 44 | memcpy(output, hash, 32); 45 | } 46 | 47 | int scanhash_fresh(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 48 | { 49 | uint32_t _ALIGN(128) hash32[8]; 50 | uint32_t _ALIGN(128) endiandata[20]; 51 | uint32_t *pdata = work->data; 52 | uint32_t *ptarget = work->target; 53 | 54 | const uint32_t first_nonce = pdata[19]; 55 | const uint32_t Htarg = ptarget[7]; 56 | const uint32_t len = 80; 57 | uint32_t n = pdata[19] - 1; 58 | 59 | uint64_t htmax[] = { 60 | 0, 61 | 0xF, 62 | 0xFF, 63 | 0xFFF, 64 | 0xFFFF, 65 | 0x10000000 66 | }; 67 | uint32_t masks[] = { 68 | 0xFFFFFFFF, 69 | 0xFFFFFFF0, 70 | 0xFFFFFF00, 71 | 0xFFFFF000, 72 | 0xFFFF0000, 73 | 0 74 | }; 75 | 76 | // we need bigendian data... 77 | for (int kk=0; kk < 32; kk++) { 78 | be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]); 79 | }; 80 | #ifdef DEBUG_ALGO 81 | if (Htarg != 0) 82 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 83 | #endif 84 | for (int m=0; m < 6; m++) { 85 | if (Htarg <= htmax[m]) { 86 | uint32_t mask = masks[m]; 87 | do { 88 | pdata[19] = ++n; 89 | be32enc(&endiandata[19], n); 90 | freshhash(hash32, endiandata, len); 91 | #ifndef DEBUG_ALGO 92 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 93 | work_set_target_ratio(work, hash32); 94 | *hashes_done = n - first_nonce + 1; 95 | return 1; 96 | } 97 | #else 98 | if (!(n % 0x1000) && !thr_id) printf("."); 99 | if (!(hash32[7] & mask)) { 100 | printf("[%d]",thr_id); 101 | if (fulltest(hash32, ptarget)) { 102 | work_set_target_ratio(work, hash32); 103 | *hashes_done = n - first_nonce + 1; 104 | return 1; 105 | } 106 | } 107 | #endif 108 | } while (n < max_nonce && !work_restart[thr_id].restart); 109 | // see blake.c if else to understand the loop on htmax => mask 110 | break; 111 | } 112 | } 113 | 114 | *hashes_done = n - first_nonce + 1; 115 | pdata[19] = n; 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /algo/groestl.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_groestl.h" 9 | 10 | // static __thread sph_groestl512_context ctx; 11 | 12 | void groestlhash(void *output, const void *input) 13 | { 14 | uint32_t _ALIGN(32) hash[16]; 15 | sph_groestl512_context ctx; 16 | 17 | // memset(&hash[0], 0, sizeof(hash)); 18 | 19 | sph_groestl512_init(&ctx); 20 | sph_groestl512(&ctx, input, 80); 21 | sph_groestl512_close(&ctx, hash); 22 | 23 | //sph_groestl512_init(&ctx); 24 | sph_groestl512(&ctx, hash, 64); 25 | sph_groestl512_close(&ctx, hash); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | int scanhash_groestl(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 31 | { 32 | uint32_t _ALIGN(128) hash[8]; 33 | uint32_t _ALIGN(128) endiandata[20]; 34 | uint32_t *pdata = work->data; 35 | uint32_t *ptarget = work->target; 36 | 37 | const uint32_t Htarg = ptarget[7]; 38 | const uint32_t first_nonce = pdata[19]; 39 | uint32_t nonce = first_nonce; 40 | 41 | if (opt_benchmark) 42 | ptarget[7] = 0x00ff; 43 | 44 | for (int k=0; k < 19; k++) 45 | be32enc(&endiandata[k], pdata[k]); 46 | 47 | do { 48 | be32enc(&endiandata[19], nonce); 49 | groestlhash(hash, endiandata); 50 | 51 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 52 | work_set_target_ratio(work, hash); 53 | pdata[19] = nonce; 54 | *hashes_done = pdata[19] - first_nonce; 55 | return 1; 56 | } 57 | nonce++; 58 | 59 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 60 | 61 | pdata[19] = nonce; 62 | *hashes_done = pdata[19] - first_nonce + 1; 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /algo/heavy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "miner.h" 6 | #include "sha3/sph_hefty1.h" 7 | #include "sha3/sph_keccak.h" 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_groestl.h" 10 | 11 | /* Combines top 64-bits from each hash into a single hash */ 12 | static void combine_hashes(uint32_t *out, uint32_t *hash1, uint32_t *hash2, uint32_t *hash3, uint32_t *hash4) 13 | { 14 | uint32_t *hash[4] = { hash1, hash2, hash3, hash4 }; 15 | 16 | /* Transpose first 64 bits of each hash into out */ 17 | memset(out, 0, 32); 18 | int bits = 0; 19 | for (unsigned int i = 7; i >= 6; i--) { 20 | for (uint32_t mask = 0x80000000; mask; mask >>= 1) { 21 | for (unsigned int k = 0; k < 4; k++) { 22 | out[(255 - bits)/32] <<= 1; 23 | if ((hash[k][i] & mask) != 0) 24 | out[(255 - bits)/32] |= 1; 25 | bits++; 26 | } 27 | } 28 | } 29 | } 30 | 31 | extern void heavyhash(unsigned char* output, const unsigned char* input, int len) 32 | { 33 | unsigned char _ALIGN(128) hash1[32]; 34 | HEFTY1(input, len, hash1); 35 | 36 | /* HEFTY1 is new, so take an extra security measure to eliminate 37 | * the possiblity of collisions: 38 | * 39 | * Hash(x) = SHA256(x + HEFTY1(x)) 40 | * 41 | * N.B. '+' is concatenation. 42 | */ 43 | unsigned char hash2[32];; 44 | SHA256_CTX ctx; 45 | SHA256_Init(&ctx); 46 | SHA256_Update(&ctx, input, len); 47 | SHA256_Update(&ctx, hash1, sizeof(hash1)); 48 | SHA256_Final(hash2, &ctx); 49 | 50 | /* Additional security: Do not rely on a single cryptographic hash 51 | * function. Instead, combine the outputs of 4 of the most secure 52 | * cryptographic hash functions-- SHA256, KECCAK512, GROESTL512 53 | * and BLAKE512. 54 | */ 55 | 56 | uint32_t hash3[16]; 57 | sph_keccak512_context keccakCtx; 58 | sph_keccak512_init(&keccakCtx); 59 | sph_keccak512(&keccakCtx, input, len); 60 | sph_keccak512(&keccakCtx, hash1, sizeof(hash1)); 61 | sph_keccak512_close(&keccakCtx, (void *)&hash3); 62 | 63 | uint32_t hash4[16]; 64 | sph_groestl512_context groestlCtx; 65 | sph_groestl512_init(&groestlCtx); 66 | sph_groestl512(&groestlCtx, input, len); 67 | sph_groestl512(&groestlCtx, hash1, sizeof(hash1)); 68 | sph_groestl512_close(&groestlCtx, (void *)&hash4); 69 | 70 | uint32_t hash5[16]; 71 | sph_blake512_context blakeCtx; 72 | sph_blake512_init(&blakeCtx); 73 | sph_blake512(&blakeCtx, input, len); 74 | sph_blake512(&blakeCtx, (unsigned char *)&hash1, sizeof(hash1)); 75 | sph_blake512_close(&blakeCtx, (void *)&hash5); 76 | 77 | uint32_t *final = (uint32_t *)output; 78 | combine_hashes(final, (uint32_t *)hash2, hash3, hash4, hash5); 79 | } 80 | 81 | int scanhash_heavy(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 82 | { 83 | uint32_t _ALIGN(128) hash[8]; 84 | uint32_t *pdata = work->data; 85 | uint32_t *ptarget = work->target; 86 | uint32_t first_nonce = pdata[19]; 87 | uint32_t nonce = first_nonce; 88 | 89 | const uint32_t Htarg = ptarget[7]; 90 | do { 91 | pdata[19] = nonce; 92 | heavyhash((unsigned char *)hash, (unsigned char *)pdata, 80); 93 | 94 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 95 | work_set_target_ratio(work, hash); 96 | pdata[19] = nonce; 97 | *hashes_done = pdata[19] - first_nonce; 98 | return 1; 99 | } 100 | nonce++; 101 | 102 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 103 | 104 | *hashes_done = pdata[19] - first_nonce; 105 | return 0; 106 | } -------------------------------------------------------------------------------- /algo/ink.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_shavite.h" 7 | 8 | extern void inkhash(void *state, const void *input) 9 | { 10 | uint32_t _ALIGN(128) hash[16]; 11 | sph_shavite512_context ctx_shavite; 12 | 13 | sph_shavite512_init(&ctx_shavite); 14 | sph_shavite512 (&ctx_shavite, (const void*) input, 80); 15 | sph_shavite512_close(&ctx_shavite, (void*) hash); 16 | 17 | sph_shavite512_init(&ctx_shavite); 18 | sph_shavite512(&ctx_shavite, (const void*) hash, 64); 19 | sph_shavite512_close(&ctx_shavite, (void*) hash); 20 | 21 | memcpy(state, hash, 32); 22 | } 23 | 24 | int scanhash_ink(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 25 | { 26 | uint32_t _ALIGN(128) hash32[8]; 27 | uint32_t _ALIGN(128) endiandata[20]; 28 | uint32_t *pdata = work->data; 29 | uint32_t *ptarget = work->target; 30 | 31 | uint32_t n = pdata[19] - 1; 32 | const uint32_t first_nonce = pdata[19]; 33 | 34 | for (int k=0; k < 19; k++) 35 | be32enc(&endiandata[k], pdata[k]); 36 | 37 | const uint32_t Htarg = ptarget[7]; 38 | do { 39 | be32enc(&endiandata[19], n); 40 | inkhash(hash32, endiandata); 41 | 42 | if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) { 43 | work_set_target_ratio(work, hash32); 44 | pdata[19] = n; 45 | *hashes_done = pdata[19] - first_nonce; 46 | return 1; 47 | } 48 | n++; 49 | 50 | } while (n < max_nonce && !work_restart[thr_id].restart); 51 | 52 | *hashes_done = n - first_nonce + 1; 53 | pdata[19] = n; 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /algo/jha.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_keccak.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_skein.h" 11 | #include "sha3/sph_blake.h" 12 | #include "sha3/sph_jh.h" 13 | 14 | void jha_hash(void *output, const void *input) 15 | { 16 | uint8_t _ALIGN(128) hash[64]; 17 | 18 | sph_blake512_context ctx_blake; 19 | sph_groestl512_context ctx_groestl; 20 | sph_jh512_context ctx_jh; 21 | sph_keccak512_context ctx_keccak; 22 | sph_skein512_context ctx_skein; 23 | 24 | // JHA v8 input is 80 bytes 25 | sph_keccak512_init(&ctx_keccak); 26 | sph_keccak512(&ctx_keccak, input, 80); 27 | sph_keccak512_close(&ctx_keccak, (&hash)); 28 | 29 | // Heavy & Light Pair Loop 30 | for (int round = 0; round < 3; round++) 31 | { 32 | if (hash[0] & 0x01) { 33 | sph_groestl512_init(&ctx_groestl); 34 | sph_groestl512(&ctx_groestl, (&hash), 64); 35 | sph_groestl512_close(&ctx_groestl, (&hash)); 36 | } else { 37 | sph_skein512_init(&ctx_skein); 38 | sph_skein512(&ctx_skein, (&hash), 64); 39 | sph_skein512_close(&ctx_skein, (&hash)); 40 | } 41 | 42 | if (hash[0] & 0x01) { 43 | sph_blake512_init(&ctx_blake); 44 | sph_blake512(&ctx_blake, (&hash), 64); 45 | sph_blake512_close(&ctx_blake, (&hash)); 46 | } else { 47 | sph_jh512_init(&ctx_jh); 48 | sph_jh512(&ctx_jh, (&hash), 64); 49 | sph_jh512_close(&ctx_jh, (&hash)); 50 | } 51 | } 52 | 53 | memcpy(output, hash, 32); 54 | } 55 | 56 | int scanhash_jha(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 57 | { 58 | uint32_t _ALIGN(128) hash32[8]; 59 | uint32_t _ALIGN(128) endiandata[20]; 60 | uint32_t *pdata = work->data; 61 | uint32_t *ptarget = work->target; 62 | const uint32_t first_nonce = pdata[19]; 63 | const uint32_t Htarg = ptarget[7]; 64 | uint32_t n = pdata[19] - 1; 65 | 66 | uint64_t htmax[] = { 67 | 0, 68 | 0xF, 69 | 0xFF, 70 | 0xFFF, 71 | 0xFFFF, 72 | 0x10000000 73 | }; 74 | uint32_t masks[] = { 75 | 0xFFFFFFFF, 76 | 0xFFFFFFF0, 77 | 0xFFFFFF00, 78 | 0xFFFFF000, 79 | 0xFFFF0000, 80 | 0 81 | }; 82 | 83 | // we need bigendian data... 84 | for (int i=0; i < 19; i++) { 85 | be32enc(&endiandata[i], pdata[i]); 86 | } 87 | 88 | #ifdef DEBUG_ALGO 89 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 90 | #endif 91 | for (int m=0; m < 6; m++) { 92 | if (Htarg <= htmax[m]) { 93 | uint32_t mask = masks[m]; 94 | do { 95 | pdata[19] = ++n; 96 | be32enc(&endiandata[19], n); 97 | jha_hash(hash32, endiandata); 98 | #ifndef DEBUG_ALGO 99 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 100 | work_set_target_ratio(work, hash32); 101 | *hashes_done = n - first_nonce + 1; 102 | return 1; 103 | } 104 | #else 105 | if (!(n % 0x1000) && !thr_id) printf("."); 106 | if (!(hash32[7] & mask)) { 107 | printf("[%d]",thr_id); 108 | if (fulltest(hash32, ptarget)) { 109 | work_set_target_ratio(work, hash32); 110 | *hashes_done = n - first_nonce + 1; 111 | return 1; 112 | } 113 | } 114 | #endif 115 | } while (n < max_nonce && !work_restart[thr_id].restart); 116 | // see blake.c if else to understand the loop on htmax => mask 117 | break; 118 | } 119 | } 120 | 121 | *hashes_done = n - first_nonce + 1; 122 | pdata[19] = n; 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /algo/keccak.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_keccak.h" 7 | 8 | extern void keccakhash(void *state, const void *input) 9 | { 10 | sph_keccak256_context ctx_keccak; 11 | uint32_t hash[32]; 12 | 13 | sph_keccak256_init(&ctx_keccak); 14 | sph_keccak256 (&ctx_keccak,input, 80); 15 | sph_keccak256_close(&ctx_keccak, hash); 16 | 17 | memcpy(state, hash, 32); 18 | } 19 | 20 | int scanhash_keccak(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 21 | { 22 | uint32_t _ALIGN(128) hash32[8]; 23 | uint32_t _ALIGN(128) endiandata[20]; 24 | uint32_t *pdata = work->data; 25 | uint32_t *ptarget = work->target; 26 | 27 | uint32_t n = pdata[19] - 1; 28 | const uint32_t first_nonce = pdata[19]; 29 | 30 | for (int k=0; k < 19; k++) 31 | be32enc(&endiandata[k], pdata[k]); 32 | 33 | const uint32_t Htarg = ptarget[7]; 34 | do { 35 | 36 | pdata[19] = ++n; 37 | be32enc(&endiandata[19], n); 38 | keccakhash(hash32, endiandata); 39 | 40 | if (hash32[7] <= Htarg && fulltest(hash32, ptarget)) { 41 | work_set_target_ratio(work, hash32); 42 | pdata[19] = n; 43 | *hashes_done = pdata[19] - first_nonce; 44 | return true; 45 | } 46 | } while (n < max_nonce && !work_restart[thr_id].restart); 47 | 48 | *hashes_done = n - first_nonce + 1; 49 | pdata[19] = n; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /algo/lbry.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Lbry sph Implementation 3 | * tpruvot@github July 2016 4 | */ 5 | 6 | #include "miner.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "sha3/sph_sha2.h" 12 | #include "sha3/sph_ripemd.h" 13 | 14 | #define A 64 15 | 16 | typedef struct { 17 | sph_sha256_context sha256; 18 | sph_sha512_context sha512; 19 | sph_ripemd160_context ripemd; 20 | } lbryhash_context_holder; 21 | 22 | static __thread lbryhash_context_holder ctx; 23 | static __thread bool ctx_init = false; 24 | 25 | static void lbry_initstate() 26 | { 27 | sph_sha256_init(&ctx.sha256); 28 | sph_sha512_init(&ctx.sha512); 29 | sph_ripemd160_init(&ctx.ripemd); 30 | ctx_init = true; 31 | } 32 | 33 | void lbry_hash(void* output, const void* input) 34 | { 35 | uint32_t _ALIGN(A) hashA[16]; 36 | uint32_t _ALIGN(A) hashB[8]; 37 | uint32_t _ALIGN(A) hashC[8]; 38 | 39 | //memset(&hashA[8], 0, 32); 40 | 41 | // sha256d 42 | sph_sha256(&ctx.sha256, input, 112); 43 | sph_sha256_close(&ctx.sha256, hashA); 44 | sph_sha256(&ctx.sha256, hashA, 32); 45 | sph_sha256_close(&ctx.sha256, hashA); 46 | 47 | sph_sha512(&ctx.sha512, hashA, 32); 48 | sph_sha512_close(&ctx.sha512, hashA); 49 | 50 | sph_ripemd160(&ctx.ripemd, hashA, 32); 51 | sph_ripemd160_close(&ctx.ripemd, hashB); 52 | 53 | sph_ripemd160(&ctx.ripemd, &hashA[8], 32); // weird 54 | sph_ripemd160_close(&ctx.ripemd, hashC); 55 | 56 | sph_sha256(&ctx.sha256, hashB, 20); 57 | sph_sha256(&ctx.sha256, hashC, 20); 58 | sph_sha256_close(&ctx.sha256, hashA); 59 | 60 | sph_sha256(&ctx.sha256, hashA, 32); 61 | sph_sha256_close(&ctx.sha256, hashA); 62 | 63 | memcpy(output, hashA, 32); 64 | } 65 | 66 | int scanhash_lbry(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 67 | { 68 | uint32_t _ALIGN(A) vhashcpu[8]; 69 | uint32_t _ALIGN(A) endiandata[28]; 70 | uint32_t *pdata = work->data; 71 | uint32_t *ptarget = work->target; 72 | 73 | const uint32_t Htarg = ptarget[7]; 74 | const uint32_t first_nonce = pdata[27]; 75 | 76 | uint32_t n = first_nonce; 77 | 78 | for (int i=0; i < 27; i++) { 79 | be32enc(&endiandata[i], pdata[i]); 80 | } 81 | 82 | if (!ctx_init) lbry_initstate(); 83 | 84 | do { 85 | be32enc(&endiandata[27], n); 86 | lbry_hash(vhashcpu, endiandata); 87 | 88 | if (vhashcpu[7] <= Htarg && fulltest(vhashcpu, ptarget)) { 89 | work_set_target_ratio(work, vhashcpu); 90 | *hashes_done = n - first_nonce + 1; 91 | work->resnonce = pdata[27] = n; // to check 92 | return 1; 93 | } 94 | n++; 95 | 96 | } while (n < max_nonce && !work_restart[thr_id].restart); 97 | 98 | *hashes_done = n - first_nonce + 1; 99 | pdata[27] = n; 100 | 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /algo/luffa.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_luffa.h" 9 | 10 | void luffahash(void *output, const void *input) 11 | { 12 | unsigned char _ALIGN(128) hash[64]; 13 | sph_luffa512_context ctx_luffa; 14 | 15 | sph_luffa512_init(&ctx_luffa); 16 | sph_luffa512 (&ctx_luffa, input, 80); 17 | sph_luffa512_close(&ctx_luffa, (void*) hash); 18 | 19 | memcpy(output, hash, 32); 20 | } 21 | 22 | int scanhash_luffa(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 23 | { 24 | uint32_t _ALIGN(128) hash32[8]; 25 | uint32_t _ALIGN(128) endiandata[20]; 26 | uint32_t *pdata = work->data; 27 | uint32_t *ptarget = work->target; 28 | 29 | const uint32_t Htarg = ptarget[7]; 30 | const uint32_t first_nonce = pdata[19]; 31 | 32 | uint32_t n = first_nonce; 33 | 34 | for (int i=0; i < 19; i++) { 35 | be32enc(&endiandata[i], pdata[i]); 36 | } 37 | 38 | do { 39 | be32enc(&endiandata[19], n); 40 | luffahash(hash32, endiandata); 41 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 42 | work_set_target_ratio(work, hash32); 43 | *hashes_done = n - first_nonce + 1; 44 | pdata[19] = n; 45 | return true; 46 | } 47 | n++; 48 | 49 | } while (n < max_nonce && !work_restart[thr_id].restart); 50 | 51 | *hashes_done = n - first_nonce + 1; 52 | pdata[19] = n; 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /algo/lyra2re.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sha3/sph_blake.h" 4 | #include "sha3/sph_groestl.h" 5 | #include "sha3/sph_skein.h" 6 | #include "sha3/sph_keccak.h" 7 | 8 | #include "lyra2/Lyra2.h" 9 | 10 | #include "miner.h" 11 | 12 | void lyra2_hash(void *state, const void *input) 13 | { 14 | sph_blake256_context ctx_blake; 15 | sph_keccak256_context ctx_keccak; 16 | sph_skein256_context ctx_skein; 17 | sph_groestl256_context ctx_groestl; 18 | 19 | uint32_t hashA[8], hashB[8]; 20 | 21 | sph_blake256_init(&ctx_blake); 22 | sph_blake256(&ctx_blake, input, 80); 23 | sph_blake256_close(&ctx_blake, hashA); 24 | 25 | sph_keccak256_init(&ctx_keccak); 26 | sph_keccak256(&ctx_keccak, hashA, 32); 27 | sph_keccak256_close(&ctx_keccak, hashB); 28 | 29 | LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 30 | 31 | sph_skein256_init(&ctx_skein); 32 | sph_skein256(&ctx_skein, hashA, 32); 33 | sph_skein256_close(&ctx_skein, hashB); 34 | 35 | sph_groestl256_init(&ctx_groestl); 36 | sph_groestl256(&ctx_groestl, hashB, 32); 37 | sph_groestl256_close(&ctx_groestl, hashA); 38 | 39 | memcpy(state, hashA, 32); 40 | } 41 | 42 | int scanhash_lyra2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 43 | { 44 | uint32_t _ALIGN(128) hash[8]; 45 | uint32_t _ALIGN(128) endiandata[20]; 46 | uint32_t *pdata = work->data; 47 | uint32_t *ptarget = work->target; 48 | 49 | const uint32_t Htarg = ptarget[7]; 50 | const uint32_t first_nonce = pdata[19]; 51 | uint32_t nonce = first_nonce; 52 | 53 | if (opt_benchmark) 54 | ptarget[7] = 0x0000ff; 55 | 56 | for (int i=0; i < 19; i++) { 57 | be32enc(&endiandata[i], pdata[i]); 58 | } 59 | 60 | do { 61 | be32enc(&endiandata[19], nonce); 62 | lyra2_hash(hash, endiandata); 63 | 64 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 65 | work_set_target_ratio(work, hash); 66 | pdata[19] = nonce; 67 | *hashes_done = pdata[19] - first_nonce; 68 | return 1; 69 | } 70 | nonce++; 71 | 72 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 73 | 74 | pdata[19] = nonce; 75 | *hashes_done = pdata[19] - first_nonce + 1; 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /algo/lyra2rev2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sha3/sph_blake.h" 4 | #include "sha3/sph_cubehash.h" 5 | #include "sha3/sph_keccak.h" 6 | #include "sha3/sph_skein.h" 7 | #include "sha3/sph_bmw.h" 8 | 9 | #include "lyra2/Lyra2.h" 10 | 11 | #include "miner.h" 12 | 13 | void lyra2rev2_hash(void *state, const void *input) 14 | { 15 | uint32_t _ALIGN(128) hashA[8], hashB[8]; 16 | 17 | sph_blake256_context ctx_blake; 18 | sph_keccak256_context ctx_keccak; 19 | sph_cubehash256_context ctx_cubehash; 20 | sph_skein256_context ctx_skein; 21 | sph_bmw256_context ctx_bmw; 22 | 23 | sph_blake256_init(&ctx_blake); 24 | sph_blake256(&ctx_blake, input, 80); 25 | sph_blake256_close(&ctx_blake, hashA); 26 | 27 | sph_keccak256_init(&ctx_keccak); 28 | sph_keccak256(&ctx_keccak, hashA, 32); 29 | sph_keccak256_close(&ctx_keccak, hashB); 30 | 31 | sph_cubehash256_init(&ctx_cubehash); 32 | sph_cubehash256(&ctx_cubehash, hashB, 32); 33 | sph_cubehash256_close(&ctx_cubehash, hashA); 34 | 35 | LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); 36 | 37 | sph_skein256_init(&ctx_skein); 38 | sph_skein256(&ctx_skein, hashB, 32); 39 | sph_skein256_close(&ctx_skein, hashA); 40 | 41 | sph_cubehash256_init(&ctx_cubehash); 42 | sph_cubehash256(&ctx_cubehash, hashA, 32); 43 | sph_cubehash256_close(&ctx_cubehash, hashB); 44 | 45 | sph_bmw256_init(&ctx_bmw); 46 | sph_bmw256(&ctx_bmw, hashB, 32); 47 | sph_bmw256_close(&ctx_bmw, hashA); 48 | 49 | memcpy(state, hashA, 32); 50 | } 51 | 52 | int scanhash_lyra2rev2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 53 | { 54 | uint32_t _ALIGN(128) hash[8]; 55 | uint32_t _ALIGN(128) endiandata[20]; 56 | uint32_t *pdata = work->data; 57 | uint32_t *ptarget = work->target; 58 | 59 | const uint32_t Htarg = ptarget[7]; 60 | const uint32_t first_nonce = pdata[19]; 61 | uint32_t nonce = first_nonce; 62 | 63 | if (opt_benchmark) 64 | ptarget[7] = 0x0000ff; 65 | 66 | for (int i=0; i < 19; i++) { 67 | be32enc(&endiandata[i], pdata[i]); 68 | } 69 | 70 | do { 71 | be32enc(&endiandata[19], nonce); 72 | lyra2rev2_hash(hash, endiandata); 73 | 74 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 75 | work_set_target_ratio(work, hash); 76 | pdata[19] = nonce; 77 | *hashes_done = pdata[19] - first_nonce; 78 | return 1; 79 | } 80 | nonce++; 81 | 82 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 83 | 84 | pdata[19] = nonce; 85 | *hashes_done = pdata[19] - first_nonce + 1; 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /algo/myr-groestl.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_sha2.h" 10 | 11 | void myriadhash(void *output, const void *input) 12 | { 13 | uint32_t _ALIGN(32) hash[16]; 14 | sph_groestl512_context ctx; 15 | sph_sha256_context sha_ctx; 16 | 17 | // memset(&hash[0], 0, sizeof(hash)); 18 | 19 | sph_groestl512_init(&ctx); 20 | sph_groestl512(&ctx, input, 80); 21 | sph_groestl512_close(&ctx, hash); 22 | 23 | sph_sha256_init(&sha_ctx); 24 | sph_sha256(&sha_ctx, hash, 64); 25 | sph_sha256_close(&sha_ctx, hash); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | int scanhash_myriad(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 31 | { 32 | uint32_t _ALIGN(128) hash[8]; 33 | uint32_t _ALIGN(128) endiandata[20]; 34 | uint32_t *pdata = work->data; 35 | uint32_t *ptarget = work->target; 36 | 37 | const uint32_t Htarg = ptarget[7]; 38 | const uint32_t first_nonce = pdata[19]; 39 | uint32_t nonce = first_nonce; 40 | 41 | if (opt_benchmark) 42 | ptarget[7] = 0x0000ff; 43 | 44 | for (int i=0; i < 19; i++) { 45 | be32enc(&endiandata[i], pdata[i]); 46 | } 47 | 48 | do { 49 | be32enc(&endiandata[19], nonce); 50 | myriadhash(hash, endiandata); 51 | 52 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 53 | work_set_target_ratio(work, hash); 54 | pdata[19] = nonce; 55 | *hashes_done = pdata[19] - first_nonce; 56 | return 1; 57 | } 58 | nonce++; 59 | 60 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 61 | 62 | pdata[19] = nonce; 63 | *hashes_done = pdata[19] - first_nonce + 1; 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /algo/nist5.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_groestl.h" 10 | #include "sha3/sph_skein.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | 14 | void nist5hash(void *output, const void *input) 15 | { 16 | sph_blake512_context ctx_blake; 17 | sph_groestl512_context ctx_groestl; 18 | sph_jh512_context ctx_jh; 19 | sph_keccak512_context ctx_keccak; 20 | sph_skein512_context ctx_skein; 21 | 22 | uint8_t hash[64]; 23 | 24 | sph_blake512_init(&ctx_blake); 25 | sph_blake512(&ctx_blake, input, 80); 26 | sph_blake512_close(&ctx_blake, (void*) hash); 27 | 28 | sph_groestl512_init(&ctx_groestl); 29 | sph_groestl512(&ctx_groestl, (const void*) hash, 64); 30 | sph_groestl512_close(&ctx_groestl, (void*) hash); 31 | 32 | sph_jh512_init(&ctx_jh); 33 | sph_jh512(&ctx_jh, (const void*) hash, 64); 34 | sph_jh512_close(&ctx_jh, (void*) hash); 35 | 36 | sph_keccak512_init(&ctx_keccak); 37 | sph_keccak512(&ctx_keccak, (const void*) hash, 64); 38 | sph_keccak512_close(&ctx_keccak, (void*) hash); 39 | 40 | sph_skein512_init(&ctx_skein); 41 | sph_skein512(&ctx_skein, (const void*) hash, 64); 42 | sph_skein512_close(&ctx_skein, (void*) hash); 43 | 44 | memcpy(output, hash, 32); 45 | } 46 | 47 | int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 48 | { 49 | uint32_t _ALIGN(128) hash32[8]; 50 | uint32_t _ALIGN(128) endiandata[20]; 51 | uint32_t *pdata = work->data; 52 | uint32_t *ptarget = work->target; 53 | const uint32_t first_nonce = pdata[19]; 54 | const uint32_t Htarg = ptarget[7]; 55 | uint32_t n = pdata[19] - 1; 56 | 57 | uint64_t htmax[] = { 58 | 0, 59 | 0xF, 60 | 0xFF, 61 | 0xFFF, 62 | 0xFFFF, 63 | 0x10000000 64 | }; 65 | uint32_t masks[] = { 66 | 0xFFFFFFFF, 67 | 0xFFFFFFF0, 68 | 0xFFFFFF00, 69 | 0xFFFFF000, 70 | 0xFFFF0000, 71 | 0 72 | }; 73 | 74 | // we need bigendian data... 75 | for (int i=0; i < 19; i++) { 76 | be32enc(&endiandata[i], pdata[i]); 77 | } 78 | 79 | #ifdef DEBUG_ALGO 80 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 81 | #endif 82 | for (int m=0; m < 6; m++) { 83 | if (Htarg <= htmax[m]) { 84 | uint32_t mask = masks[m]; 85 | do { 86 | pdata[19] = ++n; 87 | be32enc(&endiandata[19], n); 88 | nist5hash(hash32, endiandata); 89 | #ifndef DEBUG_ALGO 90 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 91 | work_set_target_ratio(work, hash32); 92 | *hashes_done = n - first_nonce + 1; 93 | return 1; 94 | } 95 | #else 96 | if (!(n % 0x1000) && !thr_id) printf("."); 97 | if (!(hash32[7] & mask)) { 98 | printf("[%d]",thr_id); 99 | if (fulltest(hash32, ptarget)) { 100 | work_set_target_ratio(work, hash32); 101 | *hashes_done = n - first_nonce + 1; 102 | return 1; 103 | } 104 | } 105 | #endif 106 | } while (n < max_nonce && !work_restart[thr_id].restart); 107 | // see blake.c if else to understand the loop on htmax => mask 108 | break; 109 | } 110 | } 111 | 112 | *hashes_done = n - first_nonce + 1; 113 | pdata[19] = n; 114 | return 0; 115 | } 116 | -------------------------------------------------------------------------------- /algo/pentablake.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | 10 | //#define DEBUG_ALGO 11 | 12 | extern void pentablakehash(void *output, const void *input) 13 | { 14 | unsigned char _ALIGN(32) hash[128]; 15 | // same as uint32_t hashA[16], hashB[16]; 16 | #define hashB hash+64 17 | 18 | sph_blake512_context ctx_blake; 19 | 20 | sph_blake512_init(&ctx_blake); 21 | sph_blake512(&ctx_blake, input, 80); 22 | sph_blake512_close(&ctx_blake, hash); 23 | 24 | sph_blake512(&ctx_blake, hash, 64); 25 | sph_blake512_close(&ctx_blake, hashB); 26 | 27 | sph_blake512(&ctx_blake, hashB, 64); 28 | sph_blake512_close(&ctx_blake, hash); 29 | 30 | sph_blake512(&ctx_blake, hash, 64); 31 | sph_blake512_close(&ctx_blake, hashB); 32 | 33 | sph_blake512(&ctx_blake, hashB, 64); 34 | sph_blake512_close(&ctx_blake, hash); 35 | 36 | memcpy(output, hash, 32); 37 | } 38 | 39 | int scanhash_pentablake(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 40 | { 41 | uint32_t _ALIGN(128) hash32[8]; 42 | uint32_t _ALIGN(128) endiandata[20]; 43 | uint32_t *pdata = work->data; 44 | uint32_t *ptarget = work->target; 45 | 46 | uint32_t n = pdata[19] - 1; 47 | const uint32_t first_nonce = pdata[19]; 48 | const uint32_t Htarg = ptarget[7]; 49 | 50 | uint64_t htmax[] = { 51 | 0, 52 | 0xF, 53 | 0xFF, 54 | 0xFFF, 55 | 0xFFFF, 56 | 0x10000000 57 | }; 58 | uint32_t masks[] = { 59 | 0xFFFFFFFF, 60 | 0xFFFFFFF0, 61 | 0xFFFFFF00, 62 | 0xFFFFF000, 63 | 0xFFFF0000, 64 | 0 65 | }; 66 | 67 | // we need bigendian data... 68 | for (int i=0; i < 19; i++) { 69 | be32enc(&endiandata[i], pdata[i]); 70 | } 71 | 72 | #ifdef DEBUG_ALGO 73 | if (Htarg != 0) 74 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 75 | #endif 76 | for (int m=0; m < 6; m++) { 77 | if (Htarg <= htmax[m]) { 78 | uint32_t mask = masks[m]; 79 | do { 80 | pdata[19] = ++n; 81 | be32enc(&endiandata[19], n); 82 | pentablakehash(hash32, endiandata); 83 | #ifndef DEBUG_ALGO 84 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 85 | work_set_target_ratio(work, hash32); 86 | *hashes_done = n - first_nonce + 1; 87 | return 1; 88 | } 89 | #else 90 | if (!(n % 0x1000) && !thr_id) printf("."); 91 | if (!(hash32[7] & mask)) { 92 | printf("[%d]",thr_id); 93 | if (fulltest(hash32, ptarget)) { 94 | work_set_target_ratio(work, hash32); 95 | *hashes_done = n - first_nonce + 1; 96 | return 1; 97 | } 98 | } 99 | #endif 100 | } while (n < max_nonce && !work_restart[thr_id].restart); 101 | // see blake.c if else to understand the loop on htmax => mask 102 | break; 103 | } 104 | } 105 | 106 | *hashes_done = n - first_nonce + 1; 107 | pdata[19] = n; 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /algo/phi1612.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Phi1612 algo Implementation (initial LUX algo) 3 | */ 4 | 5 | #include 6 | 7 | #include "sha3/sph_skein.h" 8 | #include "sha3/sph_jh.h" 9 | #include "sha3/sph_cubehash.h" 10 | #include "sha3/sph_fugue.h" 11 | #include "sha3/gost_streebog.h" 12 | #include "sha3/sph_echo.h" 13 | 14 | #include "miner.h" 15 | 16 | static char* format_hash(char* buf, uint8_t *hash) 17 | { 18 | int len = 0; 19 | for (int i=0; i < 32; i += 4) { 20 | len += sprintf(buf+len, "%02x%02x%02x%02x ", 21 | hash[i], hash[i+1], hash[i+2], hash[i+3]); 22 | } 23 | return buf; 24 | } 25 | 26 | void phi1612_hash(void *state, const void *input) 27 | { 28 | sph_skein512_context ctx_skein; 29 | sph_jh512_context ctx_jh; 30 | sph_cubehash512_context ctx_cubehash; 31 | sph_fugue512_context ctx_fugue; 32 | sph_gost512_context ctx_gost; 33 | sph_echo512_context ctx_echo; 34 | 35 | uint8_t _ALIGN(128) hash[64]; 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_jh512_init(&ctx_jh); 42 | sph_jh512(&ctx_jh, (const void*) hash, 64); 43 | sph_jh512_close(&ctx_jh, (void*) hash); 44 | 45 | sph_cubehash512_init(&ctx_cubehash); 46 | sph_cubehash512(&ctx_cubehash, (const void*) hash, 64); 47 | sph_cubehash512_close(&ctx_cubehash, (void*) hash); 48 | 49 | sph_fugue512_init(&ctx_fugue); 50 | sph_fugue512(&ctx_fugue, (const void*) hash, 64); 51 | sph_fugue512_close(&ctx_fugue, (void*) hash); 52 | 53 | sph_gost512_init(&ctx_gost); 54 | sph_gost512(&ctx_gost, (const void*) hash, 64); 55 | sph_gost512_close(&ctx_gost, (void*) hash); 56 | 57 | sph_echo512_init(&ctx_echo); 58 | sph_echo512(&ctx_echo, (const void*) hash, 64); 59 | sph_echo512_close(&ctx_echo, (void*) hash); 60 | 61 | memcpy(state, hash, 32); 62 | } 63 | 64 | int scanhash_phi1612(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 65 | { 66 | uint32_t _ALIGN(128) hash[8]; 67 | uint32_t _ALIGN(128) endiandata[20]; 68 | uint32_t *pdata = work->data; 69 | uint32_t *ptarget = work->target; 70 | 71 | const uint32_t Htarg = ptarget[7]; 72 | const uint32_t first_nonce = pdata[19]; 73 | uint32_t n = first_nonce; 74 | 75 | if(opt_benchmark){ 76 | ptarget[7] = 0x00ff; 77 | } 78 | 79 | for (int i=0; i < 19; i++) { 80 | be32enc(&endiandata[i], pdata[i]); 81 | } 82 | 83 | do { 84 | be32enc(&endiandata[19], n); 85 | phi1612_hash(hash, endiandata); 86 | 87 | if (hash[7] < Htarg && fulltest(hash, ptarget)) { 88 | work_set_target_ratio(work, hash); 89 | *hashes_done = n - first_nonce + 1; 90 | pdata[19] = n; 91 | return 1; 92 | } 93 | n++; 94 | 95 | } while (n < max_nonce && !work_restart[thr_id].restart); 96 | 97 | *hashes_done = n - first_nonce + 1; 98 | pdata[19] = n; 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /algo/phi2.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Phi-2 algo Implementation 3 | */ 4 | 5 | #include 6 | 7 | #include "sha3/sph_cubehash.h" 8 | #include "sha3/sph_skein.h" 9 | #include "sha3/sph_jh.h" 10 | //#include "sha3/sph_fugue.h" 11 | #include "sha3/gost_streebog.h" 12 | #include "sha3/sph_echo.h" 13 | 14 | #include "lyra2/Lyra2.h" 15 | 16 | #include "miner.h" 17 | 18 | static bool has_roots; 19 | 20 | void phi2_hash(void *state, const void *input) 21 | { 22 | unsigned char _ALIGN(128) hash[64]; 23 | unsigned char _ALIGN(128) hashA[64]; 24 | unsigned char _ALIGN(128) hashB[64]; 25 | 26 | sph_cubehash512_context ctx_cubehash; 27 | sph_jh512_context ctx_jh; 28 | sph_gost512_context ctx_gost; 29 | sph_echo512_context ctx_echo; 30 | sph_skein512_context ctx_skein; 31 | 32 | sph_cubehash512_init(&ctx_cubehash); 33 | sph_cubehash512(&ctx_cubehash, input, has_roots ? 144 : 80); 34 | sph_cubehash512_close(&ctx_cubehash, (void*)hashB); 35 | 36 | LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); 37 | LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); 38 | 39 | sph_jh512_init(&ctx_jh); 40 | sph_jh512(&ctx_jh, (const void*)hashA, 64); 41 | sph_jh512_close(&ctx_jh, (void*)hash); 42 | 43 | if (hash[0] & 1) { 44 | sph_gost512_init(&ctx_gost); 45 | sph_gost512(&ctx_gost, (const void*)hash, 64); 46 | sph_gost512_close(&ctx_gost, (void*)hash); 47 | } else { 48 | sph_echo512_init(&ctx_echo); 49 | sph_echo512(&ctx_echo, (const void*)hash, 64); 50 | sph_echo512_close(&ctx_echo, (void*)hash); 51 | 52 | sph_echo512_init(&ctx_echo); 53 | sph_echo512(&ctx_echo, (const void*)hash, 64); 54 | sph_echo512_close(&ctx_echo, (void*)hash); 55 | } 56 | 57 | sph_skein512_init(&ctx_skein); 58 | sph_skein512(&ctx_skein, (const void*)hash, 64); 59 | sph_skein512_close(&ctx_skein, (void*)hash); 60 | 61 | for (int i=0; i<4; i++) 62 | ((uint64_t*)hash)[i] ^= ((uint64_t*)hash)[i+4]; 63 | 64 | memcpy(state, hash, 32); 65 | } 66 | 67 | int scanhash_phi2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 68 | { 69 | uint32_t _ALIGN(128) hash[8]; 70 | uint32_t _ALIGN(128) endiandata[20]; 71 | uint32_t *pdata = work->data; 72 | uint32_t *ptarget = work->target; 73 | 74 | const uint32_t Htarg = ptarget[7]; 75 | const uint32_t first_nonce = pdata[19]; 76 | uint32_t n = first_nonce; 77 | 78 | if(opt_benchmark){ 79 | ptarget[7] = 0x00ff; 80 | } 81 | 82 | has_roots = false; 83 | for (int i=0; i < 36; i++) { 84 | be32enc(&endiandata[i], pdata[i]); 85 | if (i >= 20 && pdata[i]) has_roots = true; 86 | } 87 | 88 | do { 89 | be32enc(&endiandata[19], n); 90 | phi2_hash(hash, endiandata); 91 | 92 | if (hash[7] < Htarg && fulltest(hash, ptarget)) { 93 | work_set_target_ratio(work, hash); 94 | *hashes_done = n - first_nonce + 1; 95 | pdata[19] = n; 96 | return 1; 97 | } 98 | n++; 99 | 100 | } while (n < max_nonce && !work_restart[thr_id].restart); 101 | 102 | *hashes_done = n - first_nonce + 1; 103 | pdata[19] = n; 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /algo/qubit.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_luffa.h" 9 | #include "sha3/sph_cubehash.h" 10 | #include "sha3/sph_shavite.h" 11 | #include "sha3/sph_simd.h" 12 | #include "sha3/sph_echo.h" 13 | 14 | void qubithash(void *output, const void *input) 15 | { 16 | sph_luffa512_context ctx_luffa; 17 | sph_cubehash512_context ctx_cubehash; 18 | sph_shavite512_context ctx_shavite; 19 | sph_simd512_context ctx_simd; 20 | sph_echo512_context ctx_echo; 21 | 22 | uint8_t hash[64]; 23 | 24 | sph_luffa512_init(&ctx_luffa); 25 | sph_luffa512 (&ctx_luffa, input, 80); 26 | sph_luffa512_close(&ctx_luffa, (void*) hash); 27 | 28 | sph_cubehash512_init(&ctx_cubehash); 29 | sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64); 30 | sph_cubehash512_close(&ctx_cubehash, (void*) hash); 31 | 32 | sph_shavite512_init(&ctx_shavite); 33 | sph_shavite512 (&ctx_shavite, (const void*) hash, 64); 34 | sph_shavite512_close(&ctx_shavite, (void*) hash); 35 | 36 | sph_simd512_init(&ctx_simd); 37 | sph_simd512 (&ctx_simd, (const void*) hash, 64); 38 | sph_simd512_close(&ctx_simd, (void*) hash); 39 | 40 | sph_echo512_init(&ctx_echo); 41 | sph_echo512 (&ctx_echo, (const void*) hash, 64); 42 | sph_echo512_close(&ctx_echo, (void*) hash); 43 | 44 | memcpy(output, hash, 32); 45 | } 46 | 47 | int scanhash_qubit(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 48 | { 49 | uint32_t _ALIGN(128) hash32[8]; 50 | uint32_t _ALIGN(128) endiandata[20]; 51 | uint32_t *pdata = work->data; 52 | uint32_t *ptarget = work->target; 53 | 54 | uint32_t n = pdata[19] - 1; 55 | const uint32_t first_nonce = pdata[19]; 56 | const uint32_t Htarg = ptarget[7]; 57 | 58 | uint64_t htmax[] = { 59 | 0, 60 | 0xF, 61 | 0xFF, 62 | 0xFFF, 63 | 0xFFFF, 64 | 0x10000000 65 | }; 66 | uint32_t masks[] = { 67 | 0xFFFFFFFF, 68 | 0xFFFFFFF0, 69 | 0xFFFFFF00, 70 | 0xFFFFF000, 71 | 0xFFFF0000, 72 | 0 73 | }; 74 | 75 | // we need bigendian data... 76 | for (int i=0; i < 19; i++) { 77 | be32enc(&endiandata[i], pdata[i]); 78 | } 79 | 80 | #ifdef DEBUG_ALGO 81 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 82 | #endif 83 | for (int m=0; m < 6; m++) { 84 | if (Htarg <= htmax[m]) { 85 | uint32_t mask = masks[m]; 86 | do { 87 | pdata[19] = ++n; 88 | be32enc(&endiandata[19], n); 89 | qubithash(hash32, endiandata); 90 | #ifndef DEBUG_ALGO 91 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 92 | work_set_target_ratio(work, hash32); 93 | *hashes_done = n - first_nonce + 1; 94 | return 1; 95 | } 96 | #else 97 | if (!(n % 0x1000) && !thr_id) printf("."); 98 | if (!(hash32[7] & mask)) { 99 | printf("[%d]",thr_id); 100 | if (fulltest(hash32, ptarget)) { 101 | work_set_target_ratio(work, hash32); 102 | *hashes_done = n - first_nonce + 1; 103 | return 1; 104 | } 105 | } 106 | #endif 107 | } while (n < max_nonce && !work_restart[thr_id].restart); 108 | // see blake.c if else to understand the loop on htmax => mask 109 | break; 110 | } 111 | } 112 | 113 | *hashes_done = n - first_nonce + 1; 114 | pdata[19] = n; 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /algo/s3.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_skein.h" 9 | #include "sha3/sph_shavite.h" 10 | #include "sha3/sph_simd.h" 11 | 12 | void s3hash(void *output, const void *input) 13 | { 14 | sph_shavite512_context ctx_shavite; 15 | sph_simd512_context ctx_simd; 16 | sph_skein512_context ctx_skein; 17 | 18 | unsigned char _ALIGN(128) hash[64]; 19 | 20 | sph_shavite512_init(&ctx_shavite); 21 | sph_shavite512(&ctx_shavite, input, 80); 22 | sph_shavite512_close(&ctx_shavite, (void*)hash); 23 | 24 | sph_simd512_init(&ctx_simd); 25 | sph_simd512(&ctx_simd, (const void*)hash, 64); 26 | sph_simd512_close(&ctx_simd, (void*)hash); 27 | 28 | sph_skein512_init(&ctx_skein); 29 | sph_skein512(&ctx_skein, (const void*)hash, 64); 30 | sph_skein512_close(&ctx_skein, (void*)hash); 31 | 32 | memcpy(output, hash, 32); 33 | } 34 | 35 | int scanhash_s3(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 36 | { 37 | uint32_t _ALIGN(128) hash32[8]; 38 | uint32_t _ALIGN(128) endiandata[20]; 39 | uint32_t *pdata = work->data; 40 | uint32_t *ptarget = work->target; 41 | 42 | uint32_t n = pdata[19] - 1; 43 | const uint32_t first_nonce = pdata[19]; 44 | const uint32_t Htarg = ptarget[7]; 45 | 46 | uint64_t htmax[] = { 47 | 0, 48 | 0xF, 49 | 0xFF, 50 | 0xFFF, 51 | 0xFFFF, 52 | 0x10000000 53 | }; 54 | uint32_t masks[] = { 55 | 0xFFFFFFFF, 56 | 0xFFFFFFF0, 57 | 0xFFFFFF00, 58 | 0xFFFFF000, 59 | 0xFFFF0000, 60 | 0 61 | }; 62 | 63 | // we need bigendian data... 64 | for (int i=0; i < 19; i++) { 65 | be32enc(&endiandata[i], pdata[i]); 66 | } 67 | 68 | #ifdef DEBUG_ALGO 69 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 70 | #endif 71 | for (int m=0; m < 6; m++) { 72 | if (Htarg <= htmax[m]) { 73 | uint32_t mask = masks[m]; 74 | do { 75 | pdata[19] = ++n; 76 | be32enc(&endiandata[19], n); 77 | s3hash(hash32, endiandata); 78 | #ifndef DEBUG_ALGO 79 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 80 | work_set_target_ratio(work, hash32); 81 | *hashes_done = n - first_nonce + 1; 82 | return true; 83 | } 84 | #else 85 | if (!(n % 0x1000) && !thr_id) printf("."); 86 | if (!(hash32[7] & mask)) { 87 | printf("[%d]",thr_id); 88 | if (fulltest(hash32, ptarget)) { 89 | work_set_target_ratio(work, hash32); 90 | *hashes_done = n - first_nonce + 1; 91 | return true; 92 | } 93 | } 94 | #endif 95 | } while (n < max_nonce && !work_restart[thr_id].restart); 96 | // see blake.c if else to understand the loop on htmax => mask 97 | break; 98 | } 99 | } 100 | 101 | *hashes_done = n - first_nonce + 1; 102 | pdata[19] = n; 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /algo/sia.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Blake2-B Implementation 3 | * tpruvot@github 2015-2016 4 | */ 5 | 6 | #include "miner.h" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | static __thread blake2b_ctx s_midstate; 14 | static __thread blake2b_ctx s_ctx; 15 | #define MIDLEN 76 16 | #define A 64 17 | 18 | void blake2b_hash(void *output, const void *input) 19 | { 20 | uint8_t _ALIGN(A) hash[32]; 21 | blake2b_ctx ctx; 22 | 23 | blake2b_init(&ctx, 32, NULL, 0); 24 | blake2b_update(&ctx, input, 80); 25 | blake2b_final(&ctx, hash); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | static void blake2b_hash_end(uint32_t *output, const uint32_t *input) 31 | { 32 | s_ctx.outlen = MIDLEN; 33 | memcpy(&s_ctx, &s_midstate, 32 + 16 + MIDLEN); 34 | blake2b_update(&s_ctx, (uint8_t*) &input[MIDLEN/4], 80 - MIDLEN); 35 | blake2b_final(&s_ctx, (uint8_t*) output); 36 | } 37 | 38 | int scanhash_blake2b(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 39 | { 40 | uint32_t _ALIGN(A) vhashcpu[8]; 41 | uint32_t _ALIGN(A) endiandata[20]; 42 | uint32_t *pdata = work->data; 43 | uint32_t *ptarget = work->target; 44 | 45 | const uint32_t Htarg = ptarget[7]; 46 | const uint32_t first_nonce = pdata[19]; 47 | 48 | uint32_t n = first_nonce; 49 | 50 | for (int i=0; i < 19; i++) { 51 | be32enc(&endiandata[i], pdata[i]); 52 | } 53 | 54 | // midstate (untested yet) 55 | //blake2b_init(&s_midstate, 32, NULL, 0); 56 | //blake2b_update(&s_midstate, (uint8_t*) endiandata, MIDLEN); 57 | //memcpy(&s_ctx, &s_midstate, sizeof(blake2b_ctx)); 58 | 59 | do { 60 | be32enc(&endiandata[19], n); 61 | //blake2b_hash_end(vhashcpu, endiandata); 62 | blake2b_hash(vhashcpu, endiandata); 63 | 64 | if (vhashcpu[7] < Htarg && fulltest(vhashcpu, ptarget)) { 65 | work_set_target_ratio(work, vhashcpu); 66 | *hashes_done = n - first_nonce + 1; 67 | pdata[19] = n; 68 | return 1; 69 | } 70 | n++; 71 | 72 | } while (n < max_nonce && !work_restart[thr_id].restart); 73 | 74 | *hashes_done = n - first_nonce + 1; 75 | pdata[19] = n; 76 | 77 | return 0; 78 | } 79 | 80 | static inline void swab256(void *dest_p, const void *src_p) 81 | { 82 | uint32_t *dest = (uint32_t *)dest_p; 83 | const uint32_t *src = (uint32_t *)src_p; 84 | 85 | dest[0] = swab32(src[7]); 86 | dest[1] = swab32(src[6]); 87 | dest[2] = swab32(src[5]); 88 | dest[3] = swab32(src[4]); 89 | dest[4] = swab32(src[3]); 90 | dest[5] = swab32(src[2]); 91 | dest[6] = swab32(src[1]); 92 | dest[7] = swab32(src[0]); 93 | } 94 | 95 | int scanhash_sia(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 96 | { 97 | uint32_t _ALIGN(A) hash[8]; 98 | uint32_t _ALIGN(A) vhashcpu[8]; 99 | uint32_t _ALIGN(A) inputdata[20]; 100 | uint32_t *pdata = work->data; 101 | uint32_t *ptarget = work->target; 102 | 103 | const uint32_t Htarg = ptarget[7]; 104 | const uint32_t first_nonce = pdata[8]; 105 | 106 | uint32_t n = first_nonce; 107 | 108 | memcpy(inputdata, pdata, 80); 109 | inputdata[11] = 0; // nbits 110 | 111 | do { 112 | inputdata[8] = n; 113 | blake2b_hash(hash, inputdata); 114 | if (swab32(hash[0]) < Htarg) { 115 | swab256(vhashcpu, hash); 116 | if (fulltest(vhashcpu, ptarget)) { 117 | work_set_target_ratio(work, vhashcpu); 118 | *hashes_done = n - first_nonce + 1; 119 | pdata[8] = n; 120 | return 1; 121 | } 122 | } 123 | n++; 124 | 125 | } while (n < max_nonce && !work_restart[thr_id].restart); 126 | 127 | *hashes_done = n - first_nonce + 1; 128 | pdata[8] = n; 129 | 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /algo/skein.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "sha3/sph_skein.h" 9 | 10 | void skeinhash(void *state, const void *input) 11 | { 12 | sph_skein512_context ctx_skein; 13 | SHA256_CTX sha256; 14 | 15 | uint32_t hash[16]; 16 | 17 | sph_skein512_init(&ctx_skein); 18 | sph_skein512(&ctx_skein, input, 80); 19 | sph_skein512_close(&ctx_skein, hash); 20 | 21 | SHA256_Init(&sha256); 22 | SHA256_Update(&sha256, hash, 64); 23 | SHA256_Final((unsigned char*) hash, &sha256); 24 | 25 | memcpy(state, hash, 32); 26 | } 27 | 28 | int scanhash_skein(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 29 | { 30 | uint32_t _ALIGN(128) hash32[8]; 31 | uint32_t _ALIGN(128) endiandata[20]; 32 | uint32_t *pdata = work->data; 33 | uint32_t *ptarget = work->target; 34 | 35 | const uint32_t Htarg = ptarget[7]; 36 | const uint32_t first_nonce = pdata[19]; 37 | 38 | uint32_t n = first_nonce; 39 | 40 | for (int i=0; i < 19; i++) { 41 | be32enc(&endiandata[i], pdata[i]); 42 | }; 43 | 44 | do { 45 | be32enc(&endiandata[19], n); 46 | skeinhash(hash32, endiandata); 47 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 48 | work_set_target_ratio(work, hash32); 49 | *hashes_done = n - first_nonce + 1; 50 | pdata[19] = n; 51 | return true; 52 | } 53 | n++; 54 | 55 | } while (n < max_nonce && !work_restart[thr_id].restart); 56 | 57 | *hashes_done = n - first_nonce + 1; 58 | pdata[19] = n; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /algo/skein2.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_skein.h" 7 | 8 | void skein2hash(void *output, const void *input) 9 | { 10 | uint32_t _ALIGN(128) hash[16]; 11 | 12 | sph_skein512_context ctx_skein; 13 | 14 | sph_skein512_init(&ctx_skein); 15 | sph_skein512(&ctx_skein, input, 80); 16 | sph_skein512_close(&ctx_skein, hash); 17 | 18 | sph_skein512_init(&ctx_skein); 19 | sph_skein512(&ctx_skein, hash, 64); 20 | sph_skein512_close(&ctx_skein, hash); 21 | 22 | memcpy(output, hash, 32); 23 | } 24 | 25 | int scanhash_skein2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 26 | { 27 | uint32_t _ALIGN(128) hash32[8]; 28 | uint32_t _ALIGN(128) endiandata[20]; 29 | uint32_t *pdata = work->data; 30 | uint32_t *ptarget = work->target; 31 | 32 | const uint32_t Htarg = ptarget[7]; 33 | const uint32_t first_nonce = pdata[19]; 34 | 35 | uint32_t n = first_nonce; 36 | 37 | for (int i=0; i < 19; i++) { 38 | be32enc(&endiandata[i], pdata[i]); 39 | } 40 | 41 | do { 42 | be32enc(&endiandata[19], n); 43 | skein2hash(hash32, endiandata); 44 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 45 | work_set_target_ratio(work, hash32); 46 | *hashes_done = n - first_nonce + 1; 47 | pdata[19] = n; 48 | return true; 49 | } 50 | n++; 51 | 52 | } while (n < max_nonce && !work_restart[thr_id].restart); 53 | 54 | *hashes_done = n - first_nonce + 1; 55 | pdata[19] = n; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /algo/tribus.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_jh.h" 9 | #include "sha3/sph_keccak.h" 10 | #include "sha3/sph_echo.h" 11 | 12 | void tribus_hash(void *state, const void *input) 13 | { 14 | uint8_t _ALIGN(128) hash[64]; 15 | 16 | sph_jh512_context ctx_jh; 17 | sph_keccak512_context ctx_keccak; 18 | sph_echo512_context ctx_echo; 19 | 20 | sph_jh512_init(&ctx_jh); 21 | sph_jh512(&ctx_jh, input, 80); 22 | sph_jh512_close(&ctx_jh, (void*) hash); 23 | 24 | sph_keccak512_init(&ctx_keccak); 25 | sph_keccak512(&ctx_keccak, (const void*) hash, 64); 26 | sph_keccak512_close(&ctx_keccak, (void*) hash); 27 | 28 | sph_echo512_init(&ctx_echo); 29 | sph_echo512(&ctx_echo, (const void*) hash, 64); 30 | sph_echo512_close(&ctx_echo, (void*) hash); 31 | 32 | memcpy(state, hash, 32); 33 | } 34 | 35 | int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 36 | { 37 | uint32_t _ALIGN(128) hash32[8]; 38 | uint32_t _ALIGN(128) endiandata[20]; 39 | uint32_t *pdata = work->data; 40 | uint32_t *ptarget = work->target; 41 | const uint32_t first_nonce = pdata[19]; 42 | const uint32_t Htarg = ptarget[7]; 43 | uint32_t n = pdata[19] - 1; 44 | 45 | uint64_t htmax[] = { 46 | 0, 47 | 0xF, 48 | 0xFF, 49 | 0xFFF, 50 | 0xFFFF, 51 | 0x10000000 52 | }; 53 | uint32_t masks[] = { 54 | 0xFFFFFFFF, 55 | 0xFFFFFFF0, 56 | 0xFFFFFF00, 57 | 0xFFFFF000, 58 | 0xFFFF0000, 59 | 0 60 | }; 61 | 62 | // we need bigendian data... 63 | for (int i=0; i < 19; i++) { 64 | be32enc(&endiandata[i], pdata[i]); 65 | } 66 | 67 | #ifdef DEBUG_ALGO 68 | printf("[%d] Htarg=%X\n", thr_id, Htarg); 69 | #endif 70 | for (int m=0; m < 6; m++) { 71 | if (Htarg <= htmax[m]) { 72 | uint32_t mask = masks[m]; 73 | do { 74 | pdata[19] = ++n; 75 | be32enc(&endiandata[19], n); 76 | tribus_hash(hash32, endiandata); 77 | #ifndef DEBUG_ALGO 78 | if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { 79 | work_set_target_ratio(work, hash32); 80 | *hashes_done = n - first_nonce + 1; 81 | return 1; 82 | } 83 | #else 84 | if (!(n % 0x1000) && !thr_id) printf("."); 85 | if (!(hash32[7] & mask)) { 86 | printf("[%d]",thr_id); 87 | if (fulltest(hash32, ptarget)) { 88 | work_set_target_ratio(work, hash32); 89 | *hashes_done = n - first_nonce + 1; 90 | return 1; 91 | } 92 | } 93 | #endif 94 | } while (n < max_nonce && !work_restart[thr_id].restart); 95 | // see blake.c if else to understand the loop on htmax => mask 96 | break; 97 | } 98 | } 99 | 100 | *hashes_done = n - first_nonce + 1; 101 | pdata[19] = n; 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /algo/veltor.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */ 14 | typedef struct { 15 | sph_skein512_context skein1; 16 | sph_shavite512_context shavite1; 17 | sph_shabal512_context shabal1; 18 | sph_gost512_context gost1; 19 | } Xhash_context_holder; 20 | 21 | static __thread Xhash_context_holder base_contexts; 22 | static __thread bool init = false; 23 | 24 | static void init_Xhash_contexts() 25 | { 26 | sph_skein512_init(&base_contexts.skein1); 27 | sph_shavite512_init(&base_contexts.shavite1); 28 | sph_shabal512_init(&base_contexts.shabal1); 29 | sph_gost512_init(&base_contexts.gost1); 30 | init = true; 31 | } 32 | 33 | void veltor_hash(void *output, const void *input) 34 | { 35 | Xhash_context_holder ctx; 36 | 37 | uint32_t hashA[16]; 38 | 39 | if (!init) init_Xhash_contexts(); 40 | 41 | memcpy(&ctx, &base_contexts, sizeof(base_contexts)); 42 | 43 | sph_skein512(&ctx.skein1, input, 80); 44 | sph_skein512_close(&ctx.skein1, hashA); 45 | 46 | sph_shavite512(&ctx.shavite1, hashA, 64); 47 | sph_shavite512_close(&ctx.shavite1, hashA); 48 | 49 | sph_shabal512(&ctx.shabal1, hashA, 64); 50 | sph_shabal512_close(&ctx.shabal1, hashA); 51 | 52 | sph_gost512(&ctx.gost1, hashA, 64); 53 | sph_gost512_close(&ctx.gost1, hashA); 54 | 55 | memcpy(output, hashA, 32); 56 | } 57 | 58 | int scanhash_veltor(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 59 | { 60 | uint32_t _ALIGN(128) hash[8]; 61 | uint32_t _ALIGN(128) endiandata[20]; 62 | uint32_t *pdata = work->data; 63 | uint32_t *ptarget = work->target; 64 | 65 | const uint32_t Htarg = ptarget[7]; 66 | const uint32_t first_nonce = pdata[19]; 67 | uint32_t nonce = first_nonce; 68 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 69 | 70 | if (opt_benchmark) 71 | ptarget[7] = 0x0cff; 72 | 73 | // we need bigendian data... 74 | for (int i=0; i < 19; i++) { 75 | be32enc(&endiandata[i], pdata[i]); 76 | } 77 | do { 78 | be32enc(&endiandata[19], nonce); 79 | veltor_hash(hash, endiandata); 80 | 81 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 82 | work_set_target_ratio(work, hash); 83 | pdata[19] = nonce; 84 | *hashes_done = pdata[19] - first_nonce; 85 | return 1; 86 | } 87 | nonce++; 88 | 89 | } while (nonce < max_nonce && !(*restart)); 90 | 91 | pdata[19] = nonce; 92 | *hashes_done = pdata[19] - first_nonce + 1; 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /algo/x11.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_blake.h" 9 | #include "sha3/sph_bmw.h" 10 | #include "sha3/sph_groestl.h" 11 | #include "sha3/sph_jh.h" 12 | #include "sha3/sph_keccak.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_luffa.h" 15 | #include "sha3/sph_cubehash.h" 16 | #include "sha3/sph_shavite.h" 17 | #include "sha3/sph_simd.h" 18 | #include "sha3/sph_echo.h" 19 | 20 | 21 | void x11hash(void *output, const void *input) 22 | { 23 | sph_blake512_context ctx_blake; 24 | sph_bmw512_context ctx_bmw; 25 | sph_groestl512_context ctx_groestl; 26 | sph_skein512_context ctx_skein; 27 | sph_jh512_context ctx_jh; 28 | sph_keccak512_context ctx_keccak; 29 | 30 | sph_luffa512_context ctx_luffa1; 31 | sph_cubehash512_context ctx_cubehash1; 32 | sph_shavite512_context ctx_shavite1; 33 | sph_simd512_context ctx_simd1; 34 | sph_echo512_context ctx_echo1; 35 | 36 | //these uint512 in the c++ source of the client are backed by an array of uint32 37 | uint32_t _ALIGN(64) hashA[16], hashB[16]; 38 | 39 | sph_blake512_init(&ctx_blake); 40 | sph_blake512 (&ctx_blake, input, 80); 41 | sph_blake512_close (&ctx_blake, hashA); 42 | 43 | sph_bmw512_init(&ctx_bmw); 44 | sph_bmw512 (&ctx_bmw, hashA, 64); 45 | sph_bmw512_close(&ctx_bmw, hashB); 46 | 47 | sph_groestl512_init(&ctx_groestl); 48 | sph_groestl512 (&ctx_groestl, hashB, 64); 49 | sph_groestl512_close(&ctx_groestl, hashA); 50 | 51 | sph_skein512_init(&ctx_skein); 52 | sph_skein512 (&ctx_skein, hashA, 64); 53 | sph_skein512_close (&ctx_skein, hashB); 54 | 55 | sph_jh512_init(&ctx_jh); 56 | sph_jh512 (&ctx_jh, hashB, 64); 57 | sph_jh512_close(&ctx_jh, hashA); 58 | 59 | sph_keccak512_init(&ctx_keccak); 60 | sph_keccak512 (&ctx_keccak, hashA, 64); 61 | sph_keccak512_close(&ctx_keccak, hashB); 62 | 63 | sph_luffa512_init (&ctx_luffa1); 64 | sph_luffa512 (&ctx_luffa1, hashB, 64); 65 | sph_luffa512_close (&ctx_luffa1, hashA); 66 | 67 | sph_cubehash512_init (&ctx_cubehash1); 68 | sph_cubehash512 (&ctx_cubehash1, hashA, 64); 69 | sph_cubehash512_close(&ctx_cubehash1, hashB); 70 | 71 | sph_shavite512_init (&ctx_shavite1); 72 | sph_shavite512 (&ctx_shavite1, hashB, 64); 73 | sph_shavite512_close(&ctx_shavite1, hashA); 74 | 75 | sph_simd512_init (&ctx_simd1); 76 | sph_simd512 (&ctx_simd1, hashA, 64); 77 | sph_simd512_close(&ctx_simd1, hashB); 78 | 79 | sph_echo512_init (&ctx_echo1); 80 | sph_echo512 (&ctx_echo1, hashB, 64); 81 | sph_echo512_close(&ctx_echo1, hashA); 82 | 83 | memcpy(output, hashA, 32); 84 | } 85 | 86 | int scanhash_x11(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 87 | { 88 | uint32_t _ALIGN(128) hash[8]; 89 | uint32_t _ALIGN(128) endiandata[20]; 90 | uint32_t *pdata = work->data; 91 | uint32_t *ptarget = work->target; 92 | 93 | const uint32_t Htarg = ptarget[7]; 94 | const uint32_t first_nonce = pdata[19]; 95 | uint32_t nonce = first_nonce; 96 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 97 | 98 | if (opt_benchmark) 99 | ptarget[7] = 0x0cff; 100 | 101 | for (int k=0; k < 19; k++) 102 | be32enc(&endiandata[k], pdata[k]); 103 | 104 | do { 105 | be32enc(&endiandata[19], nonce); 106 | x11hash(hash, endiandata); 107 | 108 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 109 | work_set_target_ratio(work, hash); 110 | pdata[19] = nonce; 111 | *hashes_done = pdata[19] - first_nonce; 112 | return 1; 113 | } 114 | nonce++; 115 | 116 | } while (nonce < max_nonce && !(*restart)); 117 | 118 | pdata[19] = nonce; 119 | *hashes_done = pdata[19] - first_nonce + 1; 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /algo/x12.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void x12hash(void *output, const void *input) 22 | { 23 | uint32_t _ALIGN(64) hash[16]; 24 | 25 | sph_blake512_context ctx_blake; 26 | sph_bmw512_context ctx_bmw; 27 | sph_luffa512_context ctx_luffa; 28 | sph_cubehash512_context ctx_cubehash; 29 | sph_shavite512_context ctx_shavite; 30 | sph_simd512_context ctx_simd; 31 | sph_echo512_context ctx_echo; 32 | sph_groestl512_context ctx_groestl; 33 | sph_skein512_context ctx_skein; 34 | sph_jh512_context ctx_jh; 35 | sph_keccak512_context ctx_keccak; 36 | sph_hamsi512_context ctx_hamsi; 37 | 38 | sph_blake512_init(&ctx_blake); 39 | sph_blake512(&ctx_blake, input, 80); 40 | sph_blake512_close(&ctx_blake, hash); 41 | 42 | sph_bmw512_init(&ctx_bmw); 43 | sph_bmw512(&ctx_bmw, hash, 64); 44 | sph_bmw512_close(&ctx_bmw, hash); 45 | 46 | sph_luffa512_init(&ctx_luffa); 47 | sph_luffa512(&ctx_luffa, hash, 64); 48 | sph_luffa512_close(&ctx_luffa, hash); 49 | 50 | sph_cubehash512_init(&ctx_cubehash); 51 | sph_cubehash512(&ctx_cubehash, hash, 64); 52 | sph_cubehash512_close(&ctx_cubehash, hash); 53 | 54 | sph_shavite512_init(&ctx_shavite); 55 | sph_shavite512(&ctx_shavite, hash, 64); 56 | sph_shavite512_close(&ctx_shavite, hash); 57 | 58 | sph_simd512_init(&ctx_simd); 59 | sph_simd512(&ctx_simd, hash, 64); 60 | sph_simd512_close(&ctx_simd, hash); 61 | 62 | sph_echo512_init(&ctx_echo); 63 | sph_echo512(&ctx_echo, hash, 64); 64 | sph_echo512_close(&ctx_echo, hash); 65 | 66 | sph_groestl512_init(&ctx_groestl); 67 | sph_groestl512(&ctx_groestl, hash, 64); 68 | sph_groestl512_close(&ctx_groestl, hash); 69 | 70 | sph_skein512_init(&ctx_skein); 71 | sph_skein512(&ctx_skein, hash, 64); 72 | sph_skein512_close(&ctx_skein, hash); 73 | 74 | sph_jh512_init(&ctx_jh); 75 | sph_jh512(&ctx_jh, hash, 64); 76 | sph_jh512_close(&ctx_jh, hash); 77 | 78 | sph_keccak512_init(&ctx_keccak); 79 | sph_keccak512(&ctx_keccak, hash, 64); 80 | sph_keccak512_close(&ctx_keccak, hash); 81 | 82 | sph_hamsi512_init(&ctx_hamsi); 83 | sph_hamsi512(&ctx_hamsi, hash, 64); 84 | sph_hamsi512_close(&ctx_hamsi, hash); 85 | 86 | memcpy(output, hash, 32); 87 | } 88 | 89 | int scanhash_x12(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 90 | { 91 | uint32_t _ALIGN(128) hash[8]; 92 | uint32_t _ALIGN(128) endiandata[20]; 93 | uint32_t *pdata = work->data; 94 | uint32_t *ptarget = work->target; 95 | 96 | const uint32_t Htarg = ptarget[7]; 97 | const uint32_t first_nonce = pdata[19]; 98 | uint32_t nonce = first_nonce; 99 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 100 | 101 | if (opt_benchmark) 102 | ptarget[7] = 0x0cff; 103 | 104 | for (int k=0; k < 19; k++) 105 | be32enc(&endiandata[k], pdata[k]); 106 | 107 | do { 108 | be32enc(&endiandata[19], nonce); 109 | x12hash(hash, endiandata); 110 | 111 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 112 | work_set_target_ratio(work, hash); 113 | pdata[19] = nonce; 114 | *hashes_done = pdata[19] - first_nonce; 115 | return 1; 116 | } 117 | nonce++; 118 | 119 | } while (nonce < max_nonce && !(*restart)); 120 | 121 | pdata[19] = nonce; 122 | *hashes_done = pdata[19] - first_nonce + 1; 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /algo/yescrypt.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "yescrypt/yescrypt.h" 10 | 11 | int scanhash_yescrypt(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 12 | { 13 | uint32_t _ALIGN(64) vhash[8]; 14 | uint32_t _ALIGN(64) endiandata[20]; 15 | uint32_t *pdata = work->data; 16 | uint32_t *ptarget = work->target; 17 | 18 | const uint32_t Htarg = ptarget[7]; 19 | const uint32_t first_nonce = pdata[19]; 20 | 21 | uint32_t n = first_nonce; 22 | 23 | for (int i=0; i < 19; i++) { 24 | be32enc(&endiandata[i], pdata[i]); 25 | } 26 | 27 | do { 28 | be32enc(&endiandata[19], n); 29 | yescrypt_hash((char*) endiandata, (char*) vhash, 80); 30 | if (vhash[7] < Htarg && fulltest(vhash, ptarget)) { 31 | work_set_target_ratio(work, vhash); 32 | *hashes_done = n - first_nonce + 1; 33 | pdata[19] = n; 34 | return true; 35 | } 36 | n++; 37 | 38 | } while (n < max_nonce && !work_restart[thr_id].restart); 39 | 40 | *hashes_done = n - first_nonce + 1; 41 | pdata[19] = n; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /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 | $histo = request('histo'); 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', 'histo'))."\n"; 137 | ?> 138 | -------------------------------------------------------------------------------- /api/websocket.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Simple WebSocket call sample 6 | 7 | 8 |
9 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /argon2ref/blamka-round-ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef BLAKE_ROUND_MKA_H 19 | #define BLAKE_ROUND_MKA_H 20 | 21 | #include "argon2ref/blake2.h" 22 | #include "argon2ref/blake2-impl.h" 23 | 24 | /*designed by the Lyra PHC team */ 25 | static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) { 26 | const uint64_t m = UINT64_C(0xFFFFFFFF); 27 | const uint64_t xy = (x & m) * (y & m); 28 | return x + y + 2 * xy; 29 | } 30 | 31 | #define G(a, b, c, d) \ 32 | do { \ 33 | a = fBlaMka(a, b); \ 34 | d = rotr64(d ^ a, 32); \ 35 | c = fBlaMka(c, d); \ 36 | b = rotr64(b ^ c, 24); \ 37 | a = fBlaMka(a, b); \ 38 | d = rotr64(d ^ a, 16); \ 39 | c = fBlaMka(c, d); \ 40 | b = rotr64(b ^ c, 63); \ 41 | } while ((void)0, 0) 42 | 43 | #define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \ 44 | v12, v13, v14, v15) \ 45 | do { \ 46 | G(v0, v4, v8, v12); \ 47 | G(v1, v5, v9, v13); \ 48 | G(v2, v6, v10, v14); \ 49 | G(v3, v7, v11, v15); \ 50 | G(v0, v5, v10, v15); \ 51 | G(v1, v6, v11, v12); \ 52 | G(v2, v7, v8, v13); \ 53 | G(v3, v4, v9, v14); \ 54 | } while ((void)0, 0) 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /argon2ref/encoding.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef ENCODING_H 19 | #define ENCODING_H 20 | #include "argon2ref/argon2.h" 21 | 22 | #define ARGON2_MAX_DECODED_LANES UINT32_C(255) 23 | #define ARGON2_MIN_DECODED_SALT_LEN UINT32_C(8) 24 | #define ARGON2_MIN_DECODED_OUT_LEN UINT32_C(12) 25 | 26 | /* 27 | * encode an Argon2 hash string into the provided buffer. 'dst_len' 28 | * contains the size, in characters, of the 'dst' buffer; if 'dst_len' 29 | * is less than the number of required characters (including the 30 | * terminating 0), then this function returns ARGON2_ENCODING_ERROR. 31 | * 32 | * on success, ARGON2_OK is returned. 33 | */ 34 | int encode_string(char *dst, size_t dst_len, argon2_context *ctx, 35 | argon2_type type); 36 | 37 | /* 38 | * Decodes an Argon2 hash string into the provided structure 'ctx'. 39 | * The only fields that must be set prior to this call are ctx.saltlen and 40 | * ctx.outlen (which must be the maximal salt and out length values that are 41 | * allowed), ctx.salt and ctx.out (which must be buffers of the specified 42 | * length), and ctx.pwd and ctx.pwdlen which must hold a valid password. 43 | * 44 | * Invalid input string causes an error. On success, the ctx is valid and all 45 | * fields have been initialized. 46 | * 47 | * Returned value is ARGON2_OK on success, other ARGON2_ codes on error. 48 | */ 49 | int decode_string(argon2_context *ctx, const char *str, argon2_type type); 50 | 51 | /* Returns the length of the encoded byte stream with length len */ 52 | size_t b64len(uint32_t len); 53 | 54 | /* Returns the length of the encoded number num */ 55 | size_t numlen(uint32_t num); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /argon2ref/thread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #if !defined(ARGON2_NO_THREADS) 19 | 20 | #include "argon2ref/thread.h" 21 | #if defined(_WIN32) 22 | #include 23 | #endif 24 | 25 | int argon2_thread_create(argon2_thread_handle_t *handle, 26 | argon2_thread_func_t func, void *args) { 27 | if (NULL == handle || func == NULL) { 28 | return -1; 29 | } 30 | #if defined(_WIN32) 31 | *handle = _beginthreadex(NULL, 0, func, args, 0, NULL); 32 | return *handle != 0 ? 0 : -1; 33 | #else 34 | return pthread_create(handle, NULL, func, args); 35 | #endif 36 | } 37 | 38 | int argon2_thread_join(argon2_thread_handle_t handle) { 39 | #if defined(_WIN32) 40 | if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) { 41 | return CloseHandle((HANDLE)handle) != 0 ? 0 : -1; 42 | } 43 | return -1; 44 | #else 45 | return pthread_join(handle, NULL); 46 | #endif 47 | } 48 | 49 | void argon2_thread_exit(void) { 50 | #if defined(_WIN32) 51 | _endthreadex(0); 52 | #else 53 | pthread_exit(NULL); 54 | #endif 55 | } 56 | 57 | #endif /* ARGON2_NO_THREADS */ 58 | -------------------------------------------------------------------------------- /argon2ref/thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Argon2 reference source code package - reference C implementations 3 | * 4 | * Copyright 2015 5 | * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves 6 | * 7 | * You may use this work under the terms of a Creative Commons CC0 1.0 8 | * License/Waiver or the Apache Public License 2.0, at your option. The terms of 9 | * these licenses can be found at: 10 | * 11 | * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 12 | * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * You should have received a copy of both of these licenses along with this 15 | * software. If not, they may be obtained at the above URLs. 16 | */ 17 | 18 | #ifndef ARGON2_THREAD_H 19 | #define ARGON2_THREAD_H 20 | 21 | #if !defined(ARGON2_NO_THREADS) 22 | 23 | /* 24 | Here we implement an abstraction layer for the simpĺe requirements 25 | of the Argon2 code. We only require 3 primitives---thread creation, 26 | joining, and termination---so full emulation of the pthreads API 27 | is unwarranted. Currently we wrap pthreads and Win32 threads. 28 | 29 | The API defines 2 types: the function pointer type, 30 | argon2_thread_func_t, 31 | and the type of the thread handle---argon2_thread_handle_t. 32 | */ 33 | #if defined(_WIN32) 34 | #include 35 | typedef unsigned(__stdcall *argon2_thread_func_t)(void *); 36 | typedef uintptr_t argon2_thread_handle_t; 37 | #else 38 | #include 39 | typedef void *(*argon2_thread_func_t)(void *); 40 | typedef pthread_t argon2_thread_handle_t; 41 | #endif 42 | 43 | /* Creates a thread 44 | * @param handle pointer to a thread handle, which is the output of this 45 | * function. Must not be NULL. 46 | * @param func A function pointer for the thread's entry point. Must not be 47 | * NULL. 48 | * @param args Pointer that is passed as an argument to @func. May be NULL. 49 | * @return 0 if @handle and @func are valid pointers and a thread is successfuly 50 | * created. 51 | */ 52 | int argon2_thread_create(argon2_thread_handle_t *handle, 53 | argon2_thread_func_t func, void *args); 54 | 55 | /* Waits for a thread to terminate 56 | * @param handle Handle to a thread created with argon2_thread_create. 57 | * @return 0 if @handle is a valid handle, and joining completed successfully. 58 | */ 59 | int argon2_thread_join(argon2_thread_handle_t handle); 60 | 61 | /* Terminate the current thread. Must be run inside a thread created by 62 | * argon2_thread_create. 63 | */ 64 | void argon2_thread_exit(void); 65 | 66 | #endif /* ARGON2_NO_THREADS */ 67 | #endif 68 | -------------------------------------------------------------------------------- /asm/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/asm/.dirstamp -------------------------------------------------------------------------------- /asm/aesb-x64.S: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__linux__) && defined(__ELF__) 4 | .section .note.GNU-stack,"",%progbits 5 | #endif 6 | 7 | .text 8 | .p2align 6 9 | .globl fast_aesb_single_round 10 | .globl _fast_aesb_single_round 11 | fast_aesb_single_round: 12 | _fast_aesb_single_round: 13 | #if defined(_WIN64) || defined(__CYGWIN__) 14 | movdqa (%rcx), %xmm1 15 | aesenc (%r8), %xmm1 16 | movdqa %xmm1, (%rdx) 17 | #else 18 | movdqa (%rdi), %xmm1 19 | aesenc (%rdx), %xmm1 20 | movdqa %xmm1, (%rsi) 21 | #endif 22 | ret 23 | 24 | .text 25 | .p2align 6 26 | .globl fast_aesb_pseudo_round_mut 27 | .globl _fast_aesb_pseudo_round_mut 28 | fast_aesb_pseudo_round_mut: 29 | _fast_aesb_pseudo_round_mut: 30 | #if defined(_WIN64) || defined(__CYGWIN__) 31 | mov %rdx, %r9 32 | add $0xA0, %r9 33 | movdqa (%rcx), %xmm1 34 | 35 | .LOOP: 36 | aesenc (%rdx), %xmm1 37 | add $0x10, %rdx 38 | cmp %r9, %rdx 39 | jl .LOOP 40 | 41 | movdqa %xmm1, (%rcx) 42 | #else 43 | mov %rsi, %r9 44 | add $0xA0, %r9 45 | movdqa (%rdi), %xmm1 46 | 47 | .LOOP: 48 | aesenc (%rsi), %xmm1 49 | add $0x10, %rsi 50 | cmp %r9, %rsi 51 | jl .LOOP 52 | 53 | movdqa %xmm1, (%rdi) 54 | #endif 55 | ret 56 | 57 | .text 58 | .globl mul128 59 | .globl _mul128 60 | mul128: 61 | _mul128: 62 | #if defined(_WIN64) || defined(__CYGWIN__) 63 | mov %rcx, %rax 64 | mul %rdx 65 | mov %rdx, (%r8) 66 | #else 67 | mov %rdx, %r8 68 | mov %rdi, %rax 69 | mul %rsi 70 | mov %rdx, (%r8) 71 | #endif 72 | ret 73 | -------------------------------------------------------------------------------- /asm/aesb-x86.S: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__linux__) && defined(__ELF__) 4 | .section .note.GNU-stack,"",%progbits 5 | #endif 6 | 7 | .text 8 | .p2align 6 9 | .globl fast_aesb_single_round 10 | .globl _fast_aesb_single_round 11 | fast_aesb_single_round: 12 | _fast_aesb_single_round: 13 | ret 14 | 15 | .text 16 | .p2align 6 17 | .globl fast_aesb_pseudo_round_mut 18 | .globl _fast_aesb_pseudo_round_mut 19 | fast_aesb_pseudo_round_mut: 20 | _fast_aesb_pseudo_round_mut: 21 | ret 22 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # You need autoconf 2.5x, preferably 2.57 or later 4 | # You need automake 1.7 or later. 1.6 might work. 5 | 6 | set -e 7 | 8 | aclocal 9 | autoheader 10 | automake --foreign --add-missing --force-missing --copy 11 | # automake --gnu --add-missing --copy 12 | autoconf 13 | 14 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$OS" = "Windows_NT" ]; then 4 | ./mingw64.sh 5 | exit 0 6 | fi 7 | 8 | # Linux build 9 | 10 | make clean || echo clean 11 | 12 | rm -f config.status 13 | ./autogen.sh || echo done 14 | 15 | # Ubuntu 10.04 (gcc 4.4) 16 | # extracflags="-O3 -march=native -Wall -D_REENTRANT -funroll-loops -fvariable-expansion-in-unroller -fmerge-all-constants -fbranch-target-load-optimize2 -fsched2-use-superblocks -falign-loops=16 -falign-functions=16 -falign-jumps=16 -falign-labels=16" 17 | 18 | # Debian 7.7 / Ubuntu 14.04 (gcc 4.7+) 19 | extracflags="$extracflags -Ofast -flto -fuse-linker-plugin -ftree-loop-if-convert-stores" 20 | 21 | if [ ! "0" = `cat /proc/cpuinfo | grep -c avx` ]; then 22 | # march native doesn't always works, ex. some Pentium Gxxx (no avx) 23 | extracflags="$extracflags " 24 | fi 25 | 26 | ./configure --with-crypto --with-curl CFLAGS="-O2 $extracflags -DUSE_ASM -pg" 27 | 28 | 29 | make -j$(nproc --ignore=2) 30 | 31 | strip -s cpuminer 32 | -------------------------------------------------------------------------------- /compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | #include 8 | 9 | #ifndef localtime_r 10 | #define localtime_r(src, dst) localtime_s(dst, src) 11 | #endif 12 | 13 | #define sleep(secs) Sleep((secs) * 1000) 14 | 15 | enum { 16 | PRIO_PROCESS = 0, 17 | }; 18 | 19 | extern int opt_priority; 20 | static __inline int setpriority(int which, int who, int prio) 21 | { 22 | switch (opt_priority) { 23 | case 5: 24 | prio = THREAD_PRIORITY_TIME_CRITICAL; 25 | break; 26 | case 4: 27 | prio = THREAD_PRIORITY_HIGHEST; 28 | break; 29 | case 3: 30 | prio = THREAD_PRIORITY_ABOVE_NORMAL; 31 | break; 32 | case 2: 33 | prio = THREAD_PRIORITY_NORMAL; 34 | break; 35 | case 1: 36 | prio = THREAD_PRIORITY_BELOW_NORMAL; 37 | break; 38 | case 0: 39 | default: 40 | prio = THREAD_PRIORITY_IDLE; 41 | } 42 | return -!SetThreadPriority(GetCurrentThread(), prio); 43 | } 44 | 45 | #ifdef _MSC_VER 46 | #define snprintf(...) _snprintf(__VA_ARGS__) 47 | #define strdup(...) _strdup(__VA_ARGS__) 48 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) 49 | #define strcasecmp(x,y) _stricmp(x,y) 50 | #define __func__ __FUNCTION__ 51 | #define __thread __declspec(thread) 52 | #define _ALIGN(x) __declspec(align(x)) 53 | typedef int ssize_t; 54 | 55 | __inline int msver(void) { 56 | switch (_MSC_VER) { 57 | case 1500: return 2008; 58 | case 1600: return 2010; 59 | case 1700: return 2012; 60 | case 1800: return 2013; 61 | case 1900: return 2015; 62 | default: return (_MSC_VER/100); 63 | } 64 | } 65 | 66 | #include 67 | // This static var is made to be compatible with linux/mingw (no free on string result) 68 | // This is not thread safe but we only use that once on process start 69 | static char dirname_buffer[_MAX_PATH] = { 0 }; 70 | static __inline char * dirname(char *file) { 71 | char drive[_MAX_DRIVE] = { 0 }; 72 | char dir[_MAX_DIR] = { 0 }; 73 | char fname[_MAX_FNAME], ext[_MAX_EXT]; 74 | _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); 75 | if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') { 76 | dir[strlen(dir) - 1] = '\0'; 77 | } 78 | sprintf(dirname_buffer, "%s%s", drive, dir); 79 | return &dirname_buffer[0]; 80 | } 81 | #endif 82 | 83 | #endif /* WIN32 */ 84 | 85 | #ifndef _MSC_VER 86 | #define _ALIGN(x) __attribute__ ((aligned(x))) 87 | #endif 88 | 89 | #undef unlikely 90 | #undef likely 91 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 92 | #define unlikely(expr) (__builtin_expect(!!(expr), 0)) 93 | #define likely(expr) (__builtin_expect(!!(expr), 1)) 94 | #else 95 | #define unlikely(expr) (expr) 96 | #define likely(expr) (expr) 97 | #endif 98 | 99 | #ifndef WIN32 100 | #define MAX_PATH PATH_MAX 101 | #endif 102 | 103 | #endif /* __COMPAT_H__ */ 104 | -------------------------------------------------------------------------------- /compat/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.a 4 | .libs 5 | .deps 6 | Makefile 7 | Makefile.in 8 | aclocal.m4 9 | autom4te.cache 10 | config.guess 11 | config.h 12 | config.h.in 13 | config.log 14 | config.status 15 | config.sub 16 | configure 17 | depcomp 18 | install-sh 19 | libtool 20 | ltmain.sh 21 | missing 22 | compile 23 | test-driver 24 | *.lo 25 | *.la 26 | stamp-h1 27 | *.pyc 28 | *.pc 29 | /src/jansson_config.h 30 | /jansson_private_config.h.in 31 | /jansson_private_config.h 32 | /build 33 | *.exe 34 | .idea 35 | cmake-build-debug/ 36 | -------------------------------------------------------------------------------- /compat/.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | matrix: 3 | - JANSSON_BUILD_METHOD=cmake JANSSON_CMAKE_OPTIONS="-DJANSSON_TEST_WITH_VALGRIND=ON" JANSSON_EXTRA_INSTALL="valgrind" 4 | - JANSSON_BUILD_METHOD=autotools 5 | - JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl" 6 | language: c 7 | compiler: 8 | - gcc 9 | - clang 10 | matrix: 11 | exclude: 12 | - compiler: clang 13 | env: JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl" 14 | allow_failures: 15 | - env: JANSSON_BUILD_METHOD=coverage JANSSON_CMAKE_OPTIONS="-DJANSSON_COVERAGE=ON -DJANSSON_COVERALLS=ON -DCMAKE_BUILD_TYPE=Debug" JANSSON_EXTRA_INSTALL="lcov curl" 16 | install: 17 | - sudo apt-get update -qq 18 | - sudo apt-get install -y -qq cmake $JANSSON_EXTRA_INSTALL 19 | script: 20 | - if [ "$JANSSON_BUILD_METHOD" = "autotools" ]; then autoreconf -f -i && CFLAGS=-Werror ./configure && make check; fi 21 | - if [ "$JANSSON_BUILD_METHOD" = "cmake" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && ctest --output-on-failure; fi 22 | - if [ "$JANSSON_BUILD_METHOD" = "coverage" ]; then mkdir build && cd build && cmake $JANSSON_CMAKE_OPTIONS .. && cmake --build . && cmake --build . --target coveralls; fi 23 | -------------------------------------------------------------------------------- /compat/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH:= $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_ARM_MODE := arm 5 | 6 | LOCAL_SRC_FILES := \ 7 | src/bos_deserializer.c \ 8 | src/bos_serializer.c \ 9 | src/dump.c \ 10 | src/error.c \ 11 | src/hashtable.c \ 12 | src/hashtable_seed.c \ 13 | src/load.c \ 14 | src/memory.c \ 15 | src/pack_unpack.c \ 16 | src/strbuffer.c \ 17 | src/strconv.c \ 18 | src/utf.c \ 19 | src/value.c 20 | 21 | LOCAL_C_INCLUDES += \ 22 | $(LOCAL_PATH) \ 23 | $(LOCAL_PATH)/android \ 24 | $(LOCAL_PATH)/src 25 | 26 | LOCAL_MODULE_TAGS := optional 27 | LOCAL_SHARED_LIBRARIES := libc 28 | LOCAL_CFLAGS += -O3 -DHAVE_STDINT_H=1 29 | 30 | LOCAL_MODULE:= libbosjansson 31 | 32 | include $(BUILD_SHARED_LIBRARY) 33 | -------------------------------------------------------------------------------- /compat/CleanSpec.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # If you don't need to do a full clean build but would like to touch 17 | # a file or delete some intermediate files, add a clean step to the end 18 | # of the list. These steps will only be run once, if they haven't been 19 | # run before. 20 | # 21 | # E.g.: 22 | # $(call add-clean-step, touch -c external/sqlite/sqlite3.h) 23 | # $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) 24 | # 25 | # Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with 26 | # files that are missing or have been moved. 27 | # 28 | # Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. 29 | # Use $(OUT_DIR) to refer to the "out" directory. 30 | # 31 | # If you need to re-do something that's already mentioned, just copy 32 | # the command and add it to the bottom of the list. E.g., if a change 33 | # that you made last week required touching a file and a change you 34 | # made today requires touching the same file, just copy the old 35 | # touch step and add it to the end of the list. 36 | # 37 | # ************************************************ 38 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 39 | # ************************************************ 40 | 41 | # For example: 42 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) 43 | #$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) 44 | #$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) 45 | #$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) 46 | 47 | # ************************************************ 48 | # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST 49 | # ************************************************ 50 | -------------------------------------------------------------------------------- /compat/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009-2018 Petri Lehtinen 2 | Copyright (c) 2018 JCThePants 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /compat/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = bos-jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /compat/bos-jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = bosjansson.def 2 | 3 | include_HEADERS = bosjansson.h 4 | nodist_include_HEADERS = jansson_config.h 5 | 6 | noinst_LIBRARIES = libbosjansson.a 7 | 8 | ###lib_LTLIBRARIES = libbosjansson.la 9 | libbosjansson_a_SOURCES = \ 10 | bos_deserializer.c \ 11 | bos_serializer.c \ 12 | dump.c \ 13 | error.c \ 14 | hashtable.c \ 15 | hashtable.h \ 16 | hashtable_seed.c \ 17 | jansson_private.h \ 18 | load.c \ 19 | lookup3.h \ 20 | memory.c \ 21 | pack_unpack.c \ 22 | strbuffer.c \ 23 | strbuffer.h \ 24 | strconv.c \ 25 | utf.c \ 26 | utf.h \ 27 | value.c 28 | #libbosjansson_a_LDFLAGS = \ 29 | # -no-undefined \ 30 | # -export-symbols-regex '^json_' \ 31 | # -version-info 15:0:11 \ 32 | # @JSON_BSYMBOLIC_LDFLAGS@ 33 | 34 | -------------------------------------------------------------------------------- /compat/bos-jansson/bosjansson.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | bos_deserialize 3 | bos_serialize 4 | json_bytes 5 | json_bytes_value 6 | json_bytes_length 7 | json_bytes_set 8 | json_delete 9 | json_true 10 | json_false 11 | json_null 12 | json_sprintf 13 | json_vsprintf 14 | json_string 15 | json_stringn 16 | json_string_nocheck 17 | json_stringn_nocheck 18 | json_string_value 19 | json_string_length 20 | json_string_set 21 | json_string_setn 22 | json_string_set_nocheck 23 | json_string_setn_nocheck 24 | json_integer 25 | json_integer_value 26 | json_integer_set 27 | json_real 28 | json_real_value 29 | json_real_set 30 | json_number_value 31 | json_array 32 | json_array_size 33 | json_array_get 34 | json_array_set_new 35 | json_array_append_new 36 | json_array_insert_new 37 | json_array_remove 38 | json_array_clear 39 | json_array_extend 40 | json_object 41 | json_object_size 42 | json_object_get 43 | json_object_set_new 44 | json_object_set_new_nocheck 45 | json_object_del 46 | json_object_clear 47 | json_object_update 48 | json_object_update_existing 49 | json_object_update_missing 50 | json_object_iter 51 | json_object_iter_at 52 | json_object_iter_next 53 | json_object_iter_key 54 | json_object_iter_value 55 | json_object_iter_set_new 56 | json_object_key_to_iter 57 | json_object_seed 58 | json_dumps 59 | json_dumpb 60 | json_dumpf 61 | json_dumpfd 62 | json_dump_file 63 | json_dump_callback 64 | json_loads 65 | json_loadb 66 | json_loadf 67 | json_loadfd 68 | json_load_file 69 | json_load_callback 70 | json_equal 71 | json_copy 72 | json_deep_copy 73 | json_pack 74 | json_pack_ex 75 | json_vpack_ex 76 | json_unpack 77 | json_unpack_ex 78 | json_vunpack_ex 79 | json_set_alloc_funcs 80 | json_get_alloc_funcs 81 | 82 | -------------------------------------------------------------------------------- /compat/bos-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 | strncpy(error->source, source, length + 1); 29 | else { 30 | size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; 31 | memcpy(error->source, "...", 3); 32 | strncpy(error->source + 3, source + extra, length - extra + 1); 33 | } 34 | } 35 | 36 | void jsonp_error_set(json_error_t *error, int line, int column, 37 | size_t position, enum json_error_code code, 38 | const char *msg, ...) 39 | { 40 | va_list ap; 41 | 42 | va_start(ap, msg); 43 | jsonp_error_vset(error, line, column, position, code, msg, ap); 44 | va_end(ap); 45 | } 46 | 47 | void jsonp_error_vset(json_error_t *error, int line, int column, 48 | size_t position, enum json_error_code code, 49 | const char *msg, va_list ap) 50 | { 51 | if(!error) 52 | return; 53 | 54 | if(error->text[0] != '\0') { 55 | /* error already set */ 56 | return; 57 | } 58 | 59 | error->line = line; 60 | error->column = column; 61 | error->position = (int)position; 62 | 63 | vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH - 1, msg, ap); 64 | error->text[JSON_ERROR_TEXT_LENGTH - 2] = '\0'; 65 | error->text[JSON_ERROR_TEXT_LENGTH - 1] = code; 66 | } 67 | -------------------------------------------------------------------------------- /compat/bos-jansson/jansson_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016 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 | * bosjansson.h. 11 | * 12 | * The CMake system will generate the jansson_config.h file and 13 | * copy it to the build and install directories. 14 | */ 15 | 16 | #ifndef JANSSON_CONFIG_H 17 | #define JANSSON_CONFIG_H 18 | 19 | /* Define this so that we can disable scattered automake configuration in source files */ 20 | #ifndef JANSSON_USING_CMAKE 21 | #define JANSSON_USING_CMAKE 22 | #endif 23 | 24 | /* Note: when using cmake, JSON_INTEGER_IS_LONG_LONG is not defined nor used, 25 | * as we will also check for __int64 etc types. 26 | * (the definition was used in the automake system) */ 27 | 28 | /* Bring in the cmake-detected defines */ 29 | #define HAVE_STDINT_H 1 30 | /* #undef HAVE_INTTYPES_H */ 31 | #define HAVE_SYS_TYPES_H 1 32 | 33 | /* Include our standard type header for the integer typedef */ 34 | 35 | #if defined(HAVE_STDINT_H) 36 | # include 37 | #elif defined(HAVE_INTTYPES_H) 38 | # include 39 | #elif defined(HAVE_SYS_TYPES_H) 40 | # include 41 | #endif 42 | 43 | 44 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 45 | defined to `inline', otherwise empty. In C++, the inline is always 46 | supported. */ 47 | 48 | #ifdef _MSC_VER 49 | #define inline __inline 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | #define JSON_INLINE inline 54 | #else 55 | #define JSON_INLINE inline 56 | #endif 57 | 58 | 59 | //#define json_int_t long long 60 | #define json_strtoint strtoll 61 | #define JSON_INTEGER_FORMAT "I64d" 62 | 63 | 64 | /* If locale.h and localeconv() are available, define to 1, otherwise to 0. */ 65 | #define JSON_HAVE_LOCALECONV 1 66 | 67 | /* If __atomic builtins are available they will be used to manage 68 | reference counts of json_t. */ 69 | #define JSON_HAVE_ATOMIC_BUILTINS 0 70 | 71 | /* If __atomic builtins are not available we try using __sync builtins 72 | to manage reference counts of json_t. */ 73 | #define JSON_HAVE_SYNC_BUILTINS 0 74 | 75 | /* Maximum recursion depth for parsing JSON input. 76 | This limits the depth of e.g. array-within-array constructions. */ 77 | #define JSON_PARSER_MAX_DEPTH 2048 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /compat/bos-jansson/jansson_config.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016 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 | * bosjansson.h. 11 | * 12 | * The CMake system will generate the jansson_config.h file and 13 | * copy it to the build and install directories. 14 | */ 15 | 16 | #ifndef JANSSON_CONFIG_H 17 | #define JANSSON_CONFIG_H 18 | 19 | /* Define this so that we can disable scattered automake configuration in source files */ 20 | #ifndef JANSSON_USING_CMAKE 21 | #define JANSSON_USING_CMAKE 22 | #endif 23 | 24 | /* Note: when using cmake, JSON_INTEGER_IS_LONG_LONG is not defined nor used, 25 | * as we will also check for __int64 etc types. 26 | * (the definition was used in the automake system) */ 27 | 28 | /* Bring in the cmake-detected defines */ 29 | #define HAVE_STDINT_H 1 30 | /* #undef HAVE_INTTYPES_H */ 31 | #define HAVE_SYS_TYPES_H 1 32 | 33 | /* Include our standard type header for the integer typedef */ 34 | 35 | #if defined(HAVE_STDINT_H) 36 | # include 37 | #elif defined(HAVE_INTTYPES_H) 38 | # include 39 | #elif defined(HAVE_SYS_TYPES_H) 40 | # include 41 | #endif 42 | 43 | 44 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 45 | defined to `inline', otherwise empty. In C++, the inline is always 46 | supported. */ 47 | 48 | #ifdef _MSC_VER 49 | #define inline __inline 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | #define JSON_INLINE inline 54 | #else 55 | #define JSON_INLINE inline 56 | #endif 57 | 58 | 59 | //#define json_int_t long long 60 | #define json_strtoint strtoll 61 | #define JSON_INTEGER_FORMAT "I64d" 62 | 63 | 64 | /* If locale.h and localeconv() are available, define to 1, otherwise to 0. */ 65 | #define JSON_HAVE_LOCALECONV 1 66 | 67 | /* If __atomic builtins are available they will be used to manage 68 | reference counts of json_t. */ 69 | #define JSON_HAVE_ATOMIC_BUILTINS 0 70 | 71 | /* If __atomic builtins are not available we try using __sync builtins 72 | to manage reference counts of json_t. */ 73 | #define JSON_HAVE_SYNC_BUILTINS 0 74 | 75 | /* Maximum recursion depth for parsing JSON input. 76 | This limits the depth of e.g. array-within-array constructions. */ 77 | #define JSON_PARSER_MAX_DEPTH 2048 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /compat/bos-jansson/jansson_config.h.in_old: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016 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 | * bosjansson.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 | /* If __atomic builtins are available they will be used to manage 40 | reference counts of json_t. */ 41 | #define JSON_HAVE_ATOMIC_BUILTINS @json_have_atomic_builtins@ 42 | 43 | /* If __atomic builtins are not available we try using __sync builtins 44 | to manage reference counts of json_t. */ 45 | #define JSON_HAVE_SYNC_BUILTINS @json_have_sync_builtins@ 46 | 47 | /* Maximum recursion depth for parsing JSON input. 48 | This limits the depth of e.g. array-within-array constructions. */ 49 | #define JSON_PARSER_MAX_DEPTH 2048 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /compat/bos-jansson/jansson_private_config.h: -------------------------------------------------------------------------------- 1 | /* #undef HAVE_ENDIAN_H */ 2 | #define HAVE_CONFIG_H 1 3 | #define HAVE_FCNTL_H 1 4 | /* #undef HAVE_SCHED_H */ 5 | /* #undef HAVE_UNISTD_H */ 6 | /* #undef HAVE_SYS_PARAM_H */ 7 | #define HAVE_SYS_STAT_H 1 8 | /* #undef HAVE_SYS_TIME_H */ 9 | #define HAVE_SYS_TYPES_H 1 10 | #define HAVE_STDINT_H 1 11 | 12 | #define HAVE_CLOSE 1 13 | #define HAVE_GETPID 1 14 | /* #undef HAVE_GETTIMEOFDAY */ 15 | #define HAVE_OPEN 1 16 | #define HAVE_READ 1 17 | /* #undef HAVE_SCHED_YIELD */ 18 | 19 | /* #undef HAVE_SYNC_BUILTINS */ 20 | /* #undef HAVE_ATOMIC_BUILTINS */ 21 | 22 | #define HAVE_LOCALE_H 1 23 | #define HAVE_SETLOCALE 1 24 | 25 | #define HAVE_INT32_T 1 26 | #ifndef HAVE_INT32_T 27 | # define int32_t int32_t 28 | #endif 29 | 30 | #define HAVE_UINT32_T 1 31 | #ifndef HAVE_UINT32_T 32 | # define uint32_t uint32_t 33 | #endif 34 | 35 | #define HAVE_UINT16_T 1 36 | #ifndef HAVE_UINT16_T 37 | # define uint16_t uint16_t 38 | #endif 39 | 40 | #define HAVE_UINT8_T 1 41 | #ifndef HAVE_UINT8_T 42 | # define uint8_t uint8_t 43 | #endif 44 | 45 | /* #undef HAVE_SSIZE_T */ 46 | #define HAVE_SSIZE_T 0 47 | #ifndef HAVE_SSIZE_T 48 | # define ssize_t int 49 | #endif 50 | 51 | #define USE_URANDOM 1 52 | #define USE_WINDOWS_CRYPTOAPI 1 53 | 54 | #define INITIAL_HASHTABLE_ORDER 3 55 | -------------------------------------------------------------------------------- /compat/bos-jansson/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 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 "bosjansson.h" 13 | #include "jansson_private.h" 14 | 15 | /* C89 allows these to be macros */ 16 | #undef malloc 17 | #undef free 18 | 19 | /* memory function pointers */ 20 | static json_malloc_t do_malloc = malloc; 21 | static json_free_t do_free = free; 22 | 23 | void *jsonp_malloc(size_t size) 24 | { 25 | if(!size) 26 | return NULL; 27 | 28 | return (*do_malloc)(size); 29 | } 30 | 31 | void jsonp_free(void *ptr) 32 | { 33 | if(!ptr) 34 | return; 35 | 36 | (*do_free)(ptr); 37 | } 38 | 39 | char *jsonp_strdup(const char *str) 40 | { 41 | return jsonp_strndup(str, strlen(str)); 42 | } 43 | 44 | char *jsonp_strndup(const char *str, size_t len) 45 | { 46 | char *new_str; 47 | 48 | new_str = jsonp_malloc(len + 1); 49 | if(!new_str) 50 | return NULL; 51 | 52 | memcpy(new_str, str, len); 53 | new_str[len] = '\0'; 54 | return new_str; 55 | } 56 | 57 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) 58 | { 59 | do_malloc = malloc_fn; 60 | do_free = free_fn; 61 | } 62 | 63 | void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn) 64 | { 65 | if (malloc_fn) 66 | *malloc_fn = do_malloc; 67 | if (free_fn) 68 | *free_fn = do_free; 69 | } 70 | -------------------------------------------------------------------------------- /compat/bos-jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 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_byte(strbuffer_t *strbuff, char byte) 64 | { 65 | return strbuffer_append_bytes(strbuff, &byte, 1); 66 | } 67 | 68 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) 69 | { 70 | if(size >= strbuff->size - strbuff->length) 71 | { 72 | size_t new_size; 73 | char *new_value; 74 | 75 | /* avoid integer overflow */ 76 | if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR 77 | || size > STRBUFFER_SIZE_MAX - 1 78 | || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) 79 | return -1; 80 | 81 | new_size = max(strbuff->size * STRBUFFER_FACTOR, 82 | strbuff->length + size + 1); 83 | 84 | new_value = jsonp_malloc(new_size); 85 | if(!new_value) 86 | return -1; 87 | 88 | memcpy(new_value, strbuff->value, strbuff->length); 89 | 90 | jsonp_free(strbuff->value); 91 | 92 | // realloc(strbuff->value,new_size); 93 | strbuff->value = new_value; 94 | // memcpy(strbuff->value,new_value, new_size); 95 | strbuff->size = new_size; 96 | } 97 | 98 | memcpy(strbuff->value + strbuff->length, data, size); 99 | strbuff->length += size; 100 | strbuff->value[strbuff->length] = '\0'; 101 | 102 | return 0; 103 | } 104 | 105 | char strbuffer_pop(strbuffer_t *strbuff) 106 | { 107 | if(strbuff->length > 0) { 108 | char c = strbuff->value[--strbuff->length]; 109 | strbuff->value[strbuff->length] = '\0'; 110 | return c; 111 | } 112 | else 113 | return '\0'; 114 | } 115 | -------------------------------------------------------------------------------- /compat/bos-jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 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 | #include 12 | 13 | typedef struct { 14 | char *value; 15 | size_t length; /* bytes used */ 16 | size_t size; /* bytes allocated */ 17 | } strbuffer_t; 18 | 19 | int strbuffer_init(strbuffer_t *strbuff) JANSSON_ATTRS(warn_unused_result); 20 | void strbuffer_close(strbuffer_t *strbuff); 21 | 22 | void strbuffer_clear(strbuffer_t *strbuff); 23 | 24 | const char *strbuffer_value(const strbuffer_t *strbuff); 25 | 26 | /* Steal the value and close the strbuffer */ 27 | char *strbuffer_steal_value(strbuffer_t *strbuff); 28 | 29 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 30 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); 31 | 32 | char strbuffer_pop(strbuffer_t *strbuff); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /compat/bos-jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2016 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 13 | #endif 14 | 15 | #ifdef HAVE_STDINT_H 16 | #include 17 | #endif 18 | 19 | int utf8_encode(int32_t codepoint, char *buffer, size_t *size); 20 | 21 | size_t utf8_check_first(char byte); 22 | size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint); 23 | const char *utf8_iterate(const char *buffer, size_t size, int32_t *codepoint); 24 | 25 | int utf8_check_string(const char *string, size_t length); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /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/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/sha.h: -------------------------------------------------------------------------------- 1 | #include "../../crypto/sha/sha.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/libcryptoMT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/libcryptoMT.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/libcurl.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/libcurl.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/libeay32MT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/libeay32MT.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/libsslMT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/libsslMT.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/ssleay32MT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/ssleay32MT.lib -------------------------------------------------------------------------------- /compat/curl-for-windows/out/lib/zlibstat.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/curl-for-windows/out/lib/zlibstat.lib -------------------------------------------------------------------------------- /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/pthreads/x64/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/pthreads/x64/pthreadVC2.lib -------------------------------------------------------------------------------- /compat/pthreads/x86/pthreadVC2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/compat/pthreads/x86/pthreadVC2.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 | 3 | #ifdef __cplusplus 4 | extern "C" 5 | { 6 | #endif 7 | int gettimeofday(struct timeval *tv, struct timezone *tz); 8 | void usleep(__int64 usec); 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | typedef __int64 useconds_t; 13 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /cpuminer-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "_comment1" : "Any long-format command line argument ", 3 | "_comment2" : "may be used in this JSON configuration file", 4 | 5 | "api-bind" : "127.0.0.1:4048", 6 | 7 | "url" : "stratum+tcp://yiimp.ccminer.org:4252", 8 | "user" : "benchmark", 9 | "pass" : "d=0.024", 10 | 11 | "algo" : "decred", 12 | "threads" : 0, 13 | "cpu-priority" : 0, 14 | "cpu-affinity" : -1, 15 | 16 | "benchmark" : false, 17 | "debug" : false, 18 | "protocol": false, 19 | "show-diff": true, 20 | "quiet" : false 21 | } 22 | -------------------------------------------------------------------------------- /cpuminer.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}") = "cpuminer", "cpuminer.vcxproj", "{36DC07F9-A4A6-4877-A146-1B960083CF6F}" 6 | EndProject 7 | Global 8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 | Debug|x64 = Debug|x64 10 | Debug|Win32 = Debug|Win32 11 | Release|x64 = Release|x64 12 | Release|Win32 = Release|Win32 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.ActiveCfg = Debug|x64 16 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|x64.Build.0 = Debug|x64 18 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Debug|Win32.Build.0 = Debug|Win32 19 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.ActiveCfg = Release|x64 20 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|x64.Build.0 = Release|x64 21 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.ActiveCfg = Release|Win32 22 | {36DC07F9-A4A6-4877-A146-1B960083CF6F}.Release|Win32.Build.0 = Release|Win32 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /crypto/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/crypto/.dirstamp -------------------------------------------------------------------------------- /crypto/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 | -------------------------------------------------------------------------------- /crypto/c_blake256.h: -------------------------------------------------------------------------------- 1 | #ifndef _BLAKE256_H_ 2 | #define _BLAKE256_H_ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint32_t h[8], s[4], t[2]; 8 | int buflen, nullt; 9 | uint8_t buf[64]; 10 | } state; 11 | 12 | typedef struct { 13 | state inner; 14 | state outer; 15 | } hmac_state; 16 | 17 | void blake256_init(state *); 18 | void blake224_init(state *); 19 | 20 | void blake256_update(state *, const uint8_t *, uint64_t); 21 | void blake224_update(state *, const uint8_t *, uint64_t); 22 | 23 | void blake256_final(state *, uint8_t *); 24 | void blake224_final(state *, uint8_t *); 25 | 26 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t); 27 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t); 28 | 29 | /* HMAC functions: */ 30 | 31 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t); 32 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t); 33 | 34 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t); 35 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t); 36 | 37 | void hmac_blake256_final(hmac_state *, uint8_t *); 38 | void hmac_blake224_final(hmac_state *, uint8_t *); 39 | 40 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 41 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t); 42 | 43 | #endif /* _BLAKE256_H_ */ 44 | -------------------------------------------------------------------------------- /crypto/c_groestl.h: -------------------------------------------------------------------------------- 1 | #ifndef __hash_h 2 | #define __hash_h 3 | /* 4 | #include "crypto_uint8.h" 5 | #include "crypto_uint32.h" 6 | #include "crypto_uint64.h" 7 | #include "crypto_hash.h" 8 | 9 | typedef crypto_uint8 uint8_t; 10 | typedef crypto_uint32 uint32_t; 11 | typedef crypto_uint64 uint64_t; 12 | */ 13 | #include 14 | 15 | #include "hash.h" 16 | 17 | /* some sizes (number of bytes) */ 18 | #define ROWS 8 19 | #define LENGTHFIELDLEN ROWS 20 | #define COLS512 8 21 | 22 | #define SIZE512 (ROWS*COLS512) 23 | 24 | #define ROUNDS512 10 25 | #define HASH_BIT_LEN 256 26 | 27 | #define ROTL32(v, n) ((((v)<<(n))|((v)>>(32-(n))))&li_32(ffffffff)) 28 | 29 | 30 | #define li_32(h) 0x##h##u 31 | #define EXT_BYTE(var,n) ((uint8_t)((uint32_t)(var) >> (8*n))) 32 | #define u32BIG(a) \ 33 | ((ROTL32(a,8) & li_32(00FF00FF)) | \ 34 | (ROTL32(a,24) & li_32(FF00FF00))) 35 | 36 | 37 | /* NIST API begin */ 38 | typedef struct { 39 | uint32_t chaining[SIZE512/sizeof(uint32_t)]; /* actual state */ 40 | uint32_t block_counter1, 41 | block_counter2; /* message block counter(s) */ 42 | BitSequence buffer[SIZE512]; /* data buffer */ 43 | int buf_ptr; /* data buffer pointer */ 44 | int bits_in_last_byte; /* no. of message bits in last byte of 45 | data buffer */ 46 | } groestlHashState; 47 | 48 | /*void Init(hashState*); 49 | void Update(hashState*, const BitSequence*, DataLength); 50 | void Final(hashState*, BitSequence*); */ 51 | void groestl(const BitSequence*, DataLength, BitSequence*); 52 | /* NIST API end */ 53 | 54 | /* 55 | int crypto_hash(unsigned char *out, 56 | const unsigned char *in, 57 | unsigned long long len); 58 | */ 59 | 60 | #endif /* __hash_h */ 61 | -------------------------------------------------------------------------------- /crypto/c_jh.h: -------------------------------------------------------------------------------- 1 | /*This program gives the 64-bit optimized bitslice implementation of JH using ANSI C 2 | 3 | -------------------------------- 4 | Performance 5 | 6 | Microprocessor: Intel CORE 2 processor (Core 2 Duo Mobile T6600 2.2GHz) 7 | Operating System: 64-bit Ubuntu 10.04 (Linux kernel 2.6.32-22-generic) 8 | Speed for long message: 9 | 1) 45.8 cycles/byte compiler: Intel C++ Compiler 11.1 compilation option: icc -O2 10 | 2) 56.8 cycles/byte compiler: gcc 4.4.3 compilation option: gcc -O3 11 | 12 | -------------------------------- 13 | Last Modified: January 16, 2011 14 | */ 15 | #pragma once 16 | 17 | #include "hash.h" 18 | 19 | HashReturn jh_hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval); 20 | -------------------------------------------------------------------------------- /crypto/c_keccak.h: -------------------------------------------------------------------------------- 1 | // keccak.h 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | 4 | #ifndef KECCAK_H 5 | #define KECCAK_H 6 | 7 | #include 8 | #include 9 | 10 | #ifndef KECCAK_ROUNDS 11 | #define KECCAK_ROUNDS 24 12 | #endif 13 | 14 | #ifndef ROTL64 15 | #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) 16 | #endif 17 | 18 | // compute a keccak hash (md) of given byte length from "in" 19 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 20 | 21 | // update the state 22 | void keccakf(uint64_t st[25], int norounds); 23 | 24 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /crypto/c_skein.h: -------------------------------------------------------------------------------- 1 | #ifndef _SKEIN_H_ 2 | #define _SKEIN_H_ 1 3 | /************************************************************************** 4 | ** 5 | ** Interface declarations and internal definitions for Skein hashing. 6 | ** 7 | ** Source code author: Doug Whiting, 2008. 8 | ** 9 | ** This algorithm and source code is released to the public domain. 10 | ** 11 | *************************************************************************** 12 | ** 13 | ** The following compile-time switches may be defined to control some 14 | ** tradeoffs between speed, code size, error checking, and security. 15 | ** 16 | ** The "default" note explains what happens when the switch is not defined. 17 | ** 18 | ** SKEIN_DEBUG -- make callouts from inside Skein code 19 | ** to examine/display intermediate values. 20 | ** [default: no callouts (no overhead)] 21 | ** 22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 23 | ** code. If not defined, most error checking 24 | ** is disabled (for performance). Otherwise, 25 | ** the switch value is interpreted as: 26 | ** 0: use assert() to flag errors 27 | ** 1: return SKEIN_FAIL to flag errors 28 | ** 29 | ***************************************************************************/ 30 | #include "skein_port.h" /* get platform-specific definitions */ 31 | 32 | typedef enum 33 | { 34 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */ 35 | SKEIN_FAIL = 1, 36 | SKEIN_BAD_HASHLEN = 2 37 | } 38 | SkeinHashReturn; 39 | 40 | typedef size_t SkeinDataLength; /* bit count type */ 41 | typedef u08b_t SkeinBitSequence; /* bit stream type */ 42 | 43 | /* "all-in-one" call */ 44 | SkeinHashReturn skein_hash(int hashbitlen, const SkeinBitSequence *data, 45 | SkeinDataLength databitlen, SkeinBitSequence *hashval); 46 | 47 | #endif /* ifndef _SKEIN_H_ */ 48 | -------------------------------------------------------------------------------- /crypto/hash-ops.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #pragma once 6 | 7 | #if !defined(__cplusplus) 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "int-util.h" 15 | 16 | #if 0 17 | static inline void *padd(void *p, size_t i) { 18 | return (char *) p + i; 19 | } 20 | 21 | static inline const void *cpadd(const void *p, size_t i) { 22 | return (const char *) p + i; 23 | } 24 | 25 | static inline void place_length(uint8_t *buffer, size_t bufsize, size_t length) { 26 | if (sizeof(size_t) == 4) { 27 | *(uint32_t*) padd(buffer, bufsize - 4) = swap32be(length); 28 | } else { 29 | *(uint64_t*) padd(buffer, bufsize - 8) = swap64be(length); 30 | } 31 | } 32 | #endif 33 | 34 | #pragma pack(push, 1) 35 | union hash_state { 36 | uint8_t b[200]; 37 | uint64_t w[25]; 38 | }; 39 | #pragma pack(pop) 40 | 41 | void hash_permutation(union hash_state *state); 42 | void hash_process(union hash_state *state, const uint8_t *buf, int count); 43 | 44 | #endif 45 | 46 | enum { 47 | HASH_SIZE = 32, 48 | HASH_DATA_AREA = 136 49 | }; 50 | 51 | void cn_fast_hash(const void *data, int len, char *hash); 52 | void cn_slow_hash(const void *data, size_t length, char *hash); 53 | 54 | void hash_extra_blake(const void *data, size_t length, char *hash); 55 | void hash_extra_groestl(const void *data, size_t length, char *hash); 56 | void hash_extra_jh(const void *data, size_t length, char *hash); 57 | void hash_extra_skein(const void *data, size_t length, char *hash); 58 | 59 | void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash); 60 | -------------------------------------------------------------------------------- /crypto/hash.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2013 The Cryptonote developers 2 | // Distributed under the MIT/X11 software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "hash-ops.h" 10 | #include "c_keccak.h" 11 | 12 | void hash_permutation(union hash_state *state) { 13 | keccakf((uint64_t*)state, 24); 14 | } 15 | 16 | void hash_process(union hash_state *state, const uint8_t *buf, int count) { 17 | keccak1600(buf, count, (uint8_t*)state); 18 | } 19 | 20 | void cn_fast_hash(const void *data, int len, char *hash) { 21 | union hash_state state; 22 | hash_process(&state, data, len); 23 | memcpy(hash, &state, HASH_SIZE); 24 | } 25 | -------------------------------------------------------------------------------- /crypto/hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef unsigned char BitSequence; 4 | typedef unsigned long long DataLength; 5 | typedef enum {SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2} HashReturn; 6 | -------------------------------------------------------------------------------- /crypto/oaes_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * --------------------------------------------------------------------------- 3 | * OpenAES License 4 | * --------------------------------------------------------------------------- 5 | * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * - Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | * --------------------------------------------------------------------------- 29 | */ 30 | 31 | #ifndef _OAES_CONFIG_H 32 | #define _OAES_CONFIG_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | //#ifndef OAES_HAVE_ISAAC 39 | //#define OAES_HAVE_ISAAC 1 40 | //#endif // OAES_HAVE_ISAAC 41 | 42 | //#ifndef OAES_DEBUG 43 | //#define OAES_DEBUG 0 44 | //#endif // OAES_DEBUG 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif // _OAES_CONFIG_H 51 | -------------------------------------------------------------------------------- /lyra2/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/lyra2/.dirstamp -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/m4/.gitignore -------------------------------------------------------------------------------- /merkletree/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/merkletree/.dirstamp -------------------------------------------------------------------------------- /merkletree/LICENSE: -------------------------------------------------------------------------------- 1 | /* 2 | * ---------------------------------------------------------------------------- 3 | * "THE BEER-WARE LICENSE" (Revision 42): 4 | * wrote this file. As long as you retain this notice you 5 | * can do whatever you want with this stuff. If we meet some day, and you think 6 | * this stuff is worth it, you can buy me a beer in return. Panu Suksumonsin 7 | * ---------------------------------------------------------------------------- 8 | */ 9 | -------------------------------------------------------------------------------- /merkletree/README.md: -------------------------------------------------------------------------------- 1 | ## New Feature 2 | Push new leaf to merkletree 3 | 4 | ## Usage 5 | 6 | ```cpp 7 | #include "merkletree.h" 8 | 9 | using namespace std; 10 | 11 | int main(){ 12 | 13 | // initialize leaves 14 | vector leaves(5); 15 | leaves[0] = "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9"; 16 | leaves[1] = "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"; 17 | leaves[2] = "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35"; 18 | leaves[3] = "4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce"; 19 | leaves[4] = "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a"; 20 | 21 | // initialize merkletree 22 | merkletree mtree = merkletree(leaves); 23 | char* root = mtree.root(); 24 | 25 | // get proof 26 | char* sample_leaf = leaves[0]; 27 | vector proof = mtree.proof(sample_leaf); 28 | printf("root: %s\n",mtree.root()); 29 | 30 | // verify proof 31 | bool verified = verifyProof(sample_leaf,root,proof); 32 | printf("ver: %d\n",verified); 33 | 34 | // Push leaf 35 | // This will change value of some nodes 36 | char* newleaf = "370b126df07859afa569cd82582bc43dfb2ce3ba8069dbbcbef6b7215b7a76c6"; // sha256 of "anakin" 37 | mtree.pushleaf(newleaf); 38 | 39 | char* newroot = mtree.root(); 40 | printf("new root : %s\n",mtree.root()); 41 | 42 | // verify new leaf 43 | vector newproof = mtree.proof(newleaf); 44 | bool newverified = verifyProof(newleaf,newroot,newproof); 45 | 46 | printf("new ver : %d\n",newverified); 47 | } 48 | ``` 49 | ## To-do 50 | 51 | ## Inspiration 52 | https://github.com/blockai/merkletree 53 | -------------------------------------------------------------------------------- /merkletree/byteswap.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The Bitcoin developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #ifndef BITCOIN_COMPAT_BYTESWAP_H 6 | #define BITCOIN_COMPAT_BYTESWAP_H 7 | 8 | //#if defined(HAVE_CONFIG_H) 9 | //#include "config/bitcoin-config.h" 10 | //#endif 11 | 12 | #include 13 | 14 | #if defined(HAVE_BYTESWAP_H) 15 | #include 16 | #endif 17 | 18 | #if defined(__APPLE__) 19 | 20 | #if !defined(bswap_16) 21 | 22 | // Mac OS X / Darwin features; we include a check for bswap_16 because if it is already defined, protobuf has 23 | // defined these macros for us already; if it isn't, we do it ourselves. In either case, we get the exact same 24 | // result regardless which path was taken 25 | #include 26 | #define bswap_16(x) OSSwapInt16(x) 27 | #define bswap_32(x) OSSwapInt32(x) 28 | #define bswap_64(x) OSSwapInt64(x) 29 | 30 | #endif // !defined(bswap_16) 31 | 32 | #else 33 | // Non-Mac OS X / non-Darwin 34 | 35 | #if HAVE_DECL_BSWAP_16 == 0 36 | inline uint16_t bswap_16(uint16_t x) 37 | { 38 | return (x >> 8) | ((x & 0x00ff) << 8); 39 | } 40 | #endif // HAVE_DECL_BSWAP16 41 | 42 | #if HAVE_DECL_BSWAP_32 == 0 43 | inline uint32_t bswap_32(uint32_t x) 44 | { 45 | return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) | 46 | ((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24)); 47 | } 48 | #endif // HAVE_DECL_BSWAP32 49 | 50 | #if HAVE_DECL_BSWAP_64 == 0 51 | inline uint64_t bswap_64(uint64_t x) 52 | { 53 | return (((x & 0xff00000000000000ull) >> 56) 54 | | ((x & 0x00ff000000000000ull) >> 40) 55 | | ((x & 0x0000ff0000000000ull) >> 24) 56 | | ((x & 0x000000ff00000000ull) >> 8) 57 | | ((x & 0x00000000ff000000ull) << 8) 58 | | ((x & 0x0000000000ff0000ull) << 24) 59 | | ((x & 0x000000000000ff00ull) << 40) 60 | | ((x & 0x00000000000000ffull) << 56)); 61 | } 62 | #endif // HAVE_DECL_BSWAP64 63 | 64 | #endif // defined(__APPLE__) 65 | 66 | #endif // BITCOIN_COMPAT_BYTESWAP_H 67 | -------------------------------------------------------------------------------- /merkletree/definition.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto 2 | // Copyright (c) 2009-2015 The Bitcoin Core developers 3 | // Copyright (c) 2016-2017 The Zcoin Core developers 4 | // Distributed under the MIT software license, see the accompanying 5 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 6 | 7 | #ifndef BTZC_DEFINITION_H 8 | #define BTZC_DEFINITION_H 9 | 10 | enum { 11 | // primary version 12 | BLOCK_VERSION_DEFAULT = (1 << 0), 13 | // modifiers 14 | BLOCK_VERSION_AUXPOW = (1 << 8), 15 | // bits allocated for chain ID 16 | BLOCK_VERSION_CHAIN_START = (1 << 16), 17 | BLOCK_VERSION_CHAIN_END = (1 << 30), 18 | }; 19 | static const int64_t nStartRewardTime = 1475020800; 20 | 21 | #endif //BTZC_DEFINITION_H 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /merkletree/mtp.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | 4 | #ifndef ZCOIN_MTP_H 5 | #define ZCOIN_MTP_H 6 | 7 | #endif //ZCOIN_MTP_H 8 | 9 | 10 | 11 | #include "merkle-tree.hpp" 12 | 13 | #include 14 | #include "argon2ref/core.h" 15 | #include "argon2ref/argon2.h" 16 | #include "argon2ref/thread.h" 17 | #include "argon2ref/blake2.h" 18 | #include "argon2ref/blake2-impl.h" 19 | #include "argon2ref/blamka-round-opt.h" 20 | //#include "merkletree/sha.h" 21 | 22 | //#include "openssl\sha.h" 23 | 24 | #include "uint256.h" 25 | //#include "serialize.h" 26 | class CBlock; 27 | 28 | /* Size of MTP proof */ 29 | const unsigned int MTP_PROOF_SIZE = 1471;// 1431; 30 | /* Size of MTP block proof size */ 31 | const unsigned int MTP_BLOCK_PROOF_SIZE = 64; 32 | /* Size of MTP block */ 33 | const unsigned int MTP_BLOCK_SIZE = 140; 34 | 35 | typedef struct block_with_offset_ { 36 | block memory; 37 | // char* proof; 38 | char proof[MTP_PROOF_SIZE]; 39 | } block_with_offset; 40 | 41 | typedef struct block_mtpProof_ { 42 | block memory; 43 | char proof[MTP_PROOF_SIZE]; 44 | } block_mtpProof; 45 | 46 | typedef struct mtp_Proof_ { 47 | char proof[MTP_PROOF_SIZE]; 48 | } mtp_Proof; 49 | 50 | 51 | 52 | void mtp_hash(char* output, const char* input, unsigned int d, uint32_t TheNonce); 53 | argon2_context init_argon2d_param(const char* input); 54 | void getblockindex(uint32_t ij, argon2_instance_t *instance, uint32_t *out_ij_prev, uint32_t *out_computed_ref_block); 55 | 56 | 57 | int mtp_solver(uint32_t TheNonce, argon2_instance_t *instance, 58 | uint64_t nBlockMTP[MTP_BLOCK_PROOF_SIZE*2][128], unsigned char *nProofMTP, unsigned char* resultMerkleRoot, unsigned char* mtpHashValue, 59 | MerkleTree TheTree, uint32_t* input, uint256 hashTarget); 60 | 61 | int mtp_solver_nowriting(uint32_t TheNonce, argon2_instance_t *instance, 62 | unsigned char* resultMerkleRoot, uint32_t* input, uint256 hashTarget); 63 | 64 | uint32_t mtp_solver_nowriting_multi(uint32_t TheNonce, argon2_instance_t *instance, 65 | unsigned char* resultMerkleRoot, uint32_t* input, uint256 hashTarget); 66 | 67 | void mtp_init_parallel(int nthread, int thr_id, argon2_instance_t *instance, uint8_t *elements); 68 | 69 | // MerkleTree::Elements mtp_init(argon2_instance_t *instance); 70 | void mtp_init(argon2_instance_t *instance, uint8_t *elements); 71 | MerkleTree::Elements mtp_init2(argon2_instance_t *instance); -------------------------------------------------------------------------------- /merkletree/zeroafterfree.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto 2 | // Copyright (c) 2009-2015 The Bitcoin Core developers 3 | // Distributed under the MIT software license, see the accompanying 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 | 6 | #ifndef BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H 7 | #define BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H 8 | 9 | //#include "support/cleanse.h" 10 | 11 | #include 12 | #include 13 | 14 | template 15 | struct zero_after_free_allocator : public std::allocator { 16 | // MSVC8 default copy constructor is broken 17 | typedef std::allocator base; 18 | typedef typename base::size_type size_type; 19 | typedef typename base::difference_type difference_type; 20 | typedef typename base::pointer pointer; 21 | typedef typename base::const_pointer const_pointer; 22 | typedef typename base::reference reference; 23 | typedef typename base::const_reference const_reference; 24 | typedef typename base::value_type value_type; 25 | zero_after_free_allocator() throw() {} 26 | zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {} 27 | template 28 | zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) 29 | { 30 | } 31 | ~zero_after_free_allocator() throw() {} 32 | template 33 | struct rebind { 34 | typedef zero_after_free_allocator<_Other> other; 35 | }; 36 | 37 | void deallocate(T* p, std::size_t n) 38 | { 39 | /* if (p != NULL) 40 | memory_cleanse(p, sizeof(T) * n); 41 | std::allocator::deallocate(p, n); 42 | */ 43 | } 44 | }; 45 | 46 | // Byte-vector that clears its contents before deletion. 47 | typedef std::vector > CSerializeData; 48 | 49 | #endif // BITCOIN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H 50 | -------------------------------------------------------------------------------- /mingw64.sh: -------------------------------------------------------------------------------- 1 | ./autogen.sh 2 | 3 | CURL_PREFIX=/usr/local 4 | SSL_PREFIX=/usr/local/ssl 5 | 6 | # gcc 4.4 7 | extracflags="-O3 -Wall -D_REENTRANT -fmerge-all-constants" # -funroll-loops -fvariable-expansion-in-unroller -fbranch-target-load-optimize2 -fsched2-use-superblocks -falign-loops=16 -falign-functions=16 -falign-jumps=16 -falign-labels=16" 8 | 9 | # gcc 4.8+ 10 | # extracflags="$extracflags -Ofast -fuse-linker-plugin -ftree-loop-if-convert-stores" # -flto " 11 | 12 | # extracflags="$extracflags -march=native" 13 | 14 | # extracflags="-pg -static -fno-inline-small-functions" 15 | CFLAGS="-DCURL_STATICLIB -DOPENSSL_NO_ASM -DUSE_ASM -static-libgcc $extracflags" 16 | # CPPFLAGS="" 17 | 18 | # icon 19 | windres res/icon.rc icon.o 20 | 21 | ./configure --build=x86_64-w64-mingw32 --with-crypto=$SSL_PREFIX --with-curl=$CURL_PREFIX \ 22 | CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="icon.o" 23 | 24 | make 25 | 26 | strip -p --strip-debug --strip-unneeded cpuminer.exe 27 | 28 | if [ -e sign.sh ] ; then 29 | . sign.sh 30 | fi 31 | 32 | -------------------------------------------------------------------------------- /nomacro.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # Copyright 2012 pooler@litecoinpool.org 3 | # 4 | # This program is free software; you can redistribute it and/or modify it 5 | # under the terms of the GNU General Public License as published by the Free 6 | # Software Foundation; either version 2 of the License, or (at your option) 7 | # any later version. See COPYING for more details. 8 | # 9 | # nomacro.pl - convert assembler macros to C preprocessor macros. 10 | 11 | use strict; 12 | 13 | foreach my $f () { 14 | rename $f, "$f.orig"; 15 | open FIN, "$f.orig"; 16 | open FOUT, ">$f"; 17 | my $inmacro = 0; 18 | my %macros = (); 19 | while () { 20 | if (m/^\.macro\s+([_0-9A-Z]+)(?:\s*)(.*)$/i) { 21 | print FOUT "#define $1($2) \\\n"; 22 | $macros{$1} = 1; 23 | $inmacro = 1; 24 | next; 25 | } 26 | if (m/^\.endm/) { 27 | print FOUT "\n"; 28 | $inmacro = 0; 29 | next; 30 | } 31 | for my $m (keys %macros) { 32 | s/^([ \t]*)($m)(?:[ \t]+([^#\n]*))?([;\n])/\1\2(\3)\4/; 33 | } 34 | if ($inmacro) { 35 | if (m/^\s*#if/) { 36 | $_ = while (!m/^\s*#endif/); 37 | next; 38 | } 39 | next if (m/^\s*$/); 40 | s/\\//g; 41 | s/$/; \\/; 42 | } 43 | print FOUT; 44 | } 45 | close FOUT; 46 | close FIN; 47 | } 48 | -------------------------------------------------------------------------------- /res/cpuminer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/res/cpuminer.ico -------------------------------------------------------------------------------- /res/cpuminer.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_ICON1 ICON "cpuminer.ico" 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // 59 | // Version 60 | // 61 | 62 | VS_VERSION_INFO VERSIONINFO 63 | FILEVERSION 1,3,5,0 64 | PRODUCTVERSION 1,3,5,0 65 | FILEFLAGSMASK 0x3fL 66 | #ifdef _DEBUG 67 | FILEFLAGS 0x21L 68 | #else 69 | FILEFLAGS 0x20L 70 | #endif 71 | FILEOS 0x40004L 72 | FILETYPE 0x1L 73 | FILESUBTYPE 0x0L 74 | BEGIN 75 | BLOCK "StringFileInfo" 76 | BEGIN 77 | BLOCK "040904e4" 78 | BEGIN 79 | VALUE "FileVersion", "1.3.5" 80 | VALUE "LegalCopyright", "Copyright (C) 2018" 81 | VALUE "ProductName", "cpuminer-multi" 82 | VALUE "ProductVersion", "1.3.5" 83 | END 84 | END 85 | BLOCK "VarFileInfo" 86 | BEGIN 87 | VALUE "Translation", 0x409, 1252 88 | END 89 | END 90 | 91 | #endif // English (United States) resources 92 | ///////////////////////////////////////////////////////////////////////////// 93 | 94 | 95 | 96 | #ifndef APSTUDIO_INVOKED 97 | ///////////////////////////////////////////////////////////////////////////// 98 | // 99 | // Generated from the TEXTINCLUDE 3 resource. 100 | // 101 | 102 | 103 | ///////////////////////////////////////////////////////////////////////////// 104 | #endif // not APSTUDIO_INVOKED 105 | 106 | -------------------------------------------------------------------------------- /res/cpuminer.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /res/icon.rc: -------------------------------------------------------------------------------- 1 | 0 ICON cpuminer.ico 2 | -------------------------------------------------------------------------------- /res/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/res/resource.h -------------------------------------------------------------------------------- /res/setup.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/res/setup.ico -------------------------------------------------------------------------------- /scryptjane/scrypt-conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | pick the best algo at runtime or compile time? 3 | ---------------------------------------------- 4 | SCRYPT_CHOOSE_COMPILETIME (gcc only!) 5 | SCRYPT_CHOOSE_RUNTIME 6 | */ 7 | #define SCRYPT_CHOOSE_RUNTIME 8 | 9 | 10 | /* 11 | hash function to use 12 | ------------------------------- 13 | SCRYPT_BLAKE256 14 | SCRYPT_BLAKE512 15 | SCRYPT_SHA256 16 | SCRYPT_SHA512 17 | SCRYPT_SKEIN512 18 | */ 19 | //#define SCRYPT_SHA256 20 | 21 | 22 | /* 23 | block mixer to use 24 | ----------------------------- 25 | SCRYPT_CHACHA 26 | SCRYPT_SALSA 27 | */ 28 | //#define SCRYPT_SALSA 29 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-hash.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_BLAKE512) 2 | #include "scrypt-jane-hash_blake512.h" 3 | #elif defined(SCRYPT_BLAKE256) 4 | #include "scrypt-jane-hash_blake256.h" 5 | #elif defined(SCRYPT_SHA512) 6 | #include "scrypt-jane-hash_sha512.h" 7 | #elif defined(SCRYPT_SHA256) 8 | #include "scrypt-jane-hash_sha256.h" 9 | #elif defined(SCRYPT_SKEIN512) 10 | #include "scrypt-jane-hash_skein512.h" 11 | #elif defined(SCRYPT_KECCAK512) || defined(SCRYPT_KECCAK256) 12 | #include "scrypt-jane-hash_keccak.h" 13 | #else 14 | #define SCRYPT_HASH "ERROR" 15 | #define SCRYPT_HASH_BLOCK_SIZE 64 16 | #define SCRYPT_HASH_DIGEST_SIZE 64 17 | typedef struct scrypt_hash_state_t { size_t dummy; } scrypt_hash_state; 18 | typedef uint8_t scrypt_hash_digest[SCRYPT_HASH_DIGEST_SIZE]; 19 | static void scrypt_hash_init(scrypt_hash_state *S) {} 20 | static void scrypt_hash_update(scrypt_hash_state *S, const uint8_t *in, size_t inlen) {} 21 | static void scrypt_hash_finish(scrypt_hash_state *S, uint8_t *hash) {} 22 | static const uint8_t scrypt_test_hash_expected[SCRYPT_HASH_DIGEST_SIZE] = {0}; 23 | #error must define a hash function! 24 | #endif 25 | 26 | #include "scrypt-jane-pbkdf2.h" 27 | 28 | #define SCRYPT_TEST_HASH_LEN 257 /* (2 * largest block size) + 1 */ 29 | 30 | static int 31 | scrypt_test_hash() { 32 | scrypt_hash_state st; 33 | scrypt_hash_digest hash, final; 34 | uint8_t msg[SCRYPT_TEST_HASH_LEN]; 35 | size_t i; 36 | 37 | for (i = 0; i < SCRYPT_TEST_HASH_LEN; i++) 38 | msg[i] = (uint8_t)i; 39 | 40 | scrypt_hash_init(&st); 41 | for (i = 0; i < SCRYPT_TEST_HASH_LEN + 1; i++) { 42 | scrypt_hash(hash, msg, i); 43 | scrypt_hash_update(&st, hash, sizeof(hash)); 44 | } 45 | scrypt_hash_finish(&st, final); 46 | return scrypt_verify(final, scrypt_test_hash_expected, SCRYPT_HASH_DIGEST_SIZE); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-mix_chacha.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_CHACHA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "ChaCha20/8 Ref" 5 | 6 | #undef SCRYPT_CHACHA_INCLUDED 7 | #define SCRYPT_CHACHA_INCLUDED 8 | #define SCRYPT_CHACHA_BASIC 9 | 10 | static void 11 | chacha_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | a += b; t = d^a; d = ROTL32(t,16); \ 34 | c += d; t = b^c; b = ROTL32(t,12); \ 35 | a += b; t = d^a; d = ROTL32(t, 8); \ 36 | c += d; t = b^c; b = ROTL32(t, 7); 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x1, x5, x9,x13) 41 | quarter( x2, x6,x10,x14) 42 | quarter( x3, x7,x11,x15) 43 | quarter( x0, x5,x10,x15) 44 | quarter( x1, x6,x11,x12) 45 | quarter( x2, x7, x8,x13) 46 | quarter( x3, x4, x9,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-mix_salsa.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "Salsa20/8 Ref" 5 | 6 | #undef SCRYPT_SALSA_INCLUDED 7 | #define SCRYPT_SALSA_INCLUDED 8 | #define SCRYPT_SALSA_BASIC 9 | 10 | static void 11 | salsa_core_basic(uint32_t state[16]) { 12 | size_t rounds = 8; 13 | uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t; 14 | 15 | x0 = state[0]; 16 | x1 = state[1]; 17 | x2 = state[2]; 18 | x3 = state[3]; 19 | x4 = state[4]; 20 | x5 = state[5]; 21 | x6 = state[6]; 22 | x7 = state[7]; 23 | x8 = state[8]; 24 | x9 = state[9]; 25 | x10 = state[10]; 26 | x11 = state[11]; 27 | x12 = state[12]; 28 | x13 = state[13]; 29 | x14 = state[14]; 30 | x15 = state[15]; 31 | 32 | #define quarter(a,b,c,d) \ 33 | t = a+d; t = ROTL32(t, 7); b ^= t; \ 34 | t = b+a; t = ROTL32(t, 9); c ^= t; \ 35 | t = c+b; t = ROTL32(t, 13); d ^= t; \ 36 | t = d+c; t = ROTL32(t, 18); a ^= t; \ 37 | 38 | for (; rounds; rounds -= 2) { 39 | quarter( x0, x4, x8,x12) 40 | quarter( x5, x9,x13, x1) 41 | quarter(x10,x14, x2, x6) 42 | quarter(x15, x3, x7,x11) 43 | quarter( x0, x1, x2, x3) 44 | quarter( x5, x6, x7, x4) 45 | quarter(x10,x11, x8, x9) 46 | quarter(x15,x12,x13,x14) 47 | } 48 | 49 | state[0] += x0; 50 | state[1] += x1; 51 | state[2] += x2; 52 | state[3] += x3; 53 | state[4] += x4; 54 | state[5] += x5; 55 | state[6] += x6; 56 | state[7] += x7; 57 | state[8] += x8; 58 | state[9] += x9; 59 | state[10] += x10; 60 | state[11] += x11; 61 | state[12] += x12; 62 | state[13] += x13; 63 | state[14] += x14; 64 | state[15] += x15; 65 | 66 | #undef quarter 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-mix_salsa64.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA64_INCLUDED) 2 | 3 | #undef SCRYPT_MIX 4 | #define SCRYPT_MIX "Salsa64/8 Ref" 5 | 6 | #undef SCRYPT_SALSA64_INCLUDED 7 | #define SCRYPT_SALSA64_INCLUDED 8 | #define SCRYPT_SALSA64_BASIC 9 | 10 | static void 11 | salsa64_core_basic(uint64_t state[16]) { 12 | const size_t rounds = 8; 13 | uint64_t v[16], t; 14 | size_t i; 15 | 16 | for (i = 0; i < 16; i++) v[i] = state[i]; 17 | 18 | #define G(a,b,c,d) \ 19 | t = v[a]+v[d]; t = ROTL64(t, 32); v[b] ^= t; \ 20 | t = v[b]+v[a]; t = ROTL64(t, 13); v[c] ^= t; \ 21 | t = v[c]+v[b]; t = ROTL64(t, 39); v[d] ^= t; \ 22 | t = v[d]+v[c]; t = ROTL64(t, 32); v[a] ^= t; \ 23 | 24 | for (i = 0; i < rounds; i += 2) { 25 | G( 0, 4, 8,12); 26 | G( 5, 9,13, 1); 27 | G(10,14, 2, 6); 28 | G(15, 3, 7,11); 29 | G( 0, 1, 2, 3); 30 | G( 5, 6, 7, 4); 31 | G(10,11, 8, 9); 32 | G(15,12,13,14); 33 | } 34 | 35 | for (i = 0; i < 16; i++) state[i] += v[i]; 36 | 37 | #undef G 38 | } 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-romix-basic.h: -------------------------------------------------------------------------------- 1 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 2 | /* function type returned by scrypt_getROMix, used with cpu detection */ 3 | typedef void (FASTCALL *scrypt_ROMixfn)(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r); 4 | #endif 5 | 6 | /* romix pre/post nop function */ 7 | static void /* asm_calling_convention */ 8 | scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) { 9 | } 10 | 11 | /* romix pre/post endian conversion function */ 12 | static void /* asm_calling_convention */ 13 | scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) { 14 | #if !defined(CPU_LE) 15 | static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}}; 16 | size_t i; 17 | if (endian_test.w == 0x100) { 18 | nblocks *= SCRYPT_BLOCK_WORDS; 19 | for (i = 0; i < nblocks; i++) { 20 | SCRYPT_WORD_ENDIAN_SWAP(blocks[i]); 21 | } 22 | } 23 | #endif 24 | } 25 | 26 | /* chunkmix test function */ 27 | typedef void (*chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r); 28 | typedef void (*blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks); 29 | 30 | static int 31 | scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) { 32 | /* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */ 33 | const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS; 34 | scrypt_mix_word_t MM16 chunk[2][4 * SCRYPT_BLOCK_WORDS], v; 35 | uint8_t final[16]; 36 | size_t i; 37 | 38 | for (i = 0; i < words; i++) { 39 | v = (scrypt_mix_word_t)i; 40 | v = (v << 8) | v; 41 | v = (v << 16) | v; 42 | chunk[0][i] = v; 43 | } 44 | 45 | prefn(chunk[0], blocks); 46 | mixfn(chunk[1], chunk[0], NULL, r); 47 | postfn(chunk[1], blocks); 48 | 49 | /* grab the last 16 bytes of the final block */ 50 | for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) { 51 | SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]); 52 | } 53 | 54 | return scrypt_verify(expected, final, 16); 55 | } 56 | 57 | /* returns a pointer to item i, where item is len scrypt_mix_word_t's long */ 58 | static scrypt_mix_word_t * 59 | scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) { 60 | return base + (i * len); 61 | } 62 | 63 | /* returns a pointer to block i */ 64 | static scrypt_mix_word_t * 65 | scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) { 66 | return base + (i * SCRYPT_BLOCK_WORDS); 67 | } 68 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-romix.h: -------------------------------------------------------------------------------- 1 | #if defined(SCRYPT_CHACHA) 2 | #include "scrypt-jane-chacha.h" 3 | #elif defined(SCRYPT_SALSA) 4 | #include "scrypt-jane-salsa.h" 5 | #elif defined(SCRYPT_SALSA64) 6 | #include "scrypt-jane-salsa64.h" 7 | #else 8 | #define SCRYPT_MIX_BASE "ERROR" 9 | typedef uint32_t scrypt_mix_word_t; 10 | #define SCRYPT_WORDTO8_LE U32TO8_LE 11 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 12 | #define SCRYPT_BLOCK_BYTES 64 13 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 14 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 15 | static void FASTCALL scrypt_ROMix_error(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r) {} 16 | static scrypt_ROMixfn scrypt_getROMix() { return scrypt_ROMix_error; } 17 | #else 18 | static void FASTCALL scrypt_ROMix(scrypt_mix_word_t *X, scrypt_mix_word_t *Y, scrypt_mix_word_t *V, uint32_t N, uint32_t r) {} 19 | #endif 20 | static int scrypt_test_mix() { return 0; } 21 | #error must define a mix function! 22 | #endif 23 | 24 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 25 | #undef SCRYPT_MIX 26 | #define SCRYPT_MIX SCRYPT_MIX_BASE 27 | #endif 28 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-salsa.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "Salsa20/8" 2 | 3 | typedef uint32_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U32TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 64 9 | #define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t)) 10 | 11 | /* must have these here in case block bytes is ever != 64 */ 12 | #include "scrypt-jane-romix-basic.h" 13 | 14 | #include "scrypt-jane-mix_salsa-avx.h" 15 | #include "scrypt-jane-mix_salsa-sse2.h" 16 | #include "scrypt-jane-mix_salsa.h" 17 | 18 | #if defined(SCRYPT_SALSA_AVX) 19 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 20 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 21 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 22 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 23 | #include "scrypt-jane-romix-template.h" 24 | #endif 25 | 26 | #if defined(SCRYPT_SALSA_SSE2) 27 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 28 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 29 | #define SCRYPT_MIX_FN salsa_core_sse2 30 | #define SCRYPT_ROMIX_TANGLE_FN salsa_core_tangle_sse2 31 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa_core_tangle_sse2 32 | #include "scrypt-jane-romix-template.h" 33 | #endif 34 | 35 | /* cpu agnostic */ 36 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 37 | #define SCRYPT_MIX_FN salsa_core_basic 38 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 39 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 40 | #include "scrypt-jane-romix-template.h" 41 | 42 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 43 | static scrypt_ROMixfn 44 | scrypt_getROMix() { 45 | size_t cpuflags = detect_cpu(); 46 | 47 | #if defined(SCRYPT_SALSA_AVX) 48 | if (cpuflags & cpu_avx) 49 | return scrypt_ROMix_avx; 50 | else 51 | #endif 52 | 53 | #if defined(SCRYPT_SALSA_SSE2) 54 | if (cpuflags & cpu_sse2) 55 | return scrypt_ROMix_sse2; 56 | else 57 | #endif 58 | 59 | return scrypt_ROMix_basic; 60 | } 61 | #endif 62 | 63 | 64 | #if defined(SCRYPT_TEST_SPEED) 65 | static size_t 66 | available_implementations() { 67 | size_t cpuflags = detect_cpu(); 68 | size_t flags = 0; 69 | 70 | #if defined(SCRYPT_SALSA_AVX) 71 | if (cpuflags & cpu_avx) 72 | flags |= cpu_avx; 73 | #endif 74 | 75 | #if defined(SCRYPT_SALSA_SSE2) 76 | if (cpuflags & cpu_sse2) 77 | flags |= cpu_sse2; 78 | #endif 79 | 80 | return flags; 81 | } 82 | #endif 83 | 84 | 85 | static int 86 | scrypt_test_mix() { 87 | static const uint8_t expected[16] = { 88 | 0x41,0x1f,0x2e,0xa3,0xab,0xa3,0x1a,0x34,0x87,0x1d,0x8a,0x1c,0x76,0xa0,0x27,0x66, 89 | }; 90 | 91 | int ret = 1; 92 | size_t cpuflags = detect_cpu(); 93 | 94 | #if defined(SCRYPT_SALSA_AVX) 95 | if (cpuflags & cpu_avx) 96 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 97 | #endif 98 | 99 | #if defined(SCRYPT_SALSA_SSE2) 100 | if (cpuflags & cpu_sse2) 101 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa_core_tangle_sse2, salsa_core_tangle_sse2, expected); 102 | #endif 103 | 104 | #if defined(SCRYPT_SALSA_BASIC) 105 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 106 | #endif 107 | 108 | return ret; 109 | } 110 | -------------------------------------------------------------------------------- /sha3/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/sha3/.dirstamp -------------------------------------------------------------------------------- /sha3/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 -------------------------------------------------------------------------------- /sha3/sph_hefty1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HEFTY1 cryptographic hash function 3 | * 4 | * Copyright (c) 2014, dbcc14 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, this 11 | * list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | * 27 | * The views and conclusions contained in the software and documentation are those 28 | * of the authors and should not be interpreted as representing official policies, 29 | * either expressed or implied, of the FreeBSD Project. 30 | */ 31 | 32 | #ifndef __HEFTY1_H__ 33 | #define __HEFTY1_H__ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef WIN32 40 | #include 41 | #endif 42 | 43 | #include 44 | 45 | #define HEFTY1_DIGEST_BYTES 32 46 | #define HEFTY1_BLOCK_BYTES 64 47 | #define HEFTY1_STATE_WORDS 8 48 | #define HEFTY1_SPONGE_WORDS 4 49 | 50 | typedef struct HEFTY1_CTX { 51 | uint32_t h[HEFTY1_STATE_WORDS]; 52 | uint8_t block[HEFTY1_BLOCK_BYTES]; 53 | uint64_t written; 54 | uint32_t sponge[HEFTY1_SPONGE_WORDS]; 55 | } HEFTY1_CTX; 56 | 57 | void HEFTY1_Init(HEFTY1_CTX *cxt); 58 | void HEFTY1_Update(HEFTY1_CTX *cxt, const void *data, size_t len); 59 | void HEFTY1_Final(unsigned char *digest, HEFTY1_CTX *cxt); 60 | unsigned char* HEFTY1(const unsigned char *data, size_t len, unsigned char *digest); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __HEFTY1_H__ */ -------------------------------------------------------------------------------- /stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for cpuminer-config.h 2 | -------------------------------------------------------------------------------- /uint256.cpp: -------------------------------------------------------------------------------- 1 | #include "uint256.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C"{ 5 | #endif 6 | 7 | #include "miner.h" 8 | 9 | // compute the diff ratio between a found hash and the target 10 | double hash_target_ratio(uint32_t* hash, uint32_t* target) 11 | { 12 | uint256 h, t; 13 | double dhash; 14 | 15 | if (!opt_showdiff) 16 | return 0.0; 17 | 18 | memcpy(&t, (void*) target, 32); 19 | memcpy(&h, (void*) hash, 32); 20 | 21 | dhash = h.getdouble(); 22 | if (dhash > 0.) 23 | return t.getdouble() / dhash; 24 | else 25 | return dhash; 26 | } 27 | 28 | // store the share ratio in work struct 29 | void work_set_target_ratio(struct work* work, uint32_t* hash) 30 | { 31 | // only if the option is enabled (to reduce cpu usage) 32 | if (opt_showdiff && work) { 33 | work->shareratio = hash_target_ratio(hash, work->target); 34 | work->sharediff = work->targetdiff * work->shareratio; 35 | if (opt_debug) 36 | applog(LOG_DEBUG, "share diff %.5f (%.1fx)", work->sharediff, work->shareratio); 37 | } 38 | } 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /yescrypt/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firoorg/cpuminer/8fadee9272ca7e6c8bd191dae16d29b75fa9e09e/yescrypt/.dirstamp -------------------------------------------------------------------------------- /yescrypt/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 | #endif /* !_SHA256_H_ */ 63 | -------------------------------------------------------------------------------- /yescrypt/yescrypt-best.c: -------------------------------------------------------------------------------- 1 | #ifdef __SSE2__ 2 | #include "yescrypt-simd.c" 3 | #else 4 | #include "yescrypt-opt.c" 5 | #endif 6 | --------------------------------------------------------------------------------