3 unstable releases
0.2.1 | Jun 15, 2020 |
---|---|
0.2.0 | Mar 23, 2020 |
0.1.0 | Mar 17, 2020 |
#15 in #random-x
14KB
247 lines
randomx4r
A Rusty wrapper for RandomX hashing.
Installation
Depends on the randomx4r-sys crate for FFI. Building this crate requires the installation of CMake and a C++ compiler.
Examples
Some small examples are included in the documentation. Larger examples are in the examples directory:
multithreaded
- Hashing with multiple cores.
Links
License
The code in this repository is released under the terms of the MIT license. See LICENSE file in project root for more info.
lib.rs
:
Rust bindings to librandomx, a library for computing RandomX hashes.
Examples
Light mode hash
Requires 256M of shared memory.
use randomx4r::{RandomxCache, RandomxError, RandomxFlags, RandomxVm};
// Get flags supported by this system.
let flags = RandomxFlags::default();
let cache = RandomxCache::new(flags, b"key")?;
let vm = RandomxVm::new(flags, &cache)?;
let hash = vm.hash(b"input"); // is a [u8; 32]
Fast mode hash
Requires 2080M of shared memory.
use randomx4r::{RandomxDataset, RandomxError, RandomxFlags, RandomxVm};
// OR the default flags with FULLMEM (aka. fast mode)
let flags = RandomxFlags::default() | RandomxFlags::FULLMEM;
// Speed up dataset initialisation
const THREADS: u8 = 4;
let dataset = RandomxDataset::new(flags, b"key", THREADS)?;
let vm = RandomxVm::new_fast(flags, &dataset)?;
let hash = vm.hash(b"input");
Errors
Some operations (e.g. allocating a VM or dataset) can fail if the system doesn't have enough free memory, or if you tried to force a feature like large pages or AVX2 on a system that does not support it.
Dependencies
~0.5–2.5MB
~50K SLoC