Skip to content

Commit

Permalink
blake2: fix clippy nits
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jul 18, 2021
1 parent 18c740f commit 0586497
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.41.0 # MSRV
toolchain: 1.53.0
components: clippy
profile: minimal
override: true
Expand Down
6 changes: 3 additions & 3 deletions blake2/src/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl Hash {

/// Convert the hash to a lowercase hexadecimal
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
pub fn to_hex(&self) -> HexString {
pub fn to_hex(self) -> HexString {
bytes_to_hex(self.as_bytes())
}
}
Expand All @@ -616,14 +616,14 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
/// This implementation is constant time, if the two hashes are the same length.
impl PartialEq for Hash {
fn eq(&self, other: &Hash) -> bool {
constant_time_eq::constant_time_eq(&self.as_bytes(), &other.as_bytes())
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
}
}

/// This implementation is constant time, if the slice is the same length as the hash.
impl PartialEq<[u8]> for Hash {
fn eq(&self, other: &[u8]) -> bool {
constant_time_eq::constant_time_eq(&self.as_bytes(), other)
constant_time_eq::constant_time_eq(self.as_bytes(), other)
}
}

Expand Down
4 changes: 2 additions & 2 deletions blake2/src/blake2b/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ pub unsafe fn compress4_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
jobs[2].input.as_ptr(),
jobs[3].input.as_ptr(),
];
let mut h_vecs = transpose_state_vecs(&jobs);
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
let mut h_vecs = transpose_state_vecs(jobs);
let (mut counts_lo, mut counts_hi) = load_counts(jobs);

// Prepare the final blocks (note, which could be empty if the input is
// empty). Do all this before entering the main loop.
Expand Down
44 changes: 22 additions & 22 deletions blake2/src/blake2b/guts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ pub const MAX_DEGREE: usize = 4;
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
pub const MAX_DEGREE: usize = 1;

