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