├── .gitattributes ├── .gitignore ├── AUTHORS ├── Android.mk ├── COPYING ├── ChangeLog ├── LICENSE ├── Makefile.am ├── NEWS ├── README.md ├── algo ├── allium.c ├── axiom.c ├── bastion.c ├── bitcore.c ├── blake.c ├── blake2.c ├── blake2b.c ├── blakecoin.c ├── bmw256.c ├── c11.c ├── cryptolight.c ├── cryptonight.c ├── decred.c ├── drop.c ├── fresh.c ├── geek.c ├── groestl.c ├── heavy.c ├── ink.c ├── jha.c ├── keccak.c ├── lbry.c ├── luffa.c ├── lyra2re.c ├── lyra2rev2.c ├── lyra2v3.c ├── minotaur.c ├── myr-groestl.c ├── neoscrypt.c ├── nist5.c ├── pentablake.c ├── phi1612.c ├── phi2.c ├── pluck.c ├── quark.c ├── qubit.c ├── rainforest.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 ├── x20r.c ├── xevan.c ├── yespower │ ├── .dirstamp │ ├── README │ ├── crypto │ │ ├── .dirstamp │ │ ├── sha256.c │ │ └── sha256.h │ ├── util │ │ ├── insecure_memzero.h │ │ └── sysendian.h │ ├── yespower.c │ └── yespower.h └── zr5.c ├── api.c ├── api ├── index.php ├── local-sample.php └── websocket.htm ├── asm ├── 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 ├── build-linux-arm.sh ├── build.sh ├── compat.h ├── compat ├── Makefile.am ├── bionic │ └── cpuminer-config.h ├── 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 │ └── zlib │ │ ├── zconf.h │ │ └── zlib.h ├── getopt │ ├── getopt.h │ └── getopt_long.c ├── gettimeofday.c ├── inttypes.h ├── jansson │ ├── .gitignore │ ├── LICENSE │ ├── Makefile.am │ ├── config.h │ ├── configure.ac │ ├── dump.c │ ├── error.c │ ├── hashtable.c │ ├── hashtable.h │ ├── jansson.h │ ├── jansson_config.h │ ├── jansson_private.h │ ├── load.c │ ├── memory.c │ ├── pack_unpack.c │ ├── strbuffer.c │ ├── strbuffer.h │ ├── strconv.c │ ├── utf.c │ ├── utf.h │ ├── util.h │ └── value.c ├── pthreads │ ├── pthread.h │ └── sched.h ├── stdbool.h ├── sys │ └── time.h ├── unistd.h ├── winansi.c └── winansi.h ├── configure.ac ├── cpu-miner.c ├── cpuminer.1 ├── crypto ├── 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 ├── elist.h ├── example.cpuminer-conf.json ├── lyra2 ├── Lyra2.c ├── Lyra2.h ├── Sponge.c └── Sponge.h ├── m4 └── .gitignore ├── miner.h ├── nomacro.pl ├── 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 ├── 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_panama.c ├── sph_panama.h ├── sph_radiogatun.c ├── sph_radiogatun.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 ├── sysinfos.c ├── uint256.cpp ├── uint256.h └── util.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | minerd* 2 | cpuminer 3 | *.exe 4 | *.o 5 | *.d 6 | gmon.out 7 | 8 | autom4te.cache 9 | .deps 10 | 11 | Makefile 12 | Makefile.in 13 | INSTALL 14 | aclocal.m4 15 | configure 16 | configure.lineno 17 | depcomp 18 | missing 19 | install-sh 20 | stamp-h1 21 | cpuminer-config.h* 22 | compile 23 | config.log 24 | config.status 25 | config.status.lineno 26 | config.guess 27 | config.sub 28 | 29 | mingw32-config.cache 30 | 31 | */.dirstamp 32 | 33 | *.iml 34 | 35 | *.vcxproj.user 36 | *.opensdf 37 | *.sdf 38 | *.suo 39 | Release/ 40 | Debug/ 41 | x64/Release/ 42 | x64/Debug/ 43 | *.pdb/ 44 | 45 | installer/ 46 | res/cpuminer.aps 47 | res/RC* 48 | sign/ 49 | sign.sh 50 | 51 | compat/curl-for-windows/ 52 | just*.bat 53 | .vscode 54 | 55 | curl-* 56 | pthreads-* 57 | openssl-* 58 | zlib-* 59 | win64_deps 60 | -------------------------------------------------------------------------------- /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 | 19 | Tanner^LCC (https://github.com/litecoincash-project/) 20 | 21 | Neoncoin team (https://github.com/neoncoin-project/) 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | cpuminer is available under the terms of the GNU Public License version 2. 2 | 3 | See COPYING for details. 4 | -------------------------------------------------------------------------------- /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 | void allium_hash(void *state, const void *input) 18 | { 19 | uint32_t hashA[8], hashB[8]; 20 | 21 | sph_blake256_context ctx_blake; 22 | sph_keccak256_context ctx_keccak; 23 | sph_skein256_context ctx_skein; 24 | sph_groestl256_context ctx_groestl; 25 | sph_cubehash256_context ctx_cube; 26 | 27 | // sph_blake256_set_rounds(14); 28 | 29 | sph_blake256_init(&ctx_blake); 30 | sph_blake256(&ctx_blake, input, 80); 31 | sph_blake256_close(&ctx_blake, hashA); 32 | 33 | sph_keccak256_init(&ctx_keccak); 34 | sph_keccak256(&ctx_keccak, hashA, 32); 35 | sph_keccak256_close(&ctx_keccak, hashB); 36 | 37 | LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 38 | 39 | sph_cubehash256_init(&ctx_cube); 40 | sph_cubehash256(&ctx_cube, hashA, 32); 41 | sph_cubehash256_close(&ctx_cube, hashB); 42 | 43 | LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); 44 | 45 | sph_skein256_init(&ctx_skein); 46 | sph_skein256(&ctx_skein, hashA, 32); 47 | sph_skein256_close(&ctx_skein, hashB); 48 | 49 | sph_groestl256_init(&ctx_groestl); 50 | sph_groestl256(&ctx_groestl, hashB, 32); 51 | sph_groestl256_close(&ctx_groestl, hashA); 52 | 53 | memcpy(state, hashA, 32); 54 | } 55 | 56 | int scanhash_allium(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 57 | { 58 | uint32_t _ALIGN(128) hash[8]; 59 | uint32_t _ALIGN(128) endiandata[20]; 60 | uint32_t *pdata = work->data; 61 | uint32_t *ptarget = work->target; 62 | 63 | const uint32_t Htarg = ptarget[7]; 64 | const uint32_t first_nonce = pdata[19]; 65 | uint32_t n = first_nonce; 66 | 67 | if(opt_benchmark){ 68 | ptarget[7] = 0x00ff; 69 | } 70 | 71 | for (int i=0; i < 19; i++) { 72 | be32enc(&endiandata[i], pdata[i]); 73 | } 74 | 75 | do { 76 | be32enc(&endiandata[19], n); 77 | allium_hash(hash, endiandata); 78 | 79 | if (hash[7] < Htarg && fulltest(hash, ptarget)) { 80 | work_set_target_ratio(work, hash); 81 | *hashes_done = n - first_nonce + 1; 82 | pdata[19] = n; 83 | return 1; 84 | } 85 | n++; 86 | 87 | } while (n < max_nonce && !work_restart[thr_id].restart); 88 | 89 | *hashes_done = n - first_nonce + 1; 90 | pdata[19] = n; 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /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/bastion.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "sha3/sph_hefty1.h" 10 | 11 | #include "sha3/sph_luffa.h" 12 | #include "sha3/sph_fugue.h" 13 | #include "sha3/sph_skein.h" 14 | #include "sha3/sph_whirlpool.h" 15 | #include "sha3/sph_shabal.h" 16 | #include "sha3/sph_echo.h" 17 | #include "sha3/sph_hamsi.h" 18 | 19 | void bastionhash(void *output, const void *input) 20 | { 21 | unsigned char _ALIGN(128) hash[64] = { 0 }; 22 | 23 | sph_echo512_context ctx_echo; 24 | sph_luffa512_context ctx_luffa; 25 | sph_fugue512_context ctx_fugue; 26 | sph_whirlpool_context ctx_whirlpool; 27 | sph_shabal512_context ctx_shabal; 28 | sph_skein512_context ctx_skein; 29 | sph_hamsi512_context ctx_hamsi; 30 | 31 | HEFTY1(input, 80, hash); 32 | 33 | sph_luffa512_init(&ctx_luffa); 34 | sph_luffa512(&ctx_luffa, hash, 64); 35 | sph_luffa512_close(&ctx_luffa, hash); 36 | 37 | if (hash[0] & 0x8) 38 | { 39 | sph_fugue512_init(&ctx_fugue); 40 | sph_fugue512(&ctx_fugue, hash, 64); 41 | sph_fugue512_close(&ctx_fugue, hash); 42 | } else { 43 | sph_skein512_init(&ctx_skein); 44 | sph_skein512(&ctx_skein, hash, 64); 45 | sph_skein512_close(&ctx_skein, hash); 46 | } 47 | 48 | sph_whirlpool_init(&ctx_whirlpool); 49 | sph_whirlpool(&ctx_whirlpool, hash, 64); 50 | sph_whirlpool_close(&ctx_whirlpool, hash); 51 | 52 | sph_fugue512_init(&ctx_fugue); 53 | sph_fugue512(&ctx_fugue, hash, 64); 54 | sph_fugue512_close(&ctx_fugue, hash); 55 | 56 | if (hash[0] & 0x8) 57 | { 58 | sph_echo512_init(&ctx_echo); 59 | sph_echo512(&ctx_echo, hash, 64); 60 | sph_echo512_close(&ctx_echo, hash); 61 | } else { 62 | sph_luffa512_init(&ctx_luffa); 63 | sph_luffa512(&ctx_luffa, hash, 64); 64 | sph_luffa512_close(&ctx_luffa, hash); 65 | } 66 | 67 | sph_shabal512_init(&ctx_shabal); 68 | sph_shabal512(&ctx_shabal, hash, 64); 69 | sph_shabal512_close(&ctx_shabal, hash); 70 | 71 | sph_skein512_init(&ctx_skein); 72 | sph_skein512(&ctx_skein, hash, 64); 73 | sph_skein512_close(&ctx_skein, hash); 74 | 75 | if (hash[0] & 0x8) 76 | { 77 | sph_shabal512_init(&ctx_shabal); 78 | sph_shabal512(&ctx_shabal, hash, 64); 79 | sph_shabal512_close(&ctx_shabal, hash); 80 | } else { 81 | sph_whirlpool_init(&ctx_whirlpool); 82 | sph_whirlpool(&ctx_whirlpool, hash, 64); 83 | sph_whirlpool_close(&ctx_whirlpool, hash); 84 | } 85 | 86 | sph_shabal512_init(&ctx_shabal); 87 | sph_shabal512(&ctx_shabal, hash, 64); 88 | sph_shabal512_close(&ctx_shabal, hash); 89 | 90 | if (hash[0] & 0x8) 91 | { 92 | sph_hamsi512_init(&ctx_hamsi); 93 | sph_hamsi512(&ctx_hamsi, hash, 64); 94 | sph_hamsi512_close(&ctx_hamsi, hash); 95 | } else { 96 | sph_luffa512_init(&ctx_luffa); 97 | sph_luffa512(&ctx_luffa, hash, 64); 98 | sph_luffa512_close(&ctx_luffa, hash); 99 | } 100 | 101 | memcpy(output, hash, 32); 102 | } 103 | 104 | int scanhash_bastion(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 105 | { 106 | uint32_t _ALIGN(64) hash32[8]; 107 | uint32_t _ALIGN(64) endiandata[20]; 108 | uint32_t *pdata = work->data; 109 | uint32_t *ptarget = work->target; 110 | 111 | const uint32_t Htarg = ptarget[7]; 112 | const uint32_t first_nonce = pdata[19]; 113 | 114 | uint32_t n = first_nonce; 115 | 116 | for (int i=0; i < 19; i++) { 117 | be32enc(&endiandata[i], pdata[i]); 118 | } 119 | 120 | do { 121 | be32enc(&endiandata[19], n); 122 | bastionhash(hash32, endiandata); 123 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 124 | work_set_target_ratio(work, hash32); 125 | *hashes_done = n - first_nonce + 1; 126 | pdata[19] = n; 127 | return true; 128 | } 129 | n++; 130 | 131 | } while (n < max_nonce && !work_restart[thr_id].restart); 132 | 133 | *hashes_done = n - first_nonce + 1; 134 | pdata[19] = n; 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /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/blake2b.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litecoincash-project/cpuminer-multi/5710e52b064d2077a53d3db3ae6b1a7febbec45b/algo/blake2b.c -------------------------------------------------------------------------------- /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/geek.c: -------------------------------------------------------------------------------- 1 | #include 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 | 18 | void geekhash(void *output, const void *input) 19 | { 20 | sph_blake512_context ctx_blake; 21 | sph_bmw512_context ctx_bmw; 22 | sph_echo512_context ctx_echo; 23 | sph_shabal512_context ctx_shabal; 24 | sph_groestl512_context ctx_groestl; 25 | sph_cubehash512_context ctx_cubehash; 26 | sph_keccak512_context ctx_keccak; 27 | sph_hamsi512_context ctx_hamsi; 28 | sph_simd512_context ctx_simd; 29 | 30 | uint32_t _ALIGN(128) hash[16]; 31 | 32 | sph_blake512_init(&ctx_blake); 33 | sph_blake512 (&ctx_blake, input, 80); 34 | sph_blake512_close (&ctx_blake, hash); 35 | 36 | sph_bmw512_init(&ctx_bmw); 37 | sph_bmw512 (&ctx_bmw, hash, 64); 38 | sph_bmw512_close(&ctx_bmw, hash); 39 | 40 | sph_echo512_init (&ctx_echo); 41 | sph_echo512 (&ctx_echo, hash, 64); 42 | sph_echo512_close(&ctx_echo, hash); 43 | 44 | sph_shabal512_init (&ctx_shabal); 45 | sph_shabal512 (&ctx_shabal, hash, 64); 46 | sph_shabal512_close(&ctx_shabal, hash); 47 | 48 | sph_groestl512_init(&ctx_groestl); 49 | sph_groestl512 (&ctx_groestl, hash, 64); 50 | sph_groestl512_close(&ctx_groestl, hash); 51 | 52 | sph_cubehash512_init (&ctx_cubehash); 53 | sph_cubehash512 (&ctx_cubehash, hash, 64); 54 | sph_cubehash512_close(&ctx_cubehash, hash); 55 | 56 | sph_keccak512_init(&ctx_keccak); 57 | sph_keccak512 (&ctx_keccak, hash, 64); 58 | sph_keccak512_close(&ctx_keccak, hash); 59 | 60 | sph_hamsi512_init (&ctx_hamsi); 61 | sph_hamsi512 (&ctx_hamsi, hash, 64); 62 | sph_hamsi512_close(&ctx_hamsi, hash); 63 | 64 | sph_simd512_init (&ctx_simd); 65 | sph_simd512 (&ctx_simd, hash, 64); 66 | sph_simd512_close(&ctx_simd, hash); 67 | 68 | memcpy(output, hash, 32); 69 | } 70 | 71 | int scanhash_geek(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 72 | { 73 | uint32_t _ALIGN(64) hash[8]; 74 | uint32_t _ALIGN(64) endiandata[20]; 75 | uint32_t *pdata = work->data; 76 | uint32_t *ptarget = work->target; 77 | 78 | const uint32_t Htarg = ptarget[7]; 79 | const uint32_t first_nonce = pdata[19]; 80 | uint32_t nonce = first_nonce; 81 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 82 | 83 | if (opt_benchmark) 84 | ptarget[7] = 0x0cff; 85 | 86 | for (int k=0; k < 19; k++) 87 | be32enc(&endiandata[k], pdata[k]); 88 | 89 | do { 90 | be32enc(&endiandata[19], nonce); 91 | geekhash(hash, endiandata); 92 | 93 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 94 | work_set_target_ratio(work, hash); 95 | pdata[19] = nonce; 96 | *hashes_done = pdata[19] - first_nonce; 97 | return 1; 98 | } 99 | nonce++; 100 | 101 | } while (nonce < max_nonce && !(*restart)); 102 | 103 | pdata[19] = nonce; 104 | *hashes_done = pdata[19] - first_nonce + 1; 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /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/lyra2v3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sha3/sph_blake.h" 4 | #include "sha3/sph_cubehash.h" 5 | #include "sha3/sph_bmw.h" 6 | 7 | #include "lyra2/Lyra2.h" 8 | 9 | #include "miner.h" 10 | 11 | void lyra2v3_hash(void *state, const void *input) 12 | { 13 | uint32_t _ALIGN(128) hash[8], hashB[8]; 14 | 15 | sph_blake256_context ctx_blake; 16 | sph_cubehash256_context ctx_cubehash; 17 | sph_bmw256_context ctx_bmw; 18 | 19 | //sph_blake256_set_rounds(14); 20 | 21 | sph_blake256_init(&ctx_blake); 22 | sph_blake256(&ctx_blake, input, 80); 23 | sph_blake256_close(&ctx_blake, hash); 24 | 25 | LYRA2_3(hashB, 32, hash, 32, hash, 32, 1, 4, 4); 26 | 27 | sph_cubehash256_init(&ctx_cubehash); 28 | sph_cubehash256(&ctx_cubehash, hashB, 32); 29 | sph_cubehash256_close(&ctx_cubehash, hash); 30 | 31 | LYRA2_3(hashB, 32, hash, 32, hash, 32, 1, 4, 4); 32 | 33 | sph_bmw256_init(&ctx_bmw); 34 | sph_bmw256(&ctx_bmw, hashB, 32); 35 | sph_bmw256_close(&ctx_bmw, hash); 36 | 37 | memcpy(state, hash, 32); 38 | } 39 | 40 | int scanhash_lyra2v3(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 41 | { 42 | uint32_t _ALIGN(128) hash[8]; 43 | uint32_t _ALIGN(128) endiandata[20]; 44 | uint32_t *pdata = work->data; 45 | uint32_t *ptarget = work->target; 46 | 47 | const uint32_t Htarg = ptarget[7]; 48 | const uint32_t first_nonce = pdata[19]; 49 | uint32_t nonce = first_nonce; 50 | 51 | if (opt_benchmark) 52 | ptarget[7] = 0x0000ff; 53 | 54 | for (int i=0; i < 19; i++) { 55 | be32enc(&endiandata[i], pdata[i]); 56 | } 57 | 58 | do { 59 | be32enc(&endiandata[19], nonce); 60 | lyra2v3_hash(hash, endiandata); 61 | 62 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 63 | work_set_target_ratio(work, hash); 64 | pdata[19] = nonce; 65 | *hashes_done = pdata[19] - first_nonce; 66 | return 1; 67 | } 68 | nonce++; 69 | 70 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 71 | 72 | pdata[19] = nonce; 73 | *hashes_done = pdata[19] - first_nonce + 1; 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /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 | void phi1612_hash(void *state, const void *input) 17 | { 18 | sph_skein512_context ctx_skein; 19 | sph_jh512_context ctx_jh; 20 | sph_cubehash512_context ctx_cubehash; 21 | sph_fugue512_context ctx_fugue; 22 | sph_gost512_context ctx_gost; 23 | sph_echo512_context ctx_echo; 24 | 25 | uint8_t _ALIGN(128) hash[64]; 26 | 27 | sph_skein512_init(&ctx_skein); 28 | sph_skein512(&ctx_skein, input, 80); 29 | sph_skein512_close(&ctx_skein, (void*) hash); 30 | 31 | sph_jh512_init(&ctx_jh); 32 | sph_jh512(&ctx_jh, (const void*) hash, 64); 33 | sph_jh512_close(&ctx_jh, (void*) hash); 34 | 35 | sph_cubehash512_init(&ctx_cubehash); 36 | sph_cubehash512(&ctx_cubehash, (const void*) hash, 64); 37 | sph_cubehash512_close(&ctx_cubehash, (void*) hash); 38 | 39 | sph_fugue512_init(&ctx_fugue); 40 | sph_fugue512(&ctx_fugue, (const void*) hash, 64); 41 | sph_fugue512_close(&ctx_fugue, (void*) hash); 42 | 43 | sph_gost512_init(&ctx_gost); 44 | sph_gost512(&ctx_gost, (const void*) hash, 64); 45 | sph_gost512_close(&ctx_gost, (void*) hash); 46 | 47 | sph_echo512_init(&ctx_echo); 48 | sph_echo512(&ctx_echo, (const void*) hash, 64); 49 | sph_echo512_close(&ctx_echo, (void*) hash); 50 | 51 | memcpy(state, hash, 32); 52 | } 53 | 54 | int scanhash_phi1612(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 55 | { 56 | uint32_t _ALIGN(128) hash[8]; 57 | uint32_t _ALIGN(128) endiandata[20]; 58 | uint32_t *pdata = work->data; 59 | uint32_t *ptarget = work->target; 60 | 61 | const uint32_t Htarg = ptarget[7]; 62 | const uint32_t first_nonce = pdata[19]; 63 | uint32_t n = first_nonce; 64 | 65 | if(opt_benchmark){ 66 | ptarget[7] = 0x00ff; 67 | } 68 | 69 | for (int i=0; i < 19; i++) { 70 | be32enc(&endiandata[i], pdata[i]); 71 | } 72 | 73 | do { 74 | be32enc(&endiandata[19], n); 75 | phi1612_hash(hash, endiandata); 76 | 77 | if (hash[7] < Htarg && fulltest(hash, ptarget)) { 78 | work_set_target_ratio(work, hash); 79 | *hashes_done = n - first_nonce + 1; 80 | pdata[19] = n; 81 | return 1; 82 | } 83 | n++; 84 | 85 | } while (n < max_nonce && !work_restart[thr_id].restart); 86 | 87 | *hashes_done = n - first_nonce + 1; 88 | pdata[19] = n; 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /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[36]; 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/quark.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "sha3/sph_blake.h" 7 | #include "sha3/sph_bmw.h" 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_jh.h" 10 | #include "sha3/sph_keccak.h" 11 | #include "sha3/sph_skein.h" 12 | 13 | /* Move init out of loop, so init once externally, 14 | and then use one single memcpy with that bigger memory block */ 15 | typedef struct { 16 | sph_blake512_context blake1, blake2; 17 | sph_bmw512_context bmw1, bmw2; 18 | sph_groestl512_context groestl1, groestl2; 19 | sph_skein512_context skein1, skein2; 20 | sph_jh512_context jh1, jh2; 21 | sph_keccak512_context keccak1, keccak2; 22 | bool init_done; 23 | } quarkhash_context_holder; 24 | 25 | static quarkhash_context_holder _ALIGN(128) cached_ctx; 26 | 27 | void init_quarkhash_contexts() 28 | { 29 | sph_blake512_init(&cached_ctx.blake1); 30 | sph_bmw512_init(&cached_ctx.bmw1); 31 | sph_groestl512_init(&cached_ctx.groestl1); 32 | sph_skein512_init(&cached_ctx.skein1); 33 | sph_groestl512_init(&cached_ctx.groestl2); 34 | sph_jh512_init(&cached_ctx.jh1); 35 | sph_blake512_init(&cached_ctx.blake2); 36 | sph_bmw512_init(&cached_ctx.bmw2); 37 | sph_keccak512_init(&cached_ctx.keccak1); 38 | sph_skein512_init(&cached_ctx.skein2); 39 | sph_keccak512_init(&cached_ctx.keccak2); 40 | sph_jh512_init(&cached_ctx.jh2); 41 | cached_ctx.init_done = true; 42 | } 43 | 44 | void quarkhash(void *state, const void *input) 45 | { 46 | uint32_t _ALIGN(128) hash[16]; 47 | quarkhash_context_holder _ALIGN(128) ctx; 48 | uint32_t mask = 8; 49 | 50 | if (cached_ctx.init_done) 51 | memcpy(&ctx, &cached_ctx, sizeof(cached_ctx)); 52 | else { 53 | applog(LOG_ERR, "Attempt to hash quark without init!"); 54 | exit(1); 55 | } 56 | 57 | sph_blake512 (&ctx.blake1, input, 80); 58 | sph_blake512_close (&ctx.blake1, hash); //0 59 | 60 | sph_bmw512 (&ctx.bmw1, hash, 64); 61 | sph_bmw512_close(&ctx.bmw1, hash); //1 62 | 63 | if (hash[0] & mask) { 64 | sph_groestl512 (&ctx.groestl1, hash, 64); 65 | sph_groestl512_close(&ctx.groestl1, hash); //2 66 | } else { 67 | sph_skein512 (&ctx.skein1, hash, 64); 68 | sph_skein512_close(&ctx.skein1, hash); //2 69 | } 70 | 71 | sph_groestl512 (&ctx.groestl2, hash, 64); 72 | sph_groestl512_close(&ctx.groestl2, hash); //3 73 | 74 | sph_jh512 (&ctx.jh1, hash, 64); 75 | sph_jh512_close(&ctx.jh1, hash); //4 76 | 77 | if (hash[0] & mask) { 78 | sph_blake512 (&ctx.blake2, hash, 64); 79 | sph_blake512_close(&ctx.blake2, hash); //5 80 | } else { 81 | sph_bmw512 (&ctx.bmw2, hash, 64); 82 | sph_bmw512_close(&ctx.bmw2, hash); //5 83 | } 84 | 85 | sph_keccak512 (&ctx.keccak1, hash, 64); 86 | sph_keccak512_close(&ctx.keccak1, hash); //6 87 | 88 | sph_skein512 (&ctx.skein2, hash, 64); 89 | sph_skein512_close(&ctx.skein2, hash); //7 90 | 91 | if (hash[0] & mask) { 92 | sph_keccak512 (&ctx.keccak2, hash, 64); 93 | sph_keccak512_close(&ctx.keccak2, hash); //8 94 | } else { 95 | sph_jh512 (&ctx.jh2, hash, 64); 96 | sph_jh512_close(&ctx.jh2, hash); //8 97 | } 98 | 99 | memcpy(state, hash, 32); 100 | } 101 | 102 | int scanhash_quark(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 103 | { 104 | uint32_t _ALIGN(128) hash32[8]; 105 | uint32_t _ALIGN(128) endiandata[20]; 106 | uint32_t *pdata = work->data; 107 | uint32_t *ptarget = work->target; 108 | 109 | const uint32_t Htarg = ptarget[7]; 110 | const uint32_t first_nonce = pdata[19]; 111 | 112 | uint32_t n = first_nonce; 113 | 114 | for (int i=0; i < 19; i++) { 115 | be32enc(&endiandata[i], pdata[i]); 116 | } 117 | 118 | do { 119 | be32enc(&endiandata[19], n); 120 | quarkhash(hash32, endiandata); 121 | if (hash32[7] < Htarg && fulltest(hash32, ptarget)) { 122 | work_set_target_ratio(work, hash32); 123 | *hashes_done = n - first_nonce + 1; 124 | pdata[19] = n; 125 | return true; 126 | } 127 | n++; 128 | 129 | } while (n < max_nonce && !work_restart[thr_id].restart); 130 | 131 | *hashes_done = n - first_nonce + 1; 132 | pdata[19] = n; 133 | 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /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 | #define A 64 14 | 15 | #ifdef MIDSTATE 16 | static __thread blake2b_ctx s_midstate; 17 | static __thread blake2b_ctx s_ctx; 18 | #define MIDLEN 76 19 | 20 | static void blake2b_hash_end(uint32_t *output, const uint32_t *input) 21 | { 22 | s_ctx.outlen = MIDLEN; 23 | memcpy(&s_ctx, &s_midstate, 32 + 16 + MIDLEN); 24 | blake2b_update(&s_ctx, (uint8_t*) &input[MIDLEN/4], 80 - MIDLEN); 25 | blake2b_final(&s_ctx, (uint8_t*) output); 26 | } 27 | #endif 28 | 29 | void blake2b_hash(void *output, const void *input) 30 | { 31 | uint8_t _ALIGN(A) hash[32]; 32 | blake2b_ctx ctx; 33 | 34 | blake2b_init(&ctx, 32, NULL, 0); 35 | blake2b_update(&ctx, input, 80); 36 | blake2b_final(&ctx, hash); 37 | 38 | memcpy(output, hash, 32); 39 | } 40 | 41 | int scanhash_blake2b(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 42 | { 43 | uint32_t _ALIGN(A) vhashcpu[8]; 44 | uint32_t _ALIGN(A) endiandata[20]; 45 | uint32_t *pdata = work->data; 46 | uint32_t *ptarget = work->target; 47 | 48 | const uint32_t Htarg = ptarget[7]; 49 | const uint32_t first_nonce = pdata[19]; 50 | 51 | uint32_t n = first_nonce; 52 | 53 | for (int i=0; i < 19; i++) { 54 | be32enc(&endiandata[i], pdata[i]); 55 | } 56 | 57 | // midstate (untested yet) 58 | //blake2b_init(&s_midstate, 32, NULL, 0); 59 | //blake2b_update(&s_midstate, (uint8_t*) endiandata, MIDLEN); 60 | //memcpy(&s_ctx, &s_midstate, sizeof(blake2b_ctx)); 61 | 62 | do { 63 | be32enc(&endiandata[19], n); 64 | //blake2b_hash_end(vhashcpu, endiandata); 65 | blake2b_hash(vhashcpu, endiandata); 66 | 67 | if (vhashcpu[7] < Htarg && fulltest(vhashcpu, ptarget)) { 68 | work_set_target_ratio(work, vhashcpu); 69 | *hashes_done = n - first_nonce + 1; 70 | pdata[19] = n; 71 | return 1; 72 | } 73 | n++; 74 | 75 | } while (n < max_nonce && !work_restart[thr_id].restart); 76 | 77 | *hashes_done = n - first_nonce + 1; 78 | pdata[19] = n; 79 | 80 | return 0; 81 | } 82 | 83 | static inline void swab256(void *dest_p, const void *src_p) 84 | { 85 | uint32_t *dest = (uint32_t *)dest_p; 86 | const uint32_t *src = (uint32_t *)src_p; 87 | 88 | dest[0] = swab32(src[7]); 89 | dest[1] = swab32(src[6]); 90 | dest[2] = swab32(src[5]); 91 | dest[3] = swab32(src[4]); 92 | dest[4] = swab32(src[3]); 93 | dest[5] = swab32(src[2]); 94 | dest[6] = swab32(src[1]); 95 | dest[7] = swab32(src[0]); 96 | } 97 | 98 | int scanhash_sia(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 99 | { 100 | uint32_t _ALIGN(A) hash[8]; 101 | uint32_t _ALIGN(A) vhashcpu[8]; 102 | uint32_t _ALIGN(A) inputdata[20]; 103 | uint32_t *pdata = work->data; 104 | uint32_t *ptarget = work->target; 105 | 106 | const uint32_t Htarg = ptarget[7]; 107 | const uint32_t first_nonce = pdata[8]; 108 | 109 | uint32_t n = first_nonce; 110 | 111 | memcpy(inputdata, pdata, 80); 112 | inputdata[11] = 0; // nbits 113 | 114 | do { 115 | inputdata[8] = n; 116 | blake2b_hash(hash, inputdata); 117 | if (swab32(hash[0]) < Htarg) { 118 | swab256(vhashcpu, hash); 119 | if (fulltest(vhashcpu, ptarget)) { 120 | work_set_target_ratio(work, vhashcpu); 121 | *hashes_done = n - first_nonce + 1; 122 | pdata[8] = n; 123 | return 1; 124 | } 125 | } 126 | n++; 127 | 128 | } while (n < max_nonce && !work_restart[thr_id].restart); 129 | 130 | *hashes_done = n - first_nonce + 1; 131 | pdata[8] = n; 132 | 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /algo/sibcoin.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/gost_streebog.h" 16 | #include "sha3/sph_cubehash.h" 17 | #include "sha3/sph_shavite.h" 18 | #include "sha3/sph_simd.h" 19 | #include "sha3/sph_echo.h" 20 | 21 | /* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */ 22 | void sibhash(void *output, const void *input) 23 | { 24 | sph_blake512_context ctx_blake; 25 | sph_bmw512_context ctx_bmw; 26 | sph_groestl512_context ctx_groestl; 27 | sph_skein512_context ctx_skein; 28 | sph_jh512_context ctx_jh; 29 | sph_keccak512_context ctx_keccak; 30 | sph_gost512_context ctx_gost; 31 | sph_luffa512_context ctx_luffa; 32 | sph_cubehash512_context ctx_cubehash; 33 | sph_shavite512_context ctx_shavite; 34 | sph_simd512_context ctx_simd; 35 | sph_echo512_context ctx_echo; 36 | 37 | //these uint512 in the c++ source of the client are backed by an array of uint32 38 | uint32_t _ALIGN(64) hashA[16], hashB[16]; 39 | 40 | sph_blake512_init(&ctx_blake); 41 | sph_blake512(&ctx_blake, input, 80); 42 | sph_blake512_close(&ctx_blake, hashA); 43 | 44 | sph_bmw512_init(&ctx_bmw); 45 | sph_bmw512(&ctx_bmw, hashA, 64); 46 | sph_bmw512_close(&ctx_bmw, hashB); 47 | 48 | sph_groestl512_init(&ctx_groestl); 49 | sph_groestl512(&ctx_groestl, hashB, 64); 50 | sph_groestl512_close(&ctx_groestl, hashA); 51 | 52 | sph_skein512_init(&ctx_skein); 53 | sph_skein512(&ctx_skein, hashA, 64); 54 | sph_skein512_close(&ctx_skein, hashB); 55 | 56 | sph_jh512_init(&ctx_jh); 57 | sph_jh512(&ctx_jh, hashB, 64); 58 | sph_jh512_close(&ctx_jh, hashA); 59 | 60 | sph_keccak512_init(&ctx_keccak); 61 | sph_keccak512(&ctx_keccak, hashA, 64); 62 | sph_keccak512_close(&ctx_keccak, hashB); 63 | 64 | sph_gost512_init(&ctx_gost); 65 | sph_gost512(&ctx_gost, hashB, 64); 66 | sph_gost512_close(&ctx_gost, hashA); 67 | 68 | sph_luffa512_init(&ctx_luffa); 69 | sph_luffa512(&ctx_luffa, hashA, 64); 70 | sph_luffa512_close(&ctx_luffa, hashB); 71 | 72 | sph_cubehash512_init(&ctx_cubehash); 73 | sph_cubehash512(&ctx_cubehash, hashB, 64); 74 | sph_cubehash512_close(&ctx_cubehash, hashA); 75 | 76 | sph_shavite512_init(&ctx_shavite); 77 | sph_shavite512(&ctx_shavite, hashA, 64); 78 | sph_shavite512_close(&ctx_shavite, hashB); 79 | 80 | sph_simd512_init(&ctx_simd); 81 | sph_simd512(&ctx_simd, hashB, 64); 82 | sph_simd512_close(&ctx_simd, hashA); 83 | 84 | sph_echo512_init(&ctx_echo); 85 | sph_echo512(&ctx_echo, hashA, 64); 86 | sph_echo512_close(&ctx_echo, hashB); 87 | 88 | memcpy(output, hashB, 32); 89 | } 90 | 91 | int scanhash_sib(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 92 | { 93 | uint32_t _ALIGN(128) hash[8]; 94 | uint32_t _ALIGN(128) endiandata[20]; 95 | uint32_t *pdata = work->data; 96 | uint32_t *ptarget = work->target; 97 | 98 | const uint32_t Htarg = ptarget[7]; 99 | const uint32_t first_nonce = pdata[19]; 100 | uint32_t nonce = first_nonce; 101 | volatile uint8_t *restart = &(work_restart[thr_id].restart); 102 | 103 | if (opt_benchmark) 104 | ptarget[7] = 0x0cff; 105 | 106 | // we need bigendian data... 107 | for (int i=0; i < 19; i++) { 108 | be32enc(&endiandata[i], pdata[i]); 109 | } 110 | do { 111 | be32enc(&endiandata[19], nonce); 112 | sibhash(hash, endiandata); 113 | 114 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 115 | work_set_target_ratio(work, hash); 116 | pdata[19] = nonce; 117 | *hashes_done = pdata[19] - first_nonce; 118 | return 1; 119 | } 120 | nonce++; 121 | 122 | } while (nonce < max_nonce && !(*restart)); 123 | 124 | pdata[19] = nonce; 125 | *hashes_done = pdata[19] - first_nonce + 1; 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /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/yespower/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litecoincash-project/cpuminer-multi/5710e52b064d2077a53d3db3ae6b1a7febbec45b/algo/yespower/.dirstamp -------------------------------------------------------------------------------- /algo/yespower/crypto/.dirstamp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/litecoincash-project/cpuminer-multi/5710e52b064d2077a53d3db3ae6b1a7febbec45b/algo/yespower/crypto/.dirstamp -------------------------------------------------------------------------------- /algo/yespower/util/insecure_memzero.h: -------------------------------------------------------------------------------- 1 | #define insecure_memzero(buf, len) /* empty */ 2 | -------------------------------------------------------------------------------- /algo/yespower/util/sysendian.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2007-2014 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 | 27 | #ifndef _SYSENDIAN_H_ 28 | #define _SYSENDIAN_H_ 29 | 30 | #include 31 | 32 | /* Avoid namespace collisions with BSD . */ 33 | #define be32dec libcperciva_be32dec 34 | #define be32enc libcperciva_be32enc 35 | #define be64enc libcperciva_be64enc 36 | #define le32dec libcperciva_le32dec 37 | #define le32enc libcperciva_le32enc 38 | 39 | static inline uint32_t 40 | be32dec(const void * pp) 41 | { 42 | const uint8_t * p = (uint8_t const *)pp; 43 | 44 | return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + 45 | ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); 46 | } 47 | 48 | static inline void 49 | be32enc(void * pp, uint32_t x) 50 | { 51 | uint8_t * p = (uint8_t *)pp; 52 | 53 | p[3] = x & 0xff; 54 | p[2] = (x >> 8) & 0xff; 55 | p[1] = (x >> 16) & 0xff; 56 | p[0] = (x >> 24) & 0xff; 57 | } 58 | 59 | static inline void 60 | be64enc(void * pp, uint64_t x) 61 | { 62 | uint8_t * p = (uint8_t *)pp; 63 | 64 | p[7] = x & 0xff; 65 | p[6] = (x >> 8) & 0xff; 66 | p[5] = (x >> 16) & 0xff; 67 | p[4] = (x >> 24) & 0xff; 68 | p[3] = (x >> 32) & 0xff; 69 | p[2] = (x >> 40) & 0xff; 70 | p[1] = (x >> 48) & 0xff; 71 | p[0] = (x >> 56) & 0xff; 72 | } 73 | 74 | static inline uint32_t 75 | le32dec(const void * pp) 76 | { 77 | const uint8_t * p = (uint8_t const *)pp; 78 | 79 | return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + 80 | ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); 81 | } 82 | 83 | static inline void 84 | le32enc(void * pp, uint32_t x) 85 | { 86 | uint8_t * p = (uint8_t *)pp; 87 | 88 | p[0] = x & 0xff; 89 | p[1] = (x >> 8) & 0xff; 90 | p[2] = (x >> 16) & 0xff; 91 | p[3] = (x >> 24) & 0xff; 92 | } 93 | 94 | #endif /* !_SYSENDIAN_H_ */ 95 | -------------------------------------------------------------------------------- /algo/zr5.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 | #define ZR_BLAKE 0 15 | #define ZR_GROESTL 1 16 | #define ZR_JH512 2 17 | #define ZR_SKEIN 3 18 | 19 | #define POK_BOOL_MASK 0x00008000 20 | #define POK_DATA_MASK 0xFFFF0000 21 | 22 | static const int permut[24][4] = { 23 | {0, 1, 2, 3}, 24 | {0, 1, 3, 2}, 25 | {0, 2, 1, 3}, 26 | {0, 2, 3, 1}, 27 | {0, 3, 1, 2}, 28 | {0, 3, 2, 1}, 29 | {1, 0, 2, 3}, 30 | {1, 0, 3, 2}, 31 | {1, 2, 0, 3}, 32 | {1, 2, 3, 0}, 33 | {1, 3, 0, 2}, 34 | {1, 3, 2, 0}, 35 | {2, 0, 1, 3}, 36 | {2, 0, 3, 1}, 37 | {2, 1, 0, 3}, 38 | {2, 1, 3, 0}, 39 | {2, 3, 0, 1}, 40 | {2, 3, 1, 0}, 41 | {3, 0, 1, 2}, 42 | {3, 0, 2, 1}, 43 | {3, 1, 0, 2}, 44 | {3, 1, 2, 0}, 45 | {3, 2, 0, 1}, 46 | {3, 2, 1, 0} 47 | }; 48 | 49 | void zr5hash(void *output, const void *input) 50 | { 51 | sph_keccak512_context ctx_keccak; 52 | sph_blake512_context ctx_blake; 53 | sph_groestl512_context ctx_groestl; 54 | sph_jh512_context ctx_jh; 55 | sph_skein512_context ctx_skein; 56 | 57 | uchar _ALIGN(64) hash[64]; 58 | uint32_t *phash = (uint32_t *) hash; 59 | uint32_t norder; 60 | 61 | sph_keccak512_init(&ctx_keccak); 62 | sph_keccak512(&ctx_keccak, (const void*) input, 80); 63 | sph_keccak512_close(&ctx_keccak, (void*) phash); 64 | 65 | norder = phash[0] % ARRAY_SIZE(permut); /* % 24 */ 66 | 67 | for(int i = 0; i < 4; i++) 68 | { 69 | switch (permut[norder][i]) { 70 | case ZR_BLAKE: 71 | sph_blake512_init(&ctx_blake); 72 | sph_blake512(&ctx_blake, (const void*) phash, 64); 73 | sph_blake512_close(&ctx_blake, phash); 74 | break; 75 | case ZR_GROESTL: 76 | sph_groestl512_init(&ctx_groestl); 77 | sph_groestl512(&ctx_groestl, (const void*) phash, 64); 78 | sph_groestl512_close(&ctx_groestl, phash); 79 | break; 80 | case ZR_JH512: 81 | sph_jh512_init(&ctx_jh); 82 | sph_jh512(&ctx_jh, (const void*) phash, 64); 83 | sph_jh512_close(&ctx_jh, phash); 84 | break; 85 | case ZR_SKEIN: 86 | sph_skein512_init(&ctx_skein); 87 | sph_skein512(&ctx_skein, (const void*) phash, 64); 88 | sph_skein512_close(&ctx_skein, phash); 89 | break; 90 | default: 91 | break; 92 | } 93 | } 94 | memcpy(output, phash, 32); 95 | } 96 | 97 | void zr5hash_pok(void *output, uint32_t *pdata) 98 | { 99 | const uint32_t version = pdata[0] & (~POK_DATA_MASK); 100 | uint32_t _ALIGN(64) hash[8]; 101 | uint32_t pok; 102 | 103 | pdata[0] = version; 104 | zr5hash(hash, pdata); 105 | 106 | // fill PoK 107 | pok = version | (hash[0] & POK_DATA_MASK); 108 | if (pdata[0] != pok) { 109 | pdata[0] = pok; 110 | zr5hash(hash, pdata); 111 | } 112 | memcpy(output, hash, 32); 113 | } 114 | 115 | int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 116 | { 117 | uint32_t _ALIGN(64) hash[16]; 118 | uint32_t *pdata = work->data; 119 | uint32_t *ptarget = work->target; 120 | const uint32_t first_nonce = pdata[19]; 121 | uint32_t nonce = first_nonce; 122 | #define tmpdata pdata 123 | 124 | if (opt_benchmark) 125 | ptarget[7] = 0x00ff; 126 | 127 | do { 128 | tmpdata[19] = nonce; 129 | zr5hash_pok(hash, tmpdata); 130 | 131 | if (hash[7] <= ptarget[7] && fulltest(hash, ptarget)) 132 | { 133 | work_set_target_ratio(work, hash); 134 | pdata[0] = tmpdata[0]; 135 | pdata[19] = nonce; 136 | *hashes_done = pdata[19] - first_nonce + 1; 137 | return 1; 138 | } 139 | nonce++; 140 | 141 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 142 | 143 | pdata[19] = nonce; 144 | *hashes_done = pdata[19] - first_nonce + 1; 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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-linux-arm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Linux build, optimised for ARM devices 4 | 5 | if [ ! -e configure ]; then 6 | echo "Creating configure..." 7 | rm -rf autom4te.cache 8 | rm -f Makefile.in aclocal.m4 autom4te.cache compat/Makefile.in 9 | rm -f compile config.guess config.sub config.status configure 10 | rm -f cpuminer-config.h.in depcomp install-sh missing 11 | if ./autogen.sh; then 12 | echo " => done." 13 | else 14 | exit 1 15 | fi 16 | fi 17 | 18 | if [ -e Makefile ]; then 19 | echo "Cleaning previous build..." 20 | make distclean 21 | echo " => done." 22 | fi 23 | 24 | echo "Configuring..." 25 | 26 | # --disable-assembly: some ASM code doesn't build on ARM 27 | # Note: we don't enable -flto, it doesn't bring anything here but slows down 28 | # the build a lot. If needed, just add -flto to the CFLAGS string. 29 | # normal build. 30 | ./configure --with-crypto --with-curl --disable-assembly CC=gcc CXX=g++ CFLAGS="-Ofast -fuse-linker-plugin -ftree-loop-if-convert-stores -march=native" LDFLAGS="-march=native" 31 | 32 | # debug build 33 | #./configure --with-crypto --with-curl --disable-assembly CC=gcc CXX=g++ CFLAGS="-O0 -g3 -fuse-linker-plugin -ftree-loop-if-convert-stores -march=native" LDFLAGS="-g3 -march=native" 34 | 35 | [ $? = 0 ] || exit $? 36 | echo " => done." 37 | 38 | if [ -z "$NPROC" ]; then 39 | NPROC=$(nproc 2>/dev/null) 40 | NPROC=${NPROC:-1} 41 | fi 42 | 43 | echo "Compiling on $NPROC processes..." 44 | 45 | make -j $NPROC 46 | 47 | if [ $? != 0 ]; then 48 | echo "Compilation failed (make=$?)". 49 | echo "Common causes: missing libjansson-dev libcurl4-openssl-dev libssl-dev" 50 | echo "If you pulled updates into this directory, remove configure and try again." 51 | exit 1 52 | fi 53 | echo " => done." 54 | 55 | echo '$ ls -l cpuminer' 56 | ls -l cpuminer 57 | 58 | echo "Stripping..." 59 | 60 | strip -s cpuminer 61 | 62 | [ $? = 0 ] || exit $? 63 | echo " => done." 64 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make clean || echo clean 4 | 5 | rm -f config.status 6 | ./autogen.sh 7 | 8 | if [[ "$OSTYPE" == "darwin"* ]]; then 9 | ./nomacro.pl 10 | ./configure \ 11 | CFLAGS="-march=native -O2 -Ofast -flto -DUSE_ASM -pg" \ 12 | --with-crypto=/usr/local/opt/openssl \ 13 | --with-curl=/usr/local/opt/curl 14 | make -j4 15 | strip cpuminer 16 | exit 0 17 | fi 18 | 19 | # Linux build 20 | 21 | # Ubuntu 10.04 (gcc 4.4) 22 | # 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" 23 | 24 | # Debian 7.7 / Ubuntu 14.04 (gcc 4.7+) 25 | extracflags="$extracflags -Ofast -flto -fuse-linker-plugin -ftree-loop-if-convert-stores" 26 | 27 | if [ ! "0" = `cat /proc/cpuinfo | grep -c avx` ]; then 28 | # march native doesn't always works, ex. some Pentium Gxxx (no avx) 29 | extracflags="$extracflags -march=native" 30 | fi 31 | 32 | ./configure --with-crypto --with-curl CFLAGS="-O2 $extracflags -DUSE_ASM -pg" 33 | 34 | make -j 4 35 | 36 | strip -s cpuminer 37 | -------------------------------------------------------------------------------- /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/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WANT_JANSSON 3 | SUBDIRS = jansson 4 | else 5 | SUBDIRS = 6 | endif 7 | 8 | -------------------------------------------------------------------------------- /compat/bionic/cpuminer-config.h: -------------------------------------------------------------------------------- 1 | /* cpuminer-config.h.in. Adapted for arm bionic (Android 5.1.1 Tegra K1) */ 2 | 3 | /* Define to 1 if using `alloca.c'. */ 4 | /* #undef C_ALLOCA */ 5 | 6 | /* Define to 1 if you have `alloca', as a function or macro. */ 7 | #define HAVE_ALLOCA 1 8 | 9 | /* Define to 1 if you have and it should be used (not on Ultrix). 10 | */ 11 | #define HAVE_ALLOCA_H 1 12 | 13 | /* Define to 1 if you have the declaration of `be32dec', and to 0 if you 14 | don't. */ 15 | #define HAVE_DECL_BE32DEC 0 16 | 17 | /* Define to 1 if you have the declaration of `be32enc', and to 0 if you 18 | don't. */ 19 | #define HAVE_DECL_BE32ENC 0 20 | 21 | /* Define to 1 if you have the declaration of `le16dec', and to 0 if you 22 | don't. */ 23 | #define HAVE_DECL_LE16DEC 0 24 | 25 | /* Define to 1 if you have the declaration of `le16enc', and to 0 if you 26 | don't. */ 27 | #define HAVE_DECL_LE16ENC 0 28 | 29 | /* Define to 1 if you have the declaration of `le32dec', and to 0 if you 30 | don't. */ 31 | #define HAVE_DECL_LE32DEC 0 32 | 33 | /* Define to 1 if you have the declaration of `le32enc', and to 0 if you 34 | don't. */ 35 | #define HAVE_DECL_LE32ENC 0 36 | 37 | /* Define to 1 if you have the `getopt_long' function. */ 38 | #define HAVE_GETOPT_LONG 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_INTTYPES_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_MEMORY_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_STDINT_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_STDLIB_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_STRINGS_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_STRING_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_SYSLOG_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | /* #undef HAVE_SYS_ENDIAN_H */ 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_SYS_PARAM_H 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_SYS_STAT_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #undef HAVE_SYS_SYSCTL_H 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_SYS_TYPES_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_UNISTD_H 1 78 | 79 | /* Name of package */ 80 | #define PACKAGE "cpuminer-multi" 81 | 82 | /* Define to the address where bug reports for this package should be sent. */ 83 | #define PACKAGE_BUGREPORT "" 84 | 85 | /* Define to the full name of this package. */ 86 | #define PACKAGE_NAME "cpuminer-multi" 87 | 88 | /* Define to the full name and version of this package. */ 89 | #define PACKAGE_STRING "cpuminer-multi " VERSION 90 | 91 | /* Define to the one symbol short name of this package. */ 92 | #define PACKAGE_TARNAME "cpuminer-multi" 93 | 94 | /* Define to the home page for this package. */ 95 | #define PACKAGE_URL "http://github.com/tpruvot/cpuminer-multi" 96 | 97 | /* Define to the version of this package. */ 98 | #define PACKAGE_VERSION VERSION 99 | 100 | /* If using the C implementation of alloca, define if you know the 101 | direction of stack growth for your system; otherwise it will be 102 | automatically deduced at runtime. 103 | STACK_DIRECTION > 0 => grows toward higher addresses 104 | STACK_DIRECTION < 0 => grows toward lower addresses 105 | STACK_DIRECTION = 0 => direction of growth unknown */ 106 | /* #undef STACK_DIRECTION */ 107 | 108 | /* Define to 1 if you have the ANSI C header files. */ 109 | #define STDC_HEADERS 1 110 | 111 | /* Define to 1 if assembly routines are wanted. */ 112 | #define USE_ASM 1 113 | 114 | /* Define to 1 if AVX assembly is available. */ 115 | #define USE_AVX 1 116 | 117 | /* Define to 1 if AVX2 assembly is available. */ 118 | #define USE_AVX2 1 119 | 120 | /* Define if __uint128_t is available */ 121 | #undef USE_INT128 122 | 123 | /* Define to 1 if XOP assembly is available. */ 124 | #define USE_XOP 1 125 | 126 | /* Define to `unsigned int' if does not define. */ 127 | #undef size_t 128 | 129 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/curlver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLVER_H 2 | #define __CURL_CURLVER_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2014, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* This header file contains nothing but libcurl version info, generated by 26 | a script at release-time. This was made its own header file in 7.11.2 */ 27 | 28 | /* This is the global package copyright */ 29 | #define LIBCURL_COPYRIGHT "1996 - 2014 Daniel Stenberg, ." 30 | 31 | /* This is the version number of the libcurl package from which this header 32 | file origins: */ 33 | #define LIBCURL_VERSION "7.38.0" 34 | 35 | /* The numeric version number is also available "in parts" by using these 36 | defines: */ 37 | #define LIBCURL_VERSION_MAJOR 7 38 | #define LIBCURL_VERSION_MINOR 38 39 | #define LIBCURL_VERSION_PATCH 0 40 | 41 | /* This is the numeric version of the libcurl version number, meant for easier 42 | parsing and comparions by programs. The LIBCURL_VERSION_NUM define will 43 | always follow this syntax: 44 | 45 | 0xXXYYZZ 46 | 47 | Where XX, YY and ZZ are the main version, release and patch numbers in 48 | hexadecimal (using 8 bits each). All three numbers are always represented 49 | using two digits. 1.2 would appear as "0x010200" while version 9.11.7 50 | appears as "0x090b07". 51 | 52 | This 6-digit (24 bits) hexadecimal number does not show pre-release number, 53 | and it is always a greater number in a more recent release. It makes 54 | comparisons with greater than and less than work. 55 | */ 56 | #define LIBCURL_VERSION_NUM 0x072600 57 | 58 | /* 59 | * This is the date and time when the full source package was created. The 60 | * timestamp is not stored in git, as the timestamp is properly set in the 61 | * tarballs by the maketgz script. 62 | * 63 | * The format of the date should follow this template: 64 | * 65 | * "Mon Feb 12 11:35:33 UTC 2007" 66 | */ 67 | #define LIBCURL_TIMESTAMP "Mon Nov 03 12:00:00 UTC 2014" 68 | 69 | #endif /* __CURL_CURLVER_H */ 70 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/easy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_EASY_H 2 | #define __CURL_EASY_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | CURL_EXTERN CURL *curl_easy_init(void); 29 | CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); 30 | CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); 31 | CURL_EXTERN void curl_easy_cleanup(CURL *curl); 32 | 33 | /* 34 | * NAME curl_easy_getinfo() 35 | * 36 | * DESCRIPTION 37 | * 38 | * Request internal information from the curl session with this function. The 39 | * third argument MUST be a pointer to a long, a pointer to a char * or a 40 | * pointer to a double (as the documentation describes elsewhere). The data 41 | * pointed to will be filled in accordingly and can be relied upon only if the 42 | * function returns CURLE_OK. This function is intended to get used *AFTER* a 43 | * performed transfer, all results from this function are undefined until the 44 | * transfer is completed. 45 | */ 46 | CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); 47 | 48 | 49 | /* 50 | * NAME curl_easy_duphandle() 51 | * 52 | * DESCRIPTION 53 | * 54 | * Creates a new curl session handle with the same options set for the handle 55 | * passed in. Duplicating a handle could only be a matter of cloning data and 56 | * options, internal state info and things like persistent connections cannot 57 | * be transferred. It is useful in multithreaded applications when you can run 58 | * curl_easy_duphandle() for each new thread to avoid a series of identical 59 | * curl_easy_setopt() invokes in every thread. 60 | */ 61 | CURL_EXTERN CURL* curl_easy_duphandle(CURL *curl); 62 | 63 | /* 64 | * NAME curl_easy_reset() 65 | * 66 | * DESCRIPTION 67 | * 68 | * Re-initializes a CURL handle to the default values. This puts back the 69 | * handle to the same state as it was in when it was just created. 70 | * 71 | * It does keep: live connections, the Session ID cache, the DNS cache and the 72 | * cookies. 73 | */ 74 | CURL_EXTERN void curl_easy_reset(CURL *curl); 75 | 76 | /* 77 | * NAME curl_easy_recv() 78 | * 79 | * DESCRIPTION 80 | * 81 | * Receives data from the connected socket. Use after successful 82 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 83 | */ 84 | CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, 85 | size_t *n); 86 | 87 | /* 88 | * NAME curl_easy_send() 89 | * 90 | * DESCRIPTION 91 | * 92 | * Sends data over the connected socket. Use after successful 93 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 94 | */ 95 | CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, 96 | size_t buflen, size_t *n); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MPRINTF_H 2 | #define __CURL_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2013, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | #include /* needed for FILE */ 27 | 28 | #include "curl.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | CURL_EXTERN int curl_mprintf(const char *format, ...); 35 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 36 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 37 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, 38 | const char *format, ...); 39 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 40 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 42 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, 43 | const char *format, va_list args); 44 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 45 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 46 | 47 | #ifdef _MPRINTF_REPLACE 48 | # undef printf 49 | # undef fprintf 50 | # undef sprintf 51 | # undef vsprintf 52 | # undef snprintf 53 | # undef vprintf 54 | # undef vfprintf 55 | # undef vsnprintf 56 | # undef aprintf 57 | # undef vaprintf 58 | # define printf curl_mprintf 59 | # define fprintf curl_mfprintf 60 | #ifdef CURLDEBUG 61 | /* When built with CURLDEBUG we define away the sprintf functions since we 62 | don't want internal code to be using them */ 63 | # define sprintf sprintf_was_used 64 | # define vsprintf vsprintf_was_used 65 | #else 66 | # define sprintf curl_msprintf 67 | # define vsprintf curl_mvsprintf 68 | #endif 69 | # define snprintf curl_msnprintf 70 | # define vprintf curl_mvprintf 71 | # define vfprintf curl_mvfprintf 72 | # define vsnprintf curl_mvsnprintf 73 | # define aprintf curl_maprintf 74 | # define vaprintf curl_mvaprintf 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __CURL_MPRINTF_H */ 82 | -------------------------------------------------------------------------------- /compat/curl-for-windows/curl/include/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDC_HEADERS_H 2 | #define __STDC_HEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | size_t fread (void *, size_t, size_t, FILE *); 28 | size_t fwrite (const void *, size_t, size_t, FILE *); 29 | 30 | int strcasecmp(const char *, const char *); 31 | int strncasecmp(const char *, const char *, size_t); 32 | 33 | #endif /* __STDC_HEADERS_H */ 34 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/crypto/opensslconf.h: -------------------------------------------------------------------------------- 1 | #include "../../config/opensslconf.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/e_os2.h: -------------------------------------------------------------------------------- 1 | #include "../../e_os2.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | #include "../../crypto/opensslconf.h" 2 | -------------------------------------------------------------------------------- /compat/curl-for-windows/openssl/openssl/include/openssl/sha.h: -------------------------------------------------------------------------------- 1 | #include "../../crypto/sha/sha.h" 2 | -------------------------------------------------------------------------------- /compat/getopt/getopt.h: -------------------------------------------------------------------------------- 1 | /* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */ 2 | /* $OpenBSD: getopt.h,v 1.1 2002/12/03 20:24:29 millert Exp $ */ 3 | /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ 4 | 5 | /*- 6 | * Copyright (c) 2000 The NetBSD Foundation, Inc. 7 | * All rights reserved. 8 | * 9 | * This code is derived from software contributed to The NetBSD Foundation 10 | * by Dieter Baron and Thomas Klausner. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. All advertising materials mentioning features or use of this software 21 | * must display the following acknowledgement: 22 | * This product includes software developed by the NetBSD 23 | * Foundation, Inc. and its contributors. 24 | * 4. Neither the name of The NetBSD Foundation nor the names of its 25 | * contributors may be used to endorse or promote products derived 26 | * from this software without specific prior written permission. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | */ 40 | 41 | #ifndef _GETOPT_H_ 42 | #define _GETOPT_H_ 43 | 44 | #if 0 45 | #include 46 | #endif 47 | 48 | /* 49 | * GNU-like getopt_long() and 4.4BSD getsubopt()/optreset extensions 50 | */ 51 | #define no_argument 0 52 | #define required_argument 1 53 | #define optional_argument 2 54 | 55 | struct option { 56 | /* name of long option */ 57 | const char *name; 58 | /* 59 | * one of no_argument, required_argument, and optional_argument: 60 | * whether option takes an argument 61 | */ 62 | int has_arg; 63 | /* if not NULL, set *flag to val when option found */ 64 | int *flag; 65 | /* if flag not NULL, value to set *flag to; else return value */ 66 | int val; 67 | }; 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | int getopt_long(int, char * const *, const char *, 74 | const struct option *, int *); 75 | int getopt_long_only(int, char * const *, const char *, 76 | const struct option *, int *); 77 | #ifndef _GETOPT_DEFINED 78 | #define _GETOPT_DEFINED 79 | int getopt(int, char * const *, const char *); 80 | int getsubopt(char **, char * const *, char **); 81 | 82 | extern char *optarg; /* getopt(3) external variables */ 83 | extern int opterr; 84 | extern int optind; 85 | extern int optopt; 86 | extern int optreset; 87 | extern char *suboptarg; /* getsubopt(3) external variable */ 88 | #endif /* _GETOPT_DEFINED */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | #endif /* !_GETOPT_H_ */ 94 | -------------------------------------------------------------------------------- /compat/gettimeofday.c: -------------------------------------------------------------------------------- 1 | #include < time.h > 2 | #include //I've ommited this line. 3 | #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 4 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 5 | #else 6 | #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 7 | #endif 8 | 9 | struct timezone 10 | { 11 | int tz_minuteswest; /* minutes W of Greenwich */ 12 | int tz_dsttime; /* type of dst correction */ 13 | }; 14 | 15 | int gettimeofday(struct timeval *tv, struct timezone *tz) 16 | { 17 | FILETIME ft; 18 | unsigned __int64 tmpres = 0; 19 | static int tzflag; 20 | 21 | if (NULL != tv) 22 | { 23 | GetSystemTimeAsFileTime(&ft); 24 | 25 | tmpres |= ft.dwHighDateTime; 26 | tmpres <<= 32; 27 | tmpres |= ft.dwLowDateTime; 28 | 29 | /*converting file time to unix epoch*/ 30 | tmpres /= 10; /*convert into microseconds*/ 31 | tmpres -= DELTA_EPOCH_IN_MICROSECS; 32 | tv->tv_sec = (long)(tmpres / 1000000UL); 33 | tv->tv_usec = (long)(tmpres % 1000000UL); 34 | } 35 | 36 | if (NULL != tz) 37 | { 38 | if (!tzflag) 39 | { 40 | _tzset(); 41 | tzflag++; 42 | } 43 | tz->tz_minuteswest = _timezone / 60; 44 | tz->tz_dsttime = _daylight; 45 | } 46 | 47 | return 0; 48 | } 49 | 50 | void usleep(__int64 waitTime) 51 | { 52 | if (waitTime > 0) 53 | { 54 | if (waitTime > 100) 55 | { 56 | // use a waitable timer for larger intervals > 0.1ms 57 | 58 | HANDLE timer; 59 | LARGE_INTEGER ft; 60 | 61 | ft.QuadPart = -(10*waitTime); // Convert to 100 nanosecond interval, negative value indicates relative time 62 | 63 | timer = CreateWaitableTimer(NULL, TRUE, NULL); 64 | SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); 65 | WaitForSingleObject(timer, INFINITE); 66 | CloseHandle(timer); 67 | } 68 | else 69 | { 70 | // use a polling loop for short intervals <= 100ms 71 | 72 | LARGE_INTEGER perfCnt, start, now; 73 | __int64 elapsed; 74 | 75 | QueryPerformanceFrequency(&perfCnt); 76 | QueryPerformanceCounter(&start); 77 | do { 78 | QueryPerformanceCounter((LARGE_INTEGER*) &now); 79 | elapsed = (__int64)((now.QuadPart - start.QuadPart) / (float)perfCnt.QuadPart * 1000 * 1000); 80 | } while ( elapsed < waitTime ); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /compat/inttypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | -------------------------------------------------------------------------------- /compat/jansson/.gitignore: -------------------------------------------------------------------------------- 1 | *.h.in 2 | *.h.in~ 3 | libtool 4 | libjansson.a 5 | -------------------------------------------------------------------------------- /compat/jansson/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, 2010 Petri Lehtinen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /compat/jansson/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_LIBRARIES = libjansson.a 3 | 4 | libjansson_a_SOURCES = \ 5 | config.h \ 6 | dump.c \ 7 | error.c \ 8 | hashtable.c hashtable.h \ 9 | jansson.h \ 10 | jansson_config.h \ 11 | jansson_private.h \ 12 | load.c \ 13 | memory.c \ 14 | pack_unpack.c \ 15 | strbuffer.c strbuffer.h \ 16 | strconv.c \ 17 | utf.c utf.h \ 18 | util.h \ 19 | value.c 20 | 21 | -------------------------------------------------------------------------------- /compat/jansson/configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.60]) 2 | AC_INIT([jansson], [2.6], [petri@digip.org]) 3 | 4 | AC_CONFIG_MACRO_DIR([m4]) 5 | 6 | AM_INIT_AUTOMAKE([1.10 foreign]) 7 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 8 | 9 | AC_CONFIG_SRCDIR([value.c]) 10 | AC_CONFIG_HEADERS([config.h]) 11 | 12 | # Checks for programs. 13 | AC_PROG_CC 14 | AC_PROG_LIBTOOL 15 | AM_CONDITIONAL([GCC], [test x$GCC = xyes]) 16 | 17 | # Checks for libraries. 18 | 19 | # Checks for header files. 20 | AC_CHECK_HEADERS([endian.h fcntl.h locale.h sched.h unistd.h sys/param.h sys/stat.h sys/time.h sys/types.h]) 21 | 22 | # Checks for typedefs, structures, and compiler characteristics. 23 | AC_TYPE_INT32_T 24 | AC_TYPE_UINT32_T 25 | AC_TYPE_LONG_LONG_INT 26 | 27 | AC_C_INLINE 28 | case $ac_cv_c_inline in 29 | yes) json_inline=inline;; 30 | no) json_inline=;; 31 | *) json_inline=$ac_cv_c_inline;; 32 | esac 33 | AC_SUBST([json_inline]) 34 | 35 | # Checks for library functions. 36 | AC_CHECK_FUNCS([close getpid gettimeofday localeconv open read sched_yield strtoll]) 37 | 38 | AC_MSG_CHECKING([for gcc __sync builtins]) 39 | have_sync_builtins=no 40 | AC_TRY_LINK( 41 | [], [unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1);], 42 | [have_sync_builtins=yes], 43 | ) 44 | if test "x$have_sync_builtins" = "xyes"; then 45 | AC_DEFINE([HAVE_SYNC_BUILTINS], [1], 46 | [Define to 1 if gcc's __sync builtins are available]) 47 | fi 48 | AC_MSG_RESULT([$have_sync_builtins]) 49 | 50 | AC_MSG_CHECKING([for gcc __atomic builtins]) 51 | have_atomic_builtins=no 52 | AC_TRY_LINK( 53 | [], [char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_ACQ_REL); __atomic_load_n(&v, __ATOMIC_ACQUIRE);], 54 | [have_atomic_builtins=yes], 55 | ) 56 | if test "x$have_atomic_builtins" = "xyes"; then 57 | AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1], 58 | [Define to 1 if gcc's __atomic builtins are available]) 59 | fi 60 | AC_MSG_RESULT([$have_atomic_builtins]) 61 | 62 | case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in 63 | yesyes) json_have_long_long=1;; 64 | *) json_have_long_long=0;; 65 | esac 66 | AC_SUBST([json_have_long_long]) 67 | 68 | case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in 69 | yesyes) json_have_localeconv=1;; 70 | *) json_have_localeconv=0;; 71 | esac 72 | AC_SUBST([json_have_localeconv]) 73 | 74 | # Features 75 | AC_ARG_ENABLE([urandom], 76 | [AS_HELP_STRING([--disable-urandom], 77 | [Don't use /dev/urandom to seed the hash function])], 78 | [use_urandom=$enableval], [use_urandom=yes]) 79 | 80 | if test "x$use_urandom" = xyes; then 81 | AC_DEFINE([USE_URANDOM], [1], 82 | [Define to 1 if /dev/urandom should be used for seeding the hash function]) 83 | fi 84 | 85 | AC_ARG_ENABLE([windows-cryptoapi], 86 | [AS_HELP_STRING([--disable-windows-cryptoapi], 87 | [Don't use CryptGenRandom to seed the hash function])], 88 | [use_windows_cryptoapi=$enableval], [use_windows_cryptoapi=yes]) 89 | 90 | if test "x$use_windows_cryptoapi" = xyes; then 91 | AC_DEFINE([USE_WINDOWS_CRYPTOAPI], [1], 92 | [Define to 1 if CryptGenRandom should be used for seeding the hash function]) 93 | fi 94 | 95 | AC_CONFIG_FILES([ 96 | Makefile 97 | ]) 98 | AC_OUTPUT 99 | -------------------------------------------------------------------------------- /compat/jansson/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "jansson_private.h" 3 | 4 | void jsonp_error_init(json_error_t *error, const char *source) 5 | { 6 | if(error) 7 | { 8 | error->text[0] = '\0'; 9 | error->line = -1; 10 | error->column = -1; 11 | error->position = 0; 12 | if(source) 13 | jsonp_error_set_source(error, source); 14 | else 15 | error->source[0] = '\0'; 16 | } 17 | } 18 | 19 | void jsonp_error_set_source(json_error_t *error, const char *source) 20 | { 21 | size_t length; 22 | 23 | if(!error || !source) 24 | return; 25 | 26 | length = strlen(source); 27 | if(length < JSON_ERROR_SOURCE_LENGTH) 28 | strcpy(error->source, source); 29 | else { 30 | size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; 31 | strcpy(error->source, "..."); 32 | strcpy(error->source + 3, source + extra); 33 | } 34 | } 35 | 36 | void jsonp_error_set(json_error_t *error, int line, int column, 37 | size_t position, const char *msg, ...) 38 | { 39 | va_list ap; 40 | 41 | va_start(ap, msg); 42 | jsonp_error_vset(error, line, column, position, msg, ap); 43 | va_end(ap); 44 | } 45 | 46 | void jsonp_error_vset(json_error_t *error, int line, int column, 47 | size_t position, const char *msg, va_list ap) 48 | { 49 | if(!error) 50 | return; 51 | 52 | if(error->text[0] != '\0') { 53 | /* error already set */ 54 | return; 55 | } 56 | 57 | error->line = line; 58 | error->column = column; 59 | error->position = position; 60 | 61 | vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap); 62 | error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0'; 63 | } 64 | -------------------------------------------------------------------------------- /compat/jansson/jansson_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | * 7 | * 8 | * This file specifies a part of the site-specific configuration for 9 | * Jansson, namely those things that affect the public API in 10 | * jansson.h. 11 | * 12 | * The configure script copies this file to jansson_config.h and 13 | * replaces @var@ substitutions by values that fit your system. If you 14 | * cannot run the configure script, you can do the value substitution 15 | * by hand. 16 | */ 17 | 18 | #ifndef JANSSON_CONFIG_H 19 | #define JANSSON_CONFIG_H 20 | /* If your compiler supports the inline keyword in C, JSON_INLINE is 21 | defined to `inline', otherwise empty. In C++, the inline is always 22 | supported. */ 23 | 24 | #ifdef _MSC_VER 25 | #define inline __inline 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | #define JSON_INLINE inline 30 | #else 31 | #define JSON_INLINE inline 32 | #endif 33 | 34 | /* If your compiler supports the `long long` type and the strtoll() 35 | library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, 36 | otherwise to 0. */ 37 | #define JSON_INTEGER_IS_LONG_LONG 1 38 | 39 | /* If locale.h and localeconv() are available, define to 1, 40 | otherwise to 0. */ 41 | #define JSON_HAVE_LOCALECONV 1 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include 12 | #include "jansson.h" 13 | #include "hashtable.h" 14 | #include "strbuffer.h" 15 | 16 | #define container_of(ptr_, type_, member_) \ 17 | ((type_ *)((char *)ptr_ - offsetof(type_, member_))) 18 | 19 | /* On some platforms, max() may already be defined */ 20 | #ifndef max 21 | #define max(a, b) ((a) > (b) ? (a) : (b)) 22 | #endif 23 | 24 | /* va_copy is a C99 feature. In C89 implementations, it's sometimes 25 | available as __va_copy. If not, memcpy() should do the trick. */ 26 | #ifndef va_copy 27 | #ifdef __va_copy 28 | #define va_copy __va_copy 29 | #else 30 | #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list)) 31 | #endif 32 | #endif 33 | 34 | typedef struct { 35 | json_t json; 36 | hashtable_t hashtable; 37 | size_t serial; 38 | int visited; 39 | } json_object_t; 40 | 41 | typedef struct { 42 | json_t json; 43 | size_t size; 44 | size_t entries; 45 | json_t **table; 46 | int visited; 47 | } json_array_t; 48 | 49 | typedef struct { 50 | json_t json; 51 | char *value; 52 | } json_string_t; 53 | 54 | typedef struct { 55 | json_t json; 56 | double value; 57 | } json_real_t; 58 | 59 | typedef struct { 60 | json_t json; 61 | json_int_t value; 62 | } json_integer_t; 63 | 64 | #define json_to_object(json_) container_of(json_, json_object_t, json) 65 | #define json_to_array(json_) container_of(json_, json_array_t, json) 66 | #define json_to_string(json_) container_of(json_, json_string_t, json) 67 | #define json_to_real(json_) container_of(json_, json_real_t, json) 68 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 69 | 70 | void jsonp_error_init(json_error_t *error, const char *source); 71 | void jsonp_error_set_source(json_error_t *error, const char *source); 72 | void jsonp_error_set(json_error_t *error, int line, int column, 73 | size_t position, const char *msg, ...); 74 | void jsonp_error_vset(json_error_t *error, int line, int column, 75 | size_t position, const char *msg, va_list ap); 76 | 77 | /* Locale independent string<->double conversions */ 78 | int jsonp_strtod(strbuffer_t *strbuffer, double *out); 79 | int jsonp_dtostr(char *buffer, size_t size, double value); 80 | 81 | /* Wrappers for custom memory functions */ 82 | void* jsonp_malloc(size_t size); 83 | void jsonp_free(void *ptr); 84 | char *jsonp_strndup(const char *str, size_t length); 85 | char *jsonp_strdup(const char *str); 86 | 87 | /* Windows compatibility */ 88 | #ifdef _WIN32 89 | #define snprintf _snprintf 90 | #define vsnprintf _vsnprintf 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /compat/jansson/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * Copyright (c) 2011-2012 Basile Starynkevitch 4 | * 5 | * Jansson is free software; you can redistribute it and/or modify it 6 | * under the terms of the MIT license. See LICENSE for details. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include "jansson.h" 13 | #include "jansson_private.h" 14 | 15 | /* memory function pointers */ 16 | static json_malloc_t do_malloc = malloc; 17 | static json_free_t do_free = free; 18 | 19 | void *jsonp_malloc(size_t size) 20 | { 21 | if(!size) 22 | return NULL; 23 | 24 | return (*do_malloc)(size); 25 | } 26 | 27 | void jsonp_free(void *ptr) 28 | { 29 | if(!ptr) 30 | return; 31 | 32 | (*do_free)(ptr); 33 | } 34 | 35 | char *jsonp_strdup(const char *str) 36 | { 37 | char *new_str; 38 | size_t len; 39 | 40 | len = strlen(str); 41 | if(len == (size_t)-1) 42 | return NULL; 43 | 44 | new_str = jsonp_malloc(len + 1); 45 | if(!new_str) 46 | return NULL; 47 | 48 | memcpy(new_str, str, len + 1); 49 | return new_str; 50 | } 51 | 52 | void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn) 53 | { 54 | do_malloc = malloc_fn; 55 | do_free = free_fn; 56 | } 57 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef _GNU_SOURCE 9 | #define _GNU_SOURCE 10 | #endif 11 | 12 | #include 13 | #include 14 | #include "jansson_private.h" 15 | #include "strbuffer.h" 16 | 17 | #define STRBUFFER_MIN_SIZE 16 18 | #define STRBUFFER_FACTOR 2 19 | #define STRBUFFER_SIZE_MAX ((size_t)-1) 20 | 21 | int strbuffer_init(strbuffer_t *strbuff) 22 | { 23 | strbuff->size = STRBUFFER_MIN_SIZE; 24 | strbuff->length = 0; 25 | 26 | strbuff->value = jsonp_malloc(strbuff->size); 27 | if(!strbuff->value) 28 | return -1; 29 | 30 | /* initialize to empty */ 31 | strbuff->value[0] = '\0'; 32 | return 0; 33 | } 34 | 35 | void strbuffer_close(strbuffer_t *strbuff) 36 | { 37 | if(strbuff->value) 38 | jsonp_free(strbuff->value); 39 | 40 | strbuff->size = 0; 41 | strbuff->length = 0; 42 | strbuff->value = NULL; 43 | } 44 | 45 | void strbuffer_clear(strbuffer_t *strbuff) 46 | { 47 | strbuff->length = 0; 48 | strbuff->value[0] = '\0'; 49 | } 50 | 51 | const char *strbuffer_value(const strbuffer_t *strbuff) 52 | { 53 | return strbuff->value; 54 | } 55 | 56 | char *strbuffer_steal_value(strbuffer_t *strbuff) 57 | { 58 | char *result = strbuff->value; 59 | strbuff->value = NULL; 60 | return result; 61 | } 62 | 63 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 64 | { 65 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 66 | } 67 | 68 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 69 | { 70 | return strbuffer_append_bytes(strbuff, &byte, 1); 71 | } 72 | 73 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size) 74 | { 75 | if(size >= strbuff->size - strbuff->length) 76 | { 77 | size_t new_size; 78 | char *new_value; 79 | 80 | /* avoid integer overflow */ 81 | if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR 82 | || size > STRBUFFER_SIZE_MAX - 1 83 | || strbuff->length > STRBUFFER_SIZE_MAX - 1 - size) 84 | return -1; 85 | 86 | new_size = max(strbuff->size * STRBUFFER_FACTOR, 87 | strbuff->length + size + 1); 88 | 89 | new_value = jsonp_malloc(new_size); 90 | if(!new_value) 91 | return -1; 92 | 93 | memcpy(new_value, strbuff->value, strbuff->length); 94 | 95 | jsonp_free(strbuff->value); 96 | strbuff->value = new_value; 97 | strbuff->size = new_size; 98 | } 99 | 100 | memcpy(strbuff->value + strbuff->length, data, size); 101 | strbuff->length += size; 102 | strbuff->value[strbuff->length] = '\0'; 103 | 104 | return 0; 105 | } 106 | 107 | char strbuffer_pop(strbuffer_t *strbuff) 108 | { 109 | if(strbuff->length > 0) { 110 | char c = strbuff->value[--strbuff->length]; 111 | strbuff->value[strbuff->length] = '\0'; 112 | return c; 113 | } 114 | else 115 | return '\0'; 116 | } 117 | -------------------------------------------------------------------------------- /compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | size_t length; /* bytes used */ 14 | size_t size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | 24 | /* Steal the value and close the strbuffer */ 25 | char *strbuffer_steal_value(strbuffer_t *strbuff); 26 | 27 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 28 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 29 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size); 30 | 31 | char strbuffer_pop(strbuffer_t *strbuff); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /compat/jansson/strconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "jansson_private.h" 6 | #include "strbuffer.h" 7 | 8 | /* need config.h to get the correct snprintf */ 9 | #ifdef HAVE_CONFIG_H 10 | #include 11 | #endif 12 | 13 | #if JSON_HAVE_LOCALECONV 14 | #include 15 | 16 | /* 17 | - This code assumes that the decimal separator is exactly one 18 | character. 19 | 20 | - If setlocale() is called by another thread between the call to 21 | localeconv() and the call to sprintf() or strtod(), the result may 22 | be wrong. setlocale() is not thread-safe and should not be used 23 | this way. Multi-threaded programs should use uselocale() instead. 24 | */ 25 | 26 | static void to_locale(strbuffer_t *strbuffer) 27 | { 28 | const char *point; 29 | char *pos; 30 | 31 | point = localeconv()->decimal_point; 32 | if(*point == '.') { 33 | /* No conversion needed */ 34 | return; 35 | } 36 | 37 | pos = strchr(strbuffer->value, '.'); 38 | if(pos) 39 | *pos = *point; 40 | } 41 | 42 | static void from_locale(char *buffer) 43 | { 44 | const char *point; 45 | char *pos; 46 | 47 | point = localeconv()->decimal_point; 48 | if(*point == '.') { 49 | /* No conversion needed */ 50 | return; 51 | } 52 | 53 | pos = strchr(buffer, *point); 54 | if(pos) 55 | *pos = '.'; 56 | } 57 | #endif 58 | 59 | int jsonp_strtod(strbuffer_t *strbuffer, double *out) 60 | { 61 | double value; 62 | char *end; 63 | 64 | #if JSON_HAVE_LOCALECONV 65 | to_locale(strbuffer); 66 | #endif 67 | 68 | errno = 0; 69 | value = strtod(strbuffer->value, &end); 70 | assert(end == strbuffer->value + strbuffer->length); 71 | 72 | if(errno == ERANGE && value != 0) { 73 | /* Overflow */ 74 | return -1; 75 | } 76 | 77 | *out = value; 78 | return 0; 79 | } 80 | 81 | int jsonp_dtostr(char *buffer, size_t size, double value) 82 | { 83 | int ret; 84 | char *start, *end; 85 | size_t length; 86 | 87 | ret = snprintf(buffer, size, "%.17g", value); 88 | if(ret < 0) 89 | return -1; 90 | 91 | length = (size_t)ret; 92 | if(length >= size) 93 | return -1; 94 | 95 | #if JSON_HAVE_LOCALECONV 96 | from_locale(buffer); 97 | #endif 98 | 99 | /* Make sure there's a dot or 'e' in the output. Otherwise 100 | a real is converted to an integer when decoding */ 101 | if(strchr(buffer, '.') == NULL && 102 | strchr(buffer, 'e') == NULL) 103 | { 104 | if(length + 3 >= size) { 105 | /* No space to append ".0" */ 106 | return -1; 107 | } 108 | buffer[length] = '.'; 109 | buffer[length + 1] = '0'; 110 | buffer[length + 2] = '\0'; 111 | length += 2; 112 | } 113 | 114 | /* Remove leading '+' from positive exponent. Also remove leading 115 | zeros from exponents (added by some printf() implementations) */ 116 | start = strchr(buffer, 'e'); 117 | if(start) { 118 | start++; 119 | end = start + 1; 120 | 121 | if(*start == '-') 122 | start++; 123 | 124 | while(*end == '0') 125 | end++; 126 | 127 | if(end != start) { 128 | memmove(start, end, length - (size_t)(end - buffer)); 129 | length -= (size_t)(end - start); 130 | } 131 | } 132 | 133 | return (int)length; 134 | } 135 | -------------------------------------------------------------------------------- /compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2013 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #ifdef HAVE_CONFIG_H 12 | #include 13 | 14 | #ifdef HAVE_INTTYPES_H 15 | /* inttypes.h includes stdint.h in a standard environment, so there's 16 | no need to include stdint.h separately. If inttypes.h doesn't define 17 | int32_t, it's defined in config.h. */ 18 | #include 19 | #endif /* HAVE_INTTYPES_H */ 20 | 21 | #else /* !HAVE_CONFIG_H */ 22 | #ifdef _WIN32 23 | typedef int int32_t; 24 | #else /* !_WIN32 */ 25 | /* Assume a standard environment */ 26 | #include 27 | #endif /* _WIN32 */ 28 | 29 | #endif /* HAVE_CONFIG_H */ 30 | 31 | int utf8_encode(int codepoint, char *buffer, int *size); 32 | 33 | int utf8_check_first(char byte); 34 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 35 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 36 | 37 | int utf8_check_string(const char *string, int length); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /compat/jansson/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTIL_H 9 | #define UTIL_H 10 | 11 | #ifndef max 12 | #define max(a, b) ((a) > (b) ? (a) : (b)) 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /compat/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 -------------------------------------------------------------------------------- /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.c: -------------------------------------------------------------------------------- 1 | // keccak.c 2 | // 19-Nov-11 Markku-Juhani O. Saarinen 3 | // A baseline Keccak (3rd round) implementation. 4 | 5 | #include "hash-ops.h" 6 | #include "c_keccak.h" 7 | 8 | const uint64_t keccakf_rndc[24] = 9 | { 10 | 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 11 | 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 12 | 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 13 | 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 14 | 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 15 | 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 16 | 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 17 | 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 18 | }; 19 | 20 | const int keccakf_rotc[24] = 21 | { 22 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 23 | 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 24 | }; 25 | 26 | const int keccakf_piln[24] = 27 | { 28 | 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 29 | 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 30 | }; 31 | 32 | // update the state with given number of rounds 33 | 34 | void keccakf(uint64_t st[25], int rounds) 35 | { 36 | int i, j, round; 37 | uint64_t t, bc[5]; 38 | 39 | for (round = 0; round < rounds; ++round) { 40 | 41 | // Theta 42 | bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20]; 43 | bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21]; 44 | bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22]; 45 | bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23]; 46 | bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24]; 47 | 48 | for (i = 0; i < 5; ++i) { 49 | t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); 50 | st[i ] ^= t; 51 | st[i + 5] ^= t; 52 | st[i + 10] ^= t; 53 | st[i + 15] ^= t; 54 | st[i + 20] ^= t; 55 | } 56 | 57 | // Rho Pi 58 | t = st[1]; 59 | for (i = 0; i < 24; ++i) { 60 | bc[0] = st[keccakf_piln[i]]; 61 | st[keccakf_piln[i]] = ROTL64(t, keccakf_rotc[i]); 62 | t = bc[0]; 63 | } 64 | 65 | // Chi 66 | for (j = 0; j < 25; j += 5) { 67 | bc[0] = st[j ]; 68 | bc[1] = st[j + 1]; 69 | bc[2] = st[j + 2]; 70 | bc[3] = st[j + 3]; 71 | bc[4] = st[j + 4]; 72 | st[j ] ^= (~bc[1]) & bc[2]; 73 | st[j + 1] ^= (~bc[2]) & bc[3]; 74 | st[j + 2] ^= (~bc[3]) & bc[4]; 75 | st[j + 3] ^= (~bc[4]) & bc[0]; 76 | st[j + 4] ^= (~bc[0]) & bc[1]; 77 | } 78 | 79 | // Iota 80 | st[0] ^= keccakf_rndc[round]; 81 | } 82 | } 83 | 84 | // compute a keccak hash (md) of given byte length from "in" 85 | typedef uint64_t state_t[25]; 86 | 87 | int keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) 88 | { 89 | state_t st; 90 | uint8_t temp[144]; 91 | int i, rsiz, rsizw; 92 | 93 | rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; 94 | rsizw = rsiz / 8; 95 | 96 | memset(st, 0, sizeof(st)); 97 | 98 | for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { 99 | for (i = 0; i < rsizw; i++) 100 | st[i] ^= ((uint64_t *) in)[i]; 101 | keccakf(st, KECCAK_ROUNDS); 102 | } 103 | 104 | // last block and padding 105 | memcpy(temp, in, inlen); 106 | temp[inlen++] = 1; 107 | memset(temp + inlen, 0, rsiz - inlen); 108 | temp[rsiz - 1] |= 0x80; 109 | 110 | for (i = 0; i < rsizw; i++) 111 | st[i] ^= ((uint64_t *) temp)[i]; 112 | 113 | keccakf(st, KECCAK_ROUNDS); 114 | 115 | memcpy(md, st, mdlen); 116 | 117 | return 0; 118 | } 119 | 120 | void keccak1600(const uint8_t *in, int inlen, uint8_t *md) 121 | { 122 | keccak(in, inlen, md, sizeof(state_t)); 123 | } 124 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example.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://xxx.yyy.zzz:1234", 8 | "user" : "benchmark", 9 | "pass" : "benchmark", 10 | 11 | "algo" : "minotaurx", 12 | "threads" : 0, 13 | "cpu-priority" : 0, 14 | "cpu-affinity" : -1, 15 | 16 | "benchmark" : true, 17 | "debug" : false, 18 | "protocol": false, 19 | "show-diff": true, 20 | "quiet" : false 21 | } 22 | -------------------------------------------------------------------------------- /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 | int LYRA2_3(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); 43 | 44 | #endif /* LYRA2_H_ */ 45 | -------------------------------------------------------------------------------- /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/litecoincash-project/cpuminer-multi/5710e52b064d2077a53d3db3ae6b1a7febbec45b/m4/.gitignore -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /scryptjane/scrypt-jane-salsa64.h: -------------------------------------------------------------------------------- 1 | #define SCRYPT_MIX_BASE "Salsa64/8" 2 | 3 | typedef uint64_t scrypt_mix_word_t; 4 | 5 | #define SCRYPT_WORDTO8_LE U64TO8_LE 6 | #define SCRYPT_WORD_ENDIAN_SWAP U64_SWAP 7 | 8 | #define SCRYPT_BLOCK_BYTES 128 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_salsa64-avx.h" 15 | #include "scrypt-jane-mix_salsa64-ssse3.h" 16 | #include "scrypt-jane-mix_salsa64-sse2.h" 17 | #include "scrypt-jane-mix_salsa64.h" 18 | 19 | #if defined(SCRYPT_SALSA64_AVX) 20 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx 21 | #define SCRYPT_ROMIX_FN scrypt_ROMix_avx 22 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 23 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 24 | #include "scrypt-jane-romix-template.h" 25 | #endif 26 | 27 | #if defined(SCRYPT_SALSA64_SSSE3) 28 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3 29 | #define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3 30 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 31 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 32 | #include "scrypt-jane-romix-template.h" 33 | #endif 34 | 35 | #if defined(SCRYPT_SALSA64_SSE2) 36 | #define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2 37 | #define SCRYPT_ROMIX_FN scrypt_ROMix_sse2 38 | #define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2 39 | #define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2 40 | #include "scrypt-jane-romix-template.h" 41 | #endif 42 | 43 | /* cpu agnostic */ 44 | #define SCRYPT_ROMIX_FN scrypt_ROMix_basic 45 | #define SCRYPT_MIX_FN salsa64_core_basic 46 | #define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian 47 | #define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian 48 | #include "scrypt-jane-romix-template.h" 49 | 50 | #if !defined(SCRYPT_CHOOSE_COMPILETIME) 51 | static scrypt_ROMixfn 52 | scrypt_getROMix() { 53 | size_t cpuflags = detect_cpu(); 54 | 55 | #if defined(SCRYPT_SALSA64_AVX) 56 | if (cpuflags & cpu_avx) 57 | return scrypt_ROMix_avx; 58 | else 59 | #endif 60 | 61 | #if defined(SCRYPT_SALSA64_SSSE3) 62 | if (cpuflags & cpu_ssse3) 63 | return scrypt_ROMix_ssse3; 64 | else 65 | #endif 66 | 67 | #if defined(SCRYPT_SALSA64_SSE2) 68 | if (cpuflags & cpu_sse2) 69 | return scrypt_ROMix_sse2; 70 | else 71 | #endif 72 | 73 | return scrypt_ROMix_basic; 74 | } 75 | #endif 76 | 77 | 78 | #if defined(SCRYPT_TEST_SPEED) 79 | static size_t 80 | available_implementations() { 81 | size_t cpuflags = detect_cpu(); 82 | size_t flags = 0; 83 | 84 | #if defined(SCRYPT_SALSA64_AVX) 85 | if (cpuflags & cpu_avx) 86 | flags |= cpu_avx; 87 | #endif 88 | 89 | #if defined(SCRYPT_SALSA64_SSSE3) 90 | if (cpuflags & cpu_ssse3) 91 | flags |= cpu_ssse3; 92 | #endif 93 | 94 | #if defined(SCRYPT_SALSA64_SSE2) 95 | if (cpuflags & cpu_sse2) 96 | flags |= cpu_sse2; 97 | #endif 98 | 99 | return flags; 100 | } 101 | #endif 102 | 103 | static int 104 | scrypt_test_mix() { 105 | static const uint8_t expected[16] = { 106 | 0xf8,0x92,0x9b,0xf8,0xcc,0x1d,0xce,0x2e,0x13,0x82,0xac,0x96,0xb2,0x6c,0xee,0x2c, 107 | }; 108 | 109 | int ret = 1; 110 | size_t cpuflags = detect_cpu(); 111 | 112 | #if defined(SCRYPT_SALSA64_AVX) 113 | if (cpuflags & cpu_avx) 114 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 115 | #endif 116 | 117 | #if defined(SCRYPT_SALSA64_SSSE3) 118 | if (cpuflags & cpu_ssse3) 119 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 120 | #endif 121 | 122 | #if defined(SCRYPT_SALSA64_SSE2) 123 | if (cpuflags & cpu_sse2) 124 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected); 125 | #endif 126 | 127 | #if defined(SCRYPT_SALSA64_BASIC) 128 | ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected); 129 | #endif 130 | 131 | return ret; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /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__ */ -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------