From 6f6894b73e5268b1c4ac3ca5e5f971c31f8b1e09 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Tue, 21 Apr 2026 15:30:36 -0600 Subject: [PATCH] yescrypt: enable and fix workspace-level lints Enables and fixes the workspace-level lints added in #884, which is a standard configuration we're using across repositories --- yescrypt/Cargo.toml | 3 +++ yescrypt/README.md | 7 ++++--- yescrypt/src/lib.rs | 22 ++++++---------------- yescrypt/src/mode.rs | 3 +++ yescrypt/src/params.rs | 9 +++++++++ yescrypt/src/pwxform.rs | 2 +- yescrypt/src/smix.rs | 4 ++-- yescrypt/src/util.rs | 2 +- yescrypt/tests/mcf.rs | 4 ++-- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/yescrypt/Cargo.toml b/yescrypt/Cargo.toml index 90f3736c..86a06a91 100644 --- a/yescrypt/Cargo.toml +++ b/yescrypt/Cargo.toml @@ -35,5 +35,8 @@ kdf = ["dep:kdf"] rand_core = ["password-hash/rand_core"] password-hash = ["dep:mcf", "dep:password-hash"] +[lints] +workspace = true + [package.metadata.docs.rs] all-features = true diff --git a/yescrypt/README.md b/yescrypt/README.md index 61fb571e..1c98eb9c 100644 --- a/yescrypt/README.md +++ b/yescrypt/README.md @@ -1,4 +1,4 @@ -# RustCrypto: yescrypt +# [RustCrypto]: yescrypt [![crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] @@ -63,7 +63,8 @@ dual licensed as above, without any additional terms or conditions. [//]: # (links) -[yescrypt]: https://www.openwall.com/yescrypt/ +[RustCrypto]: https://github.com/RustCrypto +[yescrypt]: https://www.openwall.com/yescrypt [scrypt]: https://en.wikipedia.org/wiki/Scrypt -[Password Hashing Competition]: https://www.password-hashing.net/ +[Password Hashing Competition]: https://www.password-hashing.net [paper]: https://www.password-hashing.net/submissions/specs/yescrypt-v2.pdf diff --git a/yescrypt/src/lib.rs b/yescrypt/src/lib.rs index cc9280d5..a769c79e 100644 --- a/yescrypt/src/lib.rs +++ b/yescrypt/src/lib.rs @@ -6,22 +6,6 @@ html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg" )] #![deny(unsafe_code)] -#![warn( - clippy::cast_lossless, - clippy::cast_possible_truncation, - clippy::cast_possible_wrap, - clippy::cast_precision_loss, - clippy::cast_sign_loss, - clippy::checked_conversions, - clippy::implicit_saturating_sub, - clippy::panic, - clippy::panic_in_result_fn, - clippy::unwrap_used, - missing_docs, - rust_2018_idioms, - unused_lifetimes, - unused_qualifications -)] //! # Usage //! ## Password Hashing @@ -98,6 +82,9 @@ use sha2::{Digest, Sha256}; /// /// If you are looking for a higher-level interface which can express and store password hashes as /// strings, please check out the [`Yescrypt`] type. +/// +/// # Errors +/// Returns [`Error::Params`] if the params are not valid for the size of `out`. pub fn yescrypt(passwd: &[u8], salt: &[u8], params: &Params, out: &mut [u8]) -> Result<()> { let mut passwd = passwd; let mut dk = [0u8; 32]; @@ -235,6 +222,9 @@ pub struct Yescrypt { impl Yescrypt { /// Hash password into the given output buffer using the configured params. + /// + /// # Errors + /// Returns the same errors as the toplevel [`yescrypt`] function. pub fn hash_password_into(&self, password: &[u8], salt: &[u8], out: &mut [u8]) -> Result<()> { yescrypt(password, salt, &self.params, out)?; Ok(()) diff --git a/yescrypt/src/mode.rs b/yescrypt/src/mode.rs index e19f1690..4f6d9ca7 100644 --- a/yescrypt/src/mode.rs +++ b/yescrypt/src/mode.rs @@ -31,16 +31,19 @@ pub enum Mode { impl Mode { /// Is the mode scrypt classic? + #[must_use] pub fn is_classic(self) -> bool { self == Self::Classic } /// Is the mode write-once/read-many? + #[must_use] pub fn is_worm(self) -> bool { self == Self::Worm } /// Is the mode the yescrypt native read-write mode? (default) + #[must_use] pub fn is_rw(self) -> bool { self == Self::Rw } diff --git a/yescrypt/src/params.rs b/yescrypt/src/params.rs index 5fcf0f70..350fe5f9 100644 --- a/yescrypt/src/params.rs +++ b/yescrypt/src/params.rs @@ -57,6 +57,9 @@ impl Params { /// - `n`: CPU/memory cost. See [`Params::n`] for more info. /// - `r`: resource usage. See [`Params::r`] for more info. /// - `p`: parallelization. See [`Params::p`] for more info. + /// + /// # Errors + /// Returns [`Error::Params`] if the params are not valid. pub fn new(mode: Mode, n: u64, r: u32, p: u32) -> Result { Self::new_with_all_params(mode, n, r, p, 0, 0) } @@ -66,6 +69,9 @@ impl Params { /// Accepts all the same arguments as [`Params::new`] with the following additional arguments: /// - `t`: increase computation time while keeping peak memory usage the same. `0` is optimal. /// - `g`: number of cost upgrades performed on the hash so far. `0` is the only allowed value. + /// + /// # Errors + /// Returns [`Error::Params`] if the params are not valid. pub fn new_with_all_params( mode: Mode, n: u64, @@ -102,6 +108,7 @@ impl Params { /// `N`: CPU/memory cost (like `scrypt`). /// /// Memory and CPU usage scale linearly with `N`. + #[must_use] pub const fn n(&self) -> u64 { self.n } @@ -109,6 +116,7 @@ impl Params { /// `r` parameter: resource usage (like `scrypt`). /// /// Memory and CPU usage scales linearly with this parameter. + #[must_use] pub const fn r(&self) -> u32 { self.r } @@ -117,6 +125,7 @@ impl Params { /// /// Allows use of multithreaded parallelism (not currently implemented, `1` is the recommended /// setting for now). + #[must_use] pub const fn p(&self) -> u32 { self.p } diff --git a/yescrypt/src/pwxform.rs b/yescrypt/src/pwxform.rs index d68c5f5a..9ee33f45 100644 --- a/yescrypt/src/pwxform.rs +++ b/yescrypt/src/pwxform.rs @@ -15,7 +15,7 @@ use core::mem; const PWXSIMPLE: usize = 2; /// Number of parallel "simple SIMD" lanes per "gather SIMD" vector (requiring "S-box lookups" of -/// values as wide as a "simple SIMD" lane from PWXgather typically non-contiguous memory +/// values as wide as a "simple SIMD" lane from `PWXgather` typically non-contiguous memory /// locations). Must be a power of 2. const PWXGATHER: usize = 4; diff --git a/yescrypt/src/smix.rs b/yescrypt/src/smix.rs index 2351ef5b..d62c9d7d 100644 --- a/yescrypt/src/smix.rs +++ b/yescrypt/src/smix.rs @@ -47,7 +47,7 @@ pub(crate) fn smix( } } else if t != 0 { if t == 1 { - nloop_all += nloop_all.div_ceil(2) // 1.5, round up + nloop_all += nloop_all.div_ceil(2); // 1.5, round up } nloop_all *= u64::from(t); } @@ -276,7 +276,7 @@ fn smix2( // V_j <-- X if mode.is_rw() { - v[j as usize * s..][..s].copy_from_slice(x); + v[j * s..][..s].copy_from_slice(x); } // 8.2: X <-- H(X) diff --git a/yescrypt/src/util.rs b/yescrypt/src/util.rs index f9b4cd14..aa971aa8 100644 --- a/yescrypt/src/util.rs +++ b/yescrypt/src/util.rs @@ -13,7 +13,7 @@ where { assert_eq!(dst.len(), src.len()); for (dst, src) in core::iter::zip(dst, src) { - *dst ^= *src + *dst ^= *src; } } diff --git a/yescrypt/tests/mcf.rs b/yescrypt/tests/mcf.rs index 650ac52b..07ea2be7 100644 --- a/yescrypt/tests/mcf.rs +++ b/yescrypt/tests/mcf.rs @@ -15,7 +15,7 @@ const EXAMPLE_PASSWD: &[u8] = b"pleaseletmein"; const EXAMPLE_SALT: &[u8] = b"WZaPV7LSUEKMo34."; /// Adapted from `TESTS-OK` in the yescrypt reference C implementation -/// https://github.com/openwall/yescrypt/blob/caa931d/TESTS-OK#L31-L66 +/// const EXAMPLE_HASHES: &[&str] = &[ "$y$jD5.7$LdJMENpBABJJ3hIHjB1Bi.$HboGM6qPrsK.StKYGt6KErmUYtioHreJd98oIugoNB6", "$y$jC4$LdJMENpBABJJ3hIHjB1B$jVg4HoqqpbmQv/NCpin.QCMagJ8o4QX7lXdzvVV0xFC", // TODO @@ -41,7 +41,7 @@ const EXAMPLE_HASHES: &[&str] = &[ #[test] fn compute_reference_strings() { for (i, &expected_hash) in EXAMPLE_HASHES.iter().enumerate() { - let i = i as u32; + let i = u32::try_from(i).unwrap(); // Test case logic adapted from the yescrypt C reference implementation (tests.c) let mut N_log2 = if i < 14 { 16 - i } else { 2 };