Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/luffa.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_luffa.h"
9
10
void luffahash(void *output, const void *input)
11
{
12
unsigned char _ALIGN(128) hash[64];
13
sph_luffa512_context ctx_luffa;
14
15
sph_luffa512_init(&ctx_luffa);
16
sph_luffa512 (&ctx_luffa, input, 80);
17
sph_luffa512_close(&ctx_luffa, (void*) hash);
18
19
memcpy(output, hash, 32);
20
}
21
22
int scanhash_luffa(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
23
{
24
uint32_t _ALIGN(128) hash32[8];
25
uint32_t _ALIGN(128) endiandata[20];
26
uint32_t *pdata = work->data;
27
uint32_t *ptarget = work->target;
28
29
const uint32_t Htarg = ptarget[7];
30
const uint32_t first_nonce = pdata[19];
31
32
uint32_t n = first_nonce;
33
34
for (int i=0; i < 19; i++) {
35
be32enc(&endiandata[i], pdata[i]);
36
}
37
38
do {
39
be32enc(&endiandata[19], n);
40
luffahash(hash32, endiandata);
41
if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
42
work_set_target_ratio(work, hash32);
43
*hashes_done = n - first_nonce + 1;
44
pdata[19] = n;
45
return true;
46
}
47
n++;
48
49
} while (n < max_nonce && !work_restart[thr_id].restart);
50
51
*hashes_done = n - first_nonce + 1;
52
pdata[19] = n;
53
54
return 0;
55
}
56
57