Skip to content

Commit

Permalink
Add double skein (skein2) algo for Woodcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Mar 7, 2015
1 parent 0eccce9 commit 6dc12f7
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cpuminer_SOURCES = \
algo/scrypt.c \
algo/sha2.c \
algo/skein.c \
algo/skein2.c \
algo/s3.c \
algo/x11.c \
algo/x13.c \
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version 1.1-git (Tanguy Pruvot)
- Add basic API remote control (quit/seturl)
- Add GroestlCoin, Diamond and Myriad variants
- Add Pluck algo and fix gbt query crash
- Add ZR5 algo (ZRC) and fix longpoll bug on linux
- Add Skein2 algo (Double Skein for Woodcoin)
- Change some logged strings
- Use all cores by default, not N-1
- Handle a default config to run without params
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CPUMiner-Multi
CPUMiner-Multi
==============

[![Build Status](https://travis-ci.org/tpruvot/cpuminer-multi.svg)](https://travis-ci.org/tpruvot/cpuminer-multi)
Expand Down Expand Up @@ -33,12 +33,15 @@ Algorithms
*__neoscrypt__ (Feathercoin)
*__nist5__ (MistCoin [MIC], TalkCoin [TAC], ...)
*__pentablake__ (Joincoin)
*__pluck__ (Supcoin [SUP])
*__qubit__ (MyriadCoin [MYR])
*__skein2__ (Woodcoin)
*__s3__ (OneCoin)
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin, ...)
*__x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], ...)
*__x14__ (X14, Webcoin [WEB])
*__x15__ (RadianceCoin [RCE])
*__zr5__ (Ziftrcoin [ZRC])

#### Implemented, but untested
* ? keccak (Maxcoin HelixCoin, CryptoMeth, Galleon, 365coin, Slothcoin, BitcointalkCoin)
Expand Down
56 changes: 56 additions & 0 deletions algo/skein2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "miner.h"

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

#include "sha3/sph_skein.h"

void skein2hash(void *output, const void *input)
{
sph_skein512_context ctx_skein;

uint32_t hash[16];

sph_skein512_init(&ctx_skein);
sph_skein512(&ctx_skein, input, 80);
sph_skein512_close(&ctx_skein, hash);

sph_skein512_init(&ctx_skein);
sph_skein512(&ctx_skein, hash, 64);
sph_skein512_close(&ctx_skein, hash);

memcpy(output, hash, 32);
}

