]> Git Repo - cpuminer-multi.git/blob - algo/blake2.c
diff: prepare all algos for diff report (part 2)
[cpuminer-multi.git] / algo / blake2.c
1 #include "miner.h"
2
3 #include <string.h>
4 #include <stdint.h>
5
6 #include "crypto/blake2s.h"
7
8 inline void blake2s_hash(void *output, const void *input)
9 {
10         unsigned char hash[128] = { 0 };
11         blake2s_state blake2_ctx;
12
13         blake2s_init(&blake2_ctx, BLAKE2S_OUTBYTES);
14         blake2s_update(&blake2_ctx, input, 80);
15         blake2s_final(&blake2_ctx, hash, BLAKE2S_OUTBYTES);
16
17         memcpy(output, hash, 32);
18 }
19
20 int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
21 {
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;
26
27         const uint32_t Htarg = ptarget[7];
28         const uint32_t first_nonce = pdata[19];
29
30         uint32_t n = first_nonce;
31
32         for (int i=0; i < 19; i++) {
33                 be32enc(&endiandata[i], pdata[i]);
34         }
35
36         do {
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;
42                         pdata[19] = n;
43                         return 1;
44                 }
45                 n++;
46
47         } while (n < max_nonce && !work_restart[thr_id].restart);
48
49         *hashes_done = n - first_nonce + 1;
50         pdata[19] = n;
51
52         return 0;
53 }
This page took 0.024912 seconds and 4 git commands to generate.