Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/phi2.c
1201 views
1
/**
2
* Phi-2 algo Implementation
3
*/
4
5
#include <memory.h>
6
7
#include "sha3/sph_cubehash.h"
8
#include "sha3/sph_skein.h"
9
#include "sha3/sph_jh.h"
10
//#include "sha3/sph_fugue.h"
11
#include "sha3/gost_streebog.h"
12
#include "sha3/sph_echo.h"
13
14
#include "lyra2/Lyra2.h"
15
16
#include "miner.h"
17
18
static bool has_roots;
19
20
void phi2_hash(void *state, const void *input)
21
{
22
unsigned char _ALIGN(128) hash[64];
23
unsigned char _ALIGN(128) hashA[64];
24
unsigned char _ALIGN(128) hashB[64];
25
26
sph_cubehash512_context ctx_cubehash;
27
sph_jh512_context ctx_jh;
28
sph_gost512_context ctx_gost;
29
sph_echo512_context ctx_echo;
30
sph_skein512_context ctx_skein;
31
32
sph_cubehash512_init(&ctx_cubehash);
33
sph_cubehash512(&ctx_cubehash, input, has_roots ? 144 : 80);
34
sph_cubehash512_close(&ctx_cubehash, (void*)hashB);
35
36
LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8);
37
LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8);
38
39
sph_jh512_init(&ctx_jh);
40
sph_jh512(&ctx_jh, (const void*)hashA, 64);
41
sph_jh512_close(&ctx_jh, (void*)hash);
42
43
if (hash[0] & 1) {
44
sph_gost512_init(&ctx_gost);
45
sph_gost512(&ctx_gost, (const void*)hash, 64);
46
sph_gost512_close(&ctx_gost, (void*)hash);
47
} else {
48
sph_echo512_init(&ctx_echo);
49
sph_echo512(&ctx_echo, (const void*)hash, 64);
50
sph_echo512_close(&ctx_echo, (void*)hash);
51
52
sph_echo512_init(&ctx_echo);
53
sph_echo512(&ctx_echo, (const void*)hash, 64);
54
sph_echo512_close(&ctx_echo, (void*)hash);
55
}
56
57
sph_skein512_init(&ctx_skein);
58
sph_skein512(&ctx_skein, (const void*)hash, 64);
59
sph_skein512_close(&ctx_skein, (void*)hash);
60
61
for (int i=0; i<4; i++)
62
((uint64_t*)hash)[i] ^= ((uint64_t*)hash)[i+4];
63
64
memcpy(state, hash, 32);
65
}
66
67
int scanhash_phi2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
68
{
69
uint32_t _ALIGN(128) hash[8];
70
uint32_t _ALIGN(128) endiandata[36];
71
uint32_t *pdata = work->data;
72
uint32_t *ptarget = work->target;
73
74
const uint32_t Htarg = ptarget[7];
75
const uint32_t first_nonce = pdata[19];
76
uint32_t n = first_nonce;
77
78
if(opt_benchmark){
79
ptarget[7] = 0x00ff;
80
}
81
82
has_roots = false;
83
for (int i=0; i < 36; i++) {
84
be32enc(&endiandata[i], pdata[i]);
85
if (i >= 20 && pdata[i]) has_roots = true;
86
}
87
88
do {
89
be32enc(&endiandata[19], n);
90
phi2_hash(hash, endiandata);
91
92
if (hash[7] < Htarg && fulltest(hash, ptarget)) {
93
work_set_target_ratio(work, hash);
94
*hashes_done = n - first_nonce + 1;
95
pdata[19] = n;
96
return 1;
97
}
98
n++;
99
100
} while (n < max_nonce && !work_restart[thr_id].restart);
101
102
*hashes_done = n - first_nonce + 1;
103
pdata[19] = n;
104
105
return 0;
106
}
107
108