pub struct Config { /* private fields */ }Expand description
Password hash configuration parameters.
Config::interactive is the default and is suitable for online
authentication. Config::moderate and Config::sensitive spend more
time and memory per password guess. Benchmark the chosen preset on the
slowest supported system, and account for the number of concurrent hashes
when setting memory limits.
Implementations§
Source§impl Config
impl Config
Sourcepub fn with_algorithm(self, algorithm: PasswordHashAlgorithm) -> Self
pub fn with_algorithm(self, algorithm: PasswordHashAlgorithm) -> Self
Selects the password-hashing algorithm.
The preset resource limits target Argon2id. When selecting Argon2i,
choose limits that satisfy the corresponding CRYPTO_PWHASH_ARGON2I_*
constants.
Sourcepub fn with_hash_length(self, hash_length: usize) -> Self
pub fn with_hash_length(self, hash_length: usize) -> Self
Sets the hash output length in bytes.
The length must be between CRYPTO_PWHASH_BYTES_MIN and
CRYPTO_PWHASH_BYTES_MAX, inclusive. Invalid values are reported when
the config is used to hash a password.
Sourcepub fn with_memlimit(self, memlimit: usize) -> Self
pub fn with_memlimit(self, memlimit: usize) -> Self
Sets the approximate memory cost in bytes.
More memory makes parallel guessing more expensive, but every
concurrent hash also consumes that memory. The value must be between
CRYPTO_PWHASH_MEMLIMIT_MIN and CRYPTO_PWHASH_MEMLIMIT_MAX,
inclusive.
Sourcepub fn with_opslimit(self, opslimit: u64) -> Self
pub fn with_opslimit(self, opslimit: u64) -> Self
Sets the computation cost.
Larger values take longer and make each password guess more expensive.
The supported range depends on the selected algorithm. See the
CRYPTO_PWHASH_ARGON2I_OPSLIMIT_* and
CRYPTO_PWHASH_ARGON2ID_OPSLIMIT_* constants.
Sourcepub fn interactive() -> Self
pub fn interactive() -> Self
Returns libsodium’s interactive password hashing configuration.
This is the default preset for online operations where users wait for the result.
Sourcepub fn moderate() -> Self
pub fn moderate() -> Self
Returns libsodium’s moderate password hashing configuration.
This preset uses more time and memory than Config::interactive.