]> Git Repo - cpuminer-multi.git/blob - algo/yescrypt.c
update build.sh
[cpuminer-multi.git] / algo / yescrypt.c
1 #include "miner.h"
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <openssl/sha.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8
9 #include "yescrypt/yescrypt.h"
10
11 int do_scanhash(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done, void (*hash_func)(const char *, char *, uint32_t))
12 {
13         uint32_t _ALIGN(64) vhash[8];
14         uint32_t _ALIGN(64) endiandata[20];
15         uint32_t *pdata = work->data;
16         uint32_t *ptarget = work->target;
17
18         const uint32_t Htarg = ptarget[7];
19         const uint32_t first_nonce = pdata[19];
20
21         uint32_t n = first_nonce;
22
23         for (int i=0; i < 19; i++) {
24                 be32enc(&endiandata[i], pdata[i]);
25         }
26
27         do {
28                 be32enc(&endiandata[19], n);
29                 hash_func((char*) endiandata, (char*) vhash, 80);
30                 if (vhash[7] < Htarg && fulltest(vhash, ptarget)) {
31                         work_set_target_ratio(work, vhash);
32                         *hashes_done = n - first_nonce + 1;
33                         pdata[19] = n;
34                         return true;
35                 }
36                 n++;
37
38         } while (n < max_nonce && !work_restart[thr_id].restart);
39
40         *hashes_done = n - first_nonce + 1;
41         pdata[19] = n;
42
43         return 0;
44 }
45
46 int scanhash_yescrypt(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
47 {
48         return (do_scanhash(thr_id, work, max_nonce, hashes_done, yescrypt_hash));
49 }
50
51 int scanhash_yescryptr8(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
52 {
53         return (do_scanhash(thr_id, work, max_nonce, hashes_done, yescrypt_hash_r8));
54 }
55
56 int scanhash_yescryptr16(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
57 {
58         return (do_scanhash(thr_id, work, max_nonce, hashes_done, yescrypt_hash_r16));
59 }
60
61 int scanhash_yescryptr32(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
62 {
63         return (do_scanhash(thr_id, work, max_nonce, hashes_done, yescrypt_hash_r32));
64 }
This page took 0.030188 seconds and 4 git commands to generate.