Skip to content

Commit 963be0c

Browse files
committed
Implement CryptoRng for ReseedingRng
1 parent 475ee56 commit 963be0c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

rand-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub trait BlockRngCore<T>: Sized {
203203
///
204204
/// Note also that use of a `CryptoRng` does not protect against other
205205
/// weaknesses such as seeding from a weak entropy source or leaking state.
206-
pub trait CryptoRng: RngCore {}
206+
pub trait CryptoRng {}
207207

208208
/// A random number generator that can be explicitly seeded.
209209
///

src/prng/chacha.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ impl SeedableRng for ChaChaCore {
286286
}
287287
}
288288

289+
impl CryptoRng for ChaChaCore {}
290+
289291
#[cfg(test)]
290292
mod test {
291293
use {RngCore, SeedableRng};

src/prng/hc128.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ impl SeedableRng for Hc128Rng {
9696
}
9797
}
9898

99+
impl CryptoRng for Hc128Rng {}
100+
99101
#[derive(Clone)]
100102
pub struct Hc128Core {
101103
t: [u32; 1024],
@@ -309,8 +311,6 @@ impl Hc128Core {
309311
}
310312
}
311313

312-
impl CryptoRng for Hc128Rng {}
313-
314314
impl SeedableRng for Hc128Core {
315315
type Seed = [u8; SEED_WORDS*4];
316316

@@ -324,6 +324,8 @@ impl SeedableRng for Hc128Core {
324324
}
325325
}
326326

327+
impl CryptoRng for Hc128Core {}
328+
327329
#[cfg(test)]
328330
mod test {
329331
use {RngCore, SeedableRng};

src/reseeding.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! A wrapper around another PRNG that reseeds it after it
1212
//! generates a certain number of random bytes.
1313
14-
use rand_core::{RngCore, BlockRngCore, SeedableRng, Error, ErrorKind};
14+
use rand_core::{RngCore, BlockRngCore, CryptoRng, SeedableRng, Error, ErrorKind};
1515
use rand_core::impls::BlockRng;
1616

1717
/// A wrapper around any PRNG which reseeds the underlying PRNG after it has
@@ -117,6 +117,10 @@ impl<R: BlockRngCore<u32> + SeedableRng, Rsdr: RngCore> RngCore for ReseedingRng
117117
}
118118
}
119119

120+
impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
121+
where R: BlockRngCore<u32> + SeedableRng + CryptoRng,
122+
Rsdr: RngCore + CryptoRng {}
123+
120124
#[derive(Debug)]
121125
struct ReseedingCore<R, Rsdr> {
122126
inner: R,
@@ -197,6 +201,10 @@ where R: BlockRngCore<u32> + SeedableRng,
197201
}
198202
}
199203

204+
impl<R, Rsdr> CryptoRng for ReseedingCore<R, Rsdr>
205+
where R: BlockRngCore<u32> + SeedableRng + CryptoRng,
206+
Rsdr: RngCore + CryptoRng {}
207+
200208
#[cfg(test)]
201209
mod test {
202210
use {Rng, SeedableRng};

0 commit comments

Comments
 (0)