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
impl KdfPasswordAlgorithmBuilder
Sourcepub fn argon2_default(self) -> KdfPasswordAlgorithm
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
-
通用密码哈希
-
用户认证系统
-
基于密码的加密
Sourcepub fn pbkdf2_sha256_default(self) -> KdfPasswordAlgorithm
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)
-
资源受限环境
Sourcepub fn pbkdf2_sha384_default(self) -> KdfPasswordAlgorithm
pub fn pbkdf2_sha384_default(self) -> KdfPasswordAlgorithm
Sourcepub fn pbkdf2_sha512_default(self) -> KdfPasswordAlgorithm
pub fn pbkdf2_sha512_default(self) -> KdfPasswordAlgorithm
Sourcepub fn argon2_with_params(
self,
m_cost: u32,
t_cost: u32,
p_cost: u32,
) -> KdfPasswordAlgorithm
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 Level | m_cost | t_cost | p_cost |
---|---|---|---|
Interactive | 65536 | 2 | 1 |
Server | 262144 | 3 | 4 |
High Security | 1048576 | 4 | 8 |
§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);
Sourcepub fn pbkdf2_sha256_with_params(self, c: u32) -> KdfPasswordAlgorithm
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 Case | Iterations | Security Level |
---|---|---|
Legacy | 10,000 | Minimum |
Standard | 100,000 | Good |
High Sec | 1,000,000 | High |
§Performance Note | 性能注意
Higher iteration counts provide better security but increase computation time. Test on your target hardware to find the right balance.
更高的迭代次数提供更好的安全性但增加计算时间。 在目标硬件上测试以找到正确的平衡。
Sourcepub fn pbkdf2_sha384_with_params(self, c: u32) -> KdfPasswordAlgorithm
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 更高的安全级别,性能影响适中。
Sourcepub fn pbkdf2_sha512_with_params(self, c: u32) -> KdfPasswordAlgorithm
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 位平台优化。