Crate hopr_crypto_random

Source
Expand description

This Rust crate contains implementation of common random number generation functions. All functions and types from this crate supply cryptographically secure random numbers.

Instead of relying on external crates, all HOPR crates in this monorepo should exclusively rely on randomness functions only from this crate. Besides that, the OsRng type exported from this crate can be used if a type implementing random traits is necessary.

Constants§

MAX_RANDOM_INTEGER
Maximum random integer that can be generated. This is the last positive 64-bit value in the two’s complement representation.

Traits§

Rng
An automatically-implemented extension trait on RngCore providing high-level generic methods for sampling values and other convenience methods.
RngCore
The core of a random number generator.

Functions§

is_rng_fixed
Returns true if the build is using an insecure RNG with a fixed seed.
random_array
Allocates GenericArray of the given size and fills it with random bytes
random_bytes
Allocates an array of the given size and fills it with random bytes
random_fill
Fills the specific number of bytes starting from the given offset in the given buffer.
random_float
Generates a random float uniformly distributed between 0 (inclusive) and 1 (exclusive).
random_float_in_range
Generates a random float uniformly distributed in the given range.
random_integer
Generates a random unsigned integer which is at least start and optionally strictly less than end. If end is not given, the MAX_RANDOM_INTEGER value is used. The caller must make sure that 0 <= start < end <= MAX_RANDOM_INTEGER, otherwise the function will panic.
rng
Gets the default cryptographically secure random number generator.