Fabcoin Core  0.16.2
P2P Digital Currency
ethash.h
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 ethash. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
21 #pragma once
22 
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <string.h>
26 #include <stddef.h>
27 #include "compiler.h"
28 
29 #define ETHASH_REVISION 23
30 #define ETHASH_DATASET_BYTES_INIT 1073741824U // 2**30
31 #define ETHASH_DATASET_BYTES_GROWTH 8388608U // 2**23
32 #define ETHASH_CACHE_BYTES_INIT 1073741824U // 2**24
33 #define ETHASH_CACHE_BYTES_GROWTH 131072U // 2**17
34 #define ETHASH_EPOCH_LENGTH 30000U
35 #define ETHASH_MIX_BYTES 128
36 #define ETHASH_HASH_BYTES 64
37 #define ETHASH_DATASET_PARENTS 256
38 #define ETHASH_CACHE_ROUNDS 3
39 #define ETHASH_ACCESSES 64
40 #define ETHASH_DAG_MAGIC_NUM_SIZE 8
41 #define ETHASH_DAG_MAGIC_NUM 0xFEE1DEADBADDCAFE
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
48 typedef struct ethash_h256 { uint8_t b[32]; } ethash_h256_t;
49 
50 // convenience macro to statically initialize an h256_t
51 // usage:
52 // ethash_h256_t a = ethash_h256_static_init(1, 2, 3, ... )
53 // have to provide all 32 values. If you don't provide all the rest
54 // will simply be unitialized (not guranteed to be 0)
55 #define ethash_h256_static_init(...) \
56  { {__VA_ARGS__} }
57 
58 struct ethash_light;
59 typedef struct ethash_light* ethash_light_t;
60 struct ethash_full;
61 typedef struct ethash_full* ethash_full_t;
62 typedef int(*ethash_callback_t)(unsigned);
63 
64 typedef struct ethash_return_value {
67  bool success;
69 
77 ethash_light_t ethash_light_new(uint64_t block_number);
82 void ethash_light_delete(ethash_light_t light);
92  ethash_light_t light,
93  ethash_h256_t const header_hash,
94  uint64_t nonce
95 );
96 
111 ethash_full_t ethash_full_new(ethash_light_t light, ethash_callback_t callback);
112 
117 void ethash_full_delete(ethash_full_t full);
127  ethash_full_t full,
128  ethash_h256_t const header_hash,
129  uint64_t nonce
130 );
134 void const* ethash_full_dag(ethash_full_t full);
138 uint64_t ethash_full_dag_size(ethash_full_t full);
139 
143 ethash_h256_t ethash_get_seedhash(uint64_t block_number);
144 
145 #ifdef __cplusplus
146 }
147 #endif
struct ethash_full * ethash_full_t
Definition: ethash.h:61
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
ethash_light_t ethash_light_new(uint64_t block_number)
Allocate and initialize a new ethash_light handler.
Definition: internal.c:400
void ethash_light_delete(ethash_light_t light)
Frees a previously allocated ethash_light handler.
Definition: internal.c:409
struct ethash_light * ethash_light_t
Definition: ethash.h:59
struct ethash_h256 ethash_h256_t
Type of a seedhash/blockhash e.t.c.
void const * ethash_full_dag(ethash_full_t full)
Get a pointer to the full DAG data.
Definition: internal.c:595
void ethash_full_delete(ethash_full_t full)
Frees a previously allocated ethash_full handler.
Definition: internal.c:565
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
struct ethash_return_value ethash_return_value_t
Type of a seedhash/blockhash e.t.c.
Definition: ethash.h:48
uint64_t ethash_full_dag_size(ethash_full_t full)
Get the size of the DAG data.
Definition: internal.c:600
int(* ethash_callback_t)(unsigned)
Definition: ethash.h:62
uint8_t b[32]
Definition: ethash.h:48
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
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
ethash_h256_t mix_hash
Definition: ethash.h:66