Skip to content

Commit

Permalink
veltor algo
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Aug 23, 2016
1 parent 5b0f7a8 commit 4003132
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ cpuminer_SOURCES = \
sha3/sph_echo.c \
sha3/sph_hamsi.c \
sha3/sph_fugue.c \
sha3/sph_gost.c \
sha3/sph_ripemd.c \
sha3/sph_sha2.c \
sha3/sph_sha2big.c \
sha3/sph_shabal.c \
sha3/sph_whirlpool.c \
sha3/gost_streebog.c \
crypto/blake2s.c \
crypto/blake2b.c \
crypto/oaes_lib.c \
Expand Down Expand Up @@ -88,6 +88,7 @@ cpuminer_SOURCES = \
algo/skein.c \
algo/skein2.c \
algo/s3.c \
algo/veltor.c \
algo/x11evo.c \
algo/x11.c \
algo/x13.c \
Expand Down
2 changes: 1 addition & 1 deletion algo/sibcoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "sha3/sph_keccak.h"
#include "sha3/sph_skein.h"
#include "sha3/sph_luffa.h"
#include "sha3/sph_gost.h"
#include "sha3/gost_streebog.h"
#include "sha3/sph_cubehash.h"
#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
Expand Down
94 changes: 94 additions & 0 deletions algo/veltor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#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_shabal.h>
#include <sha3/gost_streebog.h>

/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
typedef struct {
sph_skein512_context skein1;
sph_shavite512_context shavite1;
sph_shabal512_context shabal1;
sph_gost512_context gost1;
} Xhash_context_holder;

static __thread Xhash_context_holder base_contexts;
static __thread bool init = false;

static void init_Xhash_contexts()
{
sph_skein512_init(&base_contexts.skein1);
sph_shavite512_init(&base_contexts.shavite1);
sph_shabal512_init(&base_contexts.shabal1);
sph_gost512_init(&base_contexts.gost1);
init = true;
}

void veltor_hash(void *output, const void *input)
{
Xhash_context_holder ctx;

uint32_t hashA[16];

if (!init) init_Xhash_contexts();

memcpy(&ctx, &base_contexts, sizeof(base_contexts));

sph_skein512(&ctx.skein1, input, 80);
sph_skein512_close(&ctx.skein1, hashA);

sph_shavite512(&ctx.shavite1, hashA, 64);
sph_shavite512_close(&ctx.shavite1, hashA);

sph_shabal512(&ctx.shabal1, hashA, 64);
sph_shabal512_close(&ctx.shabal1, hashA);

sph_gost512(&ctx.gost1, hashA, 64);
sph_gost512_close(&ctx.gost1, hashA);

memcpy(output, hashA, 32);
}

