Browse Source

sha256_via: ensure that found nonce is copied back into output data buffer

Also, some minor cleanups, removing unused args.
Jeff Garzik 15 years ago
parent
commit
d88648dd39
3 changed files with 19 additions and 17 deletions
  1. 1 3
      cpu-miner.c
  2. 1 3
      miner.h
  3. 17 11
      sha256_via.c

+ 1 - 3
cpu-miner.c

@@ -319,9 +319,7 @@ static void *miner_thread(void *thr_id_int)
 
 
 #ifdef WANT_VIA_PADLOCK
 #ifdef WANT_VIA_PADLOCK
 		case ALGO_VIA:
 		case ALGO_VIA:
-			rc = scanhash_via(work.midstate, work.data,
-					  work.hash1, work.hash,
-					  &hashes_done);
+			rc = scanhash_via(work.data, &hashes_done);
 			break;
 			break;
 #endif
 #endif
 		case ALGO_CRYPTOPP:
 		case ALGO_CRYPTOPP:

+ 1 - 3
miner.h

@@ -34,9 +34,7 @@ extern unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate,
 	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
 	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
 	unsigned long *nHashesDone);
 	unsigned long *nHashesDone);
 
 
-extern bool scanhash_via(const unsigned char *midstate, const unsigned char *data_in,
-	          unsigned char *hash1, unsigned char *hash,
-	          unsigned long *hashes_done);
+extern bool scanhash_via(unsigned char *data_inout, unsigned long *hashes_done);
 
 
 extern bool scanhash_c(const unsigned char *midstate, unsigned char *data,
 extern bool scanhash_c(const unsigned char *midstate, unsigned char *data,
 	      unsigned char *hash1, unsigned char *hash,
 	      unsigned char *hash1, unsigned char *hash,

+ 17 - 11
sha256_via.c

@@ -28,13 +28,13 @@ static void via_sha256(void *hash, void *buf, unsigned len)
 		     :"memory");
 		     :"memory");
 }
 }
 
 
-bool scanhash_via(const unsigned char *midstate, const unsigned char *data_in,
-	          unsigned char *hash1, unsigned char *hash,
-	          unsigned long *hashes_done)
+bool scanhash_via(unsigned char *data_inout, unsigned long *hashes_done)
 {
 {
 	unsigned char data[128] __attribute__((aligned(128)));
 	unsigned char data[128] __attribute__((aligned(128)));
+	unsigned char tmp_hash[32] __attribute__((aligned(128)));
 	unsigned char tmp_hash1[32] __attribute__((aligned(128)));
 	unsigned char tmp_hash1[32] __attribute__((aligned(128)));
-	uint32_t *hash32 = (uint32_t *) hash;
+	uint32_t *data32 = (uint32_t *) data;
+	uint32_t *hash32 = (uint32_t *) tmp_hash;
 	uint32_t *nonce = (uint32_t *)(data + 64 + 12);
 	uint32_t *nonce = (uint32_t *)(data + 64 + 12);
 	uint32_t n = 0;
 	uint32_t n = 0;
 	unsigned long stat_ctr = 0;
 	unsigned long stat_ctr = 0;
@@ -45,10 +45,8 @@ bool scanhash_via(const unsigned char *midstate, const unsigned char *data_in,
 	 * in order to permit the hardware to swap everything
 	 * in order to permit the hardware to swap everything
 	 * back to BE again (extra work).
 	 * back to BE again (extra work).
 	 */
 	 */
-	for (i = 0; i < 128/4; i++) {
-		uint32_t *data32 = (uint32_t *) data;
-		data32[i] = swab32(((uint32_t *)data_in)[i]);
-	}
+	for (i = 0; i < 128/4; i++)
+		data32[i] = swab32(((uint32_t *)data_inout)[i]);
 
 
 	while (1) {
 	while (1) {
 		n++;
 		n++;
@@ -63,20 +61,28 @@ bool scanhash_via(const unsigned char *midstate, const unsigned char *data_in,
 				swab32(((uint32_t *)tmp_hash1)[i]);
 				swab32(((uint32_t *)tmp_hash1)[i]);
 
 
 		/* second SHA256 transform */
 		/* second SHA256 transform */
-		memcpy(hash, sha256_init_state, 32);
-		via_sha256(hash, tmp_hash1, 32);
+		memcpy(tmp_hash, sha256_init_state, 32);
+		via_sha256(tmp_hash, tmp_hash1, 32);
 
 
 		stat_ctr++;
 		stat_ctr++;
 
 
 		if (hash32[7] == 0) {
 		if (hash32[7] == 0) {
 			char *hexstr;
 			char *hexstr;
 
 
-			hexstr = bin2hex(hash, 32);
+			hexstr = bin2hex(tmp_hash, 32);
 			fprintf(stderr,
 			fprintf(stderr,
 				"DBG: found zeroes in hash:\n%s\n",
 				"DBG: found zeroes in hash:\n%s\n",
 				hexstr);
 				hexstr);
 			free(hexstr);
 			free(hexstr);
 
 
+			/* swap nonce'd data back into original storage area;
+			 * TODO: only swap back the nonce, rather than all data
+			 */
+			for (i = 0; i < 128/4; i++) {
+				uint32_t *dout32 = (uint32_t *) data_inout;
+				dout32[i] = swab32(data32[i]);
+			}
+
 			*hashes_done = stat_ctr;
 			*hashes_done = stat_ctr;
 			return true;
 			return true;
 		}
 		}