-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#12 pbkdf2 derivation
- Loading branch information
Showing
4 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use argon2::password_hash::SaltString; | ||
use pbkdf2::pbkdf2_hmac_array; | ||
use rand::rngs::OsRng; | ||
use sha3::Sha3_256; | ||
|
||
use super::cas_password_hasher::Pbkdf2Result; | ||
|
||
pub fn derivation(password_vec: Vec<u8>, number_of_iterations: u32) -> Pbkdf2Result { | ||
// Use Argon 2 salt and return the salt to the user so they can reuse it. | ||
let salt = SaltString::generate(&mut OsRng); | ||
let salt_binding = salt.to_string(); | ||
let salt = salt_binding.as_bytes().to_vec(); | ||
let key = pbkdf2_hmac_array::<Sha3_256, 32>(&password_vec, &salt, number_of_iterations).to_vec(); | ||
return Pbkdf2Result { | ||
password: key, | ||
salt: salt | ||
} | ||
} | ||
|
||
pub fn derivation_with_salt(password_vec: Vec<u8>, number_of_iterations: u32, salt: Vec<u8>) -> Vec<u8> { | ||
let key = pbkdf2_hmac_array::<Sha3_256, 32>(&password_vec, &salt, number_of_iterations).to_vec(); | ||
key | ||
} |