Skip to content

Commit cb10a2c

Browse files
authored
Merge pull request #814 from vks/warn-jitter
rand_jitter: Discourage use for cryptographic purposes
2 parents 245fde0 + e0bffb2 commit cb10a2c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

rand_jitter/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
Non-physical true random number generator based on timing jitter.
1111

12+
Note that this RNG is not suited for use cases where cryptographic security is
13+
required (also see [this
14+
discussion](https://github.com/rust-random/rand/issues/699)).
15+
1216
This crate depends on [rand_core](https://crates.io/crates/rand_core) and is
1317
part of the [Rand project](https://github.com/rust-random/rand).
1418

rand_jitter/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
//! Non-physical true random number generator based on timing jitter.
1616
//!
17+
//! Note that this RNG is not suited for use cases where cryptographic security is
18+
//! required (also see this [discussion]).
19+
//!
1720
//! This is a true random number generator, as opposed to pseudo-random
1821
//! generators. Random numbers generated by `JitterRng` can be seen as fresh
1922
//! entropy. A consequence is that it is orders of magnitude slower than `OsRng`
@@ -24,9 +27,6 @@
2427
//! indistinguishable, and a cryptographic PRNG should also be as impossible to
2528
//! predict.
2629
//!
27-
//! Use of `JitterRng` is recommended for initializing cryptographic PRNGs when
28-
//! `OsRng` is not available.
29-
//!
3030
//! `JitterRng` can be used without the standard library, but not conveniently,
3131
//! you must provide a high-precision timer and carefully have to follow the
3232
//! instructions of [`JitterRng::new_with_timer`].
@@ -39,6 +39,7 @@
3939
//! with disabled `std` feature.
4040
//!
4141
//! [Jitterentropy]: http://www.chronox.de/jent.html
42+
//! [discussion]: https://github.com/rust-random/rand/issues/699
4243
4344
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
4445
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
@@ -81,7 +82,7 @@ doc_comment!(include_str!("../README.md"));
8182
mod platform;
8283
mod error;
8384

84-
use rand_core::{RngCore, CryptoRng, Error, impls};
85+
use rand_core::{RngCore, Error, impls};
8586
pub use error::TimerError;
8687

8788
use core::{fmt, mem, ptr};
@@ -97,6 +98,9 @@ const MEMORY_SIZE: usize = MEMORY_BLOCKS * MEMORY_BLOCKSIZE;
9798

9899
/// A true random number generator based on jitter in the CPU execution time,
99100
/// and jitter in memory access time.
101+
///
102+
/// Note that this RNG is not suitable for use cases where cryptographic
103+
/// security is required.
100104
pub struct JitterRng {
101105
data: u64, // Actual random number
102106
// Number of rounds to run the entropy collector per 64 bits
@@ -724,6 +728,3 @@ impl RngCore for JitterRng {
724728
Ok(self.fill_bytes(dest))
725729
}
726730
}
727-
728-
impl CryptoRng for JitterRng {}
729-

0 commit comments

Comments
 (0)