Skip to main content

derive_key

Function derive_key 

Source
pub fn derive_key(
    password: &[u8],
    salt: &[u8],
    secret: &[u8],
    ad: &[u8],
    params: &Params,
) -> Result<Vec<u8>, Argon2Error>
Expand description

Derive a key using Argon2id (RFC 9106).

This is the main entry point for Argon2id key derivation.

§Arguments

  • password - The password to hash
  • salt - Salt (recommended 16 bytes)
  • secret - Optional secret key (can be empty)
  • ad - Optional associated data (can be empty)
  • params - Argon2id parameters

§Returns

The derived key as a Vec of length params.tag_length.

§Example

use crypto::argon2::{derive_key, Params};

let tag = derive_key(
    b"correct horse battery staple",
    b"randomsalt123456",
    &[],  // no secret
    &[],  // no associated data
    &Params { iterations: 3, memory: 65536, parallelism: 4, tag_length: 32 },
).unwrap();
assert_eq!(tag.len(), 32);