int scanhash_skein2(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(64) hash64[8];
uint32_t _ALIGN(64) endiandata[20];

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

uint32_t n = first_nonce;

for (int i=0; i < 19; i++) {
be32enc(&endiandata[i], pdata[i]);
};

do {
be32enc(&endiandata[19], n);
skein2hash(hash64, endiandata);
if (hash64[7] < Htarg && fulltest(hash64, ptarget)) {
*hashes_done = n - first_nonce + 1;
pdata[19] = n;
return true;
}
n++;

} while (n < max_nonce && !work_restart[thr_id].restart);

*hashes_done = n - first_nonce + 1;
pdata[19] = n;

return 0;
}
35 changes: 22 additions & 13 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ enum algos {
ALGO_HEAVY, /* Heavy */
ALGO_NEOSCRYPT, /* NeoScrypt(128, 2, 1) with Salsa20/20 and ChaCha20/20 */
ALGO_QUARK, /* Quark */
ALGO_SKEIN, /* Skein */
ALGO_SHAVITE3, /* Shavite3 */
ALGO_BLAKE, /* Blake 256 */
ALGO_BLAKECOIN, /* Simplified 8 rounds Blake 256 */
ALGO_CRYPTONIGHT, /* CryptoNight */
Expand All @@ -93,6 +91,9 @@ enum algos {
ALGO_PENTABLAKE, /* Pentablake */
ALGO_PLUCK, /* Pluck (Supcoin) */
ALGO_QUBIT, /* Qubit */
ALGO_SHAVITE3, /* Shavite3 */
ALGO_SKEIN, /* Skein */
ALGO_SKEIN2, /* Double skein (Woodcoin) */
ALGO_S3, /* S3 */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
Expand All @@ -109,8 +110,6 @@ static const char *algo_names[] = {
"heavy",
"neoscrypt",
"quark",
"skein",
"shavite3",
"blake",
"blakecoin",
"cryptonight",
Expand All @@ -123,6 +122,9 @@ static const char *algo_names[] = {
"pentablake",
"pluck",
"qubit",
"shavite3",
"skein",
"skein2",
"s3",
"x11",
"x13",
Expand Down Expand Up @@ -237,7 +239,8 @@ Options:\n\
quark Quark\n\
qubit Qubit\n\
shavite3 Shavite3\n\
skein Skein\n\
skein Skein+Sha (Skeincoin)\n\
skeincoin Double Skein (Woodcoin)\n\
s3 S3\n\
x11 X11\n\
x13 X13\n\
Expand Down Expand Up @@ -1871,6 +1874,8 @@ static void *miner_thread(void *userdata)
break;
case ALGO_BLAKE:
case ALGO_BLAKECOIN:
case ALGO_SKEIN:
case ALGO_SKEIN2:
max64 = 0x7ffffLL;
break;
default:
Expand Down Expand Up @@ -1913,14 +1918,6 @@ static void *miner_thread(void *userdata)
rc = scanhash_quark(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_SKEIN:
rc = scanhash_skein(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_SHAVITE3:
rc = scanhash_ink(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_BLAKE:
rc = scanhash_blake(thr_id, work.data, work.target, max_nonce,
&hashes_done);
Expand Down Expand Up @@ -1958,6 +1955,18 @@ static void *miner_thread(void *userdata)
rc = scanhash_qubit(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_SHAVITE3:
rc = scanhash_ink(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_SKEIN:
rc = scanhash_skein(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_SKEIN2:
rc = scanhash_skein2(thr_id, work.data, work.target, max_nonce,
&hashes_done);
break;
case ALGO_S3:
rc = scanhash_s3(thr_id, work.data, work.target, max_nonce,
&hashes_done);
Expand Down
1 change: 1 addition & 0 deletions cpuminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="algo\skein2.c" />
<ClCompile Include="algo\zr5.c" />
<ClCompile Include="compat\getopt\getopt_long.c" />
<ClCompile Include="compat\gettimeofday.c" />
Expand Down
3 changes: 3 additions & 0 deletions cpuminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@
<ClCompile Include="algo\zr5.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\skein2.c">
<Filter>algo</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="sha3\sph_blake.h">
Expand Down
6 changes: 5 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ extern int scanhash_qubit(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
extern int scanhash_skein(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);

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

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

Expand Down Expand Up @@ -468,7 +471,6 @@ void cryptonight_hash(void* output, const void* input, int len);
void groestlhash(void *output, const void *input);
void heavyhash(unsigned char* output, const unsigned char* input, int len);
void quarkhash(void *state, const void *input);
void skeinhash(void *state, const void *input);
void freshhash(void* output, const void* input, uint32_t len);
void keccakhash(void *state, const void *input);
void inkhash(void *state, const void *input); /* shavite */
Expand All @@ -479,6 +481,8 @@ void nist5hash(void *output, const void *input);
void pluck_hash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N);
void pentablakehash(void *output, const void *input);
void qubithash(void *output, const void *input);
void skeinhash(void *state, const void *input);
void skein2hash(void *state, const void *input);
void s3hash(void *output, const void *input);
void x11hash(void *output, const void *input);
void x13hash(void *output, const void *input);
Expand Down
9 changes: 9 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,11 @@ void print_hash_tests(void)

printf("\n" CL_WHT "CPU HASH ON EMPTY BUFFER RESULTS:" CL_N " (dev purpose)\n\n");

//buf[0] = 1; buf[64] = 2; // for endian tests
memset(hash, 0, sizeof hash);
skein2hash(&hash[0], &buf[0]);
printpfx("skein2", hash);

memset(hash, 0, sizeof hash);
sha256d((uint8_t*) &hash[0], (uint8_t*)&buf[0], 64);
printpfx("SHA 256D", hash);
Expand Down Expand Up @@ -1799,6 +1804,10 @@ void print_hash_tests(void)
skeinhash(&hash[0], &buf[0]);
printpfx("Skein", hash);

memset(hash, 0, sizeof hash);
skein2hash(&hash[0], &buf[0]);
printpfx("Skein2", hash);

memset(hash, 0, sizeof hash);
s3hash(&hash[0], &buf[0]);
printpfx("S3", hash);
Expand Down

0 comments on commit 6dc12f7

Please sign in to comment.