/* simple cpu test (util.c) */ void scryptjanehash(void *output, const void *input ) { scrypt_aligned_alloc YX, V; uint8_t *X, *Y; uint32_t chunk_bytes; uint32_t N = (1 << ( opt_scrypt_n + 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); }
static int scrypt_power_on_self_test() { const scrypt_test_setting *t; uint8_t test_digest[64]; uint32_t i; int res = 7, scrypt_valid; scrypt_aligned_alloc YX, V; uint8_t *X, *Y; uint32_t N, chunk_bytes; const uint32_t r = SCRYPT_R; const uint32_t p = SCRYPT_P; if (!scrypt_test_mix()) { #if !defined(SCRYPT_TEST) scrypt_fatal_error("scrypt: mix function power-on-self-test failed"); #endif res &= ~1; } if (!scrypt_test_hash()) { #if !defined(SCRYPT_TEST) scrypt_fatal_error("scrypt: hash function power-on-self-test failed"); #endif res &= ~2; } for (i = 0, scrypt_valid = 1; post_settings[i].pw; i++) { t = post_settings + i; N = (1 << (t->Nfactor + 1)); chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2; V = scrypt_alloc((uint64_t)N * chunk_bytes); YX = scrypt_alloc((p + 1) * chunk_bytes); Y = YX.ptr; X = Y + chunk_bytes; scrypt_N_1_1((uint8_t *)t->pw, strlen(t->pw), (uint8_t *)t->salt, strlen(t->salt), N, test_digest, sizeof(test_digest), X, Y, V.ptr); scrypt_valid &= scrypt_verify(post_vectors[i], test_digest, sizeof(test_digest)); scrypt_free(&V); scrypt_free(&YX); } if (!scrypt_valid) { #if !defined(SCRYPT_TEST) scrypt_fatal_error("scrypt: scrypt power-on-self-test failed"); #endif res &= ~4; } return res; }
int scanhash_scryptjane( int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) { scrypt_aligned_alloc YX, V; uint8_t *X, *Y; uint32_t N, chunk_bytes; const uint32_t r = SCRYPT_R; const uint32_t p = SCRYPT_P; uint32_t *pdata = work->data; uint32_t *ptarget = work->target; uint32_t _ALIGN(64) endiandata[20]; const uint32_t first_nonce = pdata[19]; uint32_t nonce = first_nonce; if (opt_benchmark) ptarget[7] = 0x00ff; for (int k = 0; k < 19; k++) be32enc(&endiandata[k], pdata[k]); //Nfactor = GetNfactor(data[17], ntime); //if (Nfactor > scrypt_maxN) { // return 1; // //scrypt_fatal_error("scrypt: N out of range"); //} N = (1 << ( opt_scrypt_n + 1)); chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2; if (!scrypt_alloc((uint64_t)N * chunk_bytes, &V)) return 1; if (!scrypt_alloc((p + 1) * chunk_bytes, &YX)) { scrypt_free(&V); return 1; } Y = YX.ptr; X = Y + chunk_bytes; do { const uint32_t Htarg = ptarget[7]; uint32_t hash[8]; be32enc(&endiandata[19], nonce); scrypt_N_1_1((unsigned char *)endiandata, 80, (unsigned char *)endiandata, 80, N, (unsigned char *)hash, 32, X, Y, V.ptr); if (hash[7] <= Htarg && fulltest(hash, ptarget)) { pdata[19] = nonce; *hashes_done = pdata[19] - first_nonce; scrypt_free(&V); scrypt_free(&YX); return 1; } nonce++; } while (nonce < max_nonce && !work_restart[thr_id].restart); pdata[19] = nonce; *hashes_done = pdata[19] - first_nonce + 1; scrypt_free(&V); scrypt_free(&YX); return 0; }