Crates.io | data-racer |
lib.rs | data-racer |
version | 0.2.3 |
source | src |
created_at | 2023-08-06 15:12:42.120729 |
updated_at | 2023-08-28 19:04:50.294116 |
description | Is a true random number generator that uses data races to generate random numbers |
homepage | |
repository | |
max_upload_size | |
id | 937214 |
size | 12,468 |
This project is in beta and very experimental. You should not use or treat this as a cryptographically secure random number generator. Everything said in this document beyond this point is a not proven to be true.
Data-racer is an experimental project aimed at generating random numbers using a unique approach based on data races.
It leverages the inherent unpredictability of data race conditions in multithreaded environments to generate a random and non-deterministic behaviour. However, it's important to note that this approach is highly experimental and may have security implications that are not yet fully understood.
To understand this algorithm better and its security implications please read the Security of the algorithm section.
To use Data-racer in your project you can add the following lines to your Cargo.toml:
[dependencies]
data-racer = "*"
To generate a random number you can use the following example:
use datarace::DataraceRNG;
fn main() {
let mut random_number_generator = DataraceRNG::default(); // Initialize the random number generator and make it mutable
let random_i32: i32 = random_number_generator.gen(); // Generate a random i32
println!("You generated the number {}. So random!", random_i32);
}
You can also generate almost any kind of primitive type
use datarace::DataraceRNG;
fn main() {
let mut random_number_generator = DataraceRNG::default(); // Initialize the random number generator and make it mutable
// Generate (almost) any kind of primitive data
let random_i32: i32 = random_number_generator.gen();
let random_u128: u128 = random_number_generator.gen();
let random_u32: u32 = random_number_generator.gen();
let random_char: char = random_number_generator.gen();
let random_bool: bool = random_number_generator.gen();
}
You can also fill Slices of (almost) any primitive types!
use datarace::DataraceRNG;
fn main() {
let mut random_number_generator = DataraceRNG::default(); // Initialize the random number generator and make it mutable
// Initialize a mutable slice
let mut char_slice: [char; 128] = ['a'; 128];
let mut bool_slice: [bool; 128] = [true; 128];
let mut u32_slice: [u32; 128] = [0; 128];
random_number_generator.fill(&mut char_slice);
random_number_generator.fill(&mut bool_slice);
random_number_generator.fill(&mut u32_slice);
}
This method of generating random numbers is not considered "secure" by default but keep in mind that the number generated by the data race is used to seed an actual Random Number Generator (from the rand crate) so you can consider the generate to be at least as secure as the rand StdRand in the rand crate.
Another thing worth mentioning is that the actual number generated by the data race has been tested and analyzed by the NIST Statistical Test Suite improved version (Credits to the
Arcetri Team) and has passed all of the tests, scoring 188/188
. (The function that provides the data-race-generated number is the datarace::DataraceRNG::data_race()
function and you should not use this to generate random numbers, use instead the datarace::DataraceRNG::gen()
function).
So the raw data-race-based random number generator is statistically secure according to the NIST Statistical Test Suite improved version.
Last but not least, this generator uses a very fast cryptographic hashing algorithm (blake3) that is used to produce the seed so that should improve the security some bit.
Please feel free to contribute by creating a pull request to submit the code you would like to be included.
You are very welcome to give us bug fixes and improvements in the form of a GitHub Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.