pub fn derive_key(
out: &mut [u8],
password: &[u8],
salt: &[u8],
secret: &[u8],
ad: &[u8],
params: &Params,
) -> Result<(), Argon2Error>Expand description
Derive a key using Argon2id (RFC 9106).
This is the main entry point for Argon2id key derivation. The derived key is
written into out; its length determines the Argon2 output length and must
be at least 4 bytes.
§Arguments
out- Output buffer for the derived key. Its length is the tag length.password- The password to hashsalt- Salt (recommended 16 bytes)secret- Optional secret key (can be empty)ad- Optional associated data (can be empty)params- Argon2id parameters
§Errors
Returns Argon2Error::InvalidParams if out is shorter than 4 bytes or
if params is invalid.
§Example
ⓘ
use crypto::argon2::{derive_key, Params};
let mut tag = [0u8; 32];
derive_key(
&mut tag,
b"correct horse battery staple",
b"randomsalt123456",
&[], // no secret
&[], // no associated data
&Params { iterations: 3, memory: 65536, parallelism: 4 },
).unwrap();
assert_eq!(tag.len(), 32);