seal_crypto/lib.rs
1#![forbid(unsafe_code)]
2
3//! The `seal-crypto` library provides a set of pure, trait-based cryptographic
4//! capability abstractions and implementations.
5//!
6//! This library offers a comprehensive, modular approach to cryptography with a focus on
7//! type safety, performance, and ease of use. It provides both traditional and post-quantum
8//! cryptographic algorithms through a unified trait-based interface.
9//!
10//! # Design Philosophy
11//! - **Type Safety**: Extensive use of the type system to prevent misuse
12//! - **Modularity**: Clean separation between abstractions and implementations
13//! - **Performance**: Optimized implementations with hardware acceleration where available
14//! - **Security**: Constant-time implementations and secure defaults
15//! - **Flexibility**: Support for both `std` and `no_std` environments
16//!
17//! # Core Components
18//! - **Traits**: Abstract interfaces for cryptographic operations
19//! - **Schemes**: High-level, user-friendly implementations
20//! - **Systems**: Low-level algorithm implementations
21//! - **Errors**: Comprehensive error handling
22//!
23//! # Supported Algorithms
24//! ## Symmetric Cryptography
25//! - AES-GCM (128, 256-bit keys)
26//! - ChaCha20-Poly1305
27//! - XChaCha20-Poly1305
28//!
29//! ## Asymmetric Cryptography
30//! ### Traditional
31//! - RSA (OAEP, PSS)
32//! - ECDSA
33//! - ECDH
34//!
35//! ### Post-Quantum
36//! - Kyber (KEM)
37//! - Dilithium (Signatures)
38//!
39//! ## Key Derivation Functions
40//! - HKDF
41//! - PBKDF2
42//! - Argon2
43//!
44//! ## Hash Functions & XOFs
45//! - SHA-2 family (SHA-256, SHA-384, SHA-512)
46//! - SHAKE (SHAKE128, SHAKE256)
47//!
48//! # Quick Start
49//! ```rust
50//! use seal_crypto::prelude::*;
51//!
52//! // Symmetric encryption example
53//! # #[cfg(feature = "aes-gcm-default")]
54//! # {
55//! use seal_crypto::schemes::symmetric::aes_gcm::*;
56//! let scheme = Aes256Gcm::default();
57//! let key = Aes256Gcm::generate_key().unwrap();
58//! let nonce = [0u8; 12]; // In practice, use a random nonce
59//! let plaintext = b"Hello, World!";
60//! let ciphertext = Aes256Gcm::encrypt(&key, &nonce, plaintext, None).unwrap();
61//! let decrypted = Aes256Gcm::decrypt(&key, &nonce, &ciphertext, None).unwrap();
62//! assert_eq!(plaintext, &decrypted[..]);
63//! # }
64//! ```
65//!
66//! # Feature Flags
67//! The library uses feature flags to enable specific algorithms and reduce binary size:
68//! - `std`: Enable standard library support (enabled by default)
69//! - `aes-gcm-default`: Enable AES-GCM implementations
70//! - `chacha20-poly1305-default`: Enable ChaCha20-Poly1305 implementations
71//! - `rsa-default`: Enable RSA implementations
72//! - `kyber-default`: Enable Kyber post-quantum KEM
73//! - `dilithium-default`: Enable Dilithium post-quantum signatures
74//! - And many more...
75//!
76//! `seal-crypto` 库提供了一套纯粹的、基于 Trait 的加密能力抽象和实现。
77//!
78//! 此库提供了一种全面的、模块化的密码学方法,专注于类型安全、性能和易用性。
79//! 它通过统一的基于 trait 的接口提供传统和后量子密码算法。
80//!
81//! # 设计理念
82//! - **类型安全**: 广泛使用类型系统防止误用
83//! - **模块化**: 抽象和实现之间的清晰分离
84//! - **性能**: 优化的实现,在可用时使用硬件加速
85//! - **安全性**: 恒定时间实现和安全默认值
86//! - **灵活性**: 支持 `std` 和 `no_std` 环境
87//!
88//! # 核心组件
89//! - **Traits**: 加密操作的抽象接口
90//! - **Schemes**: 高级的、用户友好的实现
91//! - **Systems**: 低级算法实现
92//! - **Errors**: 全面的错误处理
93//!
94//! # 支持的算法
95//! ## 对称密码学
96//! - AES-GCM (128, 256 位密钥)
97//! - ChaCha20-Poly1305
98//! - XChaCha20-Poly1305
99//!
100//! ## 非对称密码学
101//! ### 传统算法
102//! - RSA (OAEP, PSS)
103//! - ECDSA
104//! - ECDH
105//!
106//! ### 后量子算法
107//! - Kyber (KEM)
108//! - Dilithium (签名)
109//!
110//! ## 密钥派生函数
111//! - HKDF
112//! - PBKDF2
113//! - Argon2
114//!
115//! ## 哈希函数和 XOF
116//! - SHA-2 系列 (SHA-256, SHA-384, SHA-512)
117//! - SHAKE (SHAKE128, SHAKE256)
118//!
119//! # 快速开始
120//! ```rust
121//! use seal_crypto::prelude::*;
122//!
123//! // 对称加密示例
124//! # #[cfg(feature = "aes-gcm-default")]
125//! # {
126//! use seal_crypto::schemes::symmetric::aes_gcm::*;
127//! let scheme = Aes256Gcm::default();
128//! let key = Aes256Gcm::generate_key().unwrap();
129//! let nonce = [0u8; 12]; // 实际使用中,请使用随机 nonce
130//! let plaintext = b"Hello, World!";
131//! let ciphertext = Aes256Gcm::encrypt(&key, &nonce, plaintext, None).unwrap();
132//! let decrypted = Aes256Gcm::decrypt(&key, &nonce, &ciphertext, None).unwrap();
133//! assert_eq!(plaintext, &decrypted[..]);
134//! # }
135//! ```
136//!
137//! # 特性标志
138//! 库使用特性标志来启用特定算法并减少二进制大小:
139//! - `std`: 启用标准库支持(默认启用)
140//! - `aes-gcm-default`: 启用 AES-GCM 实现
141//! - `chacha20-poly1305-default`: 启用 ChaCha20-Poly1305 实现
142//! - `rsa-default`: 启用 RSA 实现
143//! - `kyber-default`: 启用 Kyber 后量子 KEM
144//! - `dilithium-default`: 启用 Dilithium 后量子签名
145//! - 以及更多...
146
147pub mod errors;
148pub mod prelude;
149pub mod schemes;
150
151pub(crate) mod systems;
152pub(crate) mod traits;
153
154pub use ::zeroize;
155
156#[cfg(feature = "secrecy")]
157pub use ::secrecy;