hashes: conservative upgrade to workspace lints
What changed, and why it matters
This commit is a code-quality and linting cleanup for the `hashes` crate in rust-bitcoin. It moves the crate to use shared workspace lint rules, adds clippy allow attributes, fixes minor style issues (semicolons, doc formatting, import lists), and adds documentation comments. There are no functional changes to hash algorithms or public APIs, and no security bug is introduced or fixed.
No security action required. Treat as a normal maintenance/linting commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch upgrades hashes/Cargo.toml to inherit lints from the workspace ([lints] workspace = true) and adds cfg(hashes_fuzz) to the workspace-level unexpected_cfgs check-cfg list. Source changes are purely cosmetic: adding #![allow(clippy::...)] attributes, expanding wildcard imports to explicit lists, adding missing semicolons, converting as *mut u8 to .cast::<u8>(), replacing manual panic branches with assert!, and adding # Panics/# Errors doc sections. No cryptographic logic, bounds checks, or public interfaces were altered.
Changed components
hashes/Cargo.tomlhashes/src/cmp.rshashes/src/hkdf/mod.rshashes/src/hmac/mod.rshashes/src/lib.rshashes/src/macros.rshashes/src/muhash/mod.rshashes/src/ripemd160/crypto.rshashes/src/ripemd160/mod.rshashes/src/sha1/crypto.rshashes/src/sha1/mod.rshashes/src/sha256/crypto.rshashes/src/sha256/mod.rshashes/src/sha256/tests.rshashes/src/sha256d/mod.rshashes/src/sha256t/mod.rshashes/src/sha3_256/mod.rshashes/src/sha512/crypto.rshashes/src/sha512/mod.rshashes/src/sha512_256/mod.rshashes/src/siphash24/mod.rsInspect captured patch +130 / −73
diff --git a/Cargo.toml b/Cargo.toml
index 35fc0214..c8b7f779 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,7 +4,7 @@ exclude = ["benches"]
resolver = "2"
[workspace.lints.rust]
-unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(fuzzing)', 'cfg(kani)'] }
+unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(fuzzing)', 'cfg(hashes_fuzz)', 'cfg(kani)'] }
[workspace.lints.clippy]
# Exclude lints we don't think are valuable.
diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml
index 92bc7330..2b34276c 100644
--- a/hashes/Cargo.toml
+++ b/hashes/Cargo.toml
@@ -40,9 +40,5 @@ serde_test = "1.0.19"
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
-[lints.rust]
-unexpected_cfgs = { level = "deny", check-cfg = ['cfg(hashes_fuzz)'] }
-
-[lints.clippy]
-redundant_clone = "warn"
-use_self = "warn"
+[lints]
+workspace = true
diff --git a/hashes/src/cmp.rs b/hashes/src/cmp.rs
index 3eeded7a..90d6c3c5 100644
--- a/hashes/src/cmp.rs
+++ b/hashes/src/cmp.rs
@@ -14,6 +14,10 @@
///
/// As of rust 1.31.0 disassembly looks completely within reason for this, see
/// <https://godbolt.org/z/mMbGQv>.
+///
+/// # Panics
+///
+/// Panics if the slices have different lengths.
pub fn fixed_time_eq(a: &[u8], b: &[u8]) -> bool {
#[cfg(hashes_fuzz)]
{
@@ -66,6 +70,7 @@ mod tests {
use super::*;
#[test]
+ #[allow(clippy::unreadable_literal)]
fn eq_test() {
assert!(fixed_time_eq(&[0b00000000], &[0b00000000]));
assert!(fixed_time_eq(&[0b00000001], &[0b00000001]));
diff --git a/hashes/src/hkdf/mod.rs b/hashes/src/hkdf/mod.rs
index c7681788..36f17d3e 100644
--- a/hashes/src/hkdf/mod.rs
+++ b/hashes/src/hkdf/mod.rs
@@ -67,6 +67,11 @@ where
///
/// Expand may be called multiple times to derive multiple keys,
/// but the info must be independent from the ikm for security.
+ ///
+ /// # Errors
+ ///
+ /// Returns [`MaxLengthError`] if the requested output length exceeds the maximum allowed
+ /// (255 * hash output length).
pub fn expand(&self, info: &[u8], okm: &mut [u8]) -> Result<(), MaxLengthError> {
// Length of output keying material in bytes must be less than 255 * hash length.
if okm.len() > (MAX_OUTPUT_BLOCKS * T::Bytes::LEN) {
@@ -112,6 +117,11 @@ where
///
/// Expand may be called multiple times to derive multiple keys,
/// but the info must be independent from the ikm for security.
+ ///
+ /// # Errors
+ ///
+ /// Returns [`MaxLengthError`] if the requested output length exceeds the maximum allowed
+ /// (255 * hash output length).
#[cfg(feature = "alloc")]
pub fn expand_to_len(&self, info: &[u8], len: usize) -> Result<Vec<u8>, MaxLengthError> {
let mut okm = vec![0u8; len];
diff --git a/hashes/src/hmac/mod.rs b/hashes/src/hmac/mod.rs
index af7a09ac..1745d466 100644
--- a/hashes/src/hmac/mod.rs
+++ b/hashes/src/hmac/mod.rs
@@ -171,6 +171,7 @@ crate::internal_macros::impl_write!(
#[cfg(test)]
mod tests {
#[test]
+ #[allow(clippy::too_many_lines)]
fn test() {
use crate::{sha256, Hash as _, HashEngine, HmacEngine};
diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs
index 5673adea..24aa8da7 100644
--- a/hashes/src/lib.rs
+++ b/hashes/src/lib.rs
@@ -88,7 +88,7 @@ pub extern crate hex_unstable;
#[doc(hidden)]
pub mod _export {
- /// A re-export of core::*
+ /// A re-export of `core::*`
pub mod _core {
pub use core::*;
}
@@ -128,7 +128,7 @@ pub use self::{
/// HASH-160: Alias for the [`hash160::Hash`] hash type.
#[doc(inline)]
pub use hash160::Hash as Hash160;
-/// MuHash3072: Alias for the [`muhash::Hash`] hash type.
+/// `MuHash3072`: Alias for the [`muhash::Hash`] hash type.
#[doc(inline)]
pub use muhash::Hash as MuHash;
/// RIPEMD-160: Alias for the [`ripemd160::Hash`] hash type.
@@ -268,7 +268,7 @@ mod sealed {
pub(crate) fn non_secure_erase<T: ?Sized>(val: &mut T) {
use core::sync::atomic;
- let ptr = val as *mut T as *mut u8;
+ let ptr = (val as *mut T).cast::<u8>();
let len = core::mem::size_of_val(val);
for i in 0..len {
unsafe { core::ptr::write_volatile(ptr.add(i), 0) };
@@ -287,6 +287,10 @@ fn incomplete_block_len<H: HashEngine>(eng: &H) -> usize {
///
/// For when we cannot rely on having the `hex` feature enabled. Ignores formatter options and just
/// writes with plain old `f.write_char()`.
+///
+/// # Errors
+///
+/// Returns an error if writing to the formatter fails.
pub fn debug_hex<'a>(
bytes: impl IntoIterator<Item = &'a u8>,
f: &mut fmt::Formatter,
@@ -295,7 +299,7 @@ pub fn debug_hex<'a>(
for &b in bytes {
let lower = HEX_TABLE[usize::from(b >> 4)];
- let upper = HEX_TABLE[usize::from(b & 0b00001111)];
+ let upper = HEX_TABLE[usize::from(b & 0b0000_1111)];
f.write_char(char::from(lower))?;
f.write_char(char::from(upper))?;
}
@@ -336,6 +340,6 @@ mod tests {
let orig = DUMMY;
let hex = format!("{}", orig);
let roundtrip = hex.parse::<TestNewtype>().expect("failed to parse hex");
- assert_eq!(roundtrip, orig)
+ assert_eq!(roundtrip, orig);
}
}
diff --git a/hashes/src/macros.rs b/hashes/src/macros.rs
index d3e34a15..78e1718d 100644
--- a/hashes/src/macros.rs
+++ b/hashes/src/macros.rs
@@ -25,7 +25,7 @@
/// The `hash_str` marker says the midstate should be generated by hashing the supplied string in a
/// way described in BIP-0341. Alternatively, you can supply `hash_bytes` to hash raw bytes. If you
/// have the midstate already pre-computed and prefer **compiler** performance to readability you
-/// may use `raw(MIDSTATE_BYTES, HASHED_BYTES_LENGTH)` instead, note that HASHED_BYTES_LENGTH must
+/// may use `raw(MIDSTATE_BYTES, HASHED_BYTES_LENGTH)` instead, note that `HASHED_BYTES_LENGTH` must
/// be a multiple of 64.
#[macro_export]
macro_rules! sha256t_tag {
@@ -649,7 +649,7 @@ mod test {
let want = "0000000000000000000000000000000000000000000000000000000000000000";
let got = format!("{}", TestHash::all_zeros());
- assert_eq!(got, want)
+ assert_eq!(got, want);
}
#[test]
@@ -660,7 +660,7 @@ mod test {
let want = "0x0000000000000000000000000000000000000000000000000000000000000000";
let got = format!("{:#}", TestHash::all_zeros());
- assert_eq!(got, want)
+ assert_eq!(got, want);
}
#[test]
@@ -671,7 +671,7 @@ mod test {
let want = "0000000000000000000000000000000000000000000000000000000000000000";
let got = format!("{:x}", TestHash::all_zeros());
- assert_eq!(got, want)
+ assert_eq!(got, want);
}
#[test]
@@ -682,7 +682,7 @@ mod test {
let want = "0x0000000000000000000000000000000000000000000000000000000000000000";
let got = format!("{:#x}", TestHash::all_zeros());
- assert_eq!(got, want)
+ assert_eq!(got, want);
}
#[test]
diff --git a/hashes/src/muhash/mod.rs b/hashes/src/muhash/mod.rs
index 531e3cc0..a8ebc3ba 100644
--- a/hashes/src/muhash/mod.rs
+++ b/hashes/src/muhash/mod.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
-//! MuHash3072 implementation.
+//! `MuHash3072` implementation.
//!
//! Unlike other hash algorithms in this crate, [`MuHash`] is a wrapper type that provides
//! semantic meaning to a plain byte array. It cannot be computed by this crate.
diff --git a/hashes/src/ripemd160/crypto.rs b/hashes/src/ripemd160/crypto.rs
index a538d428..d9e6ffe8 100644
--- a/hashes/src/ripemd160/crypto.rs
+++ b/hashes/src/ripemd160/crypto.rs
@@ -1,5 +1,9 @@
// SPDX-License-Identifier: CC0-1.0
+#![allow(clippy::unreadable_literal)]
+#![allow(clippy::too_many_lines)]
+#![allow(clippy::many_single_char_names)]
+
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
@@ -137,7 +141,7 @@ impl HashEngine {
for block in blocks.chunks_exact(BLOCK_SIZE) {
let mut w = [0u32; 16];
for (w_val, buff_bytes) in w.iter_mut().zip(block.bitcoin_as_chunks().0) {
- *w_val = u32::from_le_bytes(*buff_bytes)
+ *w_val = u32::from_le_bytes(*buff_bytes);
}
process_block!(*state, w,
diff --git a/hashes/src/ripemd160/mod.rs b/hashes/src/ripemd160/mod.rs
index d3f855ae..018a1297 100644
--- a/hashes/src/ripemd160/mod.rs
+++ b/hashes/src/ripemd160/mod.rs
@@ -2,6 +2,8 @@
//! RIPEMD160 implementation.
+#![allow(clippy::unreadable_literal)]
+
use internals::slice::SliceExt;
mod crypto;
#[cfg(test)]
diff --git a/hashes/src/sha1/crypto.rs b/hashes/src/sha1/crypto.rs
index 596de124..8e95c48b 100644
--- a/hashes/src/sha1/crypto.rs
+++ b/hashes/src/sha1/crypto.rs
@@ -1,5 +1,8 @@
// SPDX-License-Identifier: CC0-1.0
+#![allow(clippy::unreadable_literal)]
+#![allow(clippy::many_single_char_names)]
+
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
@@ -12,7 +15,7 @@ impl HashEngine {
for block in blocks.chunks_exact(BLOCK_SIZE) {
let mut w = [0u32; 80];
for (w_val, buff_bytes) in w.iter_mut().zip(block.bitcoin_as_chunks().0) {
- *w_val = u32::from_be_bytes(*buff_bytes)
+ *w_val = u32::from_be_bytes(*buff_bytes);
}
for i in 16..80 {
w[i] = (w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]).rotate_left(1);
diff --git a/hashes/src/sha1/mod.rs b/hashes/src/sha1/mod.rs
index 13c8b1bc..ebb4ded6 100644
--- a/hashes/src/sha1/mod.rs
+++ b/hashes/src/sha1/mod.rs
@@ -2,6 +2,8 @@
//! SHA1 implementation.
+#![allow(clippy::unreadable_literal)]
+
use internals::slice::SliceExt;
mod crypto;
#[cfg(test)]
diff --git a/hashes/src/sha256/crypto.rs b/hashes/src/sha256/crypto.rs
index a6b225f2..65458adb 100644
--- a/hashes/src/sha256/crypto.rs
+++ b/hashes/src/sha256/crypto.rs
@@ -1,11 +1,23 @@
// SPDX-License-Identifier: CC0-1.0
+#![allow(clippy::unreadable_literal)]
+#![allow(clippy::cast_ptr_alignment)]
+#![allow(clippy::too_many_lines)]
+#![allow(clippy::many_single_char_names)]
+
#[cfg(all(target_arch = "aarch64", any(feature = "std", feature = "cpufeatures")))]
-use core::arch::aarch64::*;
+use core::arch::aarch64::{
+ vaddq_u32, vld1q_u32, vreinterpretq_u32_u8, vreinterpretq_u8_u32, vrev32q_u8,
+ vsha256h2q_u32, vsha256hq_u32, vsha256su0q_u32, vsha256su1q_u32, vst1q_u32,
+};
#[cfg(all(target_arch = "x86", any(feature = "std", feature = "cpufeatures")))]
-use core::arch::x86::*;
+use core::arch::x86::{
+ __m128i, _mm_add_epi32, _mm_alignr_epi8, _mm_blend_epi16, _mm_loadu_si128, _mm_set_epi64x,
+ _mm_sha256msg1_epu32, _mm_sha256msg2_epu32, _mm_sha256rnds2_epu32, _mm_shuffle_epi32,
+ _mm_shuffle_epi8, _mm_storeu_si128,
+};
#[cfg(all(target_arch = "x86_64", any(feature = "std", feature = "cpufeatures")))]
-use core::arch::x86_64::*;
+use core::arch::x86_64::{__m128i, _mm_set_epi64x, _mm_loadu_si128, _mm_shuffle_epi32, _mm_alignr_epi8, _mm_blend_epi16, _mm_shuffle_epi8, _mm_add_epi32, _mm_sha256rnds2_epu32, _mm_sha256msg1_epu32, _mm_sha256msg2_epu32, _mm_storeu_si128};
use internals::slice::SliceExt;
@@ -42,7 +54,7 @@ const fn sigma1(x: u32) -> u32 { x.rotate_left(15) ^ x.rotate_left(13) ^ (x >> 1
#[cfg(feature = "small-hash")]
#[macro_use]
mod small_hash {
- use super::*;
+ use super::{Sigma1, Ch, Sigma0, Maj, sigma1, sigma0};
#[rustfmt::skip]
#[allow(clippy::too_many_arguments)]
@@ -315,7 +327,7 @@ impl HashEngine {
}
// fallback implementation without using any intrinsics
- Self::software_process_block(state, blocks)
+ Self::software_process_block(state, blocks);
}
#[cfg(all(
diff --git a/hashes/src/sha256/mod.rs b/hashes/src/sha256/mod.rs
index 66cd1661..6d4fd262 100644
--- a/hashes/src/sha256/mod.rs
+++ b/hashes/src/sha256/mod.rs
@@ -2,6 +2,8 @@
//! SHA256 implementation.
+#![allow(clippy::unreadable_literal)]
+
mod crypto;
#[cfg(test)]
mod tests;
@@ -114,6 +116,10 @@ impl HashEngine {
/// Outputs the midstate of the hash engine.
///
/// Please see docs on [`Midstate`] before using this function.
+ ///
+ /// # Errors
+ ///
+ /// Returns [`MidstateError`] if the number of bytes hashed is not a multiple of 64.
pub fn midstate(&self) -> Result<Midstate, MidstateError> {
if !self.can_extract_midstate() {
let unprocessed_len = (self.bytes_hashed % BLOCK_SIZE as u64) as usize;
@@ -202,9 +208,7 @@ impl Midstate {
/// Panics if `bytes_hashed` is not a multiple of 64.
#[track_caller]
pub const fn new(state: [u8; 32], bytes_hashed: u64) -> Self {
- if bytes_hashed % 64 != 0 {
- panic!("bytes hashed is not a multiple of 64");
- }
+ assert!(bytes_hashed % 64 == 0, "bytes hashed is not a multiple of 64");
Self { bytes: state, bytes_hashed }
}
diff --git a/hashes/src/sha256/tests.rs b/hashes/src/sha256/tests.rs
index 09db17df..e73d6dda 100644
--- a/hashes/src/sha256/tests.rs
+++ b/hashes/src/sha256/tests.rs
@@ -78,12 +78,20 @@ fn fmt_roundtrips() {
let hash = sha256::Hash::hash(b"some arbitrary bytes");
let hex = format!("{}", hash);
let roundtrip = hex.parse::<sha256::Hash>().expect("failed to parse hex");
- assert_eq!(roundtrip, hash)
+ assert_eq!(roundtrip, hash);
}
#[test]
#[rustfmt::skip]
fn midstate() {
+ // RPC output
+ static WANT: Midstate = sha256::Midstate::new([
+ 0x0b, 0xcf, 0xe0, 0xe5, 0x4e, 0x6c, 0xc7, 0xd3,
+ 0x4f, 0x4f, 0x7c, 0x1d, 0xf0, 0xb0, 0xf5, 0x03,
+ 0xf2, 0xf7, 0x12, 0x91, 0x2a, 0x06, 0x05, 0xb4,
+ 0x14, 0xed, 0x33, 0x7f, 0x7f, 0x03, 0x2e, 0x03,
+ ], 64);
+
// Test vector obtained by doing an asset issuance on Elements
let mut engine = sha256::Hash::engine();
// sha256dhash of outpoint
@@ -97,14 +105,6 @@ fn midstate() {
// 32 bytes of zeroes representing "new asset"
engine.input(&[0; 32]);
- // RPC output
- static WANT: Midstate = sha256::Midstate::new([
- 0x0b, 0xcf, 0xe0, 0xe5, 0x4e, 0x6c, 0xc7, 0xd3,
- 0x4f, 0x4f, 0x7c, 0x1d, 0xf0, 0xb0, 0xf5, 0x03,
- 0xf2, 0xf7, 0x12, 0x91, 0x2a, 0x06, 0x05, 0xb4,
- 0x14, 0xed, 0x33, 0x7f, 0x7f, 0x03, 0x2e, 0x03,
- ], 64);
-
assert_eq!(
engine.midstate().expect("total_bytes_hashed is valid"),
WANT,
@@ -113,6 +113,24 @@ fn midstate() {
#[test]
fn engine_with_state() {
+ // Test that a specific midstate results in a specific hash. Midstate was
+ // obtained by applying sha256 to sha256("MuSig coefficient")||sha256("MuSig
+ // coefficient").
+ #[rustfmt::skip]
+ static MIDSTATE: [u8; 32] = [
+ 0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97,
+ 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, 0xd8, 0x64,
+ 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f,
+ 0x6f, 0x43, 0xb8, 0x01, 0x85, 0xce, 0x27, 0xcd,
+ ];
+ #[rustfmt::skip]
+ static HASH_EXPECTED: [u8; 32] = [
+ 0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a,
+ 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, 0x23, 0xa8,
+ 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20,
+ 0x8f, 0xf1, 0xf7, 0xa9, 0xd5, 0x69, 0x09, 0x59,
+ ];
+
let mut engine = sha256::Hash::engine();
let midstate_engine = sha256::HashEngine::from_midstate(engine.midstate_unchecked());
// Fresh engine and engine initialized with fresh state should have same state
@@ -140,23 +158,6 @@ fn engine_with_state() {
assert_eq!(hash1, hash2);
}
- // Test that a specific midstate results in a specific hash. Midstate was
- // obtained by applying sha256 to sha256("MuSig coefficient")||sha256("MuSig
- // coefficient").
- #[rustfmt::skip]
- static MIDSTATE: [u8; 32] = [
- 0x0f, 0xd0, 0x69, 0x0c, 0xfe, 0xfe, 0xae, 0x97,
- 0x99, 0x6e, 0xac, 0x7f, 0x5c, 0x30, 0xd8, 0x64,
- 0x8c, 0x4a, 0x05, 0x73, 0xac, 0xa1, 0xa2, 0x2f,
- 0x6f, 0x43, 0xb8, 0x01, 0x85, 0xce, 0x27, 0xcd,
- ];
- #[rustfmt::skip]
- static HASH_EXPECTED: [u8; 32] = [
- 0x18, 0x84, 0xe4, 0x72, 0x40, 0x4e, 0xf4, 0x5a,
- 0xb4, 0x9c, 0x4e, 0xa4, 0x9a, 0xe6, 0x23, 0xa8,
- 0x88, 0x52, 0x7f, 0x7d, 0x8a, 0x06, 0x94, 0x20,
- 0x8f, 0xf1, 0xf7, 0xa9, 0xd5, 0x69, 0x09, 0x59,
- ];
let midstate_engine = sha256::HashEngine::from_midstate(sha256::Midstate::new(MIDSTATE, 64));
let hash = sha256::Hash::from_engine(midstate_engine);
assert_eq!(hash, sha256::Hash(HASH_EXPECTED));
diff --git a/hashes/src/sha256d/mod.rs b/hashes/src/sha256d/mod.rs
index f9649771..4a174106 100644
--- a/hashes/src/sha256d/mod.rs
+++ b/hashes/src/sha256d/mod.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
-//! SHA256d implementation (double SHA256).
+//! `SHA256d` implementation (double SHA256).
use crate::sha256;
@@ -22,12 +22,12 @@ impl Hash {
}
}
-/// Engine to compute SHA256d hash function.
+/// Engine to compute `SHA256d` hash function.
#[derive(Debug, Clone)]
pub struct HashEngine(sha256::HashEngine);
impl HashEngine {
- /// Constructs a new SHA256d hash engine.
+ /// Constructs a new `SHA256d` hash engine.
pub const fn new() -> Self { Self(sha256::HashEngine::new()) }
}
@@ -113,7 +113,7 @@ mod tests {
let hash = sha256d::Hash::hash(b"some arbitrary bytes");
let hex = format!("{}", hash);
let roundtrip = hex.parse::<sha256d::Hash>().expect("failed to parse hex");
- assert_eq!(roundtrip, hash)
+ assert_eq!(roundtrip, hash);
}
#[test]
diff --git a/hashes/src/sha256t/mod.rs b/hashes/src/sha256t/mod.rs
index f49f83b8..39df5a5b 100644
--- a/hashes/src/sha256t/mod.rs
+++ b/hashes/src/sha256t/mod.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
-//! SHA256t implementation (tagged SHA256).
+//! `SHA256t` implementation (tagged SHA256).
use core::cmp;
use core::marker::PhantomData;
@@ -37,7 +37,7 @@ where
engine.finalize()
}
-/// Trait representing a tag that can be used as a context for SHA256t hashes.
+/// Trait representing a tag that can be used as a context for `SHA256t` hashes.
pub trait Tag {
/// The [`Midstate`] after pre-tagging the hash engine.
const MIDSTATE: sha256::Midstate;
@@ -127,7 +127,7 @@ impl<T: Tag> core::hash::Hash for Hash<T> {
crate::internal_macros::hash_trait_impls!(256, false, T: Tag);
-/// Engine to compute SHA256t hash function.
+/// Engine to compute `SHA256t` hash function.
#[derive(Debug)]
pub struct HashEngine<T>(sha256::HashEngine, PhantomData<T>);
diff --git a/hashes/src/sha3_256/mod.rs b/hashes/src/sha3_256/mod.rs
index 7edbd0a5..687513fc 100644
--- a/hashes/src/sha3_256/mod.rs
+++ b/hashes/src/sha3_256/mod.rs
@@ -1,5 +1,11 @@
// SPDX-License-Identifier: CC0-1.0
+#![allow(clippy::unreadable_literal)]
+#![allow(clippy::inline_always)]
+#![allow(clippy::too_many_lines)]
+#![allow(clippy::many_single_char_names)]
+#![allow(clippy::cast_ptr_alignment)]
+
//! SHA3-256 from the family of hashes based on the Keccak permutation function.
// The Keccak permutation function is defined by five functions and a state array of N-bits,
diff --git a/hashes/src/sha512/crypto.rs b/hashes/src/sha512/crypto.rs
index 060da4fd..821b74cf 100644
--- a/hashes/src/sha512/crypto.rs
+++ b/hashes/src/sha512/crypto.rs
@@ -1,5 +1,9 @@
// SPDX-License-Identifier: CC0-1.0
+#![allow(clippy::unreadable_literal)]
+#![allow(clippy::too_many_lines)]
+#![allow(clippy::many_single_char_names)]
+
use internals::slice::SliceExt;
use super::{HashEngine, BLOCK_SIZE};
@@ -18,7 +22,7 @@ fn sigma1(x: u64) -> u64 { x.rotate_left(45) ^ x.rotate_left(3) ^ (x >> 6) }
#[cfg(feature = "small-hash")]
#[macro_use]
mod small_hash {
- use super::*;
+ use super::{Sigma1, Ch, Sigma0, Maj, sigma1, sigma0};
#[rustfmt::skip]
#[allow(clippy::too_many_arguments)]
diff --git a/hashes/src/sha512/mod.rs b/hashes/src/sha512/mod.rs
index 0e70c405..5f5a02ba 100644
--- a/hashes/src/sha512/mod.rs
+++ b/hashes/src/sha512/mod.rs
@@ -2,6 +2,8 @@
//! SHA512 implementation.
+#![allow(clippy::unreadable_literal)]
+
use internals::slice::SliceExt;
mod crypto;
diff --git a/hashes/src/sha512_256/mod.rs b/hashes/src/sha512_256/mod.rs
index 1efe00ac..a3b8071d 100644
--- a/hashes/src/sha512_256/mod.rs
+++ b/hashes/src/sha512_256/mod.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0
-//! SHA512_256 implementation.
+//! `SHA512_256` implementation.
//!
//! SHA512/256 is a hash function that uses the sha512 algorithm but it truncates the output to 256
//! bits. It has different initial constants than sha512 so it produces an entirely different hash
diff --git a/hashes/src/siphash24/mod.rs b/hashes/src/siphash24/mod.rs
index b03362c1..a551ff3e 100644
--- a/hashes/src/siphash24/mod.rs
+++ b/hashes/src/siphash24/mod.rs
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: CC0-1.0
-//! SipHash 2-4 implementation.
+//! `SipHash` 2-4 implementation.
+
+#![allow(clippy::unreadable_literal)]
use core::{cmp, mem};
@@ -51,7 +53,7 @@ macro_rules! load_int_le {
}
impl Hash {
- /// Constructs a new SipHash24 engine with keys.
+ /// Constructs a new `SipHash24` engine with keys.
pub fn engine(k0: u64, k1: u64) -> HashEngine { HashEngine::with_keys(k0, k1) }
/// Produces a hash from the current state of a given engine.
@@ -115,7 +117,7 @@ pub struct State {
v3: u64,
}
-/// Engine to compute the SipHash24 hash function.
+/// Engine to compute the `SipHash24` hash function.
#[derive(Debug, Clone)]
pub struct HashEngine {
k0: u64,
@@ -127,7 +129,7 @@ pub struct HashEngine {
}
impl HashEngine {
- /// Constructs a new SipHash24 engine with keys.
+ /// Constructs a new `SipHash24` engine with keys.
#[inline]
pub const fn with_keys(k0: u64, k1: u64) -> Self {
Self {
@@ -182,12 +184,11 @@ impl crate::HashEngine for HashEngine {
if bytes_hashed < needed {
self.ntail += bytes_hashed;
return;
- } else {
- self.state.v3 ^= self.tail;
- Self::c_rounds(&mut self.state);
- self.state.v0 ^= self.tail;
- self.ntail = 0;
}
+ self.state.v3 ^= self.tail;
+ Self::c_rounds(&mut self.state);
+ self.state.v0 ^= self.tail;
+ self.ntail = 0;
}
// Buffered tail is now flushed, process new input.
@@ -228,7 +229,7 @@ unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
}
if i + 1 < len {
out |= u64::from(load_int_le!(buf, start + i, u16)) << (i * 8);
- i += 2
+ i += 2;
}
if i < len {
out |= u64::from(*buf.get_unchecked(start + i)) << (i * 8);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.