Struct Config

Source
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>

Source

pub fn new_insecure() -> Self

Create a new config. This is an insecure config and should not be used in production!

Source

pub fn new() -> Self

Create a new config. This config is somewhat more secure than new_insecure() but a secret key should still be set with the set_secret_key() function.

Source§

impl<'k> Config<'k>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn set_output_length(&mut self, output_length: Option<usize>) -> &mut Self

Set the output length of the algorithm in bytes.

Default: 32

Trait Implementations§

Source§

impl<'k> Default for Config<'k>

Source§

fn default() -> Self

Create a new default config. This is good for basic purposes, but SHOULD NOT be used in a production environment.

  • Algorithm: Argon2id
  • Version: 19 (0x13)
  • Secret key: None,
  • Memory size: 4,096 kilobytes
  • Iterations: 3
  • Parallelism: 1
  • Output length: Some(32)

Auto Trait Implementations§

§

impl<'k> Freeze for Config<'k>

§

impl<'k> RefUnwindSafe for Config<'k>

§

impl<'k> Send for Config<'k>

§

impl<'k> Sync for Config<'k>

§

impl<'k> Unpin for Config<'k>

§

impl<'k> UnwindSafe for Config<'k>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V