Struct KdfPasswordAlgorithmBuilder

Source
pub struct KdfPasswordAlgorithmBuilder;
Expand description

Builder for constructing password-based KDF algorithm instances.

用于构建基于密码的 KDF 算法实例的构建器。

§Usage Pattern | 使用模式

The builder provides both default and custom parameter methods:

  • Default methods use secure, recommended parameters
  • Custom parameter methods allow fine-tuning for specific requirements

构建器提供默认和自定义参数方法:

  • 默认方法使用安全、推荐的参数
  • 自定义参数方法允许针对特定要求进行微调

§Security Guidelines | 安全指南

  • For new applications: Use Argon2 for better security

  • For compatibility: Use PBKDF2 when required by standards

  • Parameter tuning: Test performance vs security trade-offs

  • Regular updates: Review and update parameters as hardware improves

  • 新应用: 使用 Argon2 获得更好的安全性

  • 兼容性: 标准要求时使用 PBKDF2

  • 参数调优: 测试性能与安全性的权衡

  • 定期更新: 随着硬件改进审查和更新参数

Implementations§

Source§

impl KdfPasswordAlgorithmBuilder

Source

pub fn argon2_default(self) -> KdfPasswordAlgorithm

Selects Argon2 with default parameters.

选择使用默认参数的 Argon2。

§Default Parameters | 默认参数
  • Memory Cost: 65536 KB (64 MB)
  • Time Cost: 3 iterations
  • Parallelism: 4 threads

These defaults provide a good balance of security and performance for most server applications.

这些默认值为大多数服务器应用提供了安全性和性能的良好平衡。

§Use Cases | 使用场景
  • General-purpose password hashing

  • User authentication systems

  • Password-based encryption

  • 通用密码哈希

  • 用户认证系统

  • 基于密码的加密

Source

pub fn pbkdf2_sha256_default(self) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA256 with default iteration count.

选择使用默认迭代次数的 PBKDF2-SHA256。

§Default Parameters | 默认参数
  • Hash Function: SHA-256
  • Iterations: 100,000 (recommended minimum)
§Use Cases | 使用场景
  • Legacy system compatibility

  • Standards compliance (PKCS #5)

  • Resource-constrained environments

  • 遗留系统兼容性

  • 标准合规性(PKCS #5)

  • 资源受限环境

Source

pub fn pbkdf2_sha384_default(self) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA384 with default iteration count.

选择使用默认迭代次数的 PBKDF2-SHA384。

§Properties | 属性
  • Hash Function: SHA-384
  • Security Level: 192-bit
  • Iterations: Default secure count
§Use Cases | 使用场景

Applications requiring higher security than SHA-256. 需要比 SHA-256 更高安全性的应用。

Source

pub fn pbkdf2_sha512_default(self) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA512 with default iteration count.

选择使用默认迭代次数的 PBKDF2-SHA512。

§Properties | 属性
  • Hash Function: SHA-512
  • Security Level: 256-bit
  • Iterations: Default secure count
§Use Cases | 使用场景

Maximum security applications using PBKDF2. 使用 PBKDF2 的最大安全性应用。

Source

pub fn argon2_with_params( self, m_cost: u32, t_cost: u32, p_cost: u32, ) -> KdfPasswordAlgorithm

Selects Argon2 with custom parameters.

选择使用自定义参数的 Argon2。

§Parameters | 参数
  • m_cost - Memory cost in KB (minimum 8)
  • t_cost - Time cost (iterations, minimum 1)
  • p_cost - Parallelism (threads, minimum 1)
§Parameter Guidelines | 参数指南
Security Levelm_costt_costp_cost
Interactive6553621
Server26214434
High Security104857648
§Examples | 示例
use seal_crypto_wrapper::algorithms::kdf::passwd::KdfPasswordAlgorithm;

// High security configuration
let high_sec = KdfPasswordAlgorithm::build()
    .argon2_with_params(1048576, 4, 8);

// Interactive use (faster)
let interactive = KdfPasswordAlgorithm::build()
    .argon2_with_params(65536, 2, 1);
Source

pub fn pbkdf2_sha256_with_params(self, c: u32) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA256 with custom iteration count.

选择使用自定义迭代次数的 PBKDF2-SHA256。

§Parameters | 参数
  • c - Iteration count (minimum 1000, recommended ≥100000)
§Iteration Guidelines | 迭代指南
Use CaseIterationsSecurity Level
Legacy10,000Minimum
Standard100,000Good
High Sec1,000,000High
§Performance Note | 性能注意

Higher iteration counts provide better security but increase computation time. Test on your target hardware to find the right balance.

更高的迭代次数提供更好的安全性但增加计算时间。 在目标硬件上测试以找到正确的平衡。

Source

pub fn pbkdf2_sha384_with_params(self, c: u32) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA384 with custom iteration count.

选择使用自定义迭代次数的 PBKDF2-SHA384。

§Parameters | 参数
  • c - Iteration count for SHA-384 variant

  • c - SHA-384 变体的迭代次数

Higher security level than SHA-256 with moderate performance impact. 比 SHA-256 更高的安全级别,性能影响适中。

Source

pub fn pbkdf2_sha512_with_params(self, c: u32) -> KdfPasswordAlgorithm

Selects PBKDF2-SHA512 with custom iteration count.

选择使用自定义迭代次数的 PBKDF2-SHA512。

§Parameters | 参数
  • c - Iteration count for SHA-512 variant

  • c - SHA-512 变体的迭代次数

Maximum security level for PBKDF2, optimized for 64-bit platforms. PBKDF2 的最大安全级别,针对 64 位平台优化。

Auto Trait Implementations§

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