Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions yescrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions yescrypt/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RustCrypto: yescrypt
# [RustCrypto]: yescrypt

[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
Expand Down Expand Up @@ -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
22 changes: 6 additions & 16 deletions yescrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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(())
Expand Down
3 changes: 3 additions & 0 deletions yescrypt/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions yescrypt/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Params> {
Self::new_with_all_params(mode, n, r, p, 0, 0)
}
Expand All @@ -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,
Expand Down Expand Up @@ -102,13 +108,15 @@ 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
}

/// `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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion yescrypt/src/pwxform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions yescrypt/src/smix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion yescrypt/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where
{
assert_eq!(dst.len(), src.len());
for (dst, src) in core::iter::zip(dst, src) {
*dst ^= *src
*dst ^= *src;
}
}

Expand Down
4 changes: 2 additions & 2 deletions yescrypt/tests/mcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <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
Expand All @@ -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 };
Expand Down
Loading