seyyedarashazimi/dgsp
GitHub: seyyedarashazimi/dgsp
DGSP 是一种基于 SPHINCS+ 的纯 Rust 后量子全动态群签名方案,解决大规模用户群体中兼顾匿名性、可追踪性与抗量子威胁的签名问题。
Stars: 10 | Forks: 1
# DGSP
[](https://github.com/seyyedarashazimi/dgsp/actions/workflows/rust.yml)
[](https://seyyedarashazimi.github.io/dgsp/)
[](https://crates.io/crates/dgsp)
## 概述
DGSP 是一种高效且可扩展的后量子全动态群签名方案,完全使用纯 Rust 实现。它利用
SPHINCS+ 签名方案来提供安全、可扩展且高效的群签名机制,从而
抵御未来的量子计算威胁。
DGSP 支持:
- 高达 260 个用户的庞大用户群。
- 紧凑的密钥对和签名大小。
- 高效的签名和验证流程。
- 针对正确性、不可伪造性、匿名性和可追踪性的安全保证。
- 管理员行为可被裁决。
此实现针对性能和模块化进行了优化,使其成为密码学研究
以及需要长期安全性的现实应用场景的有力选择。
## DGSP 论文
要获取有关 DGSP 群签名方案的更多信息,请参阅论文:https://eprint.iacr.org/2025/760
## API 文档
完整的 API 文档托管于:https://seyyedarashazimi.github.io/dgsp/
它是从源代码自动构建的。
要在本地从源码构建并打开文档:
```
cargo doc --no-deps --open
```
## 功能
### 核心功能
- **密钥生成**:管理员和用户的密钥生成。
- **加入**:通过密码学生成的标识符进行安全的用户注册。
- **签名**:使用高效的基于哈希的密码学原语和预计算的证书对消息进行签名。
- **验证**:验证签名的真实性和有效性。
- **打开**:管理员能够将签名追踪到特定用户,同时不泄露其他用户的匿名性。
- **撤销**:高效的撤销机制,包括撤销用户、其对应的签名以及先前生成的证书。
- **裁决管理员**:评估管理员的行为,确保管理员将给定的签名正确打开至一个 ID。
### 密码学原语
- **高效的基于哈希的密码学操作**:
- 根据 SPHINCS+ 参数,利用 SHA-2 和 SHAKE 变体的优势。
- **SPHINCS+ 封装器**:
- 提供密钥生成、签名和验证的实用工具,简化了 SPHINCS+ 的使用。
- **WOTS+ (Winternitz One-Time Signature Plus)**:
- 作为 DGSP 的基础签名原语。
- 支持唯一地址派生,以确保抵抗多目标攻击。
- **AES**:
- 扮演强伪随机置换的角色,以实现可追踪性。
### 安全性
- 构建于 **SPHINCS+** 之上,这是一种无状态的基于哈希的签名方案。
- 能够抵抗量子对手。
- 提供 **用户匿名性**、**不可伪造性**、**可追踪性** 和 **正确性**。
- 确保不再需要的敏感密码学材料通过清零操作从内存中安全擦除。
- 管理员的行为可被审计和裁决。
### 可扩展性与效率
- 支持多达 260 名用户。
- 新用户的添加和撤销是无缝且高效的。
- 提供内存和磁盘存储后端。
- 使用 rayon crate 进行并行化操作,提升性能。
- 无需设置和初始化时间。
### 存储接口
- **PLMInterface** (Private List Manager Interface,私有列表管理员接口):
- 存储与用户相关的数据,例如用户名、活动状态和证书计数器。
- 提供添加新用户、停用用户、管理已颁发证书的计数器以及通过 ID 或用户名检索用户信息的功能。
- 支持内存和磁盘存储后端,提供了灵活性。
- 将 DGSP 与存储实现解耦,使其能够与其他数据库系统集成。
- **RevokedListInterface**:
- 管理已撤销证书的列表,并确保被撤销的签名失效。
- 使用优化的数据结构支持高效插入和检查已撤销的证书。
- 旨在与内存和磁盘存储系统无缝协作。
- 允许 DGSP 独立于存储实现运行,支持与各种数据库系统集成。
库本身提供了上述接口的内存和磁盘实现。不过,开发者也可以根据自己的数据库和需求实现这两个接口。
## 基准测试
### DGSP 时间基准测试
我们在一台使用 Rust 1.84.0 (stable) 并开启 release 模式运行的 Ubuntu 24.04 电脑上进行了测试。测试在
Intel® Core™ i7-4702MQ CPU @ 2.20 GHz、配备 16 GiB 内存的机器上完成。为了保持结果稳定,我们仅使用了
单个处理器核心,并关闭了超线程和睿频加速。测试结果为 100 次测试运行的平均值。请注意,在实际中,
像 Gen Cert 这样最耗时的操作将并行执行,因为代码支持多线程。
所有基准测试时间均以毫秒为单位。
#### `sphincs_shake_256f` 功能的 DGSP 时间基准测试
```
| DB feature | in-memory | in-disk |
| GROUP SIZE | 2^10 | 2^25 | 2^10 | 2^25 |
| BATCH SIZE | 1 | 8 | 1 | 8 | 1 | 8 | 1 | 8 |
|----------------|--------|--------|--------|--------|--------|--------|--------|--------|
| Manager KeyGen | 3.0521 | 3.0534 | 3.0536 | 3.0545 | 3.0585 | 3.0594 | 3.0546 | 3.0558 |
| Join | 0.0030 | 0.0030 | 0.0029 | 0.0029 | 0.0259 | 0.0255 | 0.0278 | 0.0287 |
| CSR | 1.3630 | 10.985 | 1.3626 | 10.988 | 1.3982 | 11.045 | 1.4025 | 11.051 |
| Gen Cert | 61.451 | 491.53 | 61.552 | 491.55 | 61.910 | 495.04 | 61.596 | 492.15 |
| Sign | 1.3875 | 1.3870 | 1.3886 | 1.3869 | 1.4196 | 1.4202 | 1.4186 | 1.4192 |
| Verify | 2.7706 | 2.7678 | 2.7808 | 2.7725 | 2.7626 | 2.7670 | 2.7667 | 2.7778 |
| Open | 0.6798 | 0.6948 | 0.6987 | 0.7043 | 0.6957 | 0.6978 | 0.6831 | 0.6954 |
| Judge | 0.6917 | 0.6912 | 0.7014 | 0.6937 | 0.6914 | 0.6728 | 0.6878 | 0.6877 |
| Revoke | 0.0007 | 0.0027 | 0.0008 | 0.0027 | 0.0305 | 0.0754 | 0.0259 | 0.0909 |
```
#### `sphincs_shake_256s` 功能的 DGSP 时间基准测试
```
| DB feature | in-memory | in-disk |
| GROUP SIZE | 2^10 | 2^25 | 2^10 | 2^25 |
| BATCH SIZE | 1 | 8 | 1 | 8 | 1 | 8 | 1 | 8 |
|----------------|--------|--------|--------|--------|--------|--------|--------|--------|
| Manager KeyGen | 48.888 | 48.892 | 48.921 | 48.886 | 48.802 | 48.923 | 48.882 | 48.919 |
| Join | 0.0030 | 0.0030 | 0.0029 | 0.0029 | 0.0250 | 0.0263 | 0.0272 | 0.0280 |
| CSR | 1.3552 | 10.894 | 1.3556 | 10.905 | 1.4094 | 11.126 | 1.4117 | 11.137 |
| Gen Cert | 582.70 | 4661.6 | 583.53 | 4661.6 | 582.93 | 4664.1 | 583.52 | 4667.4 |
| Sign | 1.3847 | 1.3835 | 1.3863 | 1.3848 | 1.4418 | 1.4396 | 1.4874 | 1.4813 |
| Verify | 1.8255 | 1.8248 | 1.8207 | 1.8180 | 1.8515 | 1.8561 | 1.8571 | 1.8529 |
| Open | 0.6991 | 0.6881 | 0.6901 | 0.6911 | 0.7137 | 0.7060 | 0.7197 | 0.7237 |
| Judge | 0.6806 | 0.6813 | 0.6744 | 0.6798 | 0.7016 | 0.6987 | 0.7016 | 0.6986 |
| Revoke | 0.0012 | 0.0044 | 0.0012 | 0.0046 | 0.1773 | 0.0733 | 0.0322 | 0.0797 |
```
### DGSP 管理员密钥和签名大小
所有大小均以字节为单位。
```
| SPHINCS+ feature | Public Key | Secret Key | Signature |
|--------------------|------------|------------|-----------|
| sphincs_sha2_128f | 32 | 96 | 17696 |
| sphincs_sha2_128s | 32 | 96 | 8464 |
| sphincs_sha2_192f | 48 | 144 | 36952 |
| sphincs_sha2_192s | 48 | 144 | 17512 |
| sphincs_sha2_256f | 64 | 192 | 52080 |
| sphincs_sha2_256s | 64 | 192 | 32016 |
| sphincs_shake_128f | 32 | 96 | 17696 |
| sphincs_shake_128s | 32 | 96 | 8464 |
| sphincs_shake_192f | 48 | 144 | 36952 |
| sphincs_shake_192s | 48 | 144 | 17512 |
| sphincs_shake_256f | 64 | 192 | 52080 |
| sphincs_shake_256s | 64 | 192 | 32016 |
```
## 安装说明
### 前置条件
DGSP 完全使用 Rust 实现。请通过 [rustup](https://rustup.rs/) 安装 Rust。
- **最低支持的 Rust 版本 (MSRV):** 1.63.0
- **本 README 中用于基准测试的 Rust 版本:** 1.84.0 (stable)
- **用于基准测试的平台:** Ubuntu 24.04, Intel® Core™ i7-4702MQ @ 2.20 GHz, 16 GiB 内存
### 依赖项
下表列出了所有直接依赖项及其使用的版本:
| 依赖项 | 版本 | 备注 |
|:-----------------------|:--------|:-----------------------------------------------------------|
| `aes` | 0.8.4 | 用于可追踪性的 AES 分组密码 |
| `pqcrypto-sphincsplus` | 0.7.0 | SPHINCS+ 签名方案 |
| `pqcrypto-traits` | 0.3.5 | pqcrypto crate 的 trait |
| `rand` | 0.8.5 | 随机数生成 |
| `rayon` | 1.10.0 | 数据并行计算 |
| `thiserror` | 2.0.11 | 错误类型派生 |
| `zeroize` | 1.8.1 | 安全内存擦除 |
| `bincode` | 1.3.3 | 二进制序列化 (可选,`in-disk`) |
| `serde` | 1.0 | 序列化框架 (可选,`serialization`) |
| `serde_json` | 1.0 | JSON 序列化 (可选,`in-disk`) |
| `serde-big-array` | 0.5.1 | 对大型数组的 Serde 支持 (可选,`serialization`) |
| `sha2` | 0.10.8 | SHA-2 哈希函数 (可选,`sphincs_sha2_*`) |
| `sha3` | 0.10.8 | SHA-3/SHAKE 哈希函数 (可选,`sphincs_shake_*`) |
| `sled` | 0.34.7 | 嵌入式数据库 (可选,`in-disk`) |
开发依赖项:`criterion` 0.5 (基准测试), `tempfile` 3.15 (测试), `tracing-test` 0.2.5 (测试)。
### Docker (本地 Rust 安装的替代方案)
Docker Hub 上提供了一个预构建的 Docker 镜像,它提供了一个完全自包含的环境,其中已编译了 Rust 1.84.0 和所有依赖项:
```
docker pull arashazimi/dgsp
```
运行端到端示例:
```
docker run --rm arashazimi/dgsp cargo run --example simple --release
```
运行完整的测试套件:
```
docker run --rm arashazimi/dgsp cargo test --release
```
运行基准测试(例如:内存模式,`sphincs_shake_256f`):
```
docker run --rm arashazimi/dgsp \
cargo bench --bench dgsp_full_in_memory \
--no-default-features --features "in-memory benchmarking sphincs_shake_256f"
```
从项目根目录开始,复现所有论文基准测试配置并将日志检索到主机:
```
docker run --name dgsp_bench arashazimi/dgsp bash -c "cd benches && bash all_benchmarks.sh"
docker cp dgsp_bench:"$(docker exec dgsp_bench sh -c 'ls -d /dgsp/benches/log_*')" benches/
docker rm -f dgsp_bench
```
然后在主机上解析结果(需要 Python 3,无需额外依赖项):
```
python3 benches/parse_benchmarks.py
```
要从源码在本地构建镜像:
```
docker build -t arashazimi/dgsp .
```
### 将 DGSP 添加到您的项目
要将 DGSP 作为库使用,请将其添加到您的 `Cargo.toml` 中:
```
[dependencies]
dgsp = "0.1.2"
```
要在安装期间启用特定功能,请参考以下示例:
```
[dependencies]
dgsp = { version = "0.1.2", default-features = false, features = ["in-disk", "sphincs_shake_256f"] }
```
## 基本用法
### 管理员设置
生成管理员密钥,并打开管理员的私有列表和公开撤销列表数据库:
```
use dgsp::*;
// generate manager keypairs:
let (pkm, skm) = DGSP::keygen_manager().unwrap();
// generate plm and revoked_list using in-memory feature
let plm = InMemoryPLM::open("").unwrap();
let revoked_list = InMemoryRevokedList::open("").unwrap();
// or generate plm and revoked_list using in-disk feature
use std::path::PathBuf;
let path = PathBuf::new();
let plm = InDiskPLM::open(&path).unwrap();
let revoked_list = InDiskRevokedList::open(&path).unwrap();
```
### 用户设置
用户加入系统并获取其唯一的 ID 和密码学标识符:
```
let username = "alice";
let (id, cid_star) = DGSP::join(&skm.msk.hash_secret, username, &plm).unwrap();
```
用户还需要生成一个私有种子:
```
let seed_u = DGSP::keygen_user();
```
### CSR、证书与签名
创建一批证书签名请求:
```
let batch_size = 8;
let (wots_pks, mut wots_seeds) = DGSP::csr(&seed_u, batch_size);
```
管理员生成相应的证书:
```
let mut certs = DGSP::gen_cert(&skm, id, &cid_star, &wots_pks, &plm).unwrap();
```
用户对消息进行签名:
```
let message = b"Hello, DGSP!";
let signature = DGSP::sign(message, &seed_u, id, &cid_star, wots_seeds.pop().unwrap(), certs.pop().unwrap());
```
### 验证
验证签名:
```
DGSP::verify(message, &signature, &revoked_list, &pkm).unwrap();
```
### 打开
管理员可以打开签名以查明是谁对其进行了签名:
```
let (signer_id, signer_username, proof) = DGSP::open(&skm.msk, &plm, &signature, message).unwrap();
```
### 裁决
对管理员进行裁决,确保给定的签名和消息被正确打开至该用户 ID:
```
DGSP::judge(&signature, message, id, &proof).unwrap();
```
### 撤销
撤销用户及其关联的证书:
```
DGSP::revoke(&skm.msk.aes_key, &plm, &[id], &revoked_list).unwrap();
```
要了解更多信息,请参阅 `examples/simple.rs`。可以通过以下命令为特定的 sphincs 功能运行 `simple.rs` 示例:
```
cargo run --example simple --no-default-features --features "in-disk in-memory sphincs_shake_256f" --release
```
## 测试
使用以下命令运行测试:
```
cargo test
```
要测试特定配置,请启用相应的功能标志:
```
cargo test --no-default-features --features "in-disk sphincs_shake_256f"
```
要在类 Unix 操作系统中测试所有配置组合,请运行提供的脚本:
```
bash ./tests/all_features_full_test.sh
```
请注意,完整的测试需要一些时间才能完成。
## 基准测试
使用以下命令运行基准测试:
```
cargo bench --bench dgsp_full_in_disk
cargo bench --bench dgsp_full_in_memory
```
请注意,上述命令将为 Cargo.toml 中选择的默认功能运行基准测试。要选择特定的 SPHINCS+ 功能,请运行:
```
cargo bench --bench dgsp_full_in_disk --no-default-features --features "in-disk benchmarking sphincs_shake_256s"
cargo bench --bench dgsp_full_in_memory --no-default-features --features "in-memory benchmarking sphincs_shake_256s"
```
### 复现论文的基准测试表
要复现论文中报告的全套时间基准测试,请使用提供的脚本遍历所有配置
(两个选定的 SPHINCS+ 变体 × 两种存储后端 × 群组大小 2^10 和 2^25 × 批处理大小 1 和 8):
```
cd benches
bash all_benchmarks.sh
```
该脚本会修改基准测试常量,针对每个配置运行 Criterion,并将原始日志保存在
`benches/log_/in_memory/` 和 `benches/log_/in_disk/` 目录下。
**解析输出:** 脚本执行完毕后,使用 `parse_benchmarks.py`(需要 Python 3,无需额外依赖项)解析日志文件并打印格式化的时间表:
```
python3 benches/parse_benchmarks.py
```
该脚本会自动选择最新的 `log_*` 目录。您也可以显式传入一个路径:
```
python3 benches/parse_benchmarks.py benches/log_
```
每个 Criterion 日志块如下所示:
```
DGSP_in_memory_using_sphincs_shake_256f_with_1024_users_and_1_batch/keygen_manager
time: [3.0519 ms 3.0521 ms 3.0524 ms]
```
这三个数值分别是 100 个样本的置信下限、**平均值** 和置信上限。论文报告的是 **平均值**(中间值)。解析器会提取平均值并将所有数值转换为毫秒。
## 功能标志
该库支持多个用于自定义的功能标志:
- **`in-disk`**:使用 `sled` crate 启用磁盘存储。
- **`in-memory`**:启用内存存储。
- **`serialization`**:启用密码学密钥和结构的序列化。
- **SPHINCS+ 变体**:从基于 SHA-2 或基于 SHAKE 的配置中进行选择,以满足不同的安全级别以及性能/大小目标:
- `sphincs_sha2_128f`
- `sphincs_sha2_128s`
- `sphincs_sha2_192f`
- `sphincs_sha2_192s`
- `sphincs_sha2_256f`
- `sphincs_sha2_256s`
- `sphincs_shake_128f`
- `sphincs_shake_128s`
- `sphincs_shake_192f`
- `sphincs_shake_192s`
- `sphincs_shake_256f`
- `sphincs_shake_256s`
- **`benchmarking`**:用于基准测试目的。
## 源代码组织
```
src/
├── lib.rs # Crate root; re-exports the public API
├── scheme.rs # Core protocol: all DGSP algorithms (keygen_manager, keygen_user,
│ # join, csr, gen_cert, sign, verify, open, judge, revoke) and all
│ # key / signature / certificate type definitions
├── params.rs # Compile-time constants derived from the chosen SPHINCS+ variant
│ # (security level λ, byte sizes for keys, signatures, etc.)
├── db.rs # PLMInterface and RevokedListInterface trait definitions
├── db/
│ ├── in_memory.rs # In-memory PLM and RevokedList (feature: in-memory)
│ └── in_disk.rs # Persistent sled-backed PLM and RevokedList (feature: in-disk)
├── cipher.rs # AES wrapper used for user-ID encryption in traceability
├── hash.rs # Hash function dispatcher (SHA-2 or SHAKE, selected at compile time)
├── hash/ # Per-parameter-set SHA-2 and SHAKE implementations
├── sphincs_plus.rs # SPHINCS+ wrapper: key generation, signing, verification
├── sphincs_plus/ # Per-parameter-set SPHINCS+ constants and ADRS byte-offset tables
├── wots_plus.rs # WOTS+ (Winternitz One-Time Signature Plus) core implementation
├── wots_plus/ # ADRS (address) type used by WOTS+ operations
├── error.rs # Error and Result types (Error, VerificationError)
└── utils.rs # Internal byte-conversion helpers (u32/u64 ↔ big-endian bytes)
benches/
├── dgsp_full_in_memory.rs # Criterion benchmark suite for the in-memory backend
├── dgsp_full_in_disk.rs # Criterion benchmark suite for the in-disk backend
├── bench_utils.rs # Shared helpers (SPHINCS+ feature detection, duration formatting)
├── all_benchmarks.sh # Runs all benchmark configurations and collects log files
└── parse_benchmarks.py # Parses Criterion log files and prints timing tables (run on host)
examples/
└── simple.rs # End-to-end example covering all DGSP operations
tests/
└── all_features_full_test.sh # Iterates over all SPHINCS+ × storage feature combinations
# and runs the full test suite for each
```
## 贡献
欢迎您的贡献!要做出贡献,请:
1. Fork 本仓库。
2. 为您的功能或错误修复创建一个新分支。
3. 提交 Pull request,并详细描述您的更改。
## 许可证
本仓库基于 [MIT 许可证](https://github.com/seyyedarashazimi/dgsp/blob/main/LICENSE) 授权。
标签:CVE, Rust, SPHINCS+, 加密库, 可视化界面, 后量子密码学, 密码学, 手动系统调用, 数字签名, 网络流量审计, 群签名, 通知系统