Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nstilt1 committed Dec 16, 2023
1 parent df99ca5 commit d0bf4a6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions chacha20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ impl<R: Rounds, V: Variant> ChaChaCore<R, V> {
}

/// Generates 256 bytes of output with backends, then blindly writes them to dest_ptr
///
///
/// # Safety
/// `dest_ptr` must have at least 256 bytes available to be overwritten, or else it
/// `dest_ptr` must have at least 256 bytes available to be overwritten, or else it
/// could produce undefined behavior.
#[cfg(feature = "rand_core")]
unsafe fn generate(&mut self, dest_ptr: *mut u8) {
Expand Down
12 changes: 6 additions & 6 deletions chacha20/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ macro_rules! impl_chacha_rng {
}
}

// Calculate how many bytes we can write full 256-byte chunks to by
// excluding the last 8 bits from `(dest_len - dest_pos)`. Those 8
// Calculate how many bytes we can write full 256-byte chunks to by
// excluding the last 8 bits from `(dest_len - dest_pos)`. Those 8
// bits can amount to only 255 byte indices since it measures length.
let writable_chunk_bytes = (dest_len - dest_pos) & !0xFF;

// Calculate how many 256-byte chunks are available to write to,
// Calculate how many 256-byte chunks are available to write to,
// equivalent to writable_chunk_bytes / 256
let num_chunks = writable_chunk_bytes >> 8;

// SAFETY: This only writes to indices that have not yet been written
// to, and we have determined how many chunks are available to be
// SAFETY: This only writes to indices that have not yet been written
// to, and we have determined how many chunks are available to be
// written to.
unsafe {
let mut chunk_ptr = dest.as_mut_ptr();
Expand Down Expand Up @@ -380,7 +380,7 @@ macro_rules! impl_chacha_rng {
#[inline]
pub fn generate_and_set(&mut self, index: usize) {
assert!(index < self.buffer.as_ref().len());
// SAFETY: `self.buffer.0` is 256 bytes long, allowing `generate()`
// SAFETY: `self.buffer.0` is 256 bytes long, allowing `generate()`
// to be called safely.
unsafe {
self.core.generate(self.buffer.0.as_mut_ptr() as *mut u8);
Expand Down
2 changes: 1 addition & 1 deletion chacha20/src/variants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Distinguishing features of ChaCha variants.
//!
//!
//! To be revisited for the 64-bit counter.

/// A trait that distinguishes some ChaCha variants
Expand Down

0 comments on commit d0bf4a6

Please sign in to comment.