示例#1
0
文件: scrypt.c 项目: xxrforone/miner
int scanhash_scrypt(int thr_id, uint32_t *pdata,
	unsigned char *scratchbuf, const uint32_t *ptarget,
	uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t data[SCRYPT_MAX_WAYS * 20], hash[SCRYPT_MAX_WAYS * 8];
	uint32_t midstate[8];
	uint32_t n = pdata[19] - 1;
	const uint32_t Htarg = ptarget[7];
	int throughput = scrypt_best_throughput();
	int i;
	
#ifdef HAVE_SHA256_4WAY
	if (sha256_use_4way())
		throughput *= 4;
#endif
	
	for (i = 0; i < throughput; i++)
		memcpy(data + i * 20, pdata, 80);
	
	sha256_init(midstate);
	sha256_transform(midstate, data, 0);
	
	do {
		for (i = 0; i < throughput; i++)
			data[i * 20 + 19] = ++n;
		
#if defined(HAVE_SHA256_4WAY)
		if (throughput == 4)
			scrypt_1024_1_1_256_4way(data, hash, midstate, scratchbuf);
		else
#endif
#if defined(HAVE_SCRYPT_3WAY) && defined(HAVE_SHA256_4WAY)
		if (throughput == 12)
			scrypt_1024_1_1_256_12way(data, hash, midstate, scratchbuf);
		else
#endif
#if defined(HAVE_SCRYPT_3WAY)
		if (throughput == 3)
			scrypt_1024_1_1_256_3way(data, hash, midstate, scratchbuf);
		else
#endif
		scrypt_1024_1_1_256(data, hash, midstate, scratchbuf);
		
		for (i = 0; i < throughput; i++) {
			if (hash[i * 8 + 7] <= Htarg && fulltest(hash + i * 8, ptarget)) {
				*hashes_done = n - pdata[19] + 1;
				pdata[19] = data[i * 20 + 19];
				return 1;
			}
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	
	*hashes_done = n - pdata[19] + 1;
	pdata[19] = n;
	return 0;
}
示例#2
0
文件: sha2.c 项目: kiyominer/cpuminer
int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
	uint32_t max_nonce, unsigned long *hashes_done)
{
	uint32_t data[64] __attribute__((aligned(128)));
	uint32_t hash[8] __attribute__((aligned(32)));
	uint32_t midstate[8] __attribute__((aligned(32)));
	uint32_t prehash[8] __attribute__((aligned(32)));
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
	
#ifdef HAVE_SHA256_16WAY
	if (sha256_use_16way())
		return scanhash_sha256d_16way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
#ifdef HAVE_SHA256_8WAY
	if (sha256_use_8way())
		return scanhash_sha256d_8way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
#ifdef HAVE_SHA256_4WAY
	if (sha256_use_4way())
		return scanhash_sha256d_4way(thr_id, pdata, ptarget,
			max_nonce, hashes_done);
#endif
	
	memcpy(data, pdata + 16, 64);
	sha256d_preextend(data);
	
	sha256_init(midstate);
	sha256_transform(midstate, pdata, 0);
	memcpy(prehash, midstate, 32);
	sha256d_prehash(prehash, pdata + 16);
	
	do {
		data[3] = ++n;
		sha256d_ms(hash, data, midstate, prehash);
		if (swab32(hash[7]) <= Htarg) {
			pdata[19] = data[3];
			sha256d_80_swap(hash, pdata);
			if (fulltest(hash, ptarget)) {
				*hashes_done = n - first_nonce + 1;
				return 1;
			}
		}
	} while (n < max_nonce && !work_restart[thr_id].restart);
	
	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	return 0;
}
示例#3
0
int scanhash_sha256d(int thr_id, struct work *work,
	uint32_t max_nonce, uint64_t *hashes_done)
{
        uint32_t *pdata = work->data;
        uint32_t *ptarget = work->target;
	uint32_t _ALIGN(128) data[64];
	uint32_t _ALIGN(32) hash[8];
	uint32_t _ALIGN(32) midstate[8];
	uint32_t _ALIGN(32) prehash[8];
	uint32_t n = pdata[19] - 1;
	const uint32_t first_nonce = pdata[19];
	const uint32_t Htarg = ptarget[7];
	
#ifdef HAVE_SHA256_8WAY
	if (sha256_use_8way())
		return scanhash_sha256d_8way(thr_id, work,
			max_nonce, hashes_done);
#endif
#ifdef HAVE_SHA256_4WAY
	if (sha256_use_4way())
		return scanhash_sha256d_4way(thr_id, work,
			max_nonce, hashes_done);
#endif
	
	memcpy(data, pdata + 16, 64);
	sha256d_preextend(data);
	
	sha256_init(midstate);
	sha256_transform(midstate, pdata, 0);
	memcpy(prehash, midstate, 32);
	sha256d_prehash(prehash, pdata + 16);
	
	do {
		data[3] = ++n;
		sha256d_ms(hash, data, midstate, prehash);
		if (unlikely(swab32(hash[7]) <= Htarg)) {
			pdata[19] = data[3];
			sha256d_80_swap(hash, pdata);
			if (fulltest(hash, ptarget)) {
				*hashes_done = n - first_nonce + 1;
				return 1;
			}
		}
	} while (likely(n < max_nonce && !work_restart[thr_id].restart));
	
	*hashes_done = n - first_nonce + 1;
	pdata[19] = n;
	return 0;
}
示例#4
0
bool BlockMine2(MinerClient &client, WorkBlob &work)
{
	uint32_t data[SCRYPT_MAX_WAYS * 20]; 
	uint32_t hash[SCRYPT_MAX_WAYS * 8];
	uint32_t midstate[8];


	unsigned char*  ScratchPad = (unsigned char *)malloc(1024 * SCRYPT_MAX_WAYS * 128 + 63);
	uint32_t shareCompare = work.ShareTarget.data[7];
	//shareCompare = Helpers::BigEndian32Decode(&shareCompare);
	uint32_t nonce = 0;
	for (int i = 0; i < 20; i++) //Weird endian adjustment needed for pooler's code
	{
		((int*)work.Blob)[i] = Helpers::BigEndian32Decode(&((int*)work.Blob)[i]);
	}

	int throughput = scrypt_best_throughput();

	if (sha256_use_4way())
		throughput *= 4;
	//throughput = 1;
	for (int i = 0; i < throughput; i++)
	{
		memcpy(data + i * 20, work.Blob, 80);
	}

	sha256_init(midstate);
	sha256_transform(midstate, data, 0);

	for (uint32_t t = 0; t<32768; t++)
	{
		if (client.CurrentProtocol == Stratum)
		{
			if (client.CurrentJob.Id != work.Id)
			{
				free(ScratchPad);
				return true;
			}
		}
		if (!client.Connected || !client.LoggedIn)
		{
			free(ScratchPad);
			return false;
		}
		for (uint32_t x = 0; x<4096; x++)
		{
			for (int i = 0; i < throughput; i++)
				data[i * 20 + 19] = nonce++;

			if (throughput == 4)
				scrypt_1024_1_1_256_4way(data, hash, midstate, ScratchPad, 1024);
			else
			if (throughput == 12)
				scrypt_1024_1_1_256_12way(data, hash, midstate, ScratchPad, 1024);
			
			if (throughput == 24)
				scrypt_1024_1_1_256_24way(data, hash, midstate, ScratchPad, 1024);
			else
			if (throughput == 3)
				scrypt_1024_1_1_256_3way(data, hash, midstate, ScratchPad, 1024);
			else
				scrypt_1024_1_1_256(data, hash, midstate, ScratchPad, 1024);

			for (int i = 0; i < throughput; i++) {
				if (hash[i * 8 + 7] <= shareCompare) {
					printf("We found a share submitting!\n");
					if (client.CurrentProtocol == Stratum)
					{
						StratumShare share;
						//Helpers::BigEndian32Encode(share.Nonce, data[i * 20 + 19]);
						//Helpers::BigEndian32Encode(share.Ntime, *work.NtimePointer);
						//Helpers::BigEndian32Encode(share.ENonce2, *work.ENonce2);
						memcpy(share.Nonce, &(data[i * 20 + 19]), 4);
						memcpy(share.Ntime, work.NtimePointer, 4);
						memcpy(share.ENonce2, work.ENonce2, 4);
						share.Id = work.Id;
						StratumProtocol::AddShares( share, client);
					}
				}
			}
			client.TotalHashCount+=throughput;
		}
	}

	free(ScratchPad);
	return true;
}