int scanhash_veltor(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t _ALIGN(128) hash[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
uint32_t nonce = first_nonce;
volatile uint8_t *restart = &(work_restart[thr_id].restart);

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

// we need bigendian data...
for (int i=0; i < 19; i++) {
be32enc(&endiandata[i], pdata[i]);
}
do {
be32enc(&endiandata[19], nonce);
veltor_hash(hash, endiandata);

if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
work_set_target_ratio(work, hash);
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;
}
6 changes: 6 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum algos {
ALGO_SKEIN2, /* Double skein (Woodcoin) */
ALGO_S3, /* S3 */
ALGO_VANILLA, /* Vanilla (Blake256 8-rounds - double sha256) */
ALGO_VELTOR, /* Skein Shavite Shabal Streebog */
ALGO_X11EVO, /* Permuted X11 */
ALGO_X11, /* X11 */
ALGO_X13, /* X13 */
Expand Down Expand Up @@ -162,6 +163,7 @@ static const char *algo_names[] = {
"skein2",
"s3",
"vanilla",
"veltor",
"x11evo",
"x11",
"x13",
Expand Down Expand Up @@ -2103,6 +2105,7 @@ static void *miner_thread(void *userdata)
case ALGO_GROESTL:
case ALGO_MYR_GR:
case ALGO_SIB:
case ALGO_VELTOR:
case ALGO_X11EVO:
case ALGO_X11:
case ALGO_X13:
Expand Down Expand Up @@ -2258,6 +2261,9 @@ static void *miner_thread(void *userdata)
case ALGO_VANILLA:
rc = scanhash_blakecoin(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_VELTOR:
rc = scanhash_veltor(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_X11EVO:
rc = scanhash_x11evo(thr_id, &work, max_nonce, &hashes_done);
break;
Expand Down
5 changes: 3 additions & 2 deletions cpuminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
<ClCompile Include="algo\sibcoin.c" />
<ClCompile Include="algo\skein.c" />
<ClCompile Include="algo\skein2.c" />
<ClCompile Include="algo\veltor.c" />
<ClCompile Include="algo\x11evo.c" />
<ClCompile Include="algo\x11.c" />
<ClCompile Include="algo\x13.c" />
Expand Down Expand Up @@ -273,7 +274,7 @@
</ClCompile>
<ClCompile Include="sha3\sph_haval.c" />
<ClCompile Include="sha3\sph_whirlpool.c" />
<ClCompile Include="sha3\sph_gost.c" />
<ClCompile Include="sha3\gost_streebog.c" />
<ClCompile Include="sha3\md_helper.c">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -328,7 +329,7 @@
<ClInclude Include="sha3\sph_cubehash.h" />
<ClInclude Include="sha3\sph_echo.h" />
<ClInclude Include="sha3\sph_fugue.h" />
<ClInclude Include="sha3\sph_gost.h" />
<ClInclude Include="sha3\gost_streebog.h" />
<ClInclude Include="sha3\sph_groestl.h" />
<ClInclude Include="sha3\sph_haval.h" />
<ClInclude Include="sha3\sph_hefty1.h" />
Expand Down
7 changes: 5 additions & 2 deletions cpuminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<ClCompile Include="sha3\aes_helper.c">
<Filter>sph</Filter>
</ClCompile>
<ClCompile Include="sha3\sph_gost.c">
<ClCompile Include="sha3\gost_streebog.c">
<Filter>sph</Filter>
</ClCompile>
<ClCompile Include="compat\winansi.c">
Expand Down Expand Up @@ -252,6 +252,9 @@
<ClCompile Include="algo\skein.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\veltor.c">
<Filter>algo</Filter>
</ClCompile>
<ClCompile Include="algo\x11evo.c">
<Filter>algo</Filter>
</ClCompile>
Expand Down Expand Up @@ -365,7 +368,7 @@
<ClInclude Include="sha3\sph_whirlpool.h">
<Filter>sph</Filter>
</ClInclude>
<ClInclude Include="sha3\sph_gost.h">
<ClInclude Include="sha3\gost_streebog.h">
<Filter>sph</Filter>
</ClInclude>
<ClInclude Include="compat.h">
Expand Down
2 changes: 2 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ int scanhash_sib(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *ha
int scanhash_skein(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_skein2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_s3(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);
int scanhash_x13(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
Expand Down Expand Up @@ -515,6 +516,7 @@ void sibhash(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 veltor_hash(void *output, const void *input);
void x11evo_hash(void *output, const void *input);
void x11hash(void *output, const void *input);
void x13hash(void *output, const void *input);
Expand Down
46 changes: 12 additions & 34 deletions sha3/sph_gost.c → sha3/gost_streebog.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* GOST hash function for sib algo SibCoin */
/* GOST-R Streebog hash function for sib algo SibCoin */

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>

#include "sha3/sph_gost.h"
#include "gost_streebog.h"

#ifdef __cplusplus
extern "C"{
Expand All @@ -18,7 +18,7 @@ extern "C"{

//--------------------------------------------------------------------------------------------
//
// stribog implementation
// streebog implementation
//
//--------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -978,65 +978,43 @@ static void hash_256(const unsigned char *message, unsigned long long length, un
}


/* exported functions, to rename (streebog) */



/* see sph_gost.h */
void
sph_gost256_init(void *cc)
void sph_gost256_init(void *cc)
{
//gost_init(cc, 256);
}

/* see sph_gost.h */
void
sph_gost256(void *cc, const void *data, size_t len)
void sph_gost256(void *cc, const void *data, size_t len)
{
hash_256(data, 8*len, cc);
}

/* see sph_gost.h */
void
sph_gost256_close(void *cc, void *dst)
void sph_gost256_close(void *cc, void *dst)
{
//sph_gost256_addbits_and_close(cc, 0, 0, dst);
memcpy(dst, cc, 32);
}

/* see sph_gost.h */
void
sph_gost256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
void sph_gost256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
{
//gost_close32(cc, ub, n, dst);
}

/* see sph_gost.h */
void
sph_gost512_init(void *cc)
void sph_gost512_init(void *cc)
{
//gost_init(cc, 512);
}

/* see sph_gost.h */
void
sph_gost512(void *cc, const void *data, size_t len)
void sph_gost512(void *cc, const void *data, size_t len)
{
hash_512(data, 8*len, cc);
}

/* see sph_gost.h */
void
sph_gost512_close(void *cc, void *dst)
void sph_gost512_close(void *cc, void *dst)
{
//sph_gost512_addbits_and_close(cc, 0, 0, dst);
memcpy(dst, cc, 64);
}

/* see sph_gost.h */
void
sph_gost512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
void sph_gost512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
{
//gost_close64(cc, ub, n, dst);
}


Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2327,9 +2327,6 @@ void print_hash_tests(void)
blake2s_hash(&hash[0], &buf[0]);
printpfx("blake2s", hash);

blake2b_hash(&hash[0], &buf[0]);
printpfx("blake2b", hash);

bmwhash(&hash[0], &buf[0]);
printpfx("bmw", hash);

Expand Down Expand Up @@ -2410,6 +2407,9 @@ void print_hash_tests(void)
sha256d((uint8_t*) &hash[0], (uint8_t*)&buf[0], 64);
printpfx("sha256d", hash);

blake2b_hash(&hash[0], &buf[0]);
printpfx("sia", hash);

sibhash(&hash[0], &buf[0]);
printpfx("sib", hash);

Expand All @@ -2422,6 +2422,9 @@ void print_hash_tests(void)
s3hash(&hash[0], &buf[0]);
printpfx("s3", hash);

veltor_hash(&hash[0], &buf[0]);
printpfx("veltor", hash);

x11evo_hash(&hash[0], &buf[0]);
printpfx("x11evo", hash);

Expand Down

0 comments on commit 4003132

Please sign in to comment.