[][src]Function safe_crypto::derive_key_from_pw

pub fn derive_key_from_pw(
    password: &[u8],
    salt: &[u8],
    work_factor: Option<u8>,
    output: &mut [u8]
) -> Result<(), Error>

Uses password-based key derivation to securely derive a byte vector from a password and salt. output may be used to construct any of the keys in this library.

The optional work_factor affects the security of the operation as well as the CPU and memory required. It must be less than 64. Passing in None uses the default of 19.

output must satisfy the following condition: output.len() > 0 && output.len() <= (2^32 - 1) * 32.

Example

use safe_crypto::*;

let password = b"password!";
let salt = b"salt!";
let mut output = [0; SYMMETRIC_KEY_BYTES];

derive_key_from_pw(password, salt, None, &mut output).unwrap();
let key1 = SymmetricKey::from_bytes(output);
derive_key_from_pw(password, salt, None, &mut output).unwrap();
let key2 = SymmetricKey::from_bytes(output);

assert_eq!(key1, key2);