Monero
randomx.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef RANDOMX_H
30 #define RANDOMX_H
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #define RANDOMX_HASH_SIZE 32
36 #define RANDOMX_DATASET_ITEM_SIZE 64
37 
38 #ifndef RANDOMX_EXPORT
39 #define RANDOMX_EXPORT
40 #endif
41 
42 typedef enum {
53 
56 typedef struct randomx_vm randomx_vm;
57 
58 
59 #if defined(__cplusplus)
60 
61 #ifdef __cpp_constexpr
62 #define CONSTEXPR constexpr
63 #else
64 #define CONSTEXPR
65 #endif
66 
67 inline CONSTEXPR randomx_flags operator |(randomx_flags a, randomx_flags b) {
68  return static_cast<randomx_flags>(static_cast<int>(a) | static_cast<int>(b));
69 }
71  return static_cast<randomx_flags>(static_cast<int>(a) & static_cast<int>(b));
72 }
73 inline randomx_flags& operator |=(randomx_flags& a, randomx_flags b) {
74  return a = a | b;
75 }
76 
77 extern "C" {
78 #endif
79 
90 
111 
120 RANDOMX_EXPORT void randomx_init_cache(randomx_cache *cache, const void *key, size_t keySize);
121 
128 
139 
145 RANDOMX_EXPORT unsigned long randomx_dataset_item_count(void);
146 
158 RANDOMX_EXPORT void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount);
159 
169 
176 
203 
214 
223 
230 
240 RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output);
241 
259 RANDOMX_EXPORT void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize);
260 RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm* machine, const void* nextInput, size_t nextInputSize, void* output);
262 
272 RANDOMX_EXPORT void randomx_calculate_commitment(const void* input, size_t inputSize, const void* hash_in, void* com_out);
273 
274 #if defined(__cplusplus)
275 }
276 #endif
277 
278 #endif
Definition: dataset.hpp:46
Definition: randomx.h:51
RANDOMX_EXPORT void randomx_release_cache(randomx_cache *cache)
Definition: randomx.cpp:141
Definition: randomx.h:50
Definition: dataset.hpp:40
Definition: randomx.h:48
#define RANDOMX_EXPORT
Definition: randomx.h:39
Definition: randomx.h:47
RANDOMX_EXPORT void randomx_release_dataset(randomx_dataset *dataset)
Definition: randomx.cpp:200
Definition: randomx.h:43
RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm *machine, const void *nextInput, size_t nextInputSize, void *output)
Definition: randomx.cpp:398
const char * key
Definition: hmac_keccak.cpp:40
RANDOMX_EXPORT void * randomx_get_dataset_memory(randomx_dataset *dataset)
Definition: randomx.cpp:195
RANDOMX_EXPORT void randomx_vm_set_cache(randomx_vm *machine, randomx_cache *cache)
Definition: randomx.cpp:341
RANDOMX_EXPORT randomx_vm * randomx_create_vm(randomx_flags flags, randomx_cache *cache, randomx_dataset *dataset)
Definition: randomx.cpp:206
Definition: randomx.h:44
static int flags
Definition: mdb_load.c:31
Definition: randomx.h:49
Definition: randomx.h:46
RANDOMX_EXPORT void randomx_destroy_vm(randomx_vm *machine)
Definition: randomx.cpp:356
randomx_flags
Definition: randomx.h:42
RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output)
Definition: randomx.cpp:361
RANDOMX_EXPORT randomx_cache * randomx_alloc_cache(randomx_flags flags)
Definition: randomx.cpp:69
RANDOMX_EXPORT void randomx_calculate_hash_last(randomx_vm *machine, void *output)
Definition: randomx.cpp:411
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
output
Definition: gmock_output_test.py:175
randomx_cache * cache
Definition: tests.cpp:19
RANDOMX_EXPORT void randomx_calculate_commitment(const void *input, size_t inputSize, const void *hash_in, void *com_out)
Definition: randomx.cpp:421
RANDOMX_EXPORT unsigned long randomx_dataset_item_count(void)
Definition: randomx.cpp:183
RANDOMX_EXPORT void randomx_init_cache(randomx_cache *cache, const void *key, size_t keySize)
Definition: randomx.cpp:130
RANDOMX_EXPORT randomx_dataset * randomx_alloc_dataset(randomx_flags flags)
Definition: randomx.cpp:147
RANDOMX_EXPORT void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount)
Definition: randomx.cpp:187
RANDOMX_EXPORT randomx_flags randomx_get_flags(void)
Definition: randomx.cpp:49
RANDOMX_EXPORT void randomx_vm_set_dataset(randomx_vm *machine, randomx_dataset *dataset)
Definition: randomx.cpp:350
RANDOMX_EXPORT void randomx_calculate_hash_first(randomx_vm *machine, const void *input, size_t inputSize)
Definition: randomx.cpp:393
Definition: virtual_machine.hpp:36
static unsigned char * operator&(ec_point &point)
Definition: crypto.cpp:77
cryptonote::block b
Definition: block.cpp:40
Definition: randomx.h:45