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
//! Digital signature key types and operations.
//!
//! 数字签名密钥类型和操作。
//!
//! ## Overview | 概述
//!
//! This module provides type-safe key management for digital signature algorithms,
//! which are used for authentication, non-repudiation, and data integrity verification.
//! It supports both traditional and post-quantum signature schemes.
//!
//! 此模块为数字签名算法提供类型安全的密钥管理,
//! 用于认证、不可否认性和数据完整性验证。它支持传统和后量子签名方案。
//!
//! ## Signature Operations | 签名操作
//!
//! ### Key Generation | 密钥生成
//! Generate a public-private key pair for the signature algorithm.
//!
//! 为签名算法生成公私钥对。
//!
//! ### Signing | 签名
//! Use the private key to create a digital signature for a message.
//!
//! 使用私钥为消息创建数字签名。
//!
//! ### Verification | 验证
//! Use the public key to verify that a signature was created by the corresponding private key.
//!
//! 使用公钥验证签名是否由相应的私钥创建。
//!
//! ## Supported Algorithms | 支持的算法
//!
//! ### Traditional Algorithms | 传统算法
//! - **Ed25519**: High-performance Edwards curve signatures
//! - **ECDSA P-256**: NIST standard elliptic curve signatures
//!
//! ### Post-Quantum Algorithms | 后量子算法
//! - **Dilithium**: Lattice-based signatures (NIST standardized)
//! - Dilithium-2: 128-bit security level
//! - Dilithium-3: 192-bit security level
//! - Dilithium-5: 256-bit security level
//!
//! ## Security Considerations | 安全考虑
//!
//! - **Private Key Protection**: Private keys must be kept secret and secure
//! - **Algorithm Binding**: Keys are bound to specific algorithms to prevent misuse
//! - **Message Integrity**: Signatures provide both authentication and integrity
//! - **Non-Repudiation**: Valid signatures provide proof of origin
//!
//! - **私钥保护**: 私钥必须保密和安全
//! - **算法绑定**: 密钥绑定到特定算法以防止误用
//! - **消息完整性**: 签名提供认证和完整性
//! - **不可否认性**: 有效签名提供来源证明
//!
//! ## Examples | 示例
//!
//! ```rust
//! use seal_crypto_wrapper::algorithms::asymmetric::AsymmetricAlgorithm;
//!
//! // Generate signature key pair
//! let algorithm = AsymmetricAlgorithm::build().signature().ed25519();
//! let signer = algorithm.into_wrapper();
//! let keypair = signer.generate_keypair()?;
//!
//! // Separate keys
//! let (public_key, private_key) = keypair.into_keypair();
//!
//! // Sign a message
//! let message = b"Hello, World!";
//! let signature = signer.sign(message, &private_key)?;
//!
//! // Verify the signature
//! signer.verify(message, &public_key, &signature)?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
use crateSignatureAlgorithm;
use cratedispatch_signature;
use crateError;
use crateimpl_typed_asymmetric_private_key;
use crateimpl_typed_asymmetric_public_key;
use crate;
use ;
/// Algorithm-bound signature key pair for digital signature operations.
///
/// 用于数字签名操作的算法绑定签名密钥对。
///
/// ## Purpose | 目的
///
/// This type represents a complete signature key pair (public and private keys) that is
/// bound to a specific signature algorithm. It ensures that both keys can only be used
/// with the algorithm they were generated for, preventing cryptographic misuse.
///
/// 此类型表示绑定到特定签名算法的完整签名密钥对(公钥和私钥)。
/// 它确保两个密钥只能与生成它们的算法一起使用,防止密码误用。
///
/// ## Key Features | 关键特性
///
/// - **Algorithm Binding**: Both keys are bound to the same signature algorithm
/// - **Type Safety**: Prevents using keys with incompatible algorithms
/// - **Serialization**: Supports secure serialization with algorithm metadata
/// - **Memory Safety**: Private key material is automatically zeroed on drop
///
/// - **算法绑定**: 两个密钥都绑定到相同的签名算法
/// - **类型安全**: 防止将密钥与不兼容的算法一起使用
/// - **序列化**: 支持带算法元数据的安全序列化
/// - **内存安全**: 私钥材料在丢弃时自动清零
///
/// ## Usage Pattern | 使用模式
///
/// ```rust
/// use seal_crypto_wrapper::keys::asymmetric::signature::TypedSignatureKeyPair;
/// use seal_crypto_wrapper::algorithms::asymmetric::signature::SignatureAlgorithm;
///
/// // Generate a new key pair
/// let algorithm = SignatureAlgorithm::build().ed25519();
/// let keypair = TypedSignatureKeyPair::generate(algorithm)?;
///
/// // Access individual keys
/// let public_key = keypair.public_key();
/// let private_key = keypair.private_key();
///
/// // Or consume the pair to get owned keys
/// let (public_key, private_key) = keypair.into_keypair();
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Algorithm-bound signature public key for signature verification operations.
///
/// 用于签名验证操作的算法绑定签名公钥。
///
/// ## Purpose | 目的
///
/// This type represents a signature public key that is bound to a specific algorithm.
/// It is used for verifying digital signatures created by the corresponding private key.
/// Public keys can be safely distributed and shared for signature verification.
///
/// 此类型表示绑定到特定算法的签名公钥。
/// 它用于验证由相应私钥创建的数字签名。
/// 公钥可以安全分发和共享用于签名验证。
///
/// ## Security | 安全性
///
/// Public keys are safe to distribute and store without special protection,
/// but algorithm binding ensures they can only be used with compatible operations.
///
/// 公钥可以安全分发和存储而无需特殊保护,
/// 但算法绑定确保它们只能与兼容的操作一起使用。
///
/// ## Use Cases | 使用场景
///
/// - **Signature Verification**: Verify authenticity of signed messages
/// - **Identity Verification**: Confirm the identity of message senders
/// - **Data Integrity**: Ensure data has not been tampered with
/// - **Non-Repudiation**: Provide proof of message origin
///
/// - **签名验证**: 验证签名消息的真实性
/// - **身份验证**: 确认消息发送者的身份
/// - **数据完整性**: 确保数据未被篡改
/// - **不可否认性**: 提供消息来源证明
impl_typed_asymmetric_public_key!;
/// Algorithm-bound signature private key for digital signing operations.
///
/// 用于数字签名操作的算法绑定签名私钥。
///
/// ## Purpose | 目的
///
/// This type represents a signature private key that is bound to a specific algorithm.
/// It is used for creating digital signatures that can be verified by the corresponding
/// public key. Private keys must be kept secret and secure.
///
/// 此类型表示绑定到特定算法的签名私钥。
/// 它用于创建可由相应公钥验证的数字签名。
/// 私钥必须保密和安全。
///
/// ## Security | 安全性
///
/// Private keys contain sensitive material and are automatically zeroed when dropped.
/// They should be protected with appropriate access controls and secure storage.
/// Compromise of a private key allows an attacker to forge signatures.
///
/// 私钥包含敏感材料,在丢弃时自动清零。
/// 应使用适当的访问控制和安全存储来保护它们。
/// 私钥的泄露允许攻击者伪造签名。
///
/// ## Use Cases | 使用场景
///
/// - **Message Signing**: Create authenticated signatures for messages
/// - **Document Signing**: Provide legal proof of document approval
/// - **Code Signing**: Verify software authenticity and integrity
/// - **Certificate Signing**: Create digital certificates for PKI
///
/// - **消息签名**: 为消息创建认证签名
/// - **文档签名**: 提供文档批准的法律证明
/// - **代码签名**: 验证软件真实性和完整性
/// - **证书签名**: 为 PKI 创建数字证书
impl_typed_asymmetric_private_key!;