Skip to content

Commit

Permalink
Add c11 algo (chaincoin/flaxscript)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Jun 29, 2015
1 parent a4f51bd commit 15205b4
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cpuminer_SOURCES = \
algo/blake.c \
algo/blakecoin.c \
algo/blake2.c \
algo/c11.c \
algo/cryptonight.c \
algo/drop.c \
algo/fresh.c \
Expand Down
117 changes: 117 additions & 0 deletions algo/c11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include "miner.h"

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

#include "sha3/sph_blake.h"
#include "sha3/sph_bmw.h"
#include "sha3/sph_groestl.h"
#include "sha3/sph_jh.h"
#include "sha3/sph_keccak.h"
#include "sha3/sph_skein.h"
#include "sha3/sph_luffa.h"
#include "sha3/sph_cubehash.h"
#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
#include "sha3/sph_echo.h"


void c11hash(void *output, const void *input)
{
uint32_t _ALIGN(64) hash[16];

sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_skein512_context ctx_skein;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;

sph_luffa512_context ctx_luffa1;
sph_cubehash512_context ctx_cubehash1;
sph_shavite512_context ctx_shavite1;
sph_simd512_context ctx_simd1;
sph_echo512_context ctx_echo1;

sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, input, 80);
sph_blake512_close (&ctx_blake, hash);

sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, hash, 64);
sph_bmw512_close(&ctx_bmw, hash);

sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, hash, 64);
sph_groestl512_close(&ctx_groestl, hash);

sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, hash, 64);
sph_jh512_close(&ctx_jh, hash);

sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, hash, 64);
sph_keccak512_close(&ctx_keccak, hash);

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

sph_luffa512_init (&ctx_luffa1);
sph_luffa512 (&ctx_luffa1, hash, 64);
sph_luffa512_close (&ctx_luffa1, hash);

sph_cubehash512_init (&ctx_cubehash1);
sph_cubehash512 (&ctx_cubehash1, hash, 64);
sph_cubehash512_close(&ctx_cubehash1, hash);

sph_shavite512_init (&ctx_shavite1);
sph_shavite512 (&ctx_shavite1, hash, 64);
sph_shavite512_close(&ctx_shavite1, hash);

sph_simd512_init (&ctx_simd1);
sph_simd512 (&ctx_simd1, hash, 64);
sph_simd512_close(&ctx_simd1, hash);

sph_echo512_init (&ctx_echo1);
sph_echo512 (&ctx_echo1, hash, 64);
sph_echo512_close(&ctx_echo1, hash);

memcpy(output, hash, 32);
}

int scanhash_c11(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done)
{
const uint32_t first_nonce = pdata[19];
uint32_t _ALIGN(64) endiandata[20];
uint32_t nonce = first_nonce;
volatile uint8_t *restart = &(work_restart[thr_id].restart);

if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x0cff;

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

const uint32_t Htarg = ptarget[7];
do {
uint32_t hash[8];
be32enc(&endiandata[19], nonce);
c11hash(hash, endiandata);

if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce;
return 1;
}
nonce++;

} while (nonce < max_nonce && !(*restart));

pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce + 1;
return 0;
}
12 changes: 10 additions & 2 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum algos {
ALGO_BLAKE, /* Blake 256 */
ALGO_BLAKECOIN, /* Simplified 8 rounds Blake 256 */
ALGO_BLAKE2S, /* Blake2s */
ALGO_C11, /* C11 Chaincoin/Flaxcoin X11 variant */
ALGO_CRYPTONIGHT, /* CryptoNight */
ALGO_DMD_GR, /* Diamond */
ALGO_DROP, /* Dropcoin */
Expand Down Expand Up @@ -118,6 +119,7 @@ static const char *algo_names[] = {
"blake",
"blakecoin",
"blake2s",
"c11",
"cryptonight",
"dmd-gr",
"drop",
Expand Down Expand Up @@ -244,6 +246,7 @@ Options:\n\
blake Blake-256 (SFR)\n\
blakecoin Blakecoin\n\
blake2s Blake-2 S\n\
c11/flax C11\n\
cryptonight CryptoNight\n\
dmd-gr Diamond-Groestl\n\
drop Dropcoin\n\
Expand Down Expand Up @@ -2013,6 +2016,7 @@ static void *miner_thread(void *userdata)
case ALGO_LYRA2:
max64 = 0xffff;
break;
case ALGO_C11:
case ALGO_DMD_GR:
case ALGO_FRESH:
case ALGO_GROESTL:
Expand Down Expand Up @@ -2095,8 +2099,10 @@ static void *miner_thread(void *userdata)
&hashes_done);
break;
case ALGO_BLAKE2S:
rc = scanhash_blake2s(thr_id, work.data, work.target, max_nonce,
&hashes_done);
rc = scanhash_blake2s(thr_id, work.data, work.target, max_nonce, &hashes_done);
break;
case ALGO_C11:
rc = scanhash_c11(thr_id, work.data, work.target, max_nonce, &hashes_done);
break;
case ALGO_DROP:
rc = scanhash_drop(thr_id, &work, max_nonce, &hashes_done);
Expand Down Expand Up @@ -2620,6 +2626,8 @@ void parse_arg(int key, char *arg)
// some aliases...
if (!strcasecmp("blake2", arg))
i = opt_algo = ALGO_BLAKE2S;
else if (!strcasecmp("flax", arg))
i = opt_algo = ALGO_C11;
else if (!strcasecmp("diamond", arg))
i = opt_algo = ALGO_DMD_GR;
else if (!strcasecmp("droplp", arg))
Expand Down
5 changes: 3 additions & 2 deletions cpuminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
<ClCompile Include="algo\blake.c" />
<ClCompile Include="algo\blakecoin.c" />
<ClCompile Include="algo\blake2.c" />
<ClCompile Include="algo\c11.c" />
<ClCompile Include="algo\cryptonight.c" />
<ClCompile Include="algo\drop.c" />
<ClCompile Include="algo\fresh.c" />
Expand Down Expand Up @@ -261,8 +262,8 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\ccminer\compat\jansson\config.h" />
<ClInclude Include="..\ccminer\compat\jansson\jansson.h" />
<ClInclude Include="compat\jansson\config.h" />
<ClInclude Include="compat\jansson\jansson.h" />
<ClInclude Include="compat.h" />
<ClInclude Include="compat\getopt\getopt.h" />
<ClInclude Include="compat\inttypes.h" />
Expand Down
9 changes: 6 additions & 3 deletions cpuminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
<ClCompile Include="algo\blakecoin.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\c11.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\cryptonight.c">
<Filter>algo</Filter>
</ClCompile>
Expand Down Expand Up @@ -340,10 +343,10 @@
<ClInclude Include="compat\cpuminer-config.h">
<Filter>headers</Filter>
</ClInclude>
<ClInclude Include="..\ccminer\compat\jansson\jansson.h">
<ClInclude Include="compat\jansson\jansson.h">
<Filter>jansson</Filter>
</ClInclude>
<ClInclude Include="..\ccminer\compat\jansson\config.h">
<ClInclude Include="compat\jansson\config.h">
<Filter>jansson</Filter>
</ClInclude>
<ClInclude Include="crypto\blake2s.h">
Expand Down Expand Up @@ -499,4 +502,4 @@
<Filter>res</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
4 changes: 4 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ int scanhash_blakecoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
int scanhash_blake2s(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, uint64_t *hashes_done);

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

int scanhash_drop(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);

int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
Expand Down Expand Up @@ -488,6 +491,7 @@ void animehash(void *state, const void *input);
void blakehash(void *state, const void *input);
void blakecoinhash(void *state, const void *input);
void blake2s_hash(void *output, const void *input);
void c11hash(void *output, const void *input);
void cryptonight_hash(void* output, const void* input, int len);
void droplp_hash(void *output, const void *input);
void groestlhash(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 @@ -1793,6 +1793,9 @@ void print_hash_tests(void)
blake2s_hash(&hash[0], &buf[0]);
printpfx("blake2s", hash);

c11hash(&hash[0], &buf[0]);
printpfx("c11", hash);

cryptonight_hash(&hash[0], &buf[0], 76);
printpfx("cryptonight", hash);

Expand Down

0 comments on commit 15205b4

Please sign in to comment.