Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
handle a new tribus algo
Browse files Browse the repository at this point in the history
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
  • Loading branch information
tpruvot committed Jun 15, 2017
1 parent 4123f4c commit 7495361
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 1.3.3
- Add tribus algo

Version 1.3.2
- Add bitcore algo
- Add jha algo
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
103 changes: 103 additions & 0 deletions algo/tribus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "miner.h"

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#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;
}
4 changes: 2 additions & 2 deletions compat/cpuminer-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <sys/types.h> does not define. */
/* #undef size_t */
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -170,6 +171,7 @@ static const char *algo_names[] = {
"s3",
"timetravel",
"bitcore",
"tribus",
"vanilla",
"veltor",
"x11evo",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions cpuminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<ClCompile Include="algo\skein.c" />
<ClCompile Include="algo\skein2.c" />
<ClCompile Include="algo\timetravel.c" />
<ClCompile Include="algo\tribus.c" />
<ClCompile Include="algo\veltor.c" />
<ClCompile Include="algo\x11evo.c" />
<ClCompile Include="algo\x11.c" />
Expand Down
3 changes: 3 additions & 0 deletions cpuminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@
<ClCompile Include="algo\timetravel.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\tribus.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\veltor.c">
<Filter>algo</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7495361

Please sign in to comment.