Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/geek.c
1201 views
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_bmw.h>
10
#include <sha3/sph_echo.h>
11
#include <sha3/sph_shabal.h>
12
#include <sha3/sph_groestl.h>
13
#include <sha3/sph_cubehash.h>
14
#include <sha3/sph_keccak.h>
15
#include <sha3/sph_hamsi.h>
16
#include <sha3/sph_simd.h>
17
18
void geekhash(void *output, const void *input)
19
{
20
sph_blake512_context ctx_blake;
21
sph_bmw512_context ctx_bmw;
22
sph_echo512_context ctx_echo;
23
sph_shabal512_context ctx_shabal;
24
sph_groestl512_context ctx_groestl;
25
sph_cubehash512_context ctx_cubehash;
26
sph_keccak512_context ctx_keccak;
27
sph_hamsi512_context ctx_hamsi;
28
sph_simd512_context ctx_simd;
29
30
uint32_t _ALIGN(128) hash[16];
31
32
sph_blake512_init(&ctx_blake);
33
sph_blake512 (&ctx_blake, input, 80);
34
sph_blake512_close (&ctx_blake, hash);
35
36
sph_bmw512_init(&ctx_bmw);
37
sph_bmw512 (&ctx_bmw, hash, 64);
38
sph_bmw512_close(&ctx_bmw, hash);
39
40
sph_echo512_init (&ctx_echo);
41
sph_echo512 (&ctx_echo, hash, 64);
42
sph_echo512_close(&ctx_echo, hash);
43
44
sph_shabal512_init (&ctx_shabal);
45
sph_shabal512 (&ctx_shabal, hash, 64);
46
sph_shabal512_close(&ctx_shabal, hash);
47
48
sph_groestl512_init(&ctx_groestl);
49
sph_groestl512 (&ctx_groestl, hash, 64);
50
sph_groestl512_close(&ctx_groestl, hash);
51
52
sph_cubehash512_init (&ctx_cubehash);
53
sph_cubehash512 (&ctx_cubehash, hash, 64);
54
sph_cubehash512_close(&ctx_cubehash, hash);
55
56
sph_keccak512_init(&ctx_keccak);
57
sph_keccak512 (&ctx_keccak, hash, 64);
58
sph_keccak512_close(&ctx_keccak, hash);
59
60
sph_hamsi512_init (&ctx_hamsi);
61
sph_hamsi512 (&ctx_hamsi, hash, 64);
62
sph_hamsi512_close(&ctx_hamsi, hash);
63
64
sph_simd512_init (&ctx_simd);
65
sph_simd512 (&ctx_simd, hash, 64);
66
sph_simd512_close(&ctx_simd, hash);
67
68
memcpy(output, hash, 32);
69
}
70
71
int scanhash_geek(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
72
{
73
uint32_t _ALIGN(64) hash[8];
74
uint32_t _ALIGN(64) endiandata[20];
75
uint32_t *pdata = work->data;
76
uint32_t *ptarget = work->target;
77
78
const uint32_t Htarg = ptarget[7];
79
const uint32_t first_nonce = pdata[19];
80
uint32_t nonce = first_nonce;
81
volatile uint8_t *restart = &(work_restart[thr_id].restart);
82
83
if (opt_benchmark)
84
ptarget[7] = 0x0cff;
85
86
for (int k=0; k < 19; k++)
87
be32enc(&endiandata[k], pdata[k]);
88
89
do {
90
be32enc(&endiandata[19], nonce);
91
geekhash(hash, endiandata);
92
93
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
94
work_set_target_ratio(work, hash);
95
pdata[19] = nonce;
96
*hashes_done = pdata[19] - first_nonce;
97
return 1;
98
}
99
nonce++;
100
101
} while (nonce < max_nonce && !(*restart));
102
103
pdata[19] = nonce;
104
*hashes_done = pdata[19] - first_nonce + 1;
105
return 0;
106
}
107
108