6 #include "crypto/blake2s.h"
8 inline void blake2s_hash(void *output, const void *input)
10 unsigned char hash[128] = { 0 };
11 blake2s_state blake2_ctx;
13 blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES);
14 blake2s_update(&blake2_ctx, input, 80);
15 blake2s_final(&blake2_ctx, hash, BLAKE2S_OUTBYTES);
17 memcpy(output, hash, 32);
20 int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
22 uint32_t _ALIGN(128) hash32[8];
23 uint32_t _ALIGN(128) endiandata[20];
24 uint32_t *pdata = work->data;
25 uint32_t *ptarget = work->target;
27 const uint32_t Htarg = ptarget[7];
28 const uint32_t first_nonce = pdata[19];
30 uint32_t n = first_nonce;
32 for (int i=0; i < 19; i++) {
33 be32enc(&endiandata[i], pdata[i]);
37 be32enc(&endiandata[19], n);
38 blake2s_hash(hash32, endiandata);
39 if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
40 work_set_target_ratio(work, hash32);
41 *hashes_done = n - first_nonce + 1;
47 } while (n < max_nonce && !work_restart[thr_id].restart);
49 *hashes_done = n - first_nonce + 1;