ccp_randomx/
bindings.rs

1/* Generated with help of rust-bindgen 0.69.2 */
2
3#![allow(dead_code)]
4#![allow(non_upper_case_globals)]
5#![allow(non_camel_case_types)]
6
7pub mod flags {
8    pub const randomx_flags_RANDOMX_FLAG_DEFAULT: randomx_flags = 0;
9    pub const randomx_flags_RANDOMX_FLAG_LARGE_PAGES: randomx_flags = 1;
10    pub const randomx_flags_RANDOMX_FLAG_HARD_AES: randomx_flags = 2;
11    pub const randomx_flags_RANDOMX_FLAG_FULL_MEM: randomx_flags = 4;
12    pub const randomx_flags_RANDOMX_FLAG_JIT: randomx_flags = 8;
13    pub const randomx_flags_RANDOMX_FLAG_SECURE: randomx_flags = 16;
14    pub const randomx_flags_RANDOMX_FLAG_ARGON2_SSSE3: randomx_flags = 32;
15    pub const randomx_flags_RANDOMX_FLAG_ARGON2_AVX2: randomx_flags = 64;
16    pub const randomx_flags_RANDOMX_FLAG_ARGON2: randomx_flags = 96;
17
18    pub type randomx_flags = ::std::os::raw::c_uint;
19
20    extern "C" {
21        #[doc = " @return The recommended flags to be used on the current machine.
22                 Does not include:
23                    - RANDOMX_FLAG_LARGE_PAGES
24                    - RANDOMX_FLAG_FULL_MEM
25                    - RANDOMX_FLAG_SECURE
26                 These flags must be added manually if desired.
27                 On OpenBSD RANDOMX_FLAG_SECURE is enabled by default in JIT mode as W^X is enforced by the OS.
28        "]
29        pub fn randomx_get_flags() -> randomx_flags;
30    }
31}
32
33pub mod cache {
34    use super::flags::randomx_flags;
35
36    #[repr(C)]
37    #[derive(Debug, Copy, Clone)]
38    pub struct randomx_cache {
39        _unused: [u8; 0],
40    }
41
42    extern "C" {
43        #[doc = " Creates a randomx_cache structure and allocates memory for RandomX Cache.
44
45         @param flags is any combination of these 2 flags (each flag can be set or not set):
46                 RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages
47                 RANDOMX_FLAG_JIT - create cache structure with JIT compilation support; this makes
48                                    subsequent Dataset initialization faster
49         Optionally, one of these two flags may be selected:
50                 RANDOMX_FLAG_ARGON2_SSSE3 - optimized Argon2 for CPUs with the SSSE3 instruction set
51                                             makes subsequent cache initialization faster
52                 RANDOMX_FLAG_ARGON2_AVX2 - optimized Argon2 for CPUs with the AVX2 instruction set
53                                            makes subsequent cache initialization faster
54
55         @return Pointer to an allocated randomx_cache structure.
56                 Returns NULL if:
57                          (1) memory allocation fails
58                          (2) the RANDOMX_FLAG_JIT is set and JIT compilation is not supported on the current platform
59                          (3) an invalid or unsupported RANDOMX_FLAG_ARGON2 value is set
60        "]
61        pub fn randomx_alloc_cache(flags: randomx_flags) -> *mut randomx_cache;
62    }
63
64    extern "C" {
65        #[doc = " Initializes the cache memory and SuperscalarHash using the provided key value.
66          Does nothing if called again with the same key value.
67
68          @param cache is a pointer to a previously allocated randomx_cache structure. Must not be NULL.
69          @param key is a pointer to memory which contains the key value. Must not be NULL.
70          @param keySize is the number of bytes of the key.
71        "]
72        pub fn randomx_init_cache(
73            cache: *mut randomx_cache,
74            key: *const ::std::os::raw::c_void,
75            keySize: usize,
76        );
77    }
78
79    extern "C" {
80        #[doc = " Releases all memory occupied by the randomx_cache structure.
81
82          @param cache is a pointer to a previously allocated randomx_cache structure.
83        "]
84        pub fn randomx_release_cache(cache: *mut randomx_cache);
85    }
86}
87
88pub mod dataset {
89    use super::cache::randomx_cache;
90    use super::flags::randomx_flags;
91
92    #[repr(C)]
93    #[derive(Debug, Copy, Clone)]
94    pub struct randomx_dataset {
95        _unused: [u8; 0],
96    }
97
98    extern "C" {
99        #[doc = " Creates a randomx_dataset structure and allocates memory for RandomX Dataset.
100
101           @param flags is the initialization flags. Only one flag is supported (can be set or not set):
102                   RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages
103
104           @return Pointer to an allocated randomx_dataset structure.
105                    NULL is returned if memory allocation fails.
106        "]
107        pub fn randomx_alloc_dataset(flags: randomx_flags) -> *mut randomx_dataset;
108    }
109
110    extern "C" {
111        #[doc = " Gets the number of items contained in the dataset.
112
113          @return the number of items contained in the dataset.
114        "]
115        pub fn randomx_dataset_item_count() -> ::std::os::raw::c_ulong;
116    }
117
118    extern "C" {
119        #[doc = " Initializes dataset items.
120
121          Note: In order to use the Dataset, all items from 0 to (randomx_dataset_item_count() - 1) must be initialized.
122          This may be done by several calls to this function using non-overlapping item sequences.
123
124          @param dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL.
125          @param cache is a pointer to a previously allocated and initialized randomx_cache structure. Must not be NULL.
126          @param startItem is the item number where intialization should start.
127          @param itemCount is the number of items that should be initialized.
128        "]
129        pub fn randomx_init_dataset(
130            dataset: *mut randomx_dataset,
131            cache: *mut randomx_cache,
132            startItem: ::std::os::raw::c_ulong,
133            itemCount: ::std::os::raw::c_ulong,
134        );
135    }
136
137    extern "C" {
138        #[doc = " Returns a pointer to the internal memory buffer of the dataset structure. The size
139           of the internal memory buffer is randomx_dataset_item_count() * RANDOMX_DATASET_ITEM_SIZE.
140
141           @param dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL.
142           @return Pointer to the internal memory buffer of the dataset structure.
143        "]
144        pub fn randomx_get_dataset_memory(
145            dataset: *mut randomx_dataset,
146        ) -> *mut ::std::os::raw::c_void;
147    }
148
149    extern "C" {
150        #[doc = " Releases all memory occupied by the randomx_dataset structure.\
151          @param dataset is a pointer to a previously allocated randomx_dataset structure.\
152        "]
153        pub fn randomx_release_dataset(dataset: *mut randomx_dataset);
154    }
155}
156
157pub mod vm {
158    use super::cache::randomx_cache;
159    use super::dataset::randomx_dataset;
160    use super::flags::randomx_flags;
161
162    #[repr(C)]
163    #[derive(Debug, Copy, Clone)]
164    pub struct randomx_vm {
165        _unused: [u8; 0],
166    }
167
168    extern "C" {
169        #[doc = " Creates and initializes a RandomX virtual machine.
170
171          @param flags is any combination of these 5 flags (each flag can be set or not set):
172                  RANDOMX_FLAG_LARGE_PAGES - allocate scratchpad memory in large pages
173                  RANDOMX_FLAG_HARD_AES - virtual machine will use hardware accelerated AES
174                  RANDOMX_FLAG_FULL_MEM - virtual machine will use the full dataset
175                  RANDOMX_FLAG_JIT - virtual machine will use a JIT compiler
176                  RANDOMX_FLAG_SECURE - when combined with RANDOMX_FLAG_JIT, the JIT pages are never
177                                        writable and executable at the same time (W^X policy)
178                  The numeric values of the first 4 flags are ordered so that a higher value will provide
179                  faster hash calculation and a lower numeric value will provide higher portability.
180                  Using RANDOMX_FLAG_DEFAULT (all flags not set) works on all platforms, but is the slowest.
181          @param cache is a pointer to an initialized randomx_cache structure. Can be
182                  NULL if RANDOMX_FLAG_FULL_MEM is set.
183          @param dataset is a pointer to a randomx_dataset structure. Can be NULL
184                  if RANDOMX_FLAG_FULL_MEM is not set.
185
186          @return Pointer to an initialized randomx_vm structure.
187                  Returns NULL if:
188                  (1) Scratchpad memory allocation fails.
189                  (2) The requested initialization flags are not supported on the current platform.
190                  (3) cache parameter is NULL and RANDOMX_FLAG_FULL_MEM is not set
191                  (4) dataset parameter is NULL and RANDOMX_FLAG_FULL_MEM is set
192         "]
193        pub fn randomx_create_vm(
194            flags: randomx_flags,
195            cache: *mut randomx_cache,
196            dataset: *mut randomx_dataset,
197        ) -> *mut randomx_vm;
198    }
199
200    extern "C" {
201        #[doc = " Reinitializes a virtual machine with a new Cache. This function should be called anytime
202          the Cache is reinitialized with a new key. Does nothing if called with a Cache containing
203          the same key value as already set.
204
205           @param machine is a pointer to a randomx_vm structure that was initialized
206                  without RANDOMX_FLAG_FULL_MEM. Must not be NULL.
207           @param cache is a pointer to an initialized randomx_cache structure. Must not be NULL.
208        "]
209        pub fn randomx_vm_set_cache(machine: *mut randomx_vm, cache: *mut randomx_cache);
210    }
211
212    extern "C" {
213        #[doc = " Reinitializes a virtual machine with a new Dataset.
214          @param machine is a pointer to a randomx_vm structure that was initialized
215                 with RANDOMX_FLAG_FULL_MEM. Must not be NULL.
216          @param dataset is a pointer to an initialized randomx_dataset structure. Must not be NULL.
217        "]
218        pub fn randomx_vm_set_dataset(machine: *mut randomx_vm, dataset: *mut randomx_dataset);
219    }
220
221    extern "C" {
222        #[doc = " Releases all memory occupied by the randomx_vm structure.
223          @param machine is a pointer to a previously created randomx_vm structure.\
224        "]
225        pub fn randomx_destroy_vm(machine: *mut randomx_vm);
226    }
227
228    extern "C" {
229        #[doc = " Calculates a RandomX hash value.
230          @param machine is a pointer to a randomx_vm structure. Must not be NULL.
231          @param input is a pointer to memory to be hashed. Must not be NULL.
232          @param inputSize is the number of bytes to be hashed.
233          @param output is a pointer to memory where the hash will be stored. Must not
234                 be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing.
235        "]
236        pub fn randomx_calculate_hash(
237            machine: *mut randomx_vm,
238            input: *const ::std::os::raw::c_void,
239            inputSize: usize,
240            output: *mut ::std::os::raw::c_void,
241        );
242    }
243
244    extern "C" {
245        #[doc = " Set of functions used to calculate multiple RandomX hashes more efficiently.
246           randomx_calculate_hash_first will begin a hash calculation.
247           randomx_calculate_hash_next  will output the hash value of the previous input
248                                        and begin the calculation of the next hash.
249           randomx_calculate_hash_last  will output the hash value of the previous input.
250           WARNING: These functions may alter the floating point rounding mode of the calling thread.
251
252           @param machine is a pointer to a randomx_vm structure. Must not be NULL.
253           @param input is a pointer to memory to be hashed. Must not be NULL.
254           @param inputSize is the number of bytes to be hashed.
255           @param nextInput is a pointer to memory to be hashed for the next hash. Must not be NULL.
256           @param nextInputSize is the number of bytes to be hashed for the next hash.
257           @param output is a pointer to memory where the hash will be stored. Must not
258                  be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing.
259        "]
260        pub fn randomx_calculate_hash_first(
261            machine: *mut randomx_vm,
262            input: *const ::std::os::raw::c_void,
263            inputSize: usize,
264        );
265    }
266
267    extern "C" {
268        pub fn randomx_calculate_hash_next(
269            machine: *mut randomx_vm,
270            nextInput: *const ::std::os::raw::c_void,
271            nextInputSize: usize,
272            output: *mut ::std::os::raw::c_void,
273        );
274    }
275
276    extern "C" {
277        pub fn randomx_calculate_hash_last(
278            machine: *mut randomx_vm,
279            output: *mut ::std::os::raw::c_void,
280        );
281    }
282}