Browse Source

Merge commit '53c9cda' into cg_merges_20121203

Luke Dashjr 13 years ago
parent
commit
de6ab25a61
3 changed files with 25 additions and 20 deletions
  1. 9 7
      miner.c
  2. 1 1
      miner.h
  3. 15 12
      scrypt.c

+ 9 - 7
miner.c

@@ -2524,14 +2524,14 @@ static uint64_t share_diff(const struct work *work)
 	return ret;
 }
 
-static uint32_t scrypt_diff(const struct work *work)
+static uint64_t scrypt_diff(const struct work *work)
 {
-	const uint32_t scrypt_diffone = 0x0000fffful;
-	uint32_t d32 = work->outputhash, ret;
+	const uint64_t scrypt_diffone = 0x0000ffff00000000ul;
+	uint64_t d64 = work->outputhash, ret;
 
-	if (unlikely(!d32))
-		d32 = 1;
-	ret = scrypt_diffone / d32;
+	if (unlikely(!d64))
+		d64 = 1;
+	ret = scrypt_diffone / d64;
 	if (ret > best_diff) {
 		best_diff = ret;
 		suffix_string(best_diff, best_share, 0);
@@ -2608,12 +2608,14 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
 		hash32 = (uint32_t *)(work->hash);
 		if (opt_scrypt) {
 			uint32_t sharediff;
+			uint64_t outhash;
 
 			scrypt_outputhash(work);
 			sharediff = scrypt_diff(work);
 			suffix_string(sharediff, diffdisp, 0);
 
-			sprintf(hashshow, "%08lx Diff %s/%d", (unsigned long)work->outputhash, diffdisp, intdiff);
+			outhash = work->outputhash >> 16;
+			sprintf(hashshow, "%08lx Diff %s/%d", (unsigned long)outhash, diffdisp, intdiff);
 		} else {
 			uint64_t sharediff = share_diff(work);
 

+ 1 - 1
miner.h

@@ -1008,7 +1008,7 @@ struct work {
 	unsigned char	target[32];
 	unsigned char	hash[32];
 
-	uint32_t	outputhash;
+	uint64_t	outputhash;
 
 	int		rolls;
 

+ 15 - 12
scrypt.c

@@ -250,11 +250,10 @@ PBKDF2_SHA256_80_128(const uint32_t * passwd, uint32_t * buf)
 }
 
 
-static inline uint32_t
-PBKDF2_SHA256_80_128_32(const uint32_t * passwd, const uint32_t * salt)
+static inline void
+PBKDF2_SHA256_80_128_32(const uint32_t * passwd, const uint32_t * salt, uint32_t *ostate)
 {
 	uint32_t tstate[8];
-	uint32_t ostate[8];
 	uint32_t ihash[8];
 	uint32_t i;
 
@@ -292,8 +291,6 @@ PBKDF2_SHA256_80_128_32(const uint32_t * passwd, const uint32_t * salt)
 
 	/* Feed the inner hash to the outer SHA256 operation. */
 	SHA256_Transform(ostate, pad, 0);
-	/* Finish the outer SHA256 operation. */
-	return be32toh(ostate[7]);
 }
 
 
@@ -359,7 +356,7 @@ salsa20_8(uint32_t B[16], const uint32_t Bx[16])
 /* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
    scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
  */
-static uint32_t scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad)
+static void scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad, uint32_t *ostate)
 {
 	uint32_t * V;
 	uint32_t X[32];
@@ -402,32 +399,35 @@ static uint32_t scrypt_1024_1_1_256_sp(const uint32_t* input, char* scratchpad)
 		salsa20_8(&X[16], &X[0]);
 	}
 
-	return PBKDF2_SHA256_80_128_32(input, X);
+	PBKDF2_SHA256_80_128_32(input, X, ostate);
 }
 
 void scrypt_outputhash(struct work *work)
 {
-	uint32_t data[20];
+	uint32_t data[20], ohash[8], rhash[8];
 	char *scratchbuf;
 	uint32_t *nonce = (uint32_t *)(work->data + 76);
 
 	be32enc_vect(data, (const uint32_t *)work->data, 19);
 	data[19] = htobe32(*nonce);
 	scratchbuf = alloca(131584);
-	work->outputhash = scrypt_1024_1_1_256_sp(data, scratchbuf);
+	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash);
+	swap256(rhash, ohash);
+	work->outputhash = be64toh(*((uint64_t *)rhash));
 }
 
 /* Used externally as confirmation of correct OCL code */
 bool scrypt_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
 {
 	uint32_t tmp_hash7, Htarg = ((const uint32_t *)ptarget)[7];
+	uint32_t data[20], ohash[8];
 	char *scratchbuf;
-	uint32_t data[20];
 
 	be32enc_vect(data, (const uint32_t *)pdata, 19);
 	data[19] = htobe32(nonce);
 	scratchbuf = alloca(131584);
-	tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf);
+	scrypt_1024_1_1_256_sp(data, scratchbuf, ohash);
+	tmp_hash7 = be32toh(ohash[7]);
 
 	return (tmp_hash7 <= Htarg);
 }
@@ -453,9 +453,12 @@ bool scanhash_scrypt(struct thr_info *thr, const unsigned char __maybe_unused *p
 	}
 
 	while(1) {
+		uint32_t ostate[8];
+
 		*nonce = ++n;
 		data[19] = n;
-		tmp_hash7 = scrypt_1024_1_1_256_sp(data, scratchbuf);
+		scrypt_1024_1_1_256_sp(data, scratchbuf, ostate);
+		tmp_hash7 = be32toh(ostate[7]);
 
 		if (unlikely(tmp_hash7 <= Htarg)) {
 			((uint32_t *)pdata)[19] = htobe32(n);