pub struct Config<'k> {
pub algorithm: Algorithm,
pub version: Version,
pub secret_key: Option<&'k [u8]>,
pub memory_cost: u32,
pub iterations: u32,
pub parallelism: u32,
pub output_length: Option<usize>,
}
Expand description
Configuration for the argon2
algorithm.
Fields§
§algorithm: Algorithm
Set the hashing algorithm in use.
According to the latest (as of 5/18) Argon2 RFC … “Argon2 has one primary variant: Argon2id, and two supplementary variants: Argon2d and Argon2i. Argon2d uses data-dependent memory access, which makes it suitable for … applications with no threats from side-channel timing attacks. Argon2i uses data-independent memory access, which is preferred for password hashing and password-based key derivation. Argon2id works as Argon2i for the first half of the first iteration over the memory, and as Argon2d for the rest, thus providing both side-channel attack
version: Version
Set the version of argon2
to use.
secret_key: Option<&'k [u8]>
The secret key to use.
This is strongly recommended in production.
memory_cost: u32
The memory cost of the algorithm in kilobytes.
Argon2 has a notion of “memory size” or “memory cost” (in kilobytes). All else equal and generally speaking, the greater the memory cost, the longer it takes to perform the hash and the more secure the resulting hash. More memory cost basically means more memory used. This and “iterations” are, generally speaking, the two parameters to adjust in order to increase or decrease the security of your hash. If you’re going to use this crate in production, you should probably tweak this parameter (and the iterations parameter) in order to increase the time it takes to hash to the maximum you can reasonably allow for your use-case (e.g. to probably about 300-500 milliseconds for the use-case of hashing user passwords for a website).
iterations: u32
The number of iterations to use.
Argon2 has a notion of “iterations” or “time cost”. All else equal and generally speaking, the greater the number of iterations, the longer it takes to perform the hash and the more secure the resulting hash. More iterations basically means more CPU load. This and “memory cost” are the two primary parameters to adjust in order to increase or decrease the security of your hash. If you’re going to use this crate in production, you should probably tweak this parameter (and the memory cost parameter) in order to increase the time it takes to hash to the maximum you can reasonably allow for your use-case (e.g. to probably about 300-500 milliseconds for the use-case of hashing user passwords for a website).
parallelism: u32
The parallelism of the algorithm.
Argon2 can break up its work into one or more “lanes” during some parts of the hashing algorithm. If you configure it with multiple lanes, the hashing algorithm will perform its work in parallel in some parts, potentially speeding up the time it takes to produce a hash without diminishing the security of the result.
output_length: Option<usize>
The output length of the algorithm in bytes.
Implementations§
Source§impl<'k> Config<'k>
impl<'k> Config<'k>
Sourcepub fn new_insecure() -> Self
pub fn new_insecure() -> Self
Create a new config. This is an insecure config and should not be used in production!
Source§impl<'k> Config<'k>
impl<'k> Config<'k>
Sourcepub fn set_algorithm(&mut self, algorithm: Algorithm) -> &mut Self
pub fn set_algorithm(&mut self, algorithm: Algorithm) -> &mut Self
Set the hashing algorithm in use.
The default (Argon2id) should be fine for most uses.
Sourcepub fn set_version(&mut self, version: Version) -> &mut Self
pub fn set_version(&mut self, version: Version) -> &mut Self
Set the version of argon2
to use.
The default (0x13 or v19) should be fine for most uses.
Sourcepub fn set_secret_key(&mut self, secret_key: Option<&'k [u8]>) -> &mut Self
pub fn set_secret_key(&mut self, secret_key: Option<&'k [u8]>) -> &mut Self
Set the secret key to use. This is strongly recommended in a production environment.
Sourcepub fn set_memory_cost(&mut self, memory_cost: u32) -> &mut Self
pub fn set_memory_cost(&mut self, memory_cost: u32) -> &mut Self
Set the memory cost in kilobytes.
Default: 512 for insecure, and 4,096 for secure.
Sourcepub fn set_iterations(&mut self, iterations: u32) -> &mut Self
pub fn set_iterations(&mut self, iterations: u32) -> &mut Self
Set the number of iterations to use.
Default: 3 for insecure, and 200 for secure.
Sourcepub fn set_parallelism(&mut self, parallelism: u32) -> &mut Self
pub fn set_parallelism(&mut self, parallelism: u32) -> &mut Self
Set the parallelism of the algorithm.
Default: 1 for insecure, and the number of physical CPU cores on the host for secure.
Sourcepub fn set_output_length(&mut self, output_length: Option<usize>) -> &mut Self
pub fn set_output_length(&mut self, output_length: Option<usize>) -> &mut Self
Set the output length of the algorithm in bytes.
Default: 32