Pass ostate values around in scrypt to be able to extract full hashes if needed later on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/miner.h b/miner.h
index e7a0526..865c58a 100644
--- a/miner.h
+++ b/miner.h
@@ -945,7 +945,7 @@ struct work {
unsigned char target[32];
unsigned char hash[32];
- uint32_t outputhash;
+ uint64_t outputhash;
int rolls;
diff --git a/scrypt.c b/scrypt.c
index e48996c..db3eb09 100644
--- a/scrypt.c
+++ b/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,34 @@ 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];
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);
+ work->outputhash = be32toh(ohash[7]);
}
/* 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 +452,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);