SudarsanamR/AEGIS

GitHub: SudarsanamR/AEGIS

Stars: 0 | Forks: 0

# AEGIS — 基于FPGA的自适应防御与神经弹性 **ChipVerse '26 Hackathon 项目** AEGIS 展示了在 FPGA 上完整的侧信道攻击与防御生命周期。从易受攻击的 AES-128 实现开始,我们逐步通过布尔掩码、TRNG 熵源和随机时序进行加固,然后使用经典 DPA 和神经网络攻击验证每种防护措施的有效性。 ## ⚡ 快速开始 ``` # 激活虚拟环境 cd aegis python -m venv venv venv\Scripts\activate # Windows pip install -r requirements.txt # 为所有 3 个设计生成跟踪 python python/trace_collection/collect_traces.py --mode simulate python python/trace_collection/simulate_masked.py python python/trace_collection/simulate_hardened.py # 运行完整演示(DPA + Neural 在所有设计上) python python/demo.py --design all --attack both # 生成 5 图比较套件 python python/analysis/generate_all_plots.py ``` ## 📐 架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ AEGIS System Architecture │ │ │ │ Act 1: Vulnerable Act 2: Masked Act 3: Hardened │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │ │ │ AES Core │ │ AES Masked │ │ AES Hardened │ │ │ │ (plaintext) │ │ (constant │ │ (TRNG mask + │ │ │ │ │ │ mask 0xAC) │ │ timing jitter) │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────────┘ │ │ │ │ │ │ │ DPA breaks it DPA fails, Both DPA and │ │ in ~200 traces NN succeeds NN fail entirely │ └─────────────────────────────────────────────────────────────────┘ ``` ### 设计演进 | 设计 | 防护措施 | DPA 结果 | 神经网络结果 | |--------|----------------|------------|---------------| | **脆弱**(第一阶段) | 无 | ✓ 约 200 条迹被攻破 | N/A | | **掩码化**(第二阶段) | 布尔掩码(恒定种子) | ✗ 未攻破(r≈0.00) | ✓ 被攻破(学习掩码) | | **加固**(第三阶段) | 掩码 + TRNG 种子 + 时序抖动 | ✗ 未攻破 | ✗ 未攻破(每条迹的掩码变化) | ## 📁 仓库结构 ``` aegis/ ├── rtl/ # Verilog HDL modules │ ├── crypto/ # AES-128 encryption cores │ │ ├── aes_subbytes.v # SubBytes (S-Box × 16) │ │ ├── aes_shiftrows.v # ShiftRows (wire permutation) │ │ ├── aes_mixcolumns.v # MixColumns (GF(2^8) arithmetic) │ │ ├── aes_addroundkey.v # AddRoundKey (128-bit XOR) │ │ ├── aes_key_expansion.v # Key Schedule (11 round keys) │ │ ├── aes_core.v # Act 1: Vulnerable AES core │ │ ├── aes_core_masked.v # Act 2: Boolean-masked AES core │ │ └── aes_core_hardened.v # Act 3: Fully hardened AES core │ ├── countermeasures/ # Side-channel defense modules │ │ ├── aes_subbytes_masked.v # Masked S-Box (per-byte mask I/O) │ │ ├── aes_mixcolumns_masked.v# Masked MixColumns (linear passthrough) │ │ ├── mask_refresh.v # 8-bit LFSR mask generator │ │ ├── ring_oscillator_trng.v# 8× ring oscillator TRNG (Spartan-7 LUT1) │ │ ├── trng_validator.v # 10K-bit entropy quality gate (45–55%) │ │ └── timing_randomizer.v # 0–15 random dummy cycles per round │ ├── interface/ # Communication modules │ │ ├── uart_rx.v # UART receiver (9600 baud) │ │ ├── uart_tx.v # UART transmitter │ │ ├── control_fsm.v # System controller (RX→AES→TX) │ │ └── hamming_weight.v # 128-bit popcount (leakage monitor) │ └── top/ # Top-level integration │ ├── aes_masked.v # Act 2 top (UART + masked AES) │ └── aes_hardened.v # Act 3 top (UART + all countermeasures) ├── sim/ # Testbenches (20 files, self-checking) ├── constraints/ # Vivado XDC for Arty S7 │ └── arty_s7.xdc # Clock, UART, LEDs, TRNG Pblock ├── python/ # Analysis & attack framework │ ├── analysis/ # Shared utilities & visualization │ │ ├── aes_utils.py # S-Box, HW model, software AES │ │ ├── generate_all_plots.py # 5-figure comparison suite │ │ ├── plot_results.py # Act 1 result plots │ │ └── key_rank_analysis.py # Key rank overlay plot │ ├── attacks/ # Attack implementations │ │ ├── dpa_attack.py # Classical DPA (Pearson CPA) │ │ ├── neural_attack.py # MLP-based profiling attack │ │ ├── generate_ml_dataset.py# Training data preparation │ │ └── train_mlp.py # MLP training (PyTorch) │ ├── trace_collection/ # Trace simulation scripts │ │ ├── collect_traces.py # Act 1: Unmasked traces │ │ ├── simulate_masked.py # Act 2: Masked traces │ │ └── simulate_hardened.py # Act 3: Hardened traces │ ├── demo.py # Unified demo (argparse CLI) │ └── requirements.txt ├── docs/ # Project documentation │ └── architecture.md # Detailed architecture & security analysis ├── f4pga/ # Open-source synthesis (Yosys) │ ├── synth_vulnerable.ys # Yosys script — Act 1 AES │ ├── synth_hardened.ys # Yosys script — Act 3 AES │ ├── synth_yosys.sh # Shell wrapper │ ├── Makefile # Build automation │ └── README.md # F4PGA setup guide ├── traces/ # Generated trace data (.npy) ├── results/ # Attack results & plots (.png) ├── instructions.txt # Original project specification ├── requirements.txt └── .gitignore ``` ## 🔧 硬件目标 | 参数 | 值 | |-----------|-------| | FPGA | Xilinx Spartan-7 XC7S50 | | 开发板 | Digilent Arty S7-50 | | 系统时钟 | 100 MHz | | AES 时钟 | 50 MHz(分频) | | UART | 9600 波特,8N1 | | TRNG | 8 个环形振荡器,1 MHz 输出 | | 工具链 | Vivado 2024.1+ | ## 🛡️ 防护措施详解 ### 第二阶段:布尔掩码 - **技术**:对所有中间 AES 值进行异或掩码(统一字节掩码) - **实现**:掩码 S-Box 查找(`aes_subbytes_masked.v`),包含掩码输入/输出 - **不变量**:每周期保持 `state_masked == real_state XOR {mask × 16}` - **弱点**:掩码种子恒定(0xAC)→ 神经网络可学习映射关系 ### 第三阶段:TRNG + 时序抖动 - **环形振荡器 TRNG**:8 个并行 3 级振荡器,使用 Spartan-7 LUT1 原语并设置 `KEEP` 与 `DONT_TOUCH` 属性 - **熵验证**:10,000 位窗口,1 的比例必须在 45%–55% - **随机掩码种子**:每次加密从 TRNG 获取一个全新的 8 位种子 (取代第二阶段的恒定 0xAC) - **时序抖动**:在每一轮 AES 之间注入 0–15 个随机哑周期 通过 `round_done`/`proceed` 握手信号控制 - **综合效果**:迹在幅度上被随机化(掩码)且在时间上被移位(抖动) → 无法学习到可识别的模式 ## 🧪 测试 ### Verilog 测试平台 ``` # 使用 Icarus Verilog(或 Vivado Simulator)运行所有测试平台 iverilog -o sim/tb_aes_core rtl/crypto/*.v sim/tb_aes_core.v && vvp sim/tb_aes_core iverilog -o sim/tb_trng sim/tb_ring_oscillator_trng.v rtl/countermeasures/ring_oscillator_trng.v && vvp sim/tb_trng ``` ### Python 攻击脚本 ``` # 完整流水线 python python/trace_collection/collect_traces.py --mode simulate # Act 1 traces python python/attacks/dpa_attack.py # DPA on unmasked python python/trace_collection/simulate_masked.py # Act 2 traces python python/attacks/generate_ml_dataset.py # ML dataset python python/attacks/train_mlp.py # Train neural model python python/attacks/neural_attack.py # Neural on masked python python/trace_collection/simulate_hardened.py # Act 3 traces python python/analysis/generate_all_plots.py # Final 5-figure suite ``` ## 📊 关键结果 | 指标 | 脆弱 | 掩码化 | 加固 | |--------|-----------|--------|---------| | DPA 相关性(正确密钥) | ~0.25 | ~0.00 | ~0.00 | | DPA 密钥排名(5000 条迹) | 0(已攻破) | >100 | >100 | | 神经网络密钥排名(5000 条迹) | N/A | 0(已攻破) | >100 | | 加密延迟 | 13 周期 | 13 周期 | 13–173 周期 | | LUT 利用率 | ~5,000 | ~6,500 | ~7,300 | ## 🔓 开源综合(F4PGA / Yosys) AEGIS 同样可以使用 **全开源** 的 Yosys 综合工具链构建: ``` cd f4pga/ make synth # Synthesize vulnerable AES (Act 1) make synth-hardened # Synthesize hardened AES (Act 3) make stats # Compare resource utilization ``` | 目标 | Yosys LUT 数 | Vivado LUT 数 | 匹配 | |--------|-----------|-------------|-------| | 脆弱(第一阶段) | ~5,200 | ~5,000 | ✓ | | 加固(第三阶段) | ~7,500* | ~7,300 | ✓ | \* 环形振荡器 TRNG 可能被 Yosys 优化掉(不支持 KEEP 属性)。 实际部署 FPGA 时请使用 Vivado 以获得带 TRNG 的结果。 完整设置说明请参考 [`f4pga/README.md`](f4pga/README.md)。 ## 📄 许可证 ChipVerse '26 学术项目。所有代码均为原创作品。
标签:AEGIS, AES-128, ChipVerse, DPA, FPGA, Python, TGT, TRNG, 侧信道攻击, 安全演示, 对比分析, 布尔掩码, 抗侧信道攻击, 攻防演练, 无后门, 时序随机化, 漏洞演示, 硬件安全, 硬防护, 神经弹性, 神经网络攻击, 自适应防御, 芯片安全, 虚拟环境, 赛题项目, 迹线收集, 迹线模拟