Skip to content

Commit a6d3fef

Browse files
authored
yescrypt v0.1.0-pre.3 (#697)
1 parent 6d28fba commit a6d3fef

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yescrypt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yescrypt"
3-
version = "0.1.0-pre.2"
3+
version = "0.1.0-pre.3"
44
description = "Pure Rust implementation of the yescrypt password-based key derivation function"
55
authors = ["RustCrypto Developers"]
66
license = "MIT OR Apache-2.0"

yescrypt/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
66
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
77
)]
8+
#![deny(unsafe_code)]
89
#![warn(
910
// TODO: clippy::cast_lossless,
1011
// TODO: clippy::cast_possible_truncation,

yescrypt/src/mode.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ const SBOX_12K: u32 = 0b100000;
1212
// TODO(tarcieri): support other flavors of yescrypt?
1313
const RW_FLAVOR: u32 = 2 | ROUNDS_6 | GATHER_4 | SIMPLE_2 | SBOX_12K;
1414

15-
/// yescrypt modes
15+
/// yescrypt modes: various ways yescrypt can operate.
16+
///
17+
/// [`Mode::default`] (`Rw`) is recommended.
1618
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
1719
#[repr(u32)]
1820
pub enum Mode {
19-
/// classic scrypt
21+
/// classic scrypt: yescrypt is a superset of scrypt.
2022
Classic = 0,
2123

22-
/// write-once/read-many: conservative enhancement of classic scrypt
24+
/// write-once/read-many: conservative enhancement of classic scrypt.
2325
Worm = 1,
2426

25-
/// yescrypt’s native mode: read-write
27+
/// yescrypt’s native mode: read-write (recommended/default).
2628
#[default]
2729
Rw = RW_FLAVOR,
2830
}

yescrypt/src/params.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use core::{
1313

1414
/// `yescrypt` algorithm parameters.
1515
///
16+
/// [`Params::default`] provides the recommended parameters.
17+
///
1618
/// These are various algorithm settings which can control e.g. the amount of resource utilization.
1719
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1820
pub struct Params {
@@ -41,7 +43,7 @@ pub struct Params {
4143
/// `0` means no upgrades yet, and is currently the only allowed value.
4244
pub(crate) g: u32,
4345

44-
/// special to yescrypt.
46+
/// Number of NROM blocks (128r bytes each).
4547
pub(crate) nrom: u64,
4648
}
4749

@@ -50,11 +52,21 @@ impl Params {
5052
pub(crate) const MAX_ENCODED_LEN: usize = 8 * 6;
5153

5254
/// Initialize params.
55+
///
56+
/// Accepts the following arguments:
57+
/// - `mode`: most users will want [`Mode::default`]. See the [`Mode`] type for more info.
58+
/// - `n`: CPU/memory cost. See [`Params::n`] for more info.
59+
/// - `r`: resource usage. See [`Params::r`] for more info.
60+
/// - `p`: parallelization. See [`Params::p`] for more info.
5361
pub fn new(mode: Mode, n: u64, r: u32, p: u32) -> Result<Params> {
5462
Self::new_with_all_params(mode, n, r, p, 0, 0)
5563
}
5664

57-
/// Initialize params.
65+
/// Initialize params including additional `yescrypt`-specific settings.
66+
///
67+
/// Accepts all the same arguments as [`Params::new`] with the following additional arguments:
68+
/// - `t`: increase computation time while keeping peak memory usage the same. `0` is optimal.
69+
/// - `g`: number of cost upgrades performed on the hash so far. `0` is the only allowed value.
5870
pub fn new_with_all_params(
5971
mode: Mode,
6072
n: u64,
@@ -103,6 +115,9 @@ impl Params {
103115
}
104116

105117
/// `p` parameter: parallelization (like `scrypt`).
118+
///
119+
/// Allows use of multithreaded parallelism (not currently implemented, `1` is the recommended
120+
/// setting for now).
106121
pub const fn p(&self) -> u32 {
107122
self.p
108123
}

yescrypt/src/pwxform.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ impl PwxformCtx<'_> {
151151
}
152152
}
153153

154-
fn reshape_block(b: &mut [u32; 16]) -> &mut [[[u32; PWXSIMPLE]; 2]; 4] {
154+
#[allow(unsafe_code)]
155+
pub(crate) fn reshape_block(b: &mut [u32; 16]) -> &mut [[[u32; PWXSIMPLE]; 2]; 4] {
155156
const {
156157
assert!(
157158
size_of::<[u32; 16]>() == size_of::<[[[u32; PWXSIMPLE]; 2]; 4]>(),

yescrypt/src/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Utility functions.
22
3+
// TODO(tarcieri): find safe replacements for unsafe code if possible
4+
#![allow(unsafe_code)]
5+
36
use core::{ops::BitXorAssign, slice};
47
use sha2::Sha256;
58

0 commit comments

Comments
 (0)