Raven Core  3.0.0
P2P Digital Currency
whirlpoolx.c
Go to the documentation of this file.
1 #include "miner.h"
2 #include "algo-gate-api.h"
3 
4 #include <stdlib.h>
5 #include <stdint.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include "sph_whirlpool.h"
9 
10 void whirlpoolx_hash(void *state, const void *input)
11 {
12  sph_whirlpool_context ctx_whirlpool;
13 
14  unsigned char hash[64];
15  unsigned char hash_xored[32];
16 
17  sph_whirlpool1_init(&ctx_whirlpool);
18  sph_whirlpool1(&ctx_whirlpool, input, 80);
19  sph_whirlpool1_close(&ctx_whirlpool, hash);
20 
21  // compress the 48 first bytes of the hash to 32
22  for (int i = 0; i < 32; i++)
23  hash_xored[i] = hash[i] ^ hash[i + 16];
24 
25  memcpy(state, hash, 32);
26 }
27 
28 int scanhash_whirlpoolx(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
29 {
30  uint32_t _ALIGN(128) endiandata[20];
31  uint32_t* pdata = work->data;
32  uint32_t* ptarget = work->target;
33  const uint32_t first_nonce = pdata[19];
34  uint32_t n = first_nonce - 1;
35 
36 // if (opt_benchmark)
37 // ((uint32_t*)ptarget)[7] = 0x0000ff;
38 
39  for (int i=0; i < 19; i++)
40  be32enc(&endiandata[i], pdata[i]);
41 
42  do {
43  const uint32_t Htarg = ptarget[7];
44  uint32_t vhash[8];
45  pdata[19] = ++n;
46  be32enc(&endiandata[19], n );
47  whirlpoolx_hash(vhash, endiandata);
48 
49  if (vhash[7] <= Htarg && fulltest(vhash, ptarget))
50  {
51 // work_set_target_ratio(work, vhash);
52  *hashes_done = n - first_nonce + 1;
53  return true;
54  }
55 
56  } while ( n < max_nonce && !work_restart[thr_id].restart);
57 
58  *hashes_done = n - first_nonce + 1;
59  pdata[19] = n;
60  return 0;
61 }
62 
63 bool register_whirlpoolx_algo( algo_gate_t* gate )
64 {
65  algo_not_tested();
66  gate->scanhash = (void*)&scanhash_whirlpoolx;
67  gate->hash = (void*)&whirlpoolx_hash;
68  return true;
69 };
void whirlpoolx_hash(void *state, const void *input)
Definition: whirlpoolx.c:10
int scanhash_whirlpoolx(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
Definition: whirlpoolx.c:28
WHIRLPOOL interface.
void * memcpy(void *a, const void *b, size_t c)
bool register_whirlpoolx_algo(algo_gate_t *gate)
Definition: whirlpoolx.c:63