pub struct KdfAlgorithmBuilder;
Expand description
Builder for constructing KDF algorithm instances.
用于构建 KDF 算法实例的构建器。
§Design Pattern | 设计模式
This builder separates key-based and password-based derivation functions, ensuring that the appropriate algorithm is chosen for the input entropy level.
此构建器分离基于密钥和基于密码的派生函数, 确保为输入熵级别选择适当的算法。
§Security Guidance | 安全指导
-
Use
.key()
for high-entropy inputs (≥128 bits of entropy) -
Use
.passwd()
for low-entropy inputs (user passwords, PINs) -
对高熵输入使用
.key()
(≥128 位熵) -
对低熵输入使用
.passwd()
(用户密码、PIN)
Implementations§
Source§impl KdfAlgorithmBuilder
impl KdfAlgorithmBuilder
Sourcepub fn key(self) -> KdfKeyAlgorithmBuilder
pub fn key(self) -> KdfKeyAlgorithmBuilder
Creates a key-based KDF algorithm builder.
创建基于密钥的 KDF 算法构建器。
§Use Cases | 使用场景
-
Deriving multiple keys from a master key
-
Key expansion in cryptographic protocols
-
Deriving keys from shared secrets (ECDH, etc.)
-
Creating domain-separated keys
-
从主密钥派生多个密钥
-
密码协议中的密钥扩展
-
从共享密钥派生密钥(ECDH 等)
-
创建域分离的密钥
§Available Algorithms | 可用算法
- HKDF-SHA256: Fast, widely supported
- HKDF-SHA384: Higher security margin
- HKDF-SHA512: Maximum security
§Examples | 示例
use seal_crypto_wrapper::algorithms::kdf::KdfAlgorithm;
let hkdf = KdfAlgorithm::build().key().hkdf_sha256();
Sourcepub fn passwd(self) -> KdfPasswordAlgorithmBuilder
pub fn passwd(self) -> KdfPasswordAlgorithmBuilder
Creates a password-based KDF algorithm builder.
创建基于密码的 KDF 算法构建器。
§Use Cases | 使用场景
-
Deriving encryption keys from user passwords
-
Password-based authentication
-
Secure password storage
-
Key derivation for encrypted storage
-
从用户密码派生加密密钥
-
基于密码的认证
-
安全密码存储
-
加密存储的密钥派生
§Available Algorithms | 可用算法
- PBKDF2: Widely supported, configurable iterations
- Argon2: Memory-hard, resistant to specialized attacks
§Security Note | 安全注意
Always use sufficient iteration counts and random salts to protect against brute-force and rainbow table attacks.
始终使用足够的迭代次数和随机盐来防止暴力攻击和彩虹表攻击。
§Examples | 示例
use seal_crypto_wrapper::algorithms::kdf::KdfAlgorithm;
// PBKDF2 with 100,000 iterations
let pbkdf2 = KdfAlgorithm::build().passwd().pbkdf2_sha256_with_params(100000);
// Argon2 with memory cost, time cost, and parallelism
let argon2 = KdfAlgorithm::build().passwd().argon2_with_params(65536, 3, 4);