Skip to content

Commit e22e9c5

Browse files
authored
yescrypt: move prehashing out-of-band from Flags (#695)
Changes it to an explicit parameter of `yescrypt_kdf_body`
1 parent 2a713f3 commit e22e9c5

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

yescrypt/src/flags.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ impl Flags {
4141
/// Flavor: SBox 12k
4242
pub const SBOX_12K: Self = Self(0x080);
4343

44-
/// Prehash
45-
// TODO(tarcieri): move this out-of-band from `Flags`? Or actually make it `pub`?
46-
pub(crate) const PREHASH: Self = Self(0x10000000);
47-
4844
/// All possible flags.
4945
// Notably this only includes flags in the public API
5046
const ALL_FLAGS: Self = Self(
@@ -76,11 +72,6 @@ impl Flags {
7672
self.0 == 0
7773
}
7874

79-
/// Is the prehash bit set?
80-
pub(crate) fn has_prehash(self) -> bool {
81-
self.0 & Flags::PREHASH.0 != 0
82-
}
83-
8475
/// Is the read-write bit set?
8576
pub(crate) fn has_rw(self) -> bool {
8677
self.0 & Flags::RW.0 != 0

yescrypt/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,25 @@ pub fn yescrypt_kdf(passwd: &[u8], salt: &[u8], params: &Params, out: &mut [u8])
179179
&& params.n / (params.p as u64) * (params.r as u64) >= 0x20000
180180
{
181181
let mut prehash_params = *params;
182-
prehash_params.flags |= Flags::PREHASH;
183182
prehash_params.n >>= 6;
184183
prehash_params.t = 0;
185-
186-
yescrypt_kdf_body(passwd, salt, &prehash_params, &mut dk)?;
184+
yescrypt_kdf_body(passwd, salt, &prehash_params, true, &mut dk)?;
187185

188186
// Use derived key as the "password" for the subsequent step
189187
passwd = &dk;
190188
}
191189

192-
yescrypt_kdf_body(passwd, salt, params, out)
190+
yescrypt_kdf_body(passwd, salt, params, false, out)
193191
}
194192

195193
/// Compute yescrypt and write the result into `out`.
196-
///
197-
/// - `flags` may request special modes.
198-
/// - `t` controls computation time while not affecting peak memory usage.
199-
fn yescrypt_kdf_body(passwd: &[u8], salt: &[u8], params: &Params, out: &mut [u8]) -> Result<()> {
194+
fn yescrypt_kdf_body(
195+
passwd: &[u8],
196+
salt: &[u8],
197+
params: &Params,
198+
prehash: bool,
199+
out: &mut [u8],
200+
) -> Result<()> {
200201
let flags: Flags = params.flags;
201202
let n: u64 = params.n;
202203
let r: u32 = params.r;
@@ -220,10 +221,10 @@ fn yescrypt_kdf_body(passwd: &[u8], salt: &[u8], params: &Params, out: &mut [u8]
220221
let mut sha256 = [0u8; 32];
221222
if !flags.is_empty() {
222223
sha256 = util::hmac_sha256(
223-
if flags.has_prehash() {
224-
&b"yescrypt-prehash"[..]
224+
if prehash {
225+
b"yescrypt-prehash"
225226
} else {
226-
&b"yescrypt"[..]
227+
b"yescrypt"
227228
},
228229
passwd,
229230
);
@@ -272,7 +273,7 @@ fn yescrypt_kdf_body(passwd: &[u8], salt: &[u8], params: &Params, out: &mut [u8]
272273
// SCRAM (RFC 5802), so that an extension of SCRAM (with the steps so
273274
// far in place of SCRAM's use of PBKDF2 and with SHA-256 in place of
274275
// SCRAM's use of SHA-1) would be usable with yescrypt hashes.
275-
if !flags.is_empty() && !flags.has_prehash() {
276+
if !flags.is_empty() && !prehash {
276277
let dkp = if !flags.is_empty() && out.len() < 32 {
277278
&mut dk
278279
} else {

0 commit comments

Comments
 (0)