uint256 CPureBlockHeader::GetPoWHash(int algo, const Consensus::Params& consensusParams) const { switch (algo) { case ALGO_SHA256D: return GetHash(); case ALGO_SCRYPT: { uint256 thash; scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash)); return thash; } case ALGO_GROESTL: return HashGroestl(BEGIN(nVersion), END(nNonce)); case ALGO_SKEIN: return HashSkein(BEGIN(nVersion), END(nNonce)); case ALGO_QUBIT: return HashQubit(BEGIN(nVersion), END(nNonce)); case ALGO_YESCRYPT: { uint256 thash; yescrypt_hash(BEGIN(nVersion), BEGIN(thash)); return thash; } } return GetHash(); }
void yescrypt_regenhash(struct work *work) { 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); yescrypt_hash((unsigned char*)data, (unsigned char*)ohash); }
bool scanhash_yescrypt(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) { 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); yescrypt_hash((unsigned char*)data, (unsigned char*)ostate); 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; }
/* Used externally as confirmation of correct OCL code */ int yescrypt_test(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]; be32enc_vect(data, (const uint32_t *)pdata, 19); data[19] = htobe32(nonce); yescrypt_hash((unsigned char*)data,(unsigned char*)ohash); tmp_hash7 = be32toh(ohash[7]); applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx", (long unsigned int)Htarg, (long unsigned int)diff1targ, (long unsigned int)tmp_hash7); if (tmp_hash7 > diff1targ) return -1; if (tmp_hash7 > Htarg) return 0; return 1; }
/* for util.c test */ void yescrypthash(void *output, const void *input) { yescrypt_hash((char*) input, (char*) output, 80); }