lidailin0730/CipherNebula

GitHub: lidailin0730/CipherNebula

高性能后量子零知识证明框架,提供模块化密码学原语、形式化验证的算术库及格基密码学实现,加速隐私计算与区块链安全协议的部署。

Stars: 135 | Forks: 11

# CipherNebula:高性能零知识证明框架 [![C/C++](https://img.shields.io/badge/C/C++-11%2B-blue.svg)](https://isocpp.org/) [![GitHub Stars](https://img.shields.io/github/stars/lidailin0730/CipherNebula)](https://github.com/lidailin0730/CipherNebula/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/lidailin0730/CipherNebula?style=social)](https://github.com/lidailin0730/CipherNebula/network/members) [![Watchers](https://img.shields.io/github/watchers/lidailin0730/CipherNebula?style=social)](https://github.com/lidailin0730/CipherNebula/watchers) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/lidailin0730/CipherNebula/pulls) ## 🌐 项目愿景 构建一个**后量子安全**的零知识证明 (ZKP) 生态系统,集成密码学原语、优化算法和工程工具。CipherNebula 专为区块链、隐私计算和安全多方计算而设计,通过模块化设计和工业级性能加速 ZKP 的部署。 ## 🚀 核心功能 ### 1. 🧠 通用 ZKP 开发模板 一个用于在各种密码学场景下构建 ZKP 电路的模块化工具包: #### 基础操作套件 - **有限域引擎** - 任意精度算术:`add`、`sub`、`mul`、`div`、`scalar_mul` - 自定义域支持:通过 `field_params.h` 定义素数/特征 - 性能:使用 SIMD 向量化针对 64 位架构进行了优化 - **按位逻辑库** - 底层操作:XOR、按位移位、循环移位、掩码操作 - 电路友好设计:固定时间实现,以抵御时序攻击 - **群论抽象** - 椭圆曲线群(BN254、Secp256k1)和乘法群 - 支持 zk-SNARKs/STARKs 风格证明的双线性配对 ### 2. 🔄 环域取模修复(C 语言) 解决了 C 语言 `%` 运算符在环域中长期存在的符号歧义问题: - **数学准确性**:对负数强制执行 `a mod n ∈ [0, n)` - **API 设计**:提供用于类型安全计算的 `safe_mod(a, n)` 和 `ring_sub(a, b, n)` - **用例**:对于多项式承诺方案和基于格的密码学至关重要 ### 3. ⚛️ 后量子 LWE 模块 Learning-with-Errors (LWE) 问题的强化实现: - **算法**:采用带有分块 SWEEP 的 BKZ 2.0 进行格基规约 - **安全级别**:通过 `lwe_params.h` 支持 128 位/256 位安全性 - **互操作性**:兼容 Kyber/Saber 后量子加密标准 ### 4. 🛡️ ElGamal 加密工具链 具有同态扩展的工业级实现: - **功能**: - 密钥生成 (`elgamal_keygen`)、加密 (`elgamal_encrypt`)、解密 (`elgamal_decrypt`) - 加法同态:`encrypt(a) + encrypt(b) = encrypt(a+b)` - **性能套件**: - 吞吐量基准测试:使用 `tests/benchmark.py` 与 RSA/ECC 进行对比 - 内存分析:兼容 Valgrind,适用于低延迟优化 ## 🛠️ 技术优势 | **优势** | **详情** | |-----------------------------|-----------------------------------------------------------------------------| | **全栈覆盖** | 从汇编优化的原语到高级证明系统(例如 Groth16) | | **形式化验证** | 核心算术模块通过 Coq/ACL2 验证,实现零计算错误 | | **后量子就绪** | 基于格的基础架构,抵御未来的量子攻击 | | **多语言支持** | C/C++ 核心带有 Rust FFI 绑定(参见 `rust-bindings/` 目录) | ## 🌱 快速开始 ### 1. 环境设置 ``` # 依赖 (Ubuntu/Debian) sudo apt update && sudo apt install -y \ build-essential cmake \ libgmp3-dev libntl-dev \ valgrind python3-benchmark # macOS (Homebrew) brew install gmp ntl cmake ``` ### 2. 代码结构 ``` ├── src/ │ ├── crypto/ # Cryptographic primitives (field, group, lattice) │ ├── algorithms/ # ZKP algorithms (Groth16, ElGamal, LWE) │ ├── utils/ # Core utilities (modulo fix, memory management) │ └── bindings/ # Rust/Python interface stubs ├── examples/ # Ready-to-run ZKP demos (e.g., hash proof, circuit satisfiability) ├── tests/ # Unit tests & fuzzing (via Google Test) └── docs/ # API references & mathematical specifications ``` ### 3. 编译 ``` mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=RELEASE # Debug: -DCMAKE_BUILD_TYPE=DEBUG make -j$(nproc) ``` ### 4. 首个证明示例 ``` // Generate a simple proof for "3 * 4 = 12" #include "zkp_prover.h" int main() { ZKPSystem system = zkp_init("arithmetic_circuit"); zkp_add_witness(system, 3, 4); zkp_generate_proof(system); bool valid = zkp_verify_proof(system); printf("Proof validity: %s\n", valid ? "VALID" : "INVALID"); return 0; } ``` ## 📖 文档 - **API 参考**:[Doxygen 生成的文档](https://lidailin0730.github.io/CipherNebula/) - **数学规范**:`docs/design/arithmetic.pdf`(域操作) & `docs/design/lattice.pdf`(LWE) - **贡献指南**:[CONTRIBUTING.md](https://github.com/lidailin0730/CipherNebula/blob/main/CONTRIBUTING.md) ## ⚖️ 许可证 在 **MIT License** 下发布,允许商业使用、修改和分发。详情请参阅 [LICENSE](https://github.com/lidailin0730/CipherNebula/blob/main/LICENSE)。 #### 特定模块编译指南 ##### 1. **证明生成与验证(示例工作流)** ``` # 导航到你的项目目录 cd [your_project_path] # 构建带 debug symbols 的 proof generator gcc -std=c99 [proof_source].c -fopenmp -lssl -lcrypt -lcrypto [required_libs] -o [proof_executable] -g # 构建 verifier gcc -std=c99 [verifier_source].c -fopenmp -lssl -lcrypt -lcrypto [required_libs] -o [verifier_executable] -g # 执行示例 Generate proof: ./[proof_executable] Verify proof: ./[verifier_executable] [output_file] # Replace with your actual output file ``` ##### 2. **算法编译(例如密码学原语)** ``` cd [algorithm_directory] # Replace with your module path gcc -std=c99 [core_source].c -fopenmp -lssl -lcrypt -lcrypto [dependent_libs] -o [algorithm_executable] -g ``` ##### 3. **基于格的密码学程序** ``` cd [lattice_tool_directory] gcc -std=c99 [lattice_source].c -fopenmp -lssl -lcrypt -lcrypto -lgmp -o [lattice_executable] -g ``` ##### 4. **加密算法(例如 ElGamal)** ``` # 进入算法目录 cd [encryption_module_path] # 构建优化 release version gcc -std=c99 -O3 -fopenmp -o [encryption_executable] [source_file].c -lssl -lcrypto -lrt # 执行工作流 Encrypt: ./[encryption_executable] encrypt [plaintext_file] Decrypt: ./[encryption_executable] decrypt [ciphertext_file] ``` ##### 5. **框架编译(例如 zkboo)** ``` cd [framework_directory] # Replace with your framework path gcc -std=c99 [framework_source].c -fopenmp -lssl -lcrypt -lcrypto -o [framework_executable] -g ``` #### 调试与优化提示 ``` # GDB 调试(需要生成 core file: ulimit -c unlimited) gdb [executable] core # Debug with core dump # Release build(移除 debug symbols,提升性能) gcc -std=c99 [source_file].c -fopenmp -lssl -lcrypt -lcrypto [required_libs] -O3 -o [executable] ``` #### 路径与依赖说明 1. **路径约定**: - 将所有的 `[your_project_path]`/`[module_directory]` 替换为您实际的文件路径。 - 对于 Windows 系统,请使用绝对路径(例如 `C:\Project\Module`)。 2. **依赖安装**: - 通过包管理器安装所需的库(例如 `libgmp`、`libssl`)。 - 根据您项目的依赖关系调整库标志(`-lgmp`、`-lm`)。 3. **自定义**: - 根据您的硬件和用例(调试/发布)修改编译标志(例如 `-fopenmp`、`-O3`)。 本指南支持为不同模块编译可执行文件,助力调试、性能优化和加密功能扩展。发布构建请使用 `-O3`,并使用 `ulimit -c unlimited` 配置调试环境以进行调试。 ## 贡献与反馈 欢迎通过 **GitHub Issues** 提交错误报告或功能建议。高质量的 PR 将被优先合并。 - [项目仓库](https://github.com/your-project-url) - [Issue 跟踪器](https://github.com/your-project-url/issues) **CipherNebula:构建隐私计算的未来** [GitHub](https://github.com/lidailin0730/CipherNebula) • [网站](https://ciphernebula.org) • [Twitter](https://twitter.com/CipherNebula) **构建安全可信的下一代密码学基础设施,加速隐私计算的普及应用**
标签:Bash脚本, C++, 区块链, 后量子密码学, 安全测试工具, 密码学, 手动系统调用, 数据擦除, 通知系统, 隐私计算, 零知识证明