Browse Source

bigpic: Use bitfury_fudge_nonce

Luke Dashjr 12 years ago
parent
commit
a8c80c6883
3 changed files with 6 additions and 72 deletions
  1. 1 67
      driver-bigpic.c
  2. 4 5
      libbitfury.c
  3. 1 0
      libbitfury.h

+ 1 - 67
driver-bigpic.c

@@ -26,42 +26,6 @@
 
 struct device_drv bigpic_drv;
 
-//------------------------------------------------------------------------------
-int bigpic_rehash(unsigned char *midstate, unsigned m7, unsigned ntime, unsigned nbits, unsigned nnonce)
-{
-	uint8_t   in[16];
-	uint32_t *in32 = (uint32_t *)in;
-	char      hex[65];
-	uint32_t *mid32 = (uint32_t *)midstate;
-	uint32_t  out32[8];
-	uint8_t  *out = (uint8_t *) out32;
-	sha256_ctx ctx;
-
-	memset( &ctx, 0, sizeof(sha256_ctx));
-	memcpy(ctx.h, mid32, 8*4);
-	ctx.tot_len = 64;
-	ctx.len = 0;
-
-	nnonce = bswap_32(nnonce);
-	in32[0] = bswap_32(m7);
-	in32[1] = bswap_32(ntime);
-	in32[2] = bswap_32(nbits);
-	in32[3] = nnonce;
-
-	sha256_update(&ctx, in, 16);
-	sha256_final(&ctx, out);
-	sha256(out, 32, out);
-
-	if (out32[7] == 0)
-	{
-		bin2hex(hex, out, 32);
-		applog(LOG_DEBUG, "! MS0: %08x, m7: %08x, ntime: %08x, nbits: %08x, nnonce: %08x", mid32[0], m7, ntime, nbits, nnonce);
-		applog(LOG_DEBUG, "                         out: %s", hex);
-		return 1;
-	}
-	return 0;
-}
-
 //------------------------------------------------------------------------------
 static bool bigpic_detect_custom(const char *devpath, struct device_drv *api, struct bigpic_info *info)
 {
@@ -237,42 +201,12 @@ static void bigpic_process_results(struct thr_info *thr, struct work *work)
 		results[num_results++] = state.nonce;
 
 		//applog(LOG_DEBUG, "%"PRIpreprv": Len: %d Cmd: %c State: %c Switched: %d Nonce: %08X", board->proc_repr, info->rx_len, info->rx_buffer[i], state->state, state->switched, nonce);
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce))
+		if (bitfury_fudge_nonce(work->midstate, m7, ntime, nbits, &nonce))
 		{
 			submit_nonce(thr, work, nonce);
 			nonces--;
 			continue;
 		}
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce-0x400000))
-		{
-			submit_nonce(thr, work, nonce-0x400000);
-			nonces--;
-			continue;
-		}
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce-0x800000))
-		{
-			submit_nonce(thr, work, nonce-0x800000);
-			nonces--;
-			continue;
-		}
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce+0x2800000))
-		{
-			submit_nonce(thr, work, nonce+0x2800000);
-			nonces--;
-			continue;
-		}
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce+0x2C00000))
-		{
-			submit_nonce(thr, work, nonce+0x2C00000);
-			nonces--;
-			continue;
-		}
-		if(bigpic_rehash(work->midstate, m7, ntime, nbits, nonce+0x400000))
-		{
-			submit_nonce(thr, work, nonce+0x400000);
-			nonces--;
-			continue;
-		}
 		inc_hw_errors(thr, work, nonce);
 	}
 }

+ 4 - 5
libbitfury.c

@@ -380,8 +380,7 @@ int rehash(const void *midstate, const uint32_t m7, const uint32_t ntime, const
 	return 0;
 }
 
-static
-bool fudge_nonce(const void *midstate, const uint32_t m7, const uint32_t ntime, const uint32_t nbits, uint32_t *nonce_p) {
+bool bitfury_fudge_nonce(const void *midstate, const uint32_t m7, const uint32_t ntime, const uint32_t nbits, uint32_t *nonce_p) {
 	static const uint32_t offsets[] = {0, 0xffc00000, 0xff800000, 0x02800000, 0x02C00000, 0x00400000};
 	uint32_t nonce;
 	int i;
@@ -495,7 +494,7 @@ void libbitfury_sendHashData1(int chip_id, struct bitfury_device *d, struct thr_
 				if ((newbuf[i] & 0xFF) == 0xE0)
 					continue;
 				pn = bitfury_decnonce(newbuf[i]);
-				if (fudge_nonce(op->midstate, op->m7, op->ntime, op->nbits, &pn))
+				if (bitfury_fudge_nonce(op->midstate, op->m7, op->ntime, op->nbits, &pn))
 				{
 					int k;
 					int dup = 0;
@@ -509,13 +508,13 @@ void libbitfury_sendHashData1(int chip_id, struct bitfury_device *d, struct thr_
 					}
 				}
 				else
-				if (fudge_nonce(o2p->midstate, o2p->m7, o2p->ntime, o2p->nbits, &pn))
+				if (bitfury_fudge_nonce(o2p->midstate, o2p->m7, o2p->ntime, o2p->nbits, &pn))
 				{
 					d->old_nonce = bswap_32(pn);
 					found++;
 				}
 				else
-				if (fudge_nonce(p->midstate, p->m7, p->ntime, p->nbits, &pn))
+				if (bitfury_fudge_nonce(p->midstate, p->m7, p->ntime, p->nbits, &pn))
 				{
 					d->future_nonce = bswap_32(pn);
 					found++;

+ 1 - 0
libbitfury.h

@@ -69,5 +69,6 @@ extern void send_shutdown(struct spi_port *, int slot, int chip_n);
 extern void send_freq(struct spi_port *, int slot, int chip_n, int bits);
 extern int libbitfury_detectChips1(struct spi_port *);
 extern unsigned bitfury_decnonce(unsigned);
+extern bool bitfury_fudge_nonce(const void *midstate, const uint32_t m7, const uint32_t ntime, const uint32_t nbits, uint32_t *nonce_p);
 
 #endif /* __LIBBITFURY_H__ */