Browse Source

Merge pull request #324 from Elbandi/v5_0-stylefix

bitblock and x14 algo codestyle fix
djm34
troky 11 years ago
parent
commit
855adf1477
  1. 242
      algorithm/bitblock.c
  2. 197
      algorithm/x14.c

242
algorithm/bitblock.c

@ -66,8 +66,8 @@ typedef struct {
sph_echo512_context echo1; sph_echo512_context echo1;
sph_hamsi512_context hamsi1; sph_hamsi512_context hamsi1;
sph_fugue512_context fugue1; sph_fugue512_context fugue1;
sph_shabal512_context shabal1; sph_shabal512_context shabal1;
sph_whirlpool_context whilpool1; sph_whirlpool_context whirlpool1;
} Xhash_context_holder; } Xhash_context_holder;
static Xhash_context_holder base_contexts; static Xhash_context_holder base_contexts;
@ -75,12 +75,12 @@ static Xhash_context_holder base_contexts;
void init_Bhash_contexts() void init_Bhash_contexts()
{ {
sph_blake512_init(&base_contexts.blake1); sph_blake512_init(&base_contexts.blake1);
sph_bmw512_init(&base_contexts.bmw1); sph_bmw512_init(&base_contexts.bmw1);
sph_groestl512_init(&base_contexts.groestl1); sph_groestl512_init(&base_contexts.groestl1);
sph_skein512_init(&base_contexts.skein1); sph_skein512_init(&base_contexts.skein1);
sph_jh512_init(&base_contexts.jh1); sph_jh512_init(&base_contexts.jh1);
sph_keccak512_init(&base_contexts.keccak1); sph_keccak512_init(&base_contexts.keccak1);
sph_luffa512_init(&base_contexts.luffa1); sph_luffa512_init(&base_contexts.luffa1);
sph_cubehash512_init(&base_contexts.cubehash1); sph_cubehash512_init(&base_contexts.cubehash1);
sph_shavite512_init(&base_contexts.shavite1); sph_shavite512_init(&base_contexts.shavite1);
@ -88,8 +88,8 @@ void init_Bhash_contexts()
sph_echo512_init(&base_contexts.echo1); sph_echo512_init(&base_contexts.echo1);
sph_hamsi512_init(&base_contexts.hamsi1); sph_hamsi512_init(&base_contexts.hamsi1);
sph_fugue512_init(&base_contexts.fugue1); sph_fugue512_init(&base_contexts.fugue1);
sph_shabal512_init(&base_contexts.shabal1); sph_shabal512_init(&base_contexts.shabal1);
sph_whirlpool_init(&base_contexts.whilpool1); sph_whirlpool_init(&base_contexts.whirlpool1);
} }
/* /*
@ -99,67 +99,67 @@ void init_Bhash_contexts()
static inline void static inline void
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
{ {
uint32_t i; uint32_t i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]); dst[i] = htobe32(src[i]);
} }
inline void bitblockhash(void *state, const void *input) inline void bitblockhash(void *state, const void *input)
{ {
init_Bhash_contexts(); init_Bhash_contexts();
Xhash_context_holder ctx; Xhash_context_holder ctx;
uint32_t hashA[16], hashB[16]; uint32_t hashA[16], hashB[16];
//blake-bmw-groestl-sken-jh-meccak-luffa-cubehash-shivite-simd-echo
memcpy(&ctx, &base_contexts, sizeof(base_contexts)); memcpy(&ctx, &base_contexts, sizeof(base_contexts));
sph_blake512 (&ctx.blake1, input, 80); sph_blake512 (&ctx.blake1, input, 80);
sph_blake512_close (&ctx.blake1, hashA); sph_blake512_close (&ctx.blake1, hashA);
sph_bmw512 (&ctx.bmw1, hashA, 64);
sph_bmw512_close(&ctx.bmw1, hashB);
sph_bmw512 (&ctx.bmw1, hashA, 64); sph_groestl512 (&ctx.groestl1, hashB, 64);
sph_bmw512_close(&ctx.bmw1, hashB);
sph_groestl512 (&ctx.groestl1, hashB, 64);
sph_groestl512_close(&ctx.groestl1, hashA); sph_groestl512_close(&ctx.groestl1, hashA);
sph_skein512 (&ctx.skein1, hashA, 64); sph_skein512 (&ctx.skein1, hashA, 64);
sph_skein512_close(&ctx.skein1, hashB); sph_skein512_close(&ctx.skein1, hashB);
sph_jh512 (&ctx.jh1, hashB, 64); sph_jh512 (&ctx.jh1, hashB, 64);
sph_jh512_close(&ctx.jh1, hashA); sph_jh512_close(&ctx.jh1, hashA);
sph_keccak512 (&ctx.keccak1, hashA, 64); sph_keccak512 (&ctx.keccak1, hashA, 64);
sph_keccak512_close(&ctx.keccak1, hashB); sph_keccak512_close(&ctx.keccak1, hashB);
sph_luffa512 (&ctx.luffa1, hashB, 64); sph_luffa512 (&ctx.luffa1, hashB, 64);
sph_luffa512_close (&ctx.luffa1, hashA); sph_luffa512_close (&ctx.luffa1, hashA);
sph_cubehash512 (&ctx.cubehash1, hashA, 64); sph_cubehash512 (&ctx.cubehash1, hashA, 64);
sph_cubehash512_close(&ctx.cubehash1, hashB); sph_cubehash512_close(&ctx.cubehash1, hashB);
sph_shavite512 (&ctx.shavite1, hashB, 64); sph_shavite512 (&ctx.shavite1, hashB, 64);
sph_shavite512_close(&ctx.shavite1, hashA); sph_shavite512_close(&ctx.shavite1, hashA);
sph_simd512 (&ctx.simd1, hashA, 64); sph_simd512 (&ctx.simd1, hashA, 64);
sph_simd512_close(&ctx.simd1, hashB); sph_simd512_close(&ctx.simd1, hashB);
sph_echo512 (&ctx.echo1, hashB, 64); sph_echo512 (&ctx.echo1, hashB, 64);
sph_echo512_close(&ctx.echo1, hashA); sph_echo512_close(&ctx.echo1, hashA);
sph_hamsi512 (&ctx.hamsi1, hashA, 64); sph_hamsi512 (&ctx.hamsi1, hashA, 64);
sph_hamsi512_close(&ctx.hamsi1, hashB); sph_hamsi512_close(&ctx.hamsi1, hashB);
sph_fugue512 (&ctx.fugue1, hashB, 64); sph_fugue512 (&ctx.fugue1, hashB, 64);
sph_fugue512_close(&ctx.fugue1, hashA); sph_fugue512_close(&ctx.fugue1, hashA);
sph_shabal512 (&ctx.shabal1, (const unsigned char*)hashA, 64); sph_shabal512 (&ctx.shabal1, (const unsigned char*)hashA, 64);
sph_shabal512_close(&ctx.shabal1, hashB); sph_shabal512_close(&ctx.shabal1, hashB);
sph_whirlpool(&ctx.whilpool1, hashB, 64); sph_whirlpool (&ctx.whirlpool1, hashB, 64);
sph_whirlpool_close(&ctx.whilpool1, hashA); sph_whirlpool_close(&ctx.whirlpool1, hashA);
memcpy(state, hashA, 32); memcpy(state, hashA, 32);
@ -171,83 +171,71 @@ static const uint32_t diff1targ = 0x0000ffff;
/* Used externally as confirmation of correct OCL code */ /* Used externally as confirmation of correct OCL code */
int bitblock_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) int bitblock_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{ {
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]); uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
uint32_t data[20], ohash[8]; uint32_t data[20], ohash[8];
be32enc_vect(data, (const uint32_t *)pdata, 19); be32enc_vect(data, (const uint32_t *)pdata, 19);
data[19] = htobe32(nonce); data[19] = htobe32(nonce);
bitblockhash(ohash, data); bitblockhash(ohash, data);
tmp_hash7 = be32toh(ohash[7]); tmp_hash7 = be32toh(ohash[7]);
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx", applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
(long unsigned int)Htarg, (long unsigned int)Htarg,
(long unsigned int)diff1targ, (long unsigned int)diff1targ,
(long unsigned int)tmp_hash7); (long unsigned int)tmp_hash7);
if (tmp_hash7 > diff1targ) if (tmp_hash7 > diff1targ)
return -1; return -1;
if (tmp_hash7 > Htarg) if (tmp_hash7 > Htarg)
return 0; return 0;
return 1; return 1;
} }
void bitblock_regenhash(struct work *work) void bitblock_regenhash(struct work *work)
{ {
uint32_t data[20]; uint32_t data[20];
uint32_t *nonce = (uint32_t *)(work->data + 76); uint32_t *nonce = (uint32_t *)(work->data + 76);
uint32_t *ohash = (uint32_t *)(work->hash); uint32_t *ohash = (uint32_t *)(work->hash);
be32enc_vect(data, (const uint32_t *)work->data, 19);
data[19] = htobe32(*nonce);
bitblockhash(ohash, data);
}
static inline void be32enc(void *pp, uint32_t x) be32enc_vect(data, (const uint32_t *)work->data, 19);
{ data[19] = htobe32(*nonce);
uint8_t *p = (uint8_t *)pp; bitblockhash(ohash, data);
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
} }
bool scanhash_bitblock(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate, bool scanhash_bitblock(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
unsigned char *pdata, unsigned char __maybe_unused *phash1, unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget, unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n) uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{ {
uint32_t *nonce = (uint32_t *)(pdata + 76); uint32_t *nonce = (uint32_t *)(pdata + 76);
uint32_t data[20]; uint32_t data[20];
uint32_t tmp_hash7; uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]); uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false; bool ret = false;
be32enc_vect(data, (const uint32_t *)pdata, 19); be32enc_vect(data, (const uint32_t *)pdata, 19);
while(1) { while(1) {
uint32_t ostate[8]; uint32_t ostate[8];
*nonce = ++n; *nonce = ++n;
data[19] = (n); data[19] = (n);
bitblockhash(ostate, data); bitblockhash(ostate, data);
tmp_hash7 = (ostate[7]); tmp_hash7 = (ostate[7]);
applog(LOG_INFO, "data7 %08lx", applog(LOG_INFO, "data7 %08lx",
(long unsigned int)data[7]); (long unsigned int)data[7]);
if (unlikely(tmp_hash7 <= Htarg)) { if (unlikely(tmp_hash7 <= Htarg)) {
((uint32_t *)pdata)[19] = htobe32(n); ((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n; *last_nonce = n;
ret = true; ret = true;
break; break;
} }
if (unlikely((n >= max_nonce) || thr->work_restart)) { if (unlikely((n >= max_nonce) || thr->work_restart)) {
*last_nonce = n; *last_nonce = n;
break; break;
} }
} }
return ret; return ret;
} }

197
algorithm/x14.c

@ -65,19 +65,19 @@ typedef struct {
sph_echo512_context echo1; sph_echo512_context echo1;
sph_hamsi512_context hamsi1; sph_hamsi512_context hamsi1;
sph_fugue512_context fugue1; sph_fugue512_context fugue1;
sph_shabal512_context shabal1; sph_shabal512_context shabal1;
} Xhash_context_holder; } Xhash_context_holder;
static Xhash_context_holder base_contexts; static Xhash_context_holder base_contexts;
void init_X14hash_contexts() void init_X14hash_contexts()
{ {
sph_blake512_init(&base_contexts.blake1); sph_blake512_init(&base_contexts.blake1);
sph_bmw512_init(&base_contexts.bmw1); sph_bmw512_init(&base_contexts.bmw1);
sph_groestl512_init(&base_contexts.groestl1); sph_groestl512_init(&base_contexts.groestl1);
sph_skein512_init(&base_contexts.skein1); sph_skein512_init(&base_contexts.skein1);
sph_jh512_init(&base_contexts.jh1); sph_jh512_init(&base_contexts.jh1);
sph_keccak512_init(&base_contexts.keccak1); sph_keccak512_init(&base_contexts.keccak1);
sph_luffa512_init(&base_contexts.luffa1); sph_luffa512_init(&base_contexts.luffa1);
sph_cubehash512_init(&base_contexts.cubehash1); sph_cubehash512_init(&base_contexts.cubehash1);
sph_shavite512_init(&base_contexts.shavite1); sph_shavite512_init(&base_contexts.shavite1);
@ -94,61 +94,61 @@ void init_X14hash_contexts()
*/ */
static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 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++) for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]); dst[i] = htobe32(src[i]);
} }
inline void x14hash(void *state, const void *input) inline void x14hash(void *state, const void *input)
{ {
init_X14hash_contexts(); init_X14hash_contexts();
Xhash_context_holder ctx; Xhash_context_holder ctx;
uint32_t hashA[16], hashB[16]; uint32_t hashA[16], hashB[16];
//blake-bmw-groestl-sken-jh-meccak-luffa-cubehash-shivite-simd-echo
memcpy(&ctx, &base_contexts, sizeof(base_contexts)); memcpy(&ctx, &base_contexts, sizeof(base_contexts));
sph_blake512 (&ctx.blake1, input, 80); sph_blake512 (&ctx.blake1, input, 80);
sph_blake512_close (&ctx.blake1, hashA); sph_blake512_close (&ctx.blake1, hashA);
sph_bmw512 (&ctx.bmw1, hashA, 64); sph_bmw512 (&ctx.bmw1, hashA, 64);
sph_bmw512_close(&ctx.bmw1, hashB); sph_bmw512_close(&ctx.bmw1, hashB);
sph_groestl512 (&ctx.groestl1, hashB, 64); sph_groestl512 (&ctx.groestl1, hashB, 64);
sph_groestl512_close(&ctx.groestl1, hashA); sph_groestl512_close(&ctx.groestl1, hashA);
sph_skein512 (&ctx.skein1, hashA, 64); sph_skein512 (&ctx.skein1, hashA, 64);
sph_skein512_close(&ctx.skein1, hashB); sph_skein512_close(&ctx.skein1, hashB);
sph_jh512 (&ctx.jh1, hashB, 64); sph_jh512 (&ctx.jh1, hashB, 64);
sph_jh512_close(&ctx.jh1, hashA); sph_jh512_close(&ctx.jh1, hashA);
sph_keccak512 (&ctx.keccak1, hashA, 64); sph_keccak512 (&ctx.keccak1, hashA, 64);
sph_keccak512_close(&ctx.keccak1, hashB); sph_keccak512_close(&ctx.keccak1, hashB);
sph_luffa512 (&ctx.luffa1, hashB, 64); sph_luffa512 (&ctx.luffa1, hashB, 64);
sph_luffa512_close (&ctx.luffa1, hashA); sph_luffa512_close (&ctx.luffa1, hashA);
sph_cubehash512 (&ctx.cubehash1, hashA, 64); sph_cubehash512 (&ctx.cubehash1, hashA, 64);
sph_cubehash512_close(&ctx.cubehash1, hashB); sph_cubehash512_close(&ctx.cubehash1, hashB);
sph_shavite512 (&ctx.shavite1, hashB, 64); sph_shavite512 (&ctx.shavite1, hashB, 64);
sph_shavite512_close(&ctx.shavite1, hashA); sph_shavite512_close(&ctx.shavite1, hashA);
sph_simd512 (&ctx.simd1, hashA, 64); sph_simd512 (&ctx.simd1, hashA, 64);
sph_simd512_close(&ctx.simd1, hashB); sph_simd512_close(&ctx.simd1, hashB);
sph_echo512 (&ctx.echo1, hashB, 64); sph_echo512 (&ctx.echo1, hashB, 64);
sph_echo512_close(&ctx.echo1, hashA); sph_echo512_close(&ctx.echo1, hashA);
sph_hamsi512 (&ctx.hamsi1, hashA, 64); sph_hamsi512 (&ctx.hamsi1, hashA, 64);
sph_hamsi512_close(&ctx.hamsi1, hashB); sph_hamsi512_close(&ctx.hamsi1, hashB);
sph_fugue512 (&ctx.fugue1, hashB, 64); sph_fugue512 (&ctx.fugue1, hashB, 64);
sph_fugue512_close(&ctx.fugue1, hashA); sph_fugue512_close(&ctx.fugue1, hashA);
sph_shabal512 (&ctx.shabal1, (const unsigned char*)hashA, 64); sph_shabal512 (&ctx.shabal1, (const unsigned char*)hashA, 64);
sph_shabal512_close(&ctx.shabal1, hashB); sph_shabal512_close(&ctx.shabal1, hashB);
@ -161,26 +161,26 @@ static const uint32_t diff1targ = 0x0000ffff;
/* Used externally as confirmation of correct OCL code */ /* Used externally as confirmation of correct OCL code */
int x14_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce) int x14_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{ {
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]); uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
uint32_t data[20], ohash[8]; uint32_t data[20], ohash[8];
be32enc_vect(data, (const uint32_t *)pdata, 19); be32enc_vect(data, (const uint32_t *)pdata, 19);
data[19] = htobe32(nonce); data[19] = htobe32(nonce);
x14hash(ohash, data); x14hash(ohash, data);
tmp_hash7 = be32toh(ohash[7]); tmp_hash7 = be32toh(ohash[7]);
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx", applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
(long unsigned int)Htarg, (long unsigned int)Htarg,
(long unsigned int)diff1targ, (long unsigned int)diff1targ,
(long unsigned int)tmp_hash7); (long unsigned int)tmp_hash7);
if (tmp_hash7 > diff1targ) if (tmp_hash7 > diff1targ)
return -1; return -1;
if (tmp_hash7 > Htarg) if (tmp_hash7 > Htarg)
return 0; return 0;
return 1; return 1;
} }
void x14_regenhash(struct work *work) void x14_regenhash(struct work *work)
@ -194,54 +194,43 @@ void x14_regenhash(struct work *work)
x14hash(ohash, data); x14hash(ohash, data);
} }
static inline void be32enc(void *pp, uint32_t x)
{
uint8_t *p = (uint8_t *)pp;
p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
bool scanhash_x14(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate, bool scanhash_x14(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
unsigned char *pdata, unsigned char __maybe_unused *phash1, unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget, unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n) uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{ {
uint32_t *nonce = (uint32_t *)(pdata + 76); uint32_t *nonce = (uint32_t *)(pdata + 76);
uint32_t data[20]; uint32_t data[20];
uint32_t tmp_hash7; uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]); uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false; bool ret = false;
be32enc_vect(data, (const uint32_t *)pdata, 19); be32enc_vect(data, (const uint32_t *)pdata, 19);
while(1) while(1)
{ {
uint32_t ostate[8]; uint32_t ostate[8];
*nonce = ++n; *nonce = ++n;
data[19] = (n); data[19] = (n);
x14hash(ostate, data); x14hash(ostate, data);
tmp_hash7 = (ostate[7]); tmp_hash7 = (ostate[7]);
applog(LOG_INFO, "data7 %08lx", (long unsigned int)data[7]); applog(LOG_INFO, "data7 %08lx", (long unsigned int)data[7]);
if(unlikely(tmp_hash7 <= Htarg)) if(unlikely(tmp_hash7 <= Htarg))
{ {
((uint32_t *)pdata)[19] = htobe32(n); ((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n; *last_nonce = n;
ret = true; ret = true;
break; break;
} }
if (unlikely((n >= max_nonce) || thr->work_restart)) if (unlikely((n >= max_nonce) || thr->work_restart))
{ {
*last_nonce = n; *last_nonce = n;
break; break;
} }
} }
return ret;
}
return ret;
}
Loading…
Cancel
Save