重构:RustCrypto 兼容接口

主要变更:
- 新增 sm2/、sm3/、sm4/ 独立 crate,实现 RustCrypto traits
  - sm2:实现 signature、elliptic-curve traits
  - sm3:实现 digest、crypto-common traits
  - sm4:实现 cipher、aead traits
- 新增 fuzz/ 模糊测试目标
- 新增 tests/sm2_proptest.rs 属性测试
- 重构 src/sm4/ 使用 RustCrypto AEAD traits
- 更新 CI 工作流支持多 crate 测试
- 更新 .gitignore 忽略 fuzz/target/
This commit is contained in:
huangxt
2026-03-11 18:32:21 +08:00
parent 21e7e65b32
commit a4ca734d0d
36 changed files with 5184 additions and 961 deletions
+26 -10
View File
@@ -1,15 +1,14 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use libsmx::sm4::{sm4_encrypt_ecb, Sm4Key};
use libsmx::sm4::Sm4Key;
fn bench_sm4_ecb(c: &mut Criterion) {
let mut group = c.benchmark_group("SM4-ECB");
fn bench_sm4_block_encrypt(c: &mut Criterion) {
let mut group = c.benchmark_group("SM4-block");
let key = [0u8; 16];
for size in [16usize, 1024, 65536] {
let data = vec![0u8; size];
group.bench_with_input(BenchmarkId::new("encrypt", size), &data, |b, d| {
b.iter(|| sm4_encrypt_ecb(&key, d));
});
}
let sm4 = Sm4Key::new(&key);
group.bench_function("encrypt_block", |b| {
let mut block = [0u8; 16];
b.iter(|| sm4.encrypt_block(&mut block));
});
group.finish();
}
@@ -20,5 +19,22 @@ fn bench_sm4_key_new(c: &mut Criterion) {
});
}
criterion_group!(benches, bench_sm4_ecb, bench_sm4_key_new);
fn bench_sm4_throughput(c: &mut Criterion) {
let mut group = c.benchmark_group("SM4-throughput");
let key = [0u8; 16];
let sm4 = Sm4Key::new(&key);
for size in [16usize, 1024, 65536] {
let mut data = vec![0u8; size];
group.bench_with_input(BenchmarkId::new("encrypt", size), &size, |b, _| {
b.iter(|| {
for chunk in data.chunks_exact_mut(16) {
sm4.encrypt_block(chunk.try_into().unwrap());
}
});
});
}
group.finish();
}
criterion_group!(benches, bench_sm4_block_encrypt, bench_sm4_key_new, bench_sm4_throughput);
criterion_main!(benches);