// Variants other than Portable are unreachable in no_std, unless CPU features
// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
// This might change in the future if is_x86_feature_detected moves into libcore.
/// Variants other than Portable are unreachable in no_std, unless CPU features
/// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
/// This might change in the future if is_x86_feature_detected moves into libcore.
#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Platform {
Portable,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
SSE41,
Sse41,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
AVX2,
Avx2,
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -53,13 +53,13 @@ impl Implementation {
// Check whether SSE4.1 support is assumed by the build.
#[cfg(target_feature = "sse4.1")]
{
return Some(Implementation(Platform::SSE41));
return Some(Implementation(Platform::Sse41));
}
// Otherwise dynamically check for support if we can.
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("sse4.1") {
return Some(Implementation(Platform::SSE41));
return Some(Implementation(Platform::Sse41));
}
}
None
Expand All @@ -71,13 +71,13 @@ impl Implementation {
// Check whether AVX2 support is assumed by the build.
#[cfg(target_feature = "avx2")]
{
return Some(Implementation(Platform::AVX2));
return Some(Implementation(Platform::Avx2));
}
// Otherwise dynamically check for support if we can.
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx2") {
return Some(Implementation(Platform::AVX2));
return Some(Implementation(Platform::Avx2));
}
}
None
Expand All @@ -86,9 +86,9 @@ impl Implementation {
pub fn degree(&self) -> usize {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 => avx2::DEGREE,
Platform::Avx2 => avx2::DEGREE,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::SSE41 => sse41::DEGREE,
Platform::Sse41 => sse41::DEGREE,
Platform::Portable => 1,
}
}
Expand All @@ -104,7 +104,7 @@ impl Implementation {
) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 => unsafe {
Platform::Avx2 => unsafe {
avx2::compress1_loop(input, words, count, last_node, finalize, stride);
},
// Note that there's an SSE version of compress1 in the official C
Expand All @@ -118,7 +118,7 @@ impl Implementation {
pub fn compress2_loop(&self, jobs: &mut [Job<'_, '_>; 2], finalize: Finalize, stride: Stride) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 | Platform::SSE41 => unsafe {
Platform::Avx2 | Platform::Sse41 => unsafe {
sse41::compress2_loop(jobs, finalize, stride)
},
_ => panic!("unsupported"),
Expand All @@ -128,7 +128,7 @@ impl Implementation {
pub fn compress4_loop(&self, jobs: &mut [Job<'_, '_>; 4], finalize: Finalize, stride: Stride) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 => unsafe { avx2::compress4_loop(jobs, finalize, stride) },
Platform::Avx2 => unsafe { avx2::compress4_loop(jobs, finalize, stride) },
_ => panic!("unsupported"),
}
}
Expand Down Expand Up @@ -271,20 +271,20 @@ mod test {
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx2") {
assert_eq!(Platform::AVX2, Implementation::detect().0);
assert_eq!(Platform::Avx2, Implementation::detect().0);
assert_eq!(
Platform::AVX2,
Platform::Avx2,
Implementation::avx2_if_supported().unwrap().0
);
assert_eq!(
Platform::SSE41,
Platform::Sse41,
Implementation::sse41_if_supported().unwrap().0
);
} else if is_x86_feature_detected!("sse4.1") {
assert_eq!(Platform::SSE41, Implementation::detect().0);
assert_eq!(Platform::Sse41, Implementation::detect().0);
assert!(Implementation::avx2_if_supported().is_none());
assert_eq!(
Platform::SSE41,
Platform::Sse41,
Implementation::sse41_if_supported().unwrap().0
);
} else {
Expand All @@ -302,9 +302,9 @@ mod test {
{
// Chose counts to hit the relevant overflow cases.
let counts = &[
(0 as Count),
((1 as Count) << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
(0 as Count).wrapping_sub(BLOCKBYTES as Count),
0_u128,
(1_u128 << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
0_u128.wrapping_sub(BLOCKBYTES as Count),
];
for &stride in &[Stride::Serial, Stride::Parallel] {
let lengths = [
Expand Down
4 changes: 2 additions & 2 deletions blake2/src/blake2b/sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ pub unsafe fn compress2_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
}

let msg_ptrs = [jobs[0].input.as_ptr(), jobs[1].input.as_ptr()];
let mut h_vecs = transpose_state_vecs(&jobs);
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
let mut h_vecs = transpose_state_vecs(jobs);
let (mut counts_lo, mut counts_hi) = load_counts(jobs);

// Prepare the final blocks (note, which could be empty if the input is
// empty). Do all this before entering the main loop.
Expand Down
4 changes: 2 additions & 2 deletions blake2/src/blake2bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ fn finalize_root_words(
Stride::Serial,
);
Hash {
bytes: crate::blake2b::state_words_to_bytes(&root_words),
bytes: crate::blake2b::state_words_to_bytes(root_words),
len: hash_length,
}
}
Expand Down Expand Up @@ -537,7 +537,7 @@ pub(crate) mod test {
force_portable(&mut params);
}
let input = &buf[..num_blocks * BLOCKBYTES + extra];
let expected = blake2bp_reference(&input);
let expected = blake2bp_reference(input);
let mut state = params.to_state();
let found = state.update(input).finalize();
assert_eq!(expected, found);
Expand Down
6 changes: 3 additions & 3 deletions blake2/src/blake2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl Hash {

/// Convert the hash to a lowercase hexadecimal
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
pub fn to_hex(&self) -> HexString {
pub fn to_hex(self) -> HexString {
bytes_to_hex(self.as_bytes())
}
}
Expand All @@ -607,14 +607,14 @@ fn bytes_to_hex(bytes: &[u8]) -> HexString {
/// This implementation is constant time, if the two hashes are the same length.
impl PartialEq for Hash {
fn eq(&self, other: &Hash) -> bool {
constant_time_eq::constant_time_eq(&self.as_bytes(), &other.as_bytes())
constant_time_eq::constant_time_eq(self.as_bytes(), other.as_bytes())
}
}

/// This implementation is constant time, if the slice is the same length as the hash.
impl PartialEq<[u8]> for Hash {
fn eq(&self, other: &[u8]) -> bool {
constant_time_eq::constant_time_eq(&self.as_bytes(), other)
constant_time_eq::constant_time_eq(self.as_bytes(), other)
}
}

Expand Down
4 changes: 2 additions & 2 deletions blake2/src/blake2s/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ pub unsafe fn compress8_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
jobs[6].input.as_ptr(),
jobs[7].input.as_ptr(),
];
let mut h_vecs = transpose_state_vecs(&jobs);
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
let mut h_vecs = transpose_state_vecs(jobs);
let (mut counts_lo, mut counts_hi) = load_counts(jobs);

// Prepare the final blocks (note, which could be empty if the input is
// empty). Do all this before entering the main loop.
Expand Down
44 changes: 22 additions & 22 deletions blake2/src/blake2s/guts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ pub const MAX_DEGREE: usize = 8;
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
pub const MAX_DEGREE: usize = 1;

// Variants other than Portable are unreachable in no_std, unless CPU features
// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
// This might change in the future if is_x86_feature_detected moves into libcore.
/// Variants other than Portable are unreachable in no_std, unless CPU features
/// are explicitly enabled for the build with e.g. RUSTFLAGS="-C target-feature=avx2".
/// This might change in the future if is_x86_feature_detected moves into libcore.
#[allow(dead_code)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum Platform {
Portable,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
SSE41,
Sse41,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
AVX2,
Avx2,
}

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -53,13 +53,13 @@ impl Implementation {
// Check whether SSE4.1 support is assumed by the build.
#[cfg(target_feature = "sse4.1")]
{
return Some(Implementation(Platform::SSE41));
return Some(Implementation(Platform::Sse41));
}
// Otherwise dynamically check for support if we can.
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("sse4.1") {
return Some(Implementation(Platform::SSE41));
return Some(Implementation(Platform::Sse41));
}
}
None
Expand All @@ -71,13 +71,13 @@ impl Implementation {
// Check whether AVX2 support is assumed by the build.
#[cfg(target_feature = "avx2")]
{
return Some(Implementation(Platform::AVX2));
return Some(Implementation(Platform::Avx2));
}
// Otherwise dynamically check for support if we can.
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx2") {
return Some(Implementation(Platform::AVX2));
return Some(Implementation(Platform::Avx2));
}
}
None
Expand All @@ -86,9 +86,9 @@ impl Implementation {
pub fn degree(&self) -> usize {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 => avx2::DEGREE,
Platform::Avx2 => avx2::DEGREE,
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::SSE41 => sse41::DEGREE,
Platform::Sse41 => sse41::DEGREE,
Platform::Portable => 1,
}
}
Expand All @@ -104,7 +104,7 @@ impl Implementation {
) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 | Platform::SSE41 => unsafe {
Platform::Avx2 | Platform::Sse41 => unsafe {
sse41::compress1_loop(input, words, count, last_node, finalize, stride);
},
Platform::Portable => {
Expand All @@ -116,7 +116,7 @@ impl Implementation {
pub fn compress4_loop(&self, jobs: &mut [Job<'_, '_>; 4], finalize: Finalize, stride: Stride) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 | Platform::SSE41 => unsafe {
Platform::Avx2 | Platform::Sse41 => unsafe {
sse41::compress4_loop(jobs, finalize, stride)
},
_ => panic!("unsupported"),
Expand All @@ -126,7 +126,7 @@ impl Implementation {
pub fn compress8_loop(&self, jobs: &mut [Job<'_, '_>; 8], finalize: Finalize, stride: Stride) {
match self.0 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
Platform::AVX2 => unsafe { avx2::compress8_loop(jobs, finalize, stride) },
Platform::Avx2 => unsafe { avx2::compress8_loop(jobs, finalize, stride) },
_ => panic!("unsupported"),
}
}
Expand Down Expand Up @@ -269,20 +269,20 @@ mod test {
#[cfg(feature = "std")]
{
if is_x86_feature_detected!("avx2") {
assert_eq!(Platform::AVX2, Implementation::detect().0);
assert_eq!(Platform::Avx2, Implementation::detect().0);
assert_eq!(
Platform::AVX2,
Platform::Avx2,
Implementation::avx2_if_supported().unwrap().0
);
assert_eq!(
Platform::SSE41,
Platform::Sse41,
Implementation::sse41_if_supported().unwrap().0
);
} else if is_x86_feature_detected!("sse4.1") {
assert_eq!(Platform::SSE41, Implementation::detect().0);
assert_eq!(Platform::Sse41, Implementation::detect().0);
assert!(Implementation::avx2_if_supported().is_none());
assert_eq!(
Platform::SSE41,
Platform::Sse41,
Implementation::sse41_if_supported().unwrap().0
);
} else {
Expand All @@ -299,9 +299,9 @@ mod test {
{
// Chose counts to hit the relevant overflow cases.
let counts = &[
(0 as Count),
((1 as Count) << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
(0 as Count).wrapping_sub(BLOCKBYTES as Count),
0_u64,
(1_u64 << (8 * size_of::<Word>())) - BLOCKBYTES as Count,
0_u64.wrapping_sub(BLOCKBYTES as Count),
];
for &stride in &[Stride::Serial, Stride::Parallel] {
let lengths = [
Expand Down
4 changes: 2 additions & 2 deletions blake2/src/blake2s/sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ pub unsafe fn compress4_loop(jobs: &mut [Job<'_, '_>; DEGREE], finalize: Finaliz
jobs[2].input.as_ptr(),
jobs[3].input.as_ptr(),
];
let mut h_vecs = transpose_state_vecs(&jobs);
let (mut counts_lo, mut counts_hi) = load_counts(&jobs);
let mut h_vecs = transpose_state_vecs(jobs);
let (mut counts_lo, mut counts_hi) = load_counts(jobs);

// Prepare the final blocks (note, which could be empty if the input is
// empty). Do all this before entering the main loop.
Expand Down
Loading

0 comments on commit 0586497

Please sign in to comment.