SecurityRonin/elephant-diffuser

GitHub: SecurityRonin/elephant-diffuser

纯 Rust 实现的 BitLocker Elephant Diffuser 扩散变换原语,填补了 RustCrypto 生态中缺失的这一格式特定组件。

Stars: 0 | Forks: 0

# elephant-diffuser [![Crates.io](https://img.shields.io/crates/v/elephant-diffuser.svg)](https://crates.io/crates/elephant-diffuser) [![Docs.rs](https://img.shields.io/docsrs/elephant-diffuser?label=docs.rs)](https://docs.rs/elephant-diffuser) [![Rust 1.81+](https://img.shields.io/badge/rust-1.81%2B-blue.svg)](https://www.rust-lang.org) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) [![Sponsor](https://img.shields.io/badge/sponsor-h4x0r-ea4aaa?logo=githubsponsors)](https://github.com/sponsors/h4x0r) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/SecurityRonin/elephant-diffuser/actions/workflows/ci.yml) [![Coverage](https://img.shields.io/badge/coverage-100%25%20lines-brightgreen.svg)](docs/validation.md) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance) [![Security advisories](https://img.shields.io/badge/advisories-clean-success.svg)](https://rustsec.org) **作为独立且无依赖的 Rust 原语实现的 BitLocker Elephant Diffuser — 这是 RustCrypto 生态中任何 crate 都未提供的 BitLocker 扇区加密算法的唯一部分, 已针对真实卷上的 `libbde` 完成了逐字节的验证。** BitLocker 的 CBC+diffuser 方法(`0x8000``, `0x8001`)在 AES-CBC 之外包裹了一个带密钥的 字节混合层——即 Elephant Diffuser。AES、CBC、CCM 和 SHA-256 都有经过审计的 crate; 但 diffuser 并没有。这个 crate 就是那个缺失的部分,它从 `bitlocker-core` 中提取出来, 以便每个使用者都能共享同一个经过审查的实现。 ``` use elephant_diffuser::{decrypt, encrypt}; let mut sector = vec![0u8; 512]; let sector_key = [0u8; 32]; // caller-derived (BitLocker: AES-ECB over the offset with the TWEAK key) // Decrypt: Diffuser B, then Diffuser A, then XOR the sector key. decrypt(&mut sector, §or_key); // Encrypt is the exact inverse: XOR, then Diffuser A, then Diffuser B. encrypt(&mut sector, §or_key); ``` ## 它是什么(以及不是什么) Elephant Diffuser 是一种**带密钥的、可逆的扩散变换**,而不是一种加密算法: 它不保存任何密钥,也不提供机密性。在 AES-CBC 解密*之后*(以及 AES-CBC 加密*之前*)应用于扇区时, 它将每一个比特扩散到整个扇区中,从而实现单比特改动的雪崩效应。机密性由 AES 提供; 这只是环绕其外的扩散层。 - `decrypt(sector, sector_key)` — Diffuser B → Diffuser A → 异或 32 字节的 sector key。 - `encrypt(sector, sector_key)` — 完全相反的操作:异或 → Diffuser A → Diffuser B。 两者均原地操作,适用于任意长度的扇区(BitLocker 使用 512 字节的扇区)。 ## 为什么需要手写——有文档记载的唯一例外 通用原则是*永远不要手写加密算法——使用经过审计的 crate*。而 Elephant Diffuser 是个例外, 因为**根本不存在相应的 crate**:这是一种特定格式的变换,仅由 Microsoft 的实现以及 社区在 `dislocker`(`diffuser.c`)和 `libbde` 中的逆向工程所定义。旋转常数 (`Ra = {9,0,13,0}`,`Rb = {0,10,0,25}`)、5 轮和 3 轮的循环计数,以及 B→A→异或的顺序 均遵循该参考实现。将其隔离在一个 crate 中——经过审查、模糊测试以及基于真实数据的验证—— 正是为了确保这一例外情况保持严谨。 ## 信任但验证 - **`#![forbid(unsafe_code)]`,无 panic,零依赖。** 生产代码中没有使用 `unwrap`/`expect`; 每一个索引均通过无下溢的模运算进行计算,因此该变换对于任何输入长度都不会引发 panic。 一个 `cargo-fuzz` 目标在任意字节上驱动 `decrypt`/`encrypt` 运行,以保持“绝不 panic”的不变量。 - **基于真实数据的一级验证。** 权威证明是 `bitlocker-core` 的 oracle: 这段代码针对 `pybde` 逐字节解密了真实的 dfvfs `bdetogo.raw` 卷。它是**基于真实数据针对 `libbde` 进行正确性验证的, 而非经过独立的安全审计**——这是一种带密钥的扩散变换,而不是一种具有秘密分支的加密算法。请参阅 [`docs/validation.md`](docs/validation.md)。 [隐私政策](https://securityronin.github.io/elephant-diffuser/privacy/) · [服务条款](https://securityronin.github.io/elephant-diffuser/terms/) · © 2026 Security Ronin Ltd
标签:BitLocker, DNS 反向解析, Rust, 可视化界面, 密码学, 手动系统调用, 数据解密, 磁盘加密, 网络流量审计, 通知系统