mb-rand
A Rust library crate providing safe bindings to OpenBSD's arc4random functions.
Features
fill_bytes- Fill a byte array with cryptographically secure random datarandom_bytes- Generate a new vector filled with random bytesrandom_string- Generate a random string from a character set
Usage
Add this to your Cargo.toml:
[]
= "0.2.0"
Examples
Fill a byte array with random data:
use fill_bytes;
Generate a random string:
use random_string;
Requirements
This crate relies on the host system having OpenBSD's
[arc4random][arc4random_man] functions available. This is typically the case
on:
- OpenBSD (native)
- FreeBSD (compatible implementation)
- macOS (compatible implementation)
- Some Linux distributions with libbsd installed
On systems where these functions are not available, you will need to install the appropriate libraries:
Ubuntu/Debian
Fedora/RHEL/CentOS
Platform-Specific Configuration
For systems where the arc4random functions need explicit
linking, you may need to create a build script (build.rs):
Safety
This crate provides safe wrappers around the unsafe FFI calls to the arc4random functions. The underlying arc4random implementation is considered cryptographically secure and suitable for generating random data for security-sensitive applications.
License
Licensed under an OpenBSD-ISC-style license, see LICENSE for details.