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"
19 #define POK_BOOL_MASK 0x00008000
20 #define POK_DATA_MASK 0xFFFF0000
22 static const int permut[24][4] = {
49 void zr5hash(void *output, const void *input)
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;
57 uchar _ALIGN(64) hash[64];
58 uint32_t *phash = (uint32_t *) hash;
61 sph_keccak512_init(&ctx_keccak);
62 sph_keccak512(&ctx_keccak, (const void*) input, 80);
63 sph_keccak512_close(&ctx_keccak, (void*) phash);
65 norder = phash[0] % ARRAY_SIZE(permut); /* % 24 */
67 for(int i = 0; i < 4; i++)
69 switch (permut[norder][i]) {
71 sph_blake512_init(&ctx_blake);
72 sph_blake512(&ctx_blake, (const void*) phash, 64);
73 sph_blake512_close(&ctx_blake, phash);
76 sph_groestl512_init(&ctx_groestl);
77 sph_groestl512(&ctx_groestl, (const void*) phash, 64);
78 sph_groestl512_close(&ctx_groestl, phash);
81 sph_jh512_init(&ctx_jh);
82 sph_jh512(&ctx_jh, (const void*) phash, 64);
83 sph_jh512_close(&ctx_jh, phash);
86 sph_skein512_init(&ctx_skein);
87 sph_skein512(&ctx_skein, (const void*) phash, 64);
88 sph_skein512_close(&ctx_skein, phash);
94 memcpy(output, phash, 32);
97 void zr5hash_pok(void *output, uint32_t *pdata)
99 const uint32_t version = pdata[0] & (~POK_DATA_MASK);
100 uint32_t _ALIGN(64) hash[8];
104 zr5hash(hash, pdata);
107 pok = version | (hash[0] & POK_DATA_MASK);
108 if (pdata[0] != pok) {
110 zr5hash(hash, pdata);
112 memcpy(output, hash, 32);
115 int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
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
129 zr5hash_pok(hash, tmpdata);
131 if (hash[7] <= ptarget[7] && fulltest(hash, ptarget))
133 work_set_target_ratio(work, hash);
134 pdata[0] = tmpdata[0];
136 *hashes_done = pdata[19] - first_nonce + 1;
141 } while (nonce < max_nonce && !work_restart[thr_id].restart);
144 *hashes_done = pdata[19] - first_nonce + 1;