Skip to content

Commit

Permalink
cputest: add new scrypt algos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Dec 7, 2015
1 parent 3e415dd commit df19a20
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
31 changes: 30 additions & 1 deletion algo/scrypt-jane.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,33 @@ int scanhash_scryptjane(int Nfactor, int thr_id, uint32_t *pdata, const uint32_t
scrypt_free(&V);
scrypt_free(&YX);
return 0;
}
}

/* simple cpu test (util.c) */
void scryptjanehash(void *output, const void *input, uint32_t Nfactor)
{
scrypt_aligned_alloc YX, V;
uint8_t *X, *Y;
uint32_t chunk_bytes;
uint32_t N = (1 << (Nfactor + 1));
const uint32_t r = SCRYPT_R;
const uint32_t p = SCRYPT_P;

memset(output, 0, 32);

chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2;
if (!scrypt_alloc((uint64_t)N * chunk_bytes, &V)) return;
if (!scrypt_alloc((p + 1) * chunk_bytes, &YX)) {
scrypt_free(&V);
return;
}

Y = YX.ptr;
X = Y + chunk_bytes;

scrypt_N_1_1((unsigned char*)input, 80, (unsigned char*)input, 80,
N, (unsigned char*)output, 32, X, Y, V.ptr);

scrypt_free(&V);
scrypt_free(&YX);
}
18 changes: 18 additions & 0 deletions algo/scrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,21 @@ extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
pdata[19] = n;
return 0;
}

/* simple cpu test (util.c) */
void scrypthash(void *output, const void *input, uint32_t N)
{
uint32_t midstate[8];
char *scratchbuf = scrypt_buffer_alloc(N);

memset(output, 0, 32);
if (!scratchbuf)
return;

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

scrypt_1024_1_1_256((uint32_t*)input, (uint32_t*)output, midstate, scratchbuf, N);

free(scratchbuf);
}
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ void nist5hash(void *output, const void *input);
void pluck_hash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N);
void pentablakehash(void *output, const void *input);
void qubithash(void *output, const void *input);
void scrypthash(void *output, const void *input, uint32_t N);
void scryptjanehash(void *output, const void *input, uint32_t Nfactor);
void sibhash(void *output, const void *input);
void skeinhash(void *state, const void *input);
void skein2hash(void *state, const void *input);
Expand All @@ -565,6 +567,7 @@ void x13hash(void *output, const void *input);
void x14hash(void *output, const void *input);
void x15hash(void *output, const void *input);
void zr5hash(void *output, const void *input);
void yescrypthash(void *output, const void *input);
void zr5hash_pok(void *output, uint32_t *pdata);


Expand Down
12 changes: 12 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,15 @@ void print_hash_tests(void)
qubithash(&hash[0], &buf[0]);
printpfx("qubit", hash);

scrypthash(&hash[0], &buf[0], 1024);
printpfx("scrypt", hash);

scrypthash(&hash[0], &buf[0], 2048);
printpfx("scrypt:2048", hash);

scryptjanehash(&hash[0], &buf[0], 9);
printpfx("scrypt-jane", hash);

inkhash(&hash[0], &buf[0]);
printpfx("shavite3", hash);

Expand Down Expand Up @@ -2172,6 +2181,9 @@ void print_hash_tests(void)
x15hash(&hash[0], &buf[0]);
printpfx("x15", hash);

yescrypthash(&hash[0], &buf[0]);
printpfx("yescrypt", hash);

//zr5hash(&hash[0], &buf[0]);
zr5hash_pok(&hash[0], (uint32_t*) &buf[0]);
memset(buf, 0, sizeof(buf));
Expand Down
7 changes: 7 additions & 0 deletions yescrypt/yescrypt-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,10 @@ void yescrypt_hash(const char *input, char *output, uint32_t len)
{
yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 2048, 8, 1, (uint8_t*)output, 32);
}

/* for util.c test */
void yescrypthash(void *output, const void *input)
{
yescrypt_hash((char*) input, (char*) output, 80);
}

0 comments on commit df19a20

Please sign in to comment.