Skip to content

Commit

Permalink
wolf's whirlpoolx mod
Browse files Browse the repository at this point in the history
  • Loading branch information
troky committed Mar 25, 2015
1 parent f1bf570 commit ae87ca6
Show file tree
Hide file tree
Showing 7 changed files with 567 additions and 1,364 deletions.
32 changes: 22 additions & 10 deletions algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,21 +638,33 @@ static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_

static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
uint64_t midblock[8], key[8], tmp[8] = { 0 };
cl_ulong le_target;
cl_int status = 0;
cl_int status;

le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);

//clbuffer, hashes
kernel = &clState->kernel;
CL_SET_ARG_N(0, clState->CLbuffer0);
CL_SET_ARG_N(1, clState->padbuffer8);
memcpy(midblock, clState->cldata, 64);

// midblock = n, key = h
for (int i = 0; i < 10; ++i)
{
tmp[0] = WHIRLPOOL_ROUND_CONSTANTS[i];
whirlpool_round(key, tmp);
tmp[0] = 0;
whirlpool_round(midblock, tmp);

for (int x = 0; x < 8; ++x) midblock[x] ^= key[x];
}

for (int i = 0; i < 8; ++i) midblock[i] ^= ((uint64_t *)(clState->cldata))[i];

CL_SET_ARG_N(2, clState->outputBuffer);
CL_SET_ARG_N(3, le_target);
status = clSetKernelArg(clState->kernel, 0, sizeof(cl_ulong8), (cl_ulong8 *)&midblock);
status |= clSetKernelArg(clState->kernel, 1, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 8));
status |= clSetKernelArg(clState->kernel, 2, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 9));
status |= clSetKernelArg(clState->kernel, 3, sizeof(cl_mem), (void *)&clState->outputBuffer);
status |= clSetKernelArg(clState->kernel, 4, sizeof(cl_ulong), (void *)&le_target);

return status;
}
Expand Down Expand Up @@ -810,7 +822,7 @@ static algorithm_settings_t algos[] = {
#undef A_FUGUE

{ "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, queue_whirlcoin_kernel, sha256, NULL },
{ "whirlpoolx", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, 0, whirlpoolx_regenhash, queue_sph_kernel, gen_hash, NULL },
{ "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFFU, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, queue_whirlpoolx_kernel, gen_hash, NULL },

// Terminator (do not remove)
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
Expand Down
1 change: 1 addition & 0 deletions algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef enum {
ALGO_NIST,
ALGO_FRESH,
ALGO_WHIRL,
ALGO_WHIRLPOOLX,
ALGO_NEOSCRYPT,
ALGO_LYRA2RE,
ALGO_PLUCK
Expand Down
130 changes: 65 additions & 65 deletions algorithm/whirlcoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ Whash_context_holder base_contexts;

void init_whirlcoin_hash_contexts()
{
sph_whirlpool1_init(&base_contexts.whirlpool1);
sph_whirlpool1_init(&base_contexts.whirlpool2);
sph_whirlpool1_init(&base_contexts.whirlpool3);
sph_whirlpool1_init(&base_contexts.whirlpool4);
sph_whirlpool1_init(&base_contexts.whirlpool1);
sph_whirlpool1_init(&base_contexts.whirlpool2);
sph_whirlpool1_init(&base_contexts.whirlpool3);
sph_whirlpool1_init(&base_contexts.whirlpool4);
}

/*
Expand All @@ -62,10 +62,10 @@ void init_whirlcoin_hash_contexts()
static inline void
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
{
uint32_t i;
uint32_t i;

for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]);
for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]);
}


Expand All @@ -74,33 +74,32 @@ static
#endif
inline void whirlcoin_hash(void *state, const void *input)
{
init_whirlcoin_hash_contexts();
init_whirlcoin_hash_contexts();

Whash_context_holder ctx;
uint32_t hashA[16], hashB[16];
Whash_context_holder ctx;
uint32_t hashA[16], hashB[16];

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

sph_whirlpool1 (&ctx.whirlpool1, input, 80);
sph_whirlpool1_close (&ctx.whirlpool1, hashA);
sph_whirlpool1(&ctx.whirlpool1, input, 80);
sph_whirlpool1_close(&ctx.whirlpool1, hashA);

sph_whirlpool1(&ctx.whirlpool2, hashA, 64);
sph_whirlpool1_close(&ctx.whirlpool2, hashB);
sph_whirlpool1(&ctx.whirlpool2, hashA, 64);
sph_whirlpool1_close(&ctx.whirlpool2, hashB);

sph_whirlpool1(&ctx.whirlpool3, hashB, 64);
sph_whirlpool1_close(&ctx.whirlpool3, hashA);
sph_whirlpool1(&ctx.whirlpool3, hashB, 64);
sph_whirlpool1_close(&ctx.whirlpool3, hashA);

sph_whirlpool1(&ctx.whirlpool4, hashA, 64);
sph_whirlpool1_close(&ctx.whirlpool4, hashB);
sph_whirlpool1(&ctx.whirlpool4, hashA, 64);
sph_whirlpool1_close(&ctx.whirlpool4, hashB);

memcpy(state, hashB, 32);
memcpy(state, hashB, 32);
}

static const uint32_t diff1targ = 0x0000ffff;


/* Used externally as confirmation of correct OCL code */
int whirlcoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
int whirlcoin_test_old(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
uint32_t data[20], ohash[8];
Expand All @@ -124,51 +123,52 @@ int whirlcoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t

void whirlcoin_regenhash(struct work *work)
{
uint32_t data[20];
uint32_t *nonce = (uint32_t *)(work->data + 76);
uint32_t *ohash = (uint32_t *)(work->hash);
uint32_t data[20];
uint32_t *nonce = (uint32_t *)(work->data + 76);
uint32_t *ohash = (uint32_t *)(work->hash);

be32enc_vect(data, (const uint32_t *)work->data, 19);
data[19] = htobe32(*nonce);
whirlcoin_hash(ohash, data);
be32enc_vect(data, (const uint32_t *)work->data, 19);
data[19] = htobe32(*nonce);
whirlcoin_hash(ohash, data);
}

/*
bool scanhash_whirlcoin(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{
uint32_t *nonce = (uint32_t *)(pdata + 76);
uint32_t data[20];
uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false;

be32enc_vect(data, (const uint32_t *)pdata, 19);

while(1) {
uint32_t ostate[8];

*nonce = ++n;
data[19] = (n);
whirlcoin_hash(ostate, data);
tmp_hash7 = (ostate[7]);

applog(LOG_INFO, "data7 %08lx",
(long unsigned int)data[7]);

if (unlikely(tmp_hash7 <= Htarg)) {
((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n;
ret = true;
break;
}

if (unlikely((n >= max_nonce) || thr->work_restart)) {
*last_nonce = n;
break;
}
}

return ret;
uint32_t *nonce = (uint32_t *)(pdata + 76);
uint32_t data[20];
uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false;
be32enc_vect(data, (const uint32_t *)pdata, 19);
while (1) {
uint32_t ostate[8];
*nonce = ++n;
data[19] = (n);
whirlcoin_hash(ostate, data);
tmp_hash7 = (ostate[7]);
applog(LOG_INFO, "data7 %08lx",
(long unsigned int)data[7]);
if (unlikely(tmp_hash7 <= Htarg)) {
((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n;
ret = true;
break;
}
if (unlikely((n >= max_nonce) || thr->work_restart)) {
*last_nonce = n;
break;
}
}
return ret;
}
*/
Loading

0 comments on commit ae87ca6

Please sign in to comment.