Now scrypt params are created once

This commit is contained in:
2023-06-11 13:05:20 +03:00
parent 2f2ab35b2b
commit e1fb440991
3 changed files with 6 additions and 2 deletions

View File

@ -1,15 +1,17 @@
use entity::master_pass;
use once_cell::sync::Lazy;
use rand::{rngs::OsRng, RngCore};
use scrypt::{scrypt, Params};
use sea_orm::ActiveValue::Set;
use subtle::ConstantTimeEq;
static PARAMS: Lazy<Params> = Lazy::new(|| Params::new(14, 8, 1, 64).unwrap());
/// Hashes the password with Scrypt with the given salt
#[inline]
fn hash_password(password: &[u8], salt: &[u8]) -> [u8; 64] {
let params = Params::new(14, Params::RECOMMENDED_R, Params::RECOMMENDED_P, 64).unwrap();
let mut password_hash = [0; 64];
scrypt(password, salt, &params, &mut password_hash).unwrap();
scrypt(password, salt, &PARAMS, &mut password_hash).unwrap();
password_hash
}