Skip to content

Commit 86adc17

Browse files
committed
rand_chacha: use new rand_core::block::Generator trait
1 parent 2c1edd6 commit 86adc17

File tree

1 file changed

+6
-53
lines changed

1 file changed

+6
-53
lines changed

rand_chacha/src/chacha.rs

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
use crate::guts::ChaCha;
1212
use core::fmt;
13-
use rand_core::block::{BlockRng, BlockRngCore, CryptoBlockRng};
13+
use rand_core::block::{BlockRng, CryptoGenerator, Generator};
1414
use rand_core::{CryptoRng, RngCore, SeedableRng};
1515

1616
#[cfg(feature = "serde")]
@@ -21,52 +21,6 @@ const BUF_BLOCKS: u8 = 4;
2121
// number of 32-bit words per ChaCha block (fixed by algorithm definition)
2222
const BLOCK_WORDS: u8 = 16;
2323

24-
#[repr(transparent)]
25-
pub struct Array64<T>([T; 64]);
26-
impl<T> Default for Array64<T>
27-
where
28-
T: Default,
29-
{
30-
#[rustfmt::skip]
31-
fn default() -> Self {
32-
Self([
33-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
34-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
35-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
36-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
37-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
38-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
39-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
40-
T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(), T::default(),
41-
])
42-
}
43-
}
44-
impl<T> AsRef<[T]> for Array64<T> {
45-
fn as_ref(&self) -> &[T] {
46-
&self.0
47-
}
48-
}
49-
impl<T> AsMut<[T]> for Array64<T> {
50-
fn as_mut(&mut self) -> &mut [T] {
51-
&mut self.0
52-
}
53-
}
54-
impl<T> Clone for Array64<T>
55-
where
56-
T: Copy + Default,
57-
{
58-
fn clone(&self) -> Self {
59-
let mut new = Self::default();
60-
new.0.copy_from_slice(&self.0);
61-
new
62-
}
63-
}
64-
impl<T> fmt::Debug for Array64<T> {
65-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66-
write!(f, "Array64 {{}}")
67-
}
68-
}
69-
7024
macro_rules! chacha_impl {
7125
($ChaChaXCore:ident, $ChaChaXRng:ident, $rounds:expr, $doc:expr, $abst:ident,) => {
7226
#[doc=$doc]
@@ -82,13 +36,12 @@ macro_rules! chacha_impl {
8236
}
8337
}
8438

85-
impl BlockRngCore for $ChaChaXCore {
86-
type Item = u32;
87-
type Results = Array64<u32>;
39+
impl Generator for $ChaChaXCore {
40+
type Output = [u32; 64];
8841

8942
#[inline]
90-
fn generate(&mut self, r: &mut Self::Results) {
91-
self.state.refill4($rounds, &mut r.0);
43+
fn generate(&mut self, output: &mut Self::Output) {
44+
self.state.refill4($rounds, output);
9245
}
9346
}
9447

@@ -103,7 +56,7 @@ macro_rules! chacha_impl {
10356
}
10457
}
10558

106-
impl CryptoBlockRng for $ChaChaXCore {}
59+
impl CryptoGenerator for $ChaChaXCore {}
10760

10861
/// A cryptographically secure random number generator that uses the ChaCha algorithm.
10962
///

0 commit comments

Comments
 (0)