添加性能基准测试数据

- README 添加 Benchmarks 章节,包含 SM3/SM4/SM2/SM9 性能数据
- CHANGELOG 同步更新基准测试性能基线
This commit is contained in:
huangxt
2026-03-07 20:23:16 +08:00
parent 86998a169e
commit a7eaf413d9
4 changed files with 94 additions and 0 deletions
+5
View File
@@ -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
+5
View File
@@ -32,6 +32,11 @@
- 库级别强制 `#![forbid(unsafe_code)]`
- 通过 `zeroize::ZeroizeOnDrop` 自动清零私钥
- 所有算法的 GB/T 标准测试向量
- 所有算法的 Criterion 基准测试及性能基线数据:
- SM3374 MiB/s 吞吐量(64 KiB
- SM4-ECB27 MiB/s 吞吐量(64 KiB
- SM2 签名:258 µs,验签:316 µs
- SM9 签名:3.44 ms,验签:5.50 ms
### 安全
+42
View File
@@ -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)
+42
View File
@@ -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** |
### SM2256 位椭圆曲线)
| 操作 | 耗时 |
|------|------|
| 密钥生成 | 221 µs |
| 签名 | 258 µs |
| 验签 | 316 µs |
| 加密 | 639 µs |
| 解密 | 417 µs |
### SM9BN256 双线性配对)
| 操作 | 耗时 |
|------|------|
| 主密钥生成 | 753 µs |
| 用户密钥派生 | 324 µs |
| 签名 | 3.44 ms |
| 验签 | 5.50 ms |
| 加密 | 4.68 ms |
| 解密 | 1.54 ms |
本地运行基准测试:
```bash
cargo bench
```
## 安全性
- 所有涉密操作均为常量时间(固定迭代次数 + 掩码选择,消除数据依赖分支)