Now scrypt params are created once
This commit is contained in:
parent
2f2ab35b2b
commit
e1fb440991
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -466,6 +466,7 @@ dependencies = [
|
|||||||
"bitflags 2.3.1",
|
"bitflags 2.3.1",
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"entity",
|
"entity",
|
||||||
|
"once_cell",
|
||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"rand",
|
"rand",
|
||||||
"scrypt",
|
"scrypt",
|
||||||
|
@ -17,3 +17,4 @@ sea-orm = "0.11.3"
|
|||||||
bitflags = "2.3.1"
|
bitflags = "2.3.1"
|
||||||
arrayvec = "0.7.2"
|
arrayvec = "0.7.2"
|
||||||
subtle = "2.5.0"
|
subtle = "2.5.0"
|
||||||
|
once_cell = "1.18.0"
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
use entity::master_pass;
|
use entity::master_pass;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use rand::{rngs::OsRng, RngCore};
|
use rand::{rngs::OsRng, RngCore};
|
||||||
use scrypt::{scrypt, Params};
|
use scrypt::{scrypt, Params};
|
||||||
use sea_orm::ActiveValue::Set;
|
use sea_orm::ActiveValue::Set;
|
||||||
use subtle::ConstantTimeEq;
|
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
|
/// Hashes the password with Scrypt with the given salt
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_password(password: &[u8], salt: &[u8]) -> [u8; 64] {
|
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];
|
let mut password_hash = [0; 64];
|
||||||
scrypt(password, salt, ¶ms, &mut password_hash).unwrap();
|
scrypt(password, salt, &PARAMS, &mut password_hash).unwrap();
|
||||||
password_hash
|
password_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user