Commit 2f836810 authored by Katharina Fey's avatar Katharina Fey 🏴
Browse files

Adding double_Hash functions

parent 5e85e049
......@@ -21,12 +21,9 @@ pub fn run(args: &ArgMatches<'_>) {
.unwrap_or_else(|_| utils::log_fatal("Provided invalid UTF-8 data!"));
// Hash token twice with random salt
let hash = utils::blake2(string.as_str(), salt);
let hash_enc = utils::base64_encode(&hash.0.iter().map(|i| *i).collect());
let token = utils::blake2(hash_enc.as_str(), hash.1);
let token = utils::double_hash(string, salt);
let token_enc = utils::base64_encode(&token.0.iter().map(|i| *i).collect());
let pretty = (token_enc, hash.1).to_string();
let pretty = (token_enc, salt).to_string();
println!("{}", pretty);
}
......@@ -89,15 +89,19 @@ pub fn blake2_verify(hash: Hash, secret: String) -> bool {
.fold(false, |acc, (a, b)| (a == b) && acc)
}
/// A utility to hash a secret twice so it can be compared
pub fn double_hash(secret: String, salt: &str) -> Hash {
let h1 = blake2(secret.as_str(), salt);
let h1_enc = base64_encode(&h1.0.iter().map(|i| *i).collect());
blake2(h1_enc.as_str(), h1.1)
}
/// Derive a key from a secret token
pub fn derive_key(secret: String, salt: String) -> Key {
Key::from_pw(KeyType::Aes256, secret.as_str(), salt.as_str())
}
pub fn generate_salt() -> String {
"".into()
}
/// Decrypt some packed secret
pub fn decrypt(key: &Key, data: PackedData) -> Vec<u8> {
let mut ctx = Aes256Siv::new(key.as_slice());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment