1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//! Key Derivation Functions (KDF) for secure key generation and management.
//!
//! 用于安全密钥生成和管理的密钥派生函数 (KDF)。
//!
//! ## Overview | 概述
//!
//! Key Derivation Functions are cryptographic algorithms that derive one or more
//! secret keys from a secret value such as a master key, password, or shared secret.
//! They are essential for secure key management and cryptographic protocol design.
//!
//! 密钥派生函数是从主密钥、密码或共享密钥等秘密值派生一个或多个密钥的密码算法。
//! 它们对于安全密钥管理和密码协议设计至关重要。
//!
//! ## KDF Categories | KDF 分类
//!
//! ### Key-Based KDF | 基于密钥的 KDF
//! - **HKDF**: HMAC-based Key Derivation Function (RFC 5869)
//! - Suitable for deriving keys from high-entropy sources
//! - Fast and efficient
//! - Supports salt and context information
//!
//! ### Password-Based KDF | 基于密码的 KDF
//! - **PBKDF2**: Password-Based Key Derivation Function 2 (RFC 2898)
//! - Widely supported and standardized
//! - Configurable iteration count
//! - Suitable for password-based encryption
//! - **Argon2**: Memory-hard password hashing function
//! - Resistant to GPU and ASIC attacks
//! - Configurable memory, time, and parallelism
//! - Winner of Password Hashing Competition
//!
//! ## Security Considerations | 安全考虑
//!
//! ### Key-Based KDF | 基于密钥的 KDF
//! - Input key material should have sufficient entropy
//! - Use unique salt values when possible
//! - Context information helps prevent key reuse
//!
//! ### Password-Based KDF | 基于密码的 KDF
//! - Use high iteration counts to slow down attacks
//! - Always use random salts to prevent rainbow table attacks
//! - Consider memory-hard functions (Argon2) for better security
//!
//! ## Usage Guidelines | 使用指南
//!
//! - **High-entropy sources**: Use key-based KDF (HKDF)
//! - **Password derivation**: Use password-based KDF (PBKDF2/Argon2)
//! - **Performance critical**: HKDF or PBKDF2 with moderate iterations
//! - **Maximum security**: Argon2 with high memory and time costs
//!
//! - **高熵源**: 使用基于密钥的 KDF (HKDF)
//! - **密码派生**: 使用基于密码的 KDF (PBKDF2/Argon2)
//! - **性能关键**: HKDF 或适度迭代的 PBKDF2
//! - **最大安全性**: 高内存和时间成本的 Argon2
// Key-based derivation functions | 基于密钥的派生函数
// Password-based derivation functions | 基于密码的派生函数
use ;
use crate;
/// Key Derivation Function algorithm enumeration.
///
/// 密钥派生函数算法枚举。
///
/// ## Algorithm Selection | 算法选择
///
/// This enum provides access to two main categories of KDF algorithms:
///
/// 此枚举提供对两个主要 KDF 算法类别的访问:
///
/// - **Key-based**: For deriving keys from existing high-entropy key material
/// - **Password-based**: For deriving keys from user passwords or low-entropy sources
///
/// - **基于密钥**: 用于从现有高熵密钥材料派生密钥
/// - **基于密码**: 用于从用户密码或低熵源派生密钥
///
/// ## Usage Examples | 使用示例
///
/// ```rust
/// use seal_crypto_wrapper::algorithms::kdf::KdfAlgorithm;
///
/// // Key-based derivation (high entropy input)
/// let hkdf = KdfAlgorithm::build().key().hkdf_sha256();
///
/// // Password-based derivation (low entropy input)
/// let pbkdf2 = KdfAlgorithm::build().passwd().pbkdf2_sha256_with_params(10000);
/// let argon2 = KdfAlgorithm::build().passwd().argon2_with_params(65536, 3, 4);
/// ```
/// 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)
;