diff --git a/CHANGELOG.md b/CHANGELOG.md index ef106be..094d7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `#![forbid(unsafe_code)]` enforced at crate level - Automatic private key zeroization via `zeroize::ZeroizeOnDrop` - GB/T standard test vectors for all algorithms +- Criterion benchmarks for all algorithms with baseline performance data: + - SM3: 374 MiB/s throughput (64 KiB) + - SM4-ECB: 27 MiB/s throughput (64 KiB) + - SM2 sign: 258 µs, verify: 316 µs + - SM9 sign: 3.44 ms, verify: 5.50 ms ### Security diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 5977075..8b599c6 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -32,6 +32,11 @@ - 库级别强制 `#![forbid(unsafe_code)]` - 通过 `zeroize::ZeroizeOnDrop` 自动清零私钥 - 所有算法的 GB/T 标准测试向量 +- 所有算法的 Criterion 基准测试及性能基线数据: + - SM3:374 MiB/s 吞吐量(64 KiB) + - SM4-ECB:27 MiB/s 吞吐量(64 KiB) + - SM2 签名:258 µs,验签:316 µs + - SM9 签名:3.44 ms,验签:5.50 ms ### 安全 diff --git a/README.md b/README.md index eee3b9d..e0c03f1 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,48 @@ For `no_std` without `alloc`: libsmx = { version = "0.3", default-features = false } ``` +## Benchmarks + +Measured on Linux x86_64 (single core). All operations are constant-time. + +### Throughput + +| Algorithm | Data Size | Time | Throughput | +|-----------|-----------|------|------------| +| SM3 hash | 64 B | 349 ns | — | +| SM3 hash | 1 KiB | 2.80 µs | — | +| SM3 hash | 64 KiB | 167 µs | **374 MiB/s** | +| SM4-ECB encrypt | 16 B | 1.14 µs | — | +| SM4-ECB encrypt | 1 KiB | 37.0 µs | — | +| SM4-ECB encrypt | 64 KiB | 2.32 ms | **27 MiB/s** | + +### SM2 (256-bit ECC) + +| Operation | Time | +|-----------|------| +| Key generation | 221 µs | +| Sign | 258 µs | +| Verify | 316 µs | +| Encrypt | 639 µs | +| Decrypt | 417 µs | + +### SM9 (BN256 pairing-based) + +| Operation | Time | +|-----------|------| +| Master keygen | 753 µs | +| User keygen | 324 µs | +| Sign | 3.44 ms | +| Verify | 5.50 ms | +| Encrypt | 4.68 ms | +| Decrypt | 1.54 ms | + +Run benchmarks locally: + +```bash +cargo bench +``` + ## Security - All secret-dependent operations are constant-time (fixed iteration counts, mask-based selection) diff --git a/README.zh-CN.md b/README.zh-CN.md index d223379..b57570e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -191,6 +191,48 @@ libsmx = { version = "0.3", default-features = false } 无 `alloc` 时,SM3 哈希、SM3 HMAC、SM2 签名/验签、SM4 ECB 仍可用(固定大小数组 API)。 +## 基准性能 + +测试环境:Linux x86_64(单核)。所有操作均为常量时间。 + +### 吞吐量 + +| 算法 | 数据量 | 耗时 | 吞吐量 | +|------|--------|------|--------| +| SM3 哈希 | 64 B | 349 ns | — | +| SM3 哈希 | 1 KiB | 2.80 µs | — | +| SM3 哈希 | 64 KiB | 167 µs | **374 MiB/s** | +| SM4-ECB 加密 | 16 B | 1.14 µs | — | +| SM4-ECB 加密 | 1 KiB | 37.0 µs | — | +| SM4-ECB 加密 | 64 KiB | 2.32 ms | **27 MiB/s** | + +### SM2(256 位椭圆曲线) + +| 操作 | 耗时 | +|------|------| +| 密钥生成 | 221 µs | +| 签名 | 258 µs | +| 验签 | 316 µs | +| 加密 | 639 µs | +| 解密 | 417 µs | + +### SM9(BN256 双线性配对) + +| 操作 | 耗时 | +|------|------| +| 主密钥生成 | 753 µs | +| 用户密钥派生 | 324 µs | +| 签名 | 3.44 ms | +| 验签 | 5.50 ms | +| 加密 | 4.68 ms | +| 解密 | 1.54 ms | + +本地运行基准测试: + +```bash +cargo bench +``` + ## 安全性 - 所有涉密操作均为常量时间(固定迭代次数 + 掩码选择,消除数据依赖分支)