Skip to content

Commit

Permalink
Add Freshcoin algo (fresh)
Browse files Browse the repository at this point in the history
+ a small change to x13/14/15 which reduce a bit executable size

Signed-off-by: Tanguy Pruvot <[email protected]>
  • Loading branch information
tpruvot committed Aug 2, 2014
1 parent d971882 commit 4b5c6da
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ minerd_SOURCES = elist.h \
ink.c \
blake.c \
cryptonight.c \
fresh.c \
x11.c \
x13.c \
x14.c \
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version multi 1.0.4 (Tanguy Pruvot)

- Add x13 x14 and x15 algos (Sherlockcoin, X14Coin, Webcoin..)
- Add scrypt:N variants (Vertcoin)
- Add fresh algo
- Fix thread khashes/s value output
- Add a configure option --disable-assembly

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ Algorithms
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
*__x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..)
*__x14__ (X14, Webcoin [WEB])
*__x14__ (RadianceCoin [RCE])
*__x15__ (RadianceCoin [RCE])
*__cryptonight__ (Bytecoin [BCN], Monero)
*__fresh__ (FreshCoin)

#### Implemented, but untested
* ? keccak (Maxcoin HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin)
Expand Down Expand Up @@ -119,7 +120,8 @@ Donations for the work done in this fork are accepted at
Credits
=======
CPUMiner-multi was forked from pooler's CPUMiner, and has been developed by Lucas Jones.
* [Wolf9466](https://github.com/wolf9466) Helped with Intel AES-NI support for CryptoNight
* [tpruvot](https://github.com/tpruvot) added some features and recent SHA3 based algorythmns
* [Wolf9466](https://github.com/wolf9466) helped with Intel AES-NI support for CryptoNight

License
=======
Expand Down
10 changes: 10 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum algos {
ALGO_SKEIN, /* Skein */
ALGO_SHAVITE3, /* Shavite3 */
ALGO_BLAKE, /* Blake */
ALGO_FRESH, /* Fresh */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
ALGO_X14, /* X14 */
Expand All @@ -124,6 +125,7 @@ static const char *algo_names[] = {
[ALGO_SKEIN] = "skein",
[ALGO_SHAVITE3] = "shavite3",
[ALGO_BLAKE] = "blake",
[ALGO_FRESH] = "fresh",
[ALGO_X11] = "x11",
[ALGO_X13] = "x13",
[ALGO_X14] = "x14",
Expand Down Expand Up @@ -207,6 +209,7 @@ Options:\n\
skein Skein\n\
shavite3 Shavite3\n\
blake Blake\n\
fresh Fresh\n\
x11 X11\n\
x13 X13\n\
x14 X14\n\
Expand Down Expand Up @@ -1127,6 +1130,9 @@ static void *miner_thread(void *userdata) {
case ALGO_CRYPTONIGHT:
max64 = 0x40LL;
break;
case ALGO_FRESH:
max64 = 0x3ffff;
break;
case ALGO_X13:
max64 = 0x1ffff;
break;
Expand Down Expand Up @@ -1188,6 +1194,10 @@ static void *miner_thread(void *userdata) {
rc = scanhash_blake(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_FRESH:
rc = scanhash_fresh(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_X11:
rc = scanhash_x11(thr_id, work.data, work.target, max_nonce,
&hashes_done);
Expand Down
116 changes: 116 additions & 0 deletions fresh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "miner.h"

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

#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
#include "sha3/sph_echo.h"

//#define DEBUG_ALGO

inline void freshhash(void* output, const void* input, uint32_t len)
{
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
#define hashA hash
#define hashB hash+64

memset(hash, 0, 128);
sph_shavite512_context ctx_shavite1;
sph_simd512_context ctx_simd1;
sph_echo512_context ctx_echo1;

sph_shavite512_init(&ctx_shavite1);
sph_shavite512(&ctx_shavite1, input, len);
sph_shavite512_close(&ctx_shavite1, hashA);

sph_simd512_init(&ctx_simd1);
sph_simd512(&ctx_simd1, hashA, 64);
sph_simd512_close(&ctx_simd1, hashB);

sph_shavite512_init(&ctx_shavite1);
sph_shavite512(&ctx_shavite1, hashB, 64);
sph_shavite512_close(&ctx_shavite1, hashA);

sph_simd512_init(&ctx_simd1);
sph_simd512(&ctx_simd1, hashA, 64);
sph_simd512_close(&ctx_simd1, hashB);

sph_echo512_init(&ctx_echo1);
sph_echo512(&ctx_echo1, hashB, 64);
sph_echo512_close(&ctx_echo1, hashA);

memcpy(output, hash, 32);
}

int scanhash_fresh(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t len = 80;

uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
const uint32_t Htarg = ptarget[7];

uint32_t hash64[8] __attribute__((aligned(32)));
uint32_t endiandata[32];

uint64_t htmax[] = {
0,
0xF,
0xFF,
0xFFF,
0xFFFF,
0x10000000
};
uint32_t masks[] = {
0xFFFFFFFF,
0xFFFFFFF0,
0xFFFFFF00,
0xFFFFF000,
0xFFFF0000,
0
};

// we need bigendian data...
for (int kk=0; kk < 32; kk++) {
be32enc(&endiandata[kk], ((uint32_t*)pdata)[kk]);
};
#ifdef DEBUG_ALGO
if (Htarg != 0)
printf("[%d] Htarg=%X\n", thr_id, Htarg);
#endif
for (int m=0; m < sizeof(masks); m++) {
if (Htarg <= htmax[m]) {
uint32_t mask = masks[m];
do {
pdata[19] = ++n;
be32enc(&endiandata[19], n);
freshhash(hash64, &endiandata, len);
#ifndef DEBUG_ALGO
if ((!(hash64[7] & mask)) && fulltest(hash64, ptarget)) {
*hashes_done = n - first_nonce + 1;
return true;
}
#else
if (!(n % 0x1000) && !thr_id) printf(".");
if (!(hash64[7] & mask)) {
printf("[%d]",thr_id);
if (fulltest(hash64, ptarget)) {
*hashes_done = n - first_nonce + 1;
return true;
}
}
#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;
}
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ extern void init_blakehash_contexts();
extern int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);

extern int scanhash_fresh(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);

extern int scanhash_x11(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);

Expand Down
2 changes: 1 addition & 1 deletion x13.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "sha3/sph_hamsi.h"
#include "sha3/sph_fugue.h"

inline void x13hash(void *output, const void *input)
static void x13hash(void *output, const void *input)
{
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
#define hashB hash+64
Expand Down
6 changes: 3 additions & 3 deletions x14.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "sha3/sph_fugue.h"
#include "sha3/sph_shabal.h"

inline void x14hash(void *output, const void *input)
//#define DEBUG_ALGO

static void x14hash(void *output, const void *input)
{
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
#define hashB hash+64
Expand Down Expand Up @@ -101,8 +103,6 @@ inline void x14hash(void *output, const void *input)
memcpy(output, hash, 32);
}

//#define DEBUG_ALGO

int scanhash_x14(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
Expand Down
6 changes: 3 additions & 3 deletions x15.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include "sha3/sph_shabal.h"
#include "sha3/sph_whirlpool.h"

inline void x15hash(void *output, const void *input)
//#define DEBUG_ALGO

static void x15hash(void *output, const void *input)
{
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
#define hashB hash+64
Expand Down Expand Up @@ -107,8 +109,6 @@ inline void x15hash(void *output, const void *input)
memcpy(output, hash, 32);
}

//#define DEBUG_ALGO

int scanhash_x15(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
Expand Down

0 comments on commit 4b5c6da

Please sign in to comment.