Skip to content

Commit

Permalink
Add S3 algo
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Oct 31, 2014
1 parent 070ff29 commit 98a5c87
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ minerd_SOURCES = elist.h \
cryptonight.c \
fresh.c \
neoscrypt.c \
s3.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.6 (Tanguy Pruvot)
- Fix scrypt algo
- More work on VC2013
- Add -f tuning option to test with reduced difficulty
- Add S3 algo

Version multi 1.0.5 (Tanguy Pruvot)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Algorithms
*__scrypt__ (Litecoin, Dogecoin, Feathercoin, etc..)
*__scrypt:N__ (Vertcoin [VTC])
*__sha256d__ (Bitcoin, Freicoin, Peercoin/PPCoin, Terracoin, etc..)
*__s3__ (OneCoin)
*__x11__ (Darkcoin [DRK], Hirocoin, Limecoin)
*__x13__ (Sherlockcoin, [ACE], [B2B], [GRC], [XHC], etc..)
*__x14__ (X14, Webcoin [WEB])
Expand Down
7 changes: 7 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ enum algos {
ALGO_SHAVITE3, /* Shavite3 */
ALGO_BLAKE, /* Blake */
ALGO_FRESH, /* Fresh */
ALGO_S3, /* S3 */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
ALGO_X14, /* X14 */
Expand All @@ -150,6 +151,7 @@ static const char *algo_names[] = {
"shavite3",
"blake",
"fresh",
"s3",
"x11",
"x13",
"x14",
Expand Down Expand Up @@ -241,6 +243,7 @@ Options:\n\
shavite3 Shavite3\n\
blake Blake\n\
fresh Fresh\n\
s3 S3\n\
x11 X11\n\
x13 X13\n\
x14 X14\n\
Expand Down Expand Up @@ -1742,6 +1745,10 @@ static void *miner_thread(void *userdata)
rc = scanhash_fresh(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);
break;
case ALGO_X11:
rc = scanhash_x11(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 @@ -186,6 +186,7 @@
<ClCompile Include="crypto\hash.c" />
<ClCompile Include="crypto\oaes_lib.c" />
<ClCompile Include="ink.c" />
<ClCompile Include="s3.c" />
<ClCompile Include="sha3\blake2s.c" />
<ClCompile Include="sha3\sph_hefty1.c" />
<ClCompile Include="util.c">
Expand Down
1 change: 1 addition & 0 deletions cpuminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<ClCompile Include="aesb-x86.SS">
<Filter>arch\x86</Filter>
</ClCompile>
<ClCompile Include="s3.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="sha3\sph_blake.h">
Expand Down
4 changes: 4 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ extern int scanhash_blake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
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_s3(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 Expand Up @@ -400,6 +403,7 @@ 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 */
void neoscrypt(unsigned char *output, const unsigned char *password, uint32_t profile);
void s3hash(void *output, const void *input);
void x11hash(void *output, const void *input);
void x13hash(void *output, const void *input);
void x14hash(void *output, const void *input);
Expand Down
101 changes: 101 additions & 0 deletions s3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "miner.h"

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

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

void s3hash(void *output, const void *input)
{
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_skein512_context ctx_skein;

unsigned char _ALIGN(128) hash[64];

sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, input, 80);
sph_shavite512_close(&ctx_shavite, (void*)hash);

sph_simd512_init(&ctx_simd);
sph_simd512(&ctx_simd, (const void*)hash, 64);
sph_simd512_close(&ctx_simd, (void*)hash);

sph_skein512_init(&ctx_skein);
sph_skein512(&ctx_skein, (const void*)hash, 64);
sph_skein512_close(&ctx_skein, (void*)hash);

memcpy(output, hash, 32);
}

int scanhash_s3(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t n = pdata[19] - 1;
const uint32_t first_nonce = pdata[19];
const uint32_t Htarg = ptarget[7];

uint32_t _ALIGN(32) hash64[8];
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
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);
s3hash(hash64, endiandata);
#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;
}
4 changes: 4 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,10 @@ void print_hash_tests(void)
freshhash(&hash[0], &buf[0], 80);
printpfx("Fresh", hash);

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

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

0 comments on commit 98a5c87

Please sign in to comment.