From a6a6efaf6b12e09c2d35cca59f2a195ebe8c3faf Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 22 Jun 2016 01:23:40 -0700 Subject: [PATCH] bcrypt_pbkdf: reduce amount of copying done The final copy into |output| does not need to be done until all the rounds for the block are complete. Otherwise it is continuously overwritten each round. --- src/bcrypt_pbkdf.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bcrypt_pbkdf.rs b/src/bcrypt_pbkdf.rs index afaeb3b8..b6133890 100644 --- a/src/bcrypt_pbkdf.rs +++ b/src/bcrypt_pbkdf.rs @@ -73,12 +73,12 @@ pub fn bcrypt_pbkdf(password: &[u8], salt: &[u8], rounds: u32, output: &mut [u8] for i in 0..out.len() { out[i] ^= tmp[i]; } + } - for i in 0..out.len() { - let idx = i * nblocks + (block-1); - if idx < output.len() { - output[idx] = out[i]; - } + for i in 0..out.len() { + let idx = i * nblocks + (block-1); + if idx < output.len() { + output[idx] = out[i]; } } }