From 7495361e34bb11e0c3e2c778312281071208eb55 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 15 Jun 2017 07:12:32 +0200 Subject: [PATCH] handle a new tribus algo Signed-off-by: Tanguy Pruvot --- Makefile.am | 1 + NEWS | 3 ++ README.md | 1 + algo/tribus.c | 103 +++++++++++++++++++++++++++++++++++++++ compat/cpuminer-config.h | 4 +- configure.ac | 2 +- cpu-miner.c | 6 +++ cpuminer.vcxproj | 1 + cpuminer.vcxproj.filters | 3 ++ miner.h | 2 + util.c | 3 ++ 11 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 algo/tribus.c diff --git a/Makefile.am b/Makefile.am index 7a864e572..3e0294aed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,6 +92,7 @@ cpuminer_SOURCES = \ algo/s3.c \ algo/bitcore.c \ algo/timetravel.c \ + algo/tribus.c \ algo/veltor.c \ algo/x11evo.c \ algo/x11.c \ diff --git a/NEWS b/NEWS index 43c05e348..0509caf82 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Version 1.3.3 +- Add tribus algo + Version 1.3.2 - Add bitcore algo - Add jha algo diff --git a/README.md b/README.md index 3020097a8..b17f41092 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Algorithms * ✓ __sia__ (Reversed Blake2B for SIA [SC]) * ✓ __sib__ X11 + gost streebog (SibCoin) * ✓ __timetravel__ Permuted serie of 8 algos (MachineCoin [MAC]) + * ✓ __tribus__ 3 of the top NIST5 algos (Denarius [DNR]) * ✓ __vanilla__ (Blake-256 8-rounds - double sha256 [VNL]) * ✓ __veltor__ (Veltor [VLT]) * ✓ __xevan__ x17 x 2 on bigger header (BitSend [BSD]) diff --git a/algo/tribus.c b/algo/tribus.c new file mode 100644 index 000000000..2a7167d2b --- /dev/null +++ b/algo/tribus.c @@ -0,0 +1,103 @@ +#include "miner.h" + +#include +#include +#include +#include + +#include "sha3/sph_jh.h" +#include "sha3/sph_keccak.h" +#include "sha3/sph_echo.h" + +void tribus_hash(void *state, const void *input) +{ + uint8_t _ALIGN(128) hash[64]; + + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_echo512_context ctx_echo; + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, input, 80); + sph_jh512_close(&ctx_jh, (void*) hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, (const void*) hash, 64); + sph_keccak512_close(&ctx_keccak, (void*) hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*) hash, 64); + sph_echo512_close(&ctx_echo, (void*) hash); + + memcpy(state, hash, 32); +} + +int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) +{ + uint32_t _ALIGN(128) hash32[8]; + uint32_t _ALIGN(128) endiandata[20]; + uint32_t *pdata = work->data; + uint32_t *ptarget = work->target; + const uint32_t first_nonce = pdata[19]; + const uint32_t Htarg = ptarget[7]; + uint32_t n = pdata[19] - 1; + + uint64_t htmax[] = { + 0, + 0xF, + 0xFF, + 0xFFF, + 0xFFFF, + 0x10000000 + }; + uint32_t masks[] = { + 0xFFFFFFFF, + 0xFFFFFFF0, + 0xFFFFFF00, + 0xFFFFF000, + 0xFFFF0000, + 0 + }; + + // we need bigendian data... + for (int i=0; i < 19; i++) { + be32enc(&endiandata[i], pdata[i]); + } + +#ifdef DEBUG_ALGO + printf("[%d] Htarg=%X\n", thr_id, Htarg); +#endif + for (int m=0; m < 6; m++) { + if (Htarg <= htmax[m]) { + uint32_t mask = masks[m]; + do { + pdata[19] = ++n; + be32enc(&endiandata[19], n); + tribus_hash(hash32, endiandata); +#ifndef DEBUG_ALGO + if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) { + work_set_target_ratio(work, hash32); + *hashes_done = n - first_nonce + 1; + return 1; + } +#else + if (!(n % 0x1000) && !thr_id) printf("."); + if (!(hash32[7] & mask)) { + printf("[%d]",thr_id); + if (fulltest(hash32, ptarget)) { + work_set_target_ratio(work, hash32); + *hashes_done = n - first_nonce + 1; + return 1; + } + } +#endif + } while (n < max_nonce && !work_restart[thr_id].restart); + // see blake.c if else to understand the loop on htmax => mask + break; + } + } + + *hashes_done = n - first_nonce + 1; + pdata[19] = n; + return 0; +} diff --git a/compat/cpuminer-config.h b/compat/cpuminer-config.h index f829692cc..4bb76bf3d 100644 --- a/compat/cpuminer-config.h +++ b/compat/cpuminer-config.h @@ -103,7 +103,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.3.2" +#define PACKAGE_VERSION "1.3.3" /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be @@ -132,7 +132,7 @@ #define USE_XOP 1 /* Version number of package */ -#define VERSION "1.3.1" +#define VERSION "1.3.3" /* Define to `unsigned int' if does not define. */ /* #undef size_t */ diff --git a/configure.ac b/configure.ac index 57d9dca72..0288f42f2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([cpuminer-multi], [1.3.2]) +AC_INIT([cpuminer-multi], [1.3.3]) AC_PREREQ([2.59c]) AC_CANONICAL_SYSTEM diff --git a/cpu-miner.c b/cpu-miner.c index d4a00f8b7..9730fb62b 100644 --- a/cpu-miner.c +++ b/cpu-miner.c @@ -116,6 +116,7 @@ enum algos { ALGO_S3, /* S3 */ ALGO_TIMETRAVEL, /* Timetravel-8 (Machinecoin) */ ALGO_BITCORE, /* Timetravel-10 (Bitcore) */ + ALGO_TRIBUS, /* Denarius jh/keccak/echo */ ALGO_VANILLA, /* Vanilla (Blake256 8-rounds - double sha256) */ ALGO_VELTOR, /* Skein Shavite Shabal Streebog */ ALGO_X11EVO, /* Permuted X11 */ @@ -170,6 +171,7 @@ static const char *algo_names[] = { "s3", "timetravel", "bitcore", + "tribus", "vanilla", "veltor", "x11evo", @@ -2140,6 +2142,7 @@ static void *miner_thread(void *userdata) max64 = 0x3ffff; break; case ALGO_LBRY: + case ALGO_TRIBUS: case ALGO_X15: case ALGO_X17: case ALGO_ZR5: @@ -2295,6 +2298,9 @@ static void *miner_thread(void *userdata) case ALGO_BITCORE: rc = scanhash_bitcore(thr_id, &work, max_nonce, &hashes_done); break; + case ALGO_TRIBUS: + rc = scanhash_tribus(thr_id, &work, max_nonce, &hashes_done); + break; case ALGO_VANILLA: rc = scanhash_blakecoin(thr_id, &work, max_nonce, &hashes_done); break; diff --git a/cpuminer.vcxproj b/cpuminer.vcxproj index e0838410e..141e9f080 100644 --- a/cpuminer.vcxproj +++ b/cpuminer.vcxproj @@ -242,6 +242,7 @@ + diff --git a/cpuminer.vcxproj.filters b/cpuminer.vcxproj.filters index 6e718288a..707b9869f 100644 --- a/cpuminer.vcxproj.filters +++ b/cpuminer.vcxproj.filters @@ -264,6 +264,9 @@ algo + + algo + algo diff --git a/miner.h b/miner.h index 1d4825fa6..45e9431c5 100644 --- a/miner.h +++ b/miner.h @@ -240,6 +240,7 @@ int scanhash_skein2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t int scanhash_s3(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_timetravel(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_bitcore(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); +int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_veltor(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_x11evo(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); int scanhash_x11(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done); @@ -524,6 +525,7 @@ void skein2hash(void *state, const void *input); void s3hash(void *output, const void *input); void timetravel_hash(void *output, const void *input); void bitcore_hash(void *output, const void *input); +void tribus_hash(void *output, const void *input); void veltor_hash(void *output, const void *input); void xevan_hash(void *output, const void *input); void x11evo_hash(void *output, const void *input); diff --git a/util.c b/util.c index 227ca22cd..5cecf8431 100644 --- a/util.c +++ b/util.c @@ -2432,6 +2432,9 @@ void print_hash_tests(void) bitcore_hash(&hash[0], &buf[0]); printpfx("bitcore", hash); + tribus_hash(&hash[0], &buf[0]); + printpfx("tribus", hash); + veltor_hash(&hash[0], &buf[0]); printpfx("veltor", hash);