This commit is contained in:
Jay D Dee
2017-02-12 12:43:08 -05:00
parent 1ee41348f4
commit 8efab74183
20 changed files with 1891 additions and 1294 deletions

View File

@@ -7,44 +7,58 @@
#include <stdio.h>
#include "sph_whirlpool.h"
typedef struct {
sph_whirlpool_context whirl1;
sph_whirlpool_context whirl2;
sph_whirlpool_context whirl3;
sph_whirlpool_context whirl4;
} whirlpool_ctx_holder;
static whirlpool_ctx_holder whirl_ctx;
static __thread sph_whirlpool_context whirl1_mid_ctx;
void init_whirlpool_ctx()
{
sph_whirlpool1_init( &whirl_ctx.whirl1 );
sph_whirlpool1_init( &whirl_ctx.whirl2 );
sph_whirlpool1_init( &whirl_ctx.whirl3 );
sph_whirlpool1_init( &whirl_ctx.whirl4 );
}
void whirlpool_hash(void *state, const void *input)
{
sph_whirlpool_context ctx_whirlpool;
whirlpool_ctx_holder ctx;
memcpy( &ctx, &whirl_ctx, sizeof(whirl_ctx) );
const int midlen = 64;
const int tail = 80 - midlen;
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
#define hashB hash+64
memset(hash, 0, sizeof hash);
// copy cached midstate
memcpy( &ctx.whirl1, &whirl1_mid_ctx, sizeof whirl1_mid_ctx );
sph_whirlpool1( &ctx.whirl1, input + midlen, tail );
sph_whirlpool1_close(&ctx.whirl1, hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1(&ctx_whirlpool, input, 80);
sph_whirlpool1_close(&ctx_whirlpool, hash);
sph_whirlpool1(&ctx.whirl2, hash, 64);
sph_whirlpool1_close(&ctx.whirl2, hashB);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1(&ctx_whirlpool, hash, 64);
sph_whirlpool1_close(&ctx_whirlpool, hashB);
sph_whirlpool1(&ctx.whirl3, hashB, 64);
sph_whirlpool1_close(&ctx.whirl3, hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1(&ctx_whirlpool, hashB, 64);
sph_whirlpool1_close(&ctx_whirlpool, hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1(&ctx_whirlpool, hash, 64);
sph_whirlpool1_close(&ctx_whirlpool, hash);
sph_whirlpool1(&ctx.whirl4, hash, 64);
sph_whirlpool1_close(&ctx.whirl4, hash);
memcpy(state, hash, 32);
}
void whirlpool_midstate(void *state, const void *input)
void whirlpool_midstate( const void* input )
{
sph_whirlpool_context ctx;
sph_whirlpool1_init(&ctx);
sph_whirlpool1(&ctx, input, 64);
memcpy(state, ctx.state, 64);
memcpy( &whirl1_mid_ctx, &whirl_ctx.whirl1, sizeof whirl1_mid_ctx );
sph_whirlpool1( &whirl1_mid_ctx, input, 64 );
}
int scanhash_whirlpool(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
{
uint32_t _ALIGN(128) endiandata[20];
@@ -59,6 +73,8 @@ int scanhash_whirlpool(int thr_id, struct work* work, uint32_t max_nonce, unsign
for (int i=0; i < 19; i++)
be32enc(&endiandata[i], pdata[i]);
whirlpool_midstate( endiandata );
do {
const uint32_t Htarg = ptarget[7];
uint32_t vhash[8];
@@ -82,9 +98,9 @@ int scanhash_whirlpool(int thr_id, struct work* work, uint32_t max_nonce, unsign
bool register_whirlpool_algo( algo_gate_t* gate )
{
algo_not_tested();
gate->scanhash = (void*)&scanhash_whirlpool;
gate->hash = (void*)&whirlpool_hash;
init_whirlpool_ctx();
return true;
};