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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//! Key-based Key Derivation Functions (KDF) for high-entropy inputs.
//!
//! 用于高熵输入的基于密钥的密钥派生函数 (KDF)。
//!
//! ## Overview | 概述
//!
//! Key-based KDFs are designed to work with high-entropy input key material,
//! such as cryptographic keys, shared secrets from key agreement protocols,
//! or other sources with sufficient randomness. They efficiently expand or
//! derive multiple keys from a single master key.
//!
//! 基于密钥的 KDF 设计用于处理高熵输入密钥材料,
//! 如密码密钥、密钥协商协议的共享密钥或其他具有足够随机性的源。
//! 它们有效地从单个主密钥扩展或派生多个密钥。
//!
//! ## Supported Algorithms | 支持的算法
//!
//! ### HKDF (HMAC-based Key Derivation Function)
//! - **Standard**: RFC 5869
//! - **Type**: Extract-and-Expand KDF
//! - **Input**: High-entropy key material
//! - **Features**: Salt support, context information, variable output length
//!
//! ## HKDF Process | HKDF 过程
//!
//! HKDF operates in two phases:
//!
//! HKDF 分两个阶段运行:
//!
//! 1. **Extract Phase**: `PRK = HKDF-Extract(salt, IKM)`
//! - Extracts a pseudorandom key from input key material
//! - 从输入密钥材料中提取伪随机密钥
//!
//! 2. **Expand Phase**: `OKM = HKDF-Expand(PRK, info, L)`
//! - Expands the PRK to desired output length
//! - 将 PRK 扩展到所需的输出长度
//!
//! ## Security Properties | 安全属性
//!
//! - **Pseudorandomness**: Output is indistinguishable from random
//! - **Key Separation**: Different contexts produce independent keys
//! - **Forward Security**: Compromise of derived keys doesn't affect others
//! - **Efficiency**: Fast computation suitable for real-time applications
//!
//! - **伪随机性**: 输出与随机数据无法区分
//! - **密钥分离**: 不同上下文产生独立的密钥
//! - **前向安全**: 派生密钥的泄露不影响其他密钥
//! - **效率**: 适用于实时应用的快速计算
//!
//! ## Usage Guidelines | 使用指南
//!
//! - **Input Requirements**: Use only high-entropy key material (≥128 bits entropy)
//! - **Salt Usage**: Use unique salts when possible for key separation
//! - **Context Information**: Include application-specific context for domain separation
//! - **Output Length**: Request only the amount of key material needed
//!
//! - **输入要求**: 仅使用高熵密钥材料(≥128 位熵)
//! - **盐的使用**: 尽可能使用唯一盐进行密钥分离
//! - **上下文信息**: 包含应用特定上下文进行域分离
//! - **输出长度**: 仅请求所需的密钥材料数量
use crateHashAlgorithm;
use ;
/// Key-based Key Derivation Function algorithm enumeration.
///
/// 基于密钥的密钥派生函数算法枚举。
///
/// ## Algorithm Selection | 算法选择
///
/// Choose the hash function based on your security requirements:
/// - **HKDF-SHA256**: Standard choice, good performance, 128-bit security
/// - **HKDF-SHA384**: Higher security margin, 192-bit security
/// - **HKDF-SHA512**: Maximum security, 256-bit security
///
/// 根据您的安全要求选择哈希函数:
/// - **HKDF-SHA256**: 标准选择,良好性能,128 位安全性
/// - **HKDF-SHA384**: 更高安全边际,192 位安全性
/// - **HKDF-SHA512**: 最大安全性,256 位安全性
/// Builder for constructing key-based KDF algorithm instances.
///
/// 用于构建基于密钥的 KDF 算法实例的构建器。
///
/// ## Usage Pattern | 使用模式
///
/// ```rust
/// use seal_crypto_wrapper::algorithms::kdf::key::KdfKeyAlgorithm;
///
/// // Different hash functions for different security levels
/// let hkdf_sha256 = KdfKeyAlgorithm::build().hkdf_sha256(); // 128-bit security
/// let hkdf_sha384 = KdfKeyAlgorithm::build().hkdf_sha384(); // 192-bit security
/// let hkdf_sha512 = KdfKeyAlgorithm::build().hkdf_sha512(); // 256-bit security
/// ```
///
/// ## Hash Function Selection | 哈希函数选择
///
/// The choice of hash function affects both security and performance:
/// - **SHA-256**: Fastest, suitable for most applications
/// - **SHA-384**: Good balance of security and performance
/// - **SHA-512**: Highest security, slower on 32-bit platforms
///
/// 哈希函数的选择影响安全性和性能:
/// - **SHA-256**: 最快,适用于大多数应用
/// - **SHA-384**: 安全性和性能的良好平衡
/// - **SHA-512**: 最高安全性,在 32 位平台上较慢
;
use crateKdfKeyWrapper;