]> Git Repo - cpuminer-multi.git/blob - algo/zr5.c
update build.sh
[cpuminer-multi.git] / algo / zr5.c
1 #include "miner.h"
2
3 #include <stdlib.h>
4 #include <stdint.h>
5 #include <string.h>
6 #include <stdio.h>
7
8 #include "sha3/sph_blake.h"
9 #include "sha3/sph_groestl.h"
10 #include "sha3/sph_skein.h"
11 #include "sha3/sph_jh.h"
12 #include "sha3/sph_keccak.h"
13
14 #define ZR_BLAKE   0
15 #define ZR_GROESTL 1
16 #define ZR_JH512   2
17 #define ZR_SKEIN   3
18
19 #define POK_BOOL_MASK 0x00008000
20 #define POK_DATA_MASK 0xFFFF0000
21
22 static const int permut[24][4] = {
23         {0, 1, 2, 3},
24         {0, 1, 3, 2},
25         {0, 2, 1, 3},
26         {0, 2, 3, 1},
27         {0, 3, 1, 2},
28         {0, 3, 2, 1},
29         {1, 0, 2, 3},
30         {1, 0, 3, 2},
31         {1, 2, 0, 3},
32         {1, 2, 3, 0},
33         {1, 3, 0, 2},
34         {1, 3, 2, 0},
35         {2, 0, 1, 3},
36         {2, 0, 3, 1},
37         {2, 1, 0, 3},
38         {2, 1, 3, 0},
39         {2, 3, 0, 1},
40         {2, 3, 1, 0},
41         {3, 0, 1, 2},
42         {3, 0, 2, 1},
43         {3, 1, 0, 2},
44         {3, 1, 2, 0},
45         {3, 2, 0, 1},
46         {3, 2, 1, 0}
47 };
48
49 void zr5hash(void *output, const void *input)
50 {
51         sph_keccak512_context ctx_keccak;
52         sph_blake512_context ctx_blake;
53         sph_groestl512_context ctx_groestl;
54         sph_jh512_context ctx_jh;
55         sph_skein512_context ctx_skein;
56
57         uchar _ALIGN(64) hash[64];
58         uint32_t *phash = (uint32_t *) hash;
59         uint32_t norder;
60
61         sph_keccak512_init(&ctx_keccak);
62         sph_keccak512(&ctx_keccak, (const void*) input, 80);
63         sph_keccak512_close(&ctx_keccak, (void*) phash);
64
65         norder = phash[0] % ARRAY_SIZE(permut); /* % 24 */
66
67         for(int i = 0; i < 4; i++)
68         {
69                 switch (permut[norder][i]) {
70                 case ZR_BLAKE:
71                         sph_blake512_init(&ctx_blake);
72                         sph_blake512(&ctx_blake, (const void*) phash, 64);
73                         sph_blake512_close(&ctx_blake, phash);
74                         break;
75                 case ZR_GROESTL:
76                         sph_groestl512_init(&ctx_groestl);
77                         sph_groestl512(&ctx_groestl, (const void*) phash, 64);
78                         sph_groestl512_close(&ctx_groestl, phash);
79                         break;
80                 case ZR_JH512:
81                         sph_jh512_init(&ctx_jh);
82                         sph_jh512(&ctx_jh, (const void*) phash, 64);
83                         sph_jh512_close(&ctx_jh, phash);
84                         break;
85                 case ZR_SKEIN:
86                         sph_skein512_init(&ctx_skein);
87                         sph_skein512(&ctx_skein, (const void*) phash, 64);
88                         sph_skein512_close(&ctx_skein, phash);
89                         break;
90                 default:
91                         break;
92                 }
93         }
94         memcpy(output, phash, 32);
95 }
96
97 void zr5hash_pok(void *output, uint32_t *pdata)
98 {
99         const uint32_t version = pdata[0] & (~POK_DATA_MASK);
100         uint32_t _ALIGN(64) hash[8];
101         uint32_t pok;
102
103         pdata[0] = version;
104         zr5hash(hash, pdata);
105
106         // fill PoK
107         pok = version | (hash[0] & POK_DATA_MASK);
108         if (pdata[0] != pok) {
109                 pdata[0] = pok;
110                 zr5hash(hash, pdata);
111         }
112         memcpy(output, hash, 32);
113 }
114
115 int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
116 {
117         uint32_t _ALIGN(64) hash[16];
118         uint32_t *pdata = work->data;
119         uint32_t *ptarget = work->target;
120         const uint32_t first_nonce = pdata[19];
121         uint32_t nonce = first_nonce;
122         #define tmpdata pdata
123
124         if (opt_benchmark)
125                 ptarget[7] = 0x00ff;
126
127         do {
128                 tmpdata[19] = nonce;
129                 zr5hash_pok(hash, tmpdata);
130
131                 if (hash[7] <= ptarget[7] && fulltest(hash, ptarget))
132                 {
133                         work_set_target_ratio(work, hash);
134                         pdata[0] = tmpdata[0];
135                         pdata[19] = nonce;
136                         *hashes_done = pdata[19] - first_nonce + 1;
137                         return 1;
138                 }
139                 nonce++;
140
141         } while (nonce < max_nonce && !work_restart[thr_id].restart);
142
143         pdata[19] = nonce;
144         *hashes_done = pdata[19] - first_nonce + 1;
145         return 0;
146 }
This page took 0.032435 seconds and 4 git commands to generate.