Skip to content

Commit

Permalink
use gostd for merkle in case of stratum
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Sep 16, 2017
1 parent 28a1544 commit 12224ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,22 @@ static void stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
memcpy(work->xnonce2, sctx->job.xnonce2, sctx->xnonce2_size);

/* Generate merkle root */
sha256d(merkle_root, sctx->job.coinbase, sctx->job.coinbase_size);
for (i = 0; i < sctx->job.merkle_count; i++) {
memcpy(merkle_root + 32, sctx->job.merkle[i], 32);
sha256d(merkle_root, merkle_root, 64);
}
if (opt_algo == ALGO_GOSTD)
{
gostd(merkle_root, sctx->job.coinbase, sctx->job.coinbase_size);
for (i = 0; i < sctx->job.merkle_count; i++) {
memcpy(merkle_root + 32, merkle_root, 32);
gostd(merkle_root, merkle_root, 64);
}
}
else
{
sha256d(merkle_root, sctx->job.coinbase, sctx->job.coinbase_size);
for (i = 0; i < sctx->job.merkle_count; i++) {
memcpy(merkle_root + 32, sctx->job.merkle[i], 32);
sha256d(merkle_root, merkle_root, 64);
}
}

/* Increment extranonce2 */
for (i = 0; i < sctx->xnonce2_size && !++sctx->job.xnonce2[i]; i++);
Expand Down
10 changes: 10 additions & 0 deletions gost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,16 @@ void sph_gostd(void *cc, const void *data, size_t len)
hash_256(digest, 64, cc);
}

void gostd(void *output, const void *input, size_t len)
{
unsigned char hash[64];

sph_gost512(hash, (const void*)input, len);
sph_gost256(hash, (const void*)hash, 64);

memcpy(output, hash, 32);
}

int scanhash_gostd(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done)
{
Expand Down
2 changes: 2 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ void sha256_init(uint32_t *state);
void sha256_transform(uint32_t *state, const uint32_t *block, int swap);
void sha256d(unsigned char *hash, const unsigned char *data, int len);

void gostd(void *output, const void *input, size_t len);

#if defined(__ARM_NEON__) || defined(__i386__) || defined(__x86_64__)
#define HAVE_SHA256_4WAY 1
int sha256_use_4way();
Expand Down

0 comments on commit 12224ad

Please sign in to comment.