FipsPbkdf2

Struct FipsPbkdf2 

Source
pub struct FipsPbkdf2<H: Hash + Fips> { /* private fields */ }
Expand description

A wrapper type enforcing FIPS compliance for PBKDF2 operations.

The FipsPbkdf2 type ensures that PBKDF2 operations are performed using FIPS-compliant hash functions and salts at the type level.

If the allow-non-fips flag is disabled, the constraints the FipsPbkdf2 struct enforces are equivalent to that of the pbkdf2 and pbkdf2_into functions alone.

This type implements this crate’s Fips marker type.

§Examples

use wolf_crypto::kdf::FipsPbkdf2;
use wolf_crypto::hash::Sha256;
use wolf_crypto::kdf::Iters;

let password = b"my password";
let salt = [42; 16];
let iters = Iters::new(100_000).unwrap();

let key = FipsPbkdf2::<Sha256>::array::<32>(password, salt, iters).unwrap();
assert_eq!(key.len(), 32);
let salt = [3; 8]; // won't compile! must be at least 16 bytes for FIPS compliance.

FipsPbkdf2::<Sha256>::into(password, salt, iters, &mut out_key).unwrap();

Implementations§

Source§

impl<H: Hash + Fips> FipsPbkdf2<H>

Source

pub fn array<const KL: usize>( password: &[u8], salt: impl Salt<Min16>, iters: Iters, ) -> Result<[u8; KL], Unspecified>

Performs PBKDF2 and returns the result as a fixed-size array.

§Arguments
  • password - The password to use for the key derivation.
  • salt - The salt to use for key derivation.
  • iters - The number of times to process the hash.
§Errors
  • The length of the password was greater than i32::MAX.
  • The length of the salt was greater than i32::MAX.
  • The number of iters was greater than i32::MAX.
  • The KL generic was greater than i32::MAX.
  • The KL generic was less than FIPS_MIN_KEY (14 bytes).
§Example
use wolf_crypto::kdf::{FipsPbkdf2, Sha256, Iters};

type Sha256Pbkdf2 = FipsPbkdf2<Sha256>;

let password = b"my secret password";
let salt = [42; 16];
let iters = Iters::new(600_000).unwrap();

let key = Sha256Pbkdf2::array::<32>(password, salt, iters).unwrap();
assert_eq!(key.len(), 32);
Source

pub fn into( password: &[u8], salt: impl Salt<Min16>, iters: Iters, out_key: &mut [u8], ) -> Result<(), Unspecified>

Performs PBKDF2 and writes the result into the provided out_key buffer.

§Arguments
  • password - The password to use for the key derivation.
  • salt - The salt to use for key derivation.
  • iters - The number of times to process the hash.
  • out_key - The buffer to write the generated key into.
§Errors
  • The length of the password was greater than i32::MAX.
  • The length of the salt was greater than i32::MAX.
  • The number of iters was greater than i32::MAX.
  • The length of the out_key was greater than i32::MAX.
  • The length of the out_key was less than FIPS_MIN_KEY (14 bytes).
§Example
use wolf_crypto::kdf::{FipsPbkdf2, Sha256, Iters};

type Sha256Pbkdf2 = FipsPbkdf2<Sha256>;

let password = b"my secret password";
let salt = [42; 16];
let iters = Iters::new(600_000).unwrap();
let mut out_key = [0u8; 32];

Sha256Pbkdf2::into(password, salt, iters, out_key.as_mut_slice()).unwrap();

Trait Implementations§

Source§

impl<H: Clone + Hash + Fips> Clone for FipsPbkdf2<H>

Source§

fn clone(&self) -> FipsPbkdf2<H>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H: Hash + Fips> Debug for FipsPbkdf2<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<H: Copy + Hash + Fips> Copy for FipsPbkdf2<H>

Source§

impl<H: Hash + Fips> Fips for FipsPbkdf2<H>

Auto Trait Implementations§

§

impl<H> Freeze for FipsPbkdf2<H>

§

impl<H> RefUnwindSafe for FipsPbkdf2<H>
where H: RefUnwindSafe,

§

impl<H> Send for FipsPbkdf2<H>
where H: Send,

§

impl<H> Sync for FipsPbkdf2<H>
where H: Sync,

§

impl<H> Unpin for FipsPbkdf2<H>
where H: Unpin,

§

impl<H> UnwindSafe for FipsPbkdf2<H>
where H: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.