bool scanhash_via(struct thr_info*thr, const unsigned char __maybe_unused *pmidstate, unsigned char *data_inout, unsigned char __maybe_unused *phash1, unsigned char __maybe_unused *phash, const unsigned char *target, uint32_t max_nonce, uint32_t *last_nonce, uint32_t n) { unsigned char data[128] __attribute__((aligned(128))); unsigned char tmp_hash[32] __attribute__((aligned(128))); unsigned char tmp_hash1[32] __attribute__((aligned(128))); uint32_t *data32 = (uint32_t *) data; uint32_t *hash32 = (uint32_t *) tmp_hash; uint32_t *nonce = (uint32_t *)(data + 64 + 12); uint32_t *nonce_inout = (uint32_t *)(data_inout + 64 + 12); unsigned long stat_ctr = 0; /* bitcoin gives us big endian input, but via wants LE, * so we reverse the swapping bitcoin has already done (extra work) * in order to permit the hardware to swap everything * back to BE again (extra work). */ swap32yes(data32, data_inout, 128/4); while (1) { *nonce = n; /* first SHA256 transform */ memcpy(tmp_hash1, sha256_init_state, 32); via_sha256(tmp_hash1, data, 80); /* or maybe 128? */ swap32yes(tmp_hash1, tmp_hash1, 32/4); /* second SHA256 transform */ memcpy(tmp_hash, sha256_init_state, 32); via_sha256(tmp_hash, tmp_hash1, 32); stat_ctr++; if (unlikely((hash32[7] == 0) && fulltest(tmp_hash, target))) { /* swap nonce'd data back into original storage area; */ *nonce_inout = bswap_32(n); *last_nonce = n; return true; } if ((n >= max_nonce) || thr->work_restart) { *last_nonce = n; return false; } n++; } }
static void fill_minergate_request(minergate_do_job_req_sp30* work, struct work *cg_work, int max_offset) { uint32_t x[64 / 4]; uint64_t wd; memset(work, 0, sizeof(minergate_do_job_req_sp30)); //work-> LOCAL_swap32le(unsigned char, cg_work->midstate, 32 / 4) LOCAL_swap32le(unsigned char, cg_work->data + 64, 64 / 4) swap32yes(x, cg_work->data + 64, 64 / 4); memcpy(work->midstate, cg_work->midstate, 32); work->mrkle_root = ntohl(x[0]); work->timestamp = ntohl(x[1]); work->difficulty = ntohl(x[2]); //work->leading_zeroes = get_leading_zeroes(cg_work->target); // Is there no better way to get leading zeroes? work->leading_zeroes = 31; wd = round(cg_work->device_diff); while (wd) { work->leading_zeroes++; wd = wd >> 1; } //printf("%d %d\n",work->leading_zeroes, (int)round(cg_work->work_difficulty)); work->work_id_in_sw = cg_work->subid; work->ntime_limit = max_offset; //printf("ID:%d, TS:%x\n",work->work_id_in_sw,work->timestamp); //work->ntime_offset = ntime_offset; }
static bool ztex_checkNonce(struct cgpu_info *cgpu, struct work *work, struct libztex_hash_data *hdata) { uint32_t *data32 = (uint32_t *)(work->data); unsigned char swap[80]; uint32_t *swap32 = (uint32_t *)swap; unsigned char hash1[32]; unsigned char hash2[32]; uint32_t *hash2_32 = (uint32_t *)hash2; swap32[76/4] = htobe32(hdata->nonce); swap32yes(swap32, data32, 76 / 4); sha256(swap, 80, hash1); sha256(hash1, 32, hash2); if (be32toh(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) { applog(LOG_DEBUG, "%"PRIpreprv": checkNonce failed for %08x", cgpu->proc_repr, hdata->nonce); return false; } return true; }
static void fill_pxgate_request(pxgate_do_mrkljob_req* job, struct cgpu_info *cgpu) { int i; uint32_t converted[2]; uint8_t bytes[8]; // ntime 32 bit, nbits 32 bit struct spond_adapter *device = cgpu->device_data; int sw_job_id = device->current_job_id; int job_id = get_array_id(sw_job_id); struct pool *pool = &device->my_jobs[job_id].pool; cg_rlock(&device->my_jobs[job_id].data_lock); /* * fill the job */ memset(job, 0, sizeof(pxgate_do_mrkljob_req)); job->work_id_in_sw = sw_job_id; memcpy( bytes, pool->header_bin + 4 /*bbversion*/ + 32 /*prev_hash*/ + 32 /*blank_merkle*/, 4 /*ntime*/ + 4 /*nbits*/ ); swap32yes(converted, bytes, 2); job->timestamp = ntohl(converted[0]); job->difficulty = ntohl(converted[1]); memcpy(job->header_bin, pool->header_bin, sizeof(job->header_bin)); /* * taking target and count leading zeros */ unsigned char target[32]; unsigned char target_swap[32]; set_target(target, pool->sdiff); // order bytes, so we have bits from left to right swab256(target_swap, target); // set termination point target_swap[31] |= 0x01; job->leading_zeroes = 0; int pos = 0; while (((target_swap[pos / 8] >> (7 - (pos % 8))) & 0x1) == 0x0) { job->leading_zeroes++; pos++; } if (opt_debug) { char *target_str; target_str = bin2hex(target_swap, 32); SPONDLOG(LOG_DEBUG, "stratum target[%s] job->leading_zeroes[%d]\n", target_str, job->leading_zeroes ); free(target_str); } job->ntime_limit = NTIME_LIMIT; job->resr1 = 0; job->coinbase_len = pool->coinbase_len; memcpy(job->coinbase, pool->coinbase, job->coinbase_len); job->nonce2_offset = pool->nonce2_offset; if (pool->n2size < 8) { applog(LOG_ERR, "NONCE2 TOO SMALL (%d)!\n", pool->n2size); passert(0); } job->merkles = pool->merkles; // each merkle is 32 bytes size for (i = 0; i < pool->merkles; ++i) { memcpy(job->merkle + 32 * i, pool->swork.merkle_bin[i], 32); } cg_runlock(&device->my_jobs[job_id].data_lock); }