Add RandomX hashing wrapper
This commit is contained in:
parent
285d68b78a
commit
1a927ccb44
3 changed files with 61 additions and 0 deletions
35
src/crypto/randomx_hash.cpp
Normal file
35
src/crypto/randomx_hash.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <crypto/randomx_hash.h>
|
||||
|
||||
#include <randomx.h>
|
||||
|
||||
bool VextaRandomXHash(
|
||||
const void* input,
|
||||
std::size_t input_size,
|
||||
const void* key,
|
||||
std::size_t key_size,
|
||||
uint8_t output[VEXTA_RANDOMX_HASH_SIZE])
|
||||
{
|
||||
randomx_cache* cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT);
|
||||
if (cache == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
randomx_init_cache(cache, key, key_size);
|
||||
|
||||
randomx_vm* vm = randomx_create_vm(
|
||||
RANDOMX_FLAG_DEFAULT,
|
||||
cache,
|
||||
nullptr);
|
||||
|
||||
if (vm == nullptr) {
|
||||
randomx_release_cache(cache);
|
||||
return false;
|
||||
}
|
||||
|
||||
randomx_calculate_hash(vm, input, input_size, output);
|
||||
|
||||
randomx_destroy_vm(vm);
|
||||
randomx_release_cache(cache);
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in a new issue