Fabcoin Core  0.16.2
P2P Digital Currency
internal.c
Go to the documentation of this file.
1 /*
2  This file is part of ethash.
3 
4  ethash is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  ethash is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #include <assert.h>
24 #include <inttypes.h>
25 #include <stddef.h>
26 #include <errno.h>
27 #include <math.h>
28 #include "mmap.h"
29 #include "ethash.h"
30 #include "fnv.h"
31 #include "endian.h"
32 #include "internal.h"
33 #include "data_sizes.h"
34 #include "io.h"
35 
36 #ifdef WITH_CRYPTOPP
37 
38 #include "sha3_cryptopp.h"
39 
40 #else
41 #ifndef FASC_BUILD
42 #include "sha3.h"
43 #else
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #include "compiler.h"
49 #include <stdint.h>
50 #include <stdlib.h>
51 
52 struct ethash_h256;
53 
54 #define decsha3(bits) \
55  int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t);
56 
57 decsha3(256)
58 decsha3(512)
59 
60 void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size)
61 {
62  sha3_256((uint8_t*)ret, 32, data, size);
63 }
64 
65 void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size)
66 {
67  sha3_512(ret, 64, data, size);
68 }
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 #endif //else FASC_BUILD
74 #endif // WITH_CRYPTOPP
75 
76 uint64_t ethash_get_datasize(uint64_t const block_number)
77 {
78  assert(block_number / ETHASH_EPOCH_LENGTH < 2048);
79  return dag_sizes[block_number / ETHASH_EPOCH_LENGTH];
80 }
81 
82 uint64_t ethash_get_cachesize(uint64_t const block_number)
83 {
84  assert(block_number / ETHASH_EPOCH_LENGTH < 2048);
85  return cache_sizes[block_number / ETHASH_EPOCH_LENGTH];
86 }
87 
88 // Follows Sergio's "STRICT MEMORY HARD HASHING FUNCTIONS" (2014)
89 // https://bitslog.files.wordpress.com/2013/12/memohash-v0-3.pdf
90 // SeqMemoHash(s, R, N)
91 static bool ethash_compute_cache_nodes(
92  node* const nodes,
93  uint64_t cache_size,
94  ethash_h256_t const* seed
95 )
96 {
97  if (cache_size % sizeof(node) != 0) {
98  return false;
99  }
100  uint32_t const num_nodes = (uint32_t) (cache_size / sizeof(node));
101 
102  SHA3_512(nodes[0].bytes, (uint8_t*)seed, 32);
103 
104  for (uint32_t i = 1; i != num_nodes; ++i) {
105  SHA3_512(nodes[i].bytes, nodes[i - 1].bytes, 64);
106  }
107 
108  for (uint32_t j = 0; j != ETHASH_CACHE_ROUNDS; j++) {
109  for (uint32_t i = 0; i != num_nodes; i++) {
110  uint32_t const idx = nodes[i].words[0] % num_nodes;
111  node data;
112  data = nodes[(num_nodes - 1 + i) % num_nodes];
113  for (uint32_t w = 0; w != NODE_WORDS; ++w) {
114  data.words[w] ^= nodes[idx].words[w];
115  }
116  SHA3_512(nodes[i].bytes, data.bytes, sizeof(data));
117  }
118  }
119 
120  // now perform endian conversion
121  fix_endian_arr32(nodes->words, num_nodes * NODE_WORDS);
122  return true;
123 }
124 
126  node* const ret,
127  uint32_t node_index,
128  ethash_light_t const light
129 )
130 {
131  uint32_t num_parent_nodes = (uint32_t) (light->cache_size / sizeof(node));
132  node const* cache_nodes = (node const *) light->cache;
133  node const* init = &cache_nodes[node_index % num_parent_nodes];
134  memcpy(ret, init, sizeof(node));
135  ret->words[0] ^= node_index;
136  SHA3_512(ret->bytes, ret->bytes, sizeof(node));
137 #if defined(_M_X64) && ENABLE_SSE
138  __m128i const fnv_prime = _mm_set1_epi32(FNV_PRIME);
139  __m128i xmm0 = ret->xmm[0];
140  __m128i xmm1 = ret->xmm[1];
141  __m128i xmm2 = ret->xmm[2];
142  __m128i xmm3 = ret->xmm[3];
143 #elif defined(__MIC__)
144  __m512i const fnv_prime = _mm512_set1_epi32(FNV_PRIME);
145  __m512i zmm0 = ret->zmm[0];
146 #endif
147 
148  for (uint32_t i = 0; i != ETHASH_DATASET_PARENTS; ++i) {
149  uint32_t parent_index = fnv_hash(node_index ^ i, ret->words[i % NODE_WORDS]) % num_parent_nodes;
150  node const *parent = &cache_nodes[parent_index];
151 
152 #if defined(_M_X64) && ENABLE_SSE
153  {
154  xmm0 = _mm_mullo_epi32(xmm0, fnv_prime);
155  xmm1 = _mm_mullo_epi32(xmm1, fnv_prime);
156  xmm2 = _mm_mullo_epi32(xmm2, fnv_prime);
157  xmm3 = _mm_mullo_epi32(xmm3, fnv_prime);
158  xmm0 = _mm_xor_si128(xmm0, parent->xmm[0]);
159  xmm1 = _mm_xor_si128(xmm1, parent->xmm[1]);
160  xmm2 = _mm_xor_si128(xmm2, parent->xmm[2]);
161  xmm3 = _mm_xor_si128(xmm3, parent->xmm[3]);
162 
163  // have to write to ret as values are used to compute index
164  ret->xmm[0] = xmm0;
165  ret->xmm[1] = xmm1;
166  ret->xmm[2] = xmm2;
167  ret->xmm[3] = xmm3;
168  }
169  #elif defined(__MIC__)
170  {
171  zmm0 = _mm512_mullo_epi32(zmm0, fnv_prime);
172 
173  // have to write to ret as values are used to compute index
174  zmm0 = _mm512_xor_si512(zmm0, parent->zmm[0]);
175  ret->zmm[0] = zmm0;
176  }
177  #else
178  {
179  for (unsigned w = 0; w != NODE_WORDS; ++w) {
180  ret->words[w] = fnv_hash(ret->words[w], parent->words[w]);
181  }
182  }
183 #endif
184  }
185  SHA3_512(ret->bytes, ret->bytes, sizeof(node));
186 }
187 
189  void* mem,
190  uint64_t full_size,
191  ethash_light_t const light,
192  ethash_callback_t callback
193 )
194 {
195  if (full_size % (sizeof(uint32_t) * MIX_WORDS) != 0 ||
196  (full_size % sizeof(node)) != 0) {
197  return false;
198  }
199  uint32_t const max_n = (uint32_t)(full_size / sizeof(node));
200  node* full_nodes = mem;
201  double const progress_change = 1.0f / max_n;
202  double progress = 0.0f;
203  // now compute full nodes
204  for (uint32_t n = 0; n != max_n; ++n) {
205  if (callback &&
206  n % (max_n / 100) == 0 &&
207  callback((unsigned int)(ceil(progress * 100.0f))) != 0) {
208 
209  return false;
210  }
211  progress += progress_change;
212  ethash_calculate_dag_item(&(full_nodes[n]), n, light);
213  }
214  return true;
215 }
216 
217 static bool ethash_hash(
219  node const* full_nodes,
220  ethash_light_t const light,
221  uint64_t full_size,
222  ethash_h256_t const header_hash,
223  uint64_t const nonce
224 )
225 {
226  if (full_size % MIX_WORDS != 0) {
227  return false;
228  }
229 
230  // pack hash and nonce together into first 40 bytes of s_mix
231  assert(sizeof(node) * 8 == 512);
232  node s_mix[MIX_NODES + 1];
233  memcpy(s_mix[0].bytes, &header_hash, 32);
234  fix_endian64(s_mix[0].double_words[4], nonce);
235 
236  // compute sha3-512 hash and replicate across mix
237  SHA3_512(s_mix->bytes, s_mix->bytes, 40);
238  fix_endian_arr32(s_mix[0].words, 16);
239 
240  node* const mix = s_mix + 1;
241  for (uint32_t w = 0; w != MIX_WORDS; ++w) {
242  mix->words[w] = s_mix[0].words[w % NODE_WORDS];
243  }
244 
245  unsigned const page_size = sizeof(uint32_t) * MIX_WORDS;
246  unsigned const num_full_pages = (unsigned) (full_size / page_size);
247 
248  for (unsigned i = 0; i != ETHASH_ACCESSES; ++i) {
249  uint32_t const index = fnv_hash(s_mix->words[0] ^ i, mix->words[i % MIX_WORDS]) % num_full_pages;
250 
251  for (unsigned n = 0; n != MIX_NODES; ++n) {
252  node const* dag_node;
253  if (full_nodes) {
254  dag_node = &full_nodes[MIX_NODES * index + n];
255  } else {
256  node tmp_node;
257  ethash_calculate_dag_item(&tmp_node, index * MIX_NODES + n, light);
258  dag_node = &tmp_node;
259  }
260 
261 #if defined(_M_X64) && ENABLE_SSE
262  {
263  __m128i fnv_prime = _mm_set1_epi32(FNV_PRIME);
264  __m128i xmm0 = _mm_mullo_epi32(fnv_prime, mix[n].xmm[0]);
265  __m128i xmm1 = _mm_mullo_epi32(fnv_prime, mix[n].xmm[1]);
266  __m128i xmm2 = _mm_mullo_epi32(fnv_prime, mix[n].xmm[2]);
267  __m128i xmm3 = _mm_mullo_epi32(fnv_prime, mix[n].xmm[3]);
268  mix[n].xmm[0] = _mm_xor_si128(xmm0, dag_node->xmm[0]);
269  mix[n].xmm[1] = _mm_xor_si128(xmm1, dag_node->xmm[1]);
270  mix[n].xmm[2] = _mm_xor_si128(xmm2, dag_node->xmm[2]);
271  mix[n].xmm[3] = _mm_xor_si128(xmm3, dag_node->xmm[3]);
272  }
273  #elif defined(__MIC__)
274  {
275  // __m512i implementation via union
276  // Each vector register (zmm) can store sixteen 32-bit integer numbers
277  __m512i fnv_prime = _mm512_set1_epi32(FNV_PRIME);
278  __m512i zmm0 = _mm512_mullo_epi32(fnv_prime, mix[n].zmm[0]);
279  mix[n].zmm[0] = _mm512_xor_si512(zmm0, dag_node->zmm[0]);
280  }
281  #else
282  {
283  for (unsigned w = 0; w != NODE_WORDS; ++w) {
284  mix[n].words[w] = fnv_hash(mix[n].words[w], dag_node->words[w]);
285  }
286  }
287 #endif
288  }
289 
290  }
291 
292 // Workaround for a GCC regression which causes a bogus -Warray-bounds warning.
293 // The regression was introduced in GCC 4.8.4, fixed in GCC 5.0.0 and backported to GCC 4.9.3 but
294 // never to the GCC 4.8.x line.
295 //
296 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56273
297 //
298 // This regression is affecting Debian Jesse (8.5) builds of cpp-ethereum (GCC 4.9.2) and also
299 // manifests in the doublethinkco armel v5 cross-builds, which use crosstool-ng and resulting
300 // in the use of GCC 4.8.4. The Tizen runtime wants an even older GLIBC version - the one from
301 // GCC 4.6.0!
302 
303 #if defined(__GNUC__) && (__GNUC__ < 5)
304 #pragma GCC diagnostic push
305 #pragma GCC diagnostic ignored "-Warray-bounds"
306 #endif // define (__GNUC__)
307 
308  // compress mix
309  for (uint32_t w = 0; w != MIX_WORDS; w += 4) {
310  uint32_t reduction = mix->words[w + 0];
311  reduction = reduction * FNV_PRIME ^ mix->words[w + 1];
312  reduction = reduction * FNV_PRIME ^ mix->words[w + 2];
313  reduction = reduction * FNV_PRIME ^ mix->words[w + 3];
314  mix->words[w / 4] = reduction;
315  }
316 
317 #if defined(__GNUC__) && (__GNUC__ < 5)
318 #pragma GCC diagnostic pop
319 #endif // define (__GNUC__)
320 
321  fix_endian_arr32(mix->words, MIX_WORDS / 4);
322  memcpy(&ret->mix_hash, mix->bytes, 32);
323  // final Keccak hash
324  SHA3_256(&ret->result, s_mix->bytes, 64 + 32); // Keccak-256(s + compressed_mix)
325  return true;
326 }
327 
329  ethash_h256_t* return_hash,
330  ethash_h256_t const* header_hash,
331  uint64_t const nonce,
332  ethash_h256_t const* mix_hash
333 )
334 {
335  uint8_t buf[64 + 32];
336  memcpy(buf, header_hash, 32);
337  fix_endian64_same(nonce);
338  memcpy(&(buf[32]), &nonce, 8);
339  SHA3_512(buf, buf, 40);
340  memcpy(&(buf[64]), mix_hash, 32);
341  SHA3_256(return_hash, buf, 64 + 32);
342 }
343 
344 ethash_h256_t ethash_get_seedhash(uint64_t block_number)
345 {
346  ethash_h256_t ret;
347  ethash_h256_reset(&ret);
348  uint64_t const epochs = block_number / ETHASH_EPOCH_LENGTH;
349  for (uint32_t i = 0; i < epochs; ++i)
350  SHA3_256(&ret, (uint8_t*)&ret, 32);
351  return ret;
352 }
353 
355  ethash_h256_t const* header_hash,
356  uint64_t const nonce,
357  ethash_h256_t const* mix_hash,
358  ethash_h256_t const* boundary
359 )
360 {
361 
362  ethash_h256_t return_hash;
363  ethash_quick_hash(&return_hash, header_hash, nonce, mix_hash);
364  return ethash_check_difficulty(&return_hash, boundary);
365 }
366 
367 ethash_light_t ethash_light_new_internal(uint64_t cache_size, ethash_h256_t const* seed)
368 {
369  struct ethash_light *ret;
370  ret = calloc(sizeof(*ret), 1);
371  if (!ret) {
372  return NULL;
373  }
374 #if defined(__MIC__)
375  ret->cache = _mm_malloc((size_t)cache_size, 64);
376 #else
377  ret->cache = malloc((size_t)cache_size);
378 #endif
379  if (!ret->cache) {
380  goto fail_free_light;
381  }
382  node* nodes = (node*)ret->cache;
383  if (!ethash_compute_cache_nodes(nodes, cache_size, seed)) {
384  goto fail_free_cache_mem;
385  }
386  ret->cache_size = cache_size;
387  return ret;
388 
389 fail_free_cache_mem:
390 #if defined(__MIC__)
391  _mm_free(ret->cache);
392 #else
393  free(ret->cache);
394 #endif
395 fail_free_light:
396  free(ret);
397  return NULL;
398 }
399 
401 {
402  ethash_h256_t seedhash = ethash_get_seedhash(block_number);
403  ethash_light_t ret;
404  ret = ethash_light_new_internal(ethash_get_cachesize(block_number), &seedhash);
405  ret->block_number = block_number;
406  return ret;
407 }
408 
410 {
411  if (light->cache) {
412  free(light->cache);
413  }
414  free(light);
415 }
416 
418  ethash_light_t light,
419  uint64_t full_size,
420  ethash_h256_t const header_hash,
421  uint64_t nonce
422 )
423 {
425  ret.success = true;
426  if (!ethash_hash(&ret, NULL, light, full_size, header_hash, nonce)) {
427  ret.success = false;
428  }
429  return ret;
430 }
431 
433  ethash_light_t light,
434  ethash_h256_t const header_hash,
435  uint64_t nonce
436 )
437 {
438  uint64_t full_size = ethash_get_datasize(light->block_number);
439  return ethash_light_compute_internal(light, full_size, header_hash, nonce);
440 }
441 
442 static bool ethash_mmap(struct ethash_full* ret, FILE* f)
443 {
444  int fd;
445  char* mmapped_data;
446  errno = 0;
447  ret->file = f;
448  if ((fd = ethash_fileno(ret->file)) == -1) {
449  return false;
450  }
451  mmapped_data = mmap(
452  NULL,
453  (size_t)ret->file_size + ETHASH_DAG_MAGIC_NUM_SIZE,
454  PROT_READ | PROT_WRITE,
455  MAP_SHARED,
456  fd,
457  0
458  );
459  if (mmapped_data == MAP_FAILED) {
460  return false;
461  }
462  ret->data = (node*)(mmapped_data + ETHASH_DAG_MAGIC_NUM_SIZE);
463  return true;
464 }
465 
467  char const* dirname,
468  ethash_h256_t const seed_hash,
469  uint64_t full_size,
470  ethash_light_t const light,
471  ethash_callback_t callback
472 )
473 {
474  struct ethash_full* ret;
475  FILE *f = NULL;
476  ret = calloc(sizeof(*ret), 1);
477  if (!ret) {
478  return NULL;
479  }
480  ret->file_size = (size_t)full_size;
481  switch (ethash_io_prepare(dirname, seed_hash, &f, (size_t)full_size, false)) {
482  case ETHASH_IO_FAIL:
483  // ethash_io_prepare will do all ETHASH_CRITICAL() logging in fail case
484  goto fail_free_full;
486  if (!ethash_mmap(ret, f)) {
487  ETHASH_CRITICAL("mmap failure()");
488  goto fail_close_file;
489  }
490 #if defined(__MIC__)
491  node* tmp_nodes = _mm_malloc((size_t)full_size, 64);
492  //copy all nodes from ret->data
493  //mmapped_nodes are not aligned properly
494  uint32_t const countnodes = (uint32_t) ((size_t)ret->file_size / sizeof(node));
495  //fprintf(stderr,"ethash_full_new_internal:countnodes:%d",countnodes);
496  for (uint32_t i = 1; i != countnodes; ++i) {
497  tmp_nodes[i] = ret->data[i];
498  }
499  ret->data = tmp_nodes;
500 #endif
501  return ret;
503  // if a DAG of same filename but unexpected size is found, silently force new file creation
504  if (ethash_io_prepare(dirname, seed_hash, &f, (size_t)full_size, true) != ETHASH_IO_MEMO_MISMATCH) {
505  ETHASH_CRITICAL("Could not recreate DAG file after finding existing DAG with unexpected size.");
506  goto fail_free_full;
507  }
508  // fallthrough to the mismatch case here, DO NOT go through match
510  if (!ethash_mmap(ret, f)) {
511  ETHASH_CRITICAL("mmap failure()");
512  goto fail_close_file;
513  }
514  break;
515  }
516 
517 #if defined(__MIC__)
518  ret->data = _mm_malloc((size_t)full_size, 64);
519 #endif
520  if (!ethash_compute_full_data(ret->data, full_size, light, callback)) {
521  ETHASH_CRITICAL("Failure at computing DAG data.");
522  goto fail_free_full_data;
523  }
524 
525  // after the DAG has been filled then we finalize it by writting the magic number at the beginning
526  if (fseek(f, 0, SEEK_SET) != 0) {
527  ETHASH_CRITICAL("Could not seek to DAG file start to write magic number.");
528  goto fail_free_full_data;
529  }
530  uint64_t const magic_num = ETHASH_DAG_MAGIC_NUM;
531  if (fwrite(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) {
532  ETHASH_CRITICAL("Could not write magic number to DAG's beginning.");
533  goto fail_free_full_data;
534  }
535  if (fflush(f) != 0) {// make sure the magic number IS there
536  ETHASH_CRITICAL("Could not flush memory mapped data to DAG file. Insufficient space?");
537  goto fail_free_full_data;
538  }
539  return ret;
540 
541 fail_free_full_data:
542  // could check that munmap(..) == 0 but even if it did not can't really do anything here
543  munmap(ret->data, (size_t)full_size);
544 #if defined(__MIC__)
545  _mm_free(ret->data);
546 #endif
547 fail_close_file:
548  fclose(ret->file);
549 fail_free_full:
550  free(ret);
551  return NULL;
552 }
553 
555 {
556  char strbuf[256];
557  if (!ethash_get_default_dirname(strbuf, 256)) {
558  return NULL;
559  }
560  uint64_t full_size = ethash_get_datasize(light->block_number);
562  return ethash_full_new_internal(strbuf, seedhash, full_size, light, callback);
563 }
564 
566 {
567  // could check that munmap(..) == 0 but even if it did not can't really do anything here
568  munmap(full->data, (size_t)full->file_size);
569  if (full->file) {
570  fclose(full->file);
571  }
572  free(full);
573 }
574 
576  ethash_full_t full,
577  ethash_h256_t const header_hash,
578  uint64_t nonce
579 )
580 {
582  ret.success = true;
583  if (!ethash_hash(
584  &ret,
585  (node const*)full->data,
586  NULL,
587  full->file_size,
588  header_hash,
589  nonce)) {
590  ret.success = false;
591  }
592  return ret;
593 }
594 
596 {
597  return full->data;
598 }
599 
601 {
602  return full->file_size;
603 }
union node node
bool ethash_compute_full_data(void *mem, uint64_t full_size, ethash_light_t const light, ethash_callback_t callback)
Compute the memory data for a full node&#39;s memory.
Definition: internal.c:188
FILE * file
Definition: internal.h:119
void ethash_full_delete(ethash_full_t full)
Frees a previously allocated ethash_full handler.
Definition: internal.c:565
DAG with revision/hash match, but file size was wrong.
Definition: io.h:46
uint64_t ethash_get_datasize(uint64_t const block_number)
Definition: internal.c:76
#define ETHASH_CRITICAL(...)
Logs a critical error in important parts of ethash.
Definition: io.h:71
#define fix_endian64_same(val_)
Definition: endian.h:50
#define MIX_WORDS
Definition: internal.h:21
bool ethash_quick_check_difficulty(ethash_h256_t const *header_hash, uint64_t const nonce, ethash_h256_t const *mix_hash, ethash_h256_t const *boundary)
Difficulty quick check for POW preverification.
Definition: internal.c:354
ethash_light_t ethash_light_new_internal(uint64_t cache_size, ethash_h256_t const *seed)
Allocate and initialize a new ethash_light handler.
Definition: internal.c:367
SHA3-256 message digest.
ethash_return_value_t ethash_light_compute_internal(ethash_light_t light, uint64_t full_size, ethash_h256_t const header_hash, uint64_t nonce)
Calculate the light client data.
Definition: internal.c:417
ethash_h256_t ethash_get_seedhash(uint64_t block_number)
Calculate the seedhash for a given block number.
Definition: internal.c:344
ethash_h256_t result
Definition: ethash.h:65
assert(len-trim+(2 *lenIndices)<=WIDTH)
#define ETHASH_DATASET_PARENTS
Definition: ethash.h:37
ethash_full_t ethash_full_new_internal(char const *dirname, ethash_h256_t const seed_hash, uint64_t full_size, ethash_light_t const light, ethash_callback_t callback)
Allocate and initialize a new ethash_full handler.
Definition: internal.c:466
uint64_t cache_size
Definition: internal.h:87
if(a.IndicesBefore(b, len, lenIndices))
Definition: equihash.cpp:243
#define ETHASH_EPOCH_LENGTH
Definition: ethash.h:34
#define MIX_NODES
Definition: internal.h:22
SHA3_Final< 64 > SHA3_512
Definition: sha3.h:89
SHA3_Final< 32 > SHA3_256
Definition: sha3.h:81
DAG file existed and revision/hash matched. No need to do anything.
Definition: io.h:48
void ethash_light_delete(ethash_light_t light)
Frees a previously allocated ethash_light handler.
Definition: internal.c:409
const uint64_t cache_sizes[2048]
Definition: data_sizes.h:480
node * data
Definition: internal.h:121
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_h256_t const seedhash, FILE **output_file, uint64_t file_size, bool force_create)
Prepares io for ethash.
Definition: io.c:26
decsha3(256) decsha3(512) static inline void SHA3_256(struct ethash_h256 const *ret
#define ETHASH_DAG_MAGIC_NUM_SIZE
Definition: ethash.h:40
std::vector< byte > bytes
Definition: Common.h:75
#define NODE_WORDS
Definition: internal.h:20
#define ETHASH_CACHE_ROUNDS
Definition: ethash.h:38
int ethash_fileno(FILE *f)
Get a file descriptor number from a FILE stream.
Definition: io_posix.c:48
Type of a seedhash/blockhash e.t.c.
Definition: ethash.h:48
ethash_light_t ethash_light_new(uint64_t block_number)
Allocate and initialize a new ethash_light handler.
Definition: internal.c:400
ethash_return_value_t ethash_light_compute(ethash_light_t light, ethash_h256_t const header_hash, uint64_t nonce)
Calculate the light client data.
Definition: internal.c:432
#define f(x)
Definition: gost.cpp:57
void ethash_calculate_dag_item(node *const ret, uint32_t node_index, ethash_light_t const light)
Definition: internal.c:125
#define ETHASH_ACCESSES
Definition: ethash.h:39
uint32_t words[NODE_WORDS]
Definition: internal.h:27
#define fd(x)
Definition: rijndael.cpp:172
The DAG file did not exist or there was revision/hash mismatch.
Definition: io.h:47
uint64_t ethash_get_cachesize(uint64_t const block_number)
Definition: internal.c:82
uint8_t const size_t const size
Definition: sha3.h:20
void * memcpy(void *a, const void *b, size_t c)
void ethash_quick_hash(ethash_h256_t *return_hash, ethash_h256_t const *header_hash, uint64_t const nonce, ethash_h256_t const *mix_hash)
Definition: internal.c:328
#define fix_endian_arr32(arr_, size_)
Definition: endian.h:51
uint64_t file_size
Definition: internal.h:120
int(* ethash_callback_t)(unsigned)
Definition: ethash.h:62
#define ETHASH_DAG_MAGIC_NUM
Definition: ethash.h:41
uint64_t block_number
Definition: internal.h:88
uint64_t ethash_full_dag_size(ethash_full_t full)
Get the size of the DAG data.
Definition: internal.c:600
ethash_full_t ethash_full_new(ethash_light_t light, ethash_callback_t callback)
Allocate and initialize a new ethash_full handler.
Definition: internal.c:554
#define FNV_PRIME
Definition: fnv.h:30
bool ethash_get_default_dirname(char *strbuf, size_t buffsize)
Gets the default directory name for the DAG depending on the system.
Definition: io_posix.c:89
void const * ethash_full_dag(ethash_full_t full)
Get a pointer to the full DAG data.
Definition: internal.c:595
uint8_t const * data
Definition: sha3.h:19
ethash_return_value_t ethash_full_compute(ethash_full_t full, ethash_h256_t const header_hash, uint64_t nonce)
Calculate the full client data.
Definition: internal.c:575
uint8_t bytes[NODE_WORDS *4]
Definition: internal.h:26
There has been an IO failure.
Definition: io.h:45
#define fix_endian64(dst_, src_)
Definition: endian.h:49
void * cache
Definition: internal.h:86
ethash_h256_t mix_hash
Definition: ethash.h:66
Definition: internal.h:25