Skip to main content

Crate elephant_diffuser

Crate elephant_diffuser 

Source
Expand description

§elephant-diffuser — the BitLocker Elephant Diffuser

The BitLocker Elephant Diffuser as a standalone, dependency-free primitive: Diffuser A, Diffuser B, and the per-sector-key XOR that together form the diffuser stage of BitLocker’s CBC-plus-diffuser sector cipher (encryption methods 0x8000 and 0x8001).

The diffuser is not a cipher and holds no secret — it is a keyed, invertible byte-mixing transform applied to a sector after AES-CBC decryption (and before AES-CBC encryption), spreading each bit across the whole sector. Every other primitive in BitLocker’s cipher (AES, CBC, CCM, SHA-256) has an audited RustCrypto crate; the Elephant Diffuser does not, so it is the one documented exception to “never hand-roll crypto.” The rotation constants and cycle order follow the dislocker (diffuser.c) / libbde reference; correctness is proven in situ by bitlocker-core’s Tier-1 bdetogo.raw-vs-pybde oracle (see docs/validation.md).

let mut sector = vec![0u8; 512];
let sector_key = [0u8; 32]; // caller-derived (BitLocker: AES-ECB over the offset with the TWEAK key)
elephant_diffuser::decrypt(&mut sector, &sector_key);
elephant_diffuser::encrypt(&mut sector, &sector_key); // exact inverse
assert_eq!(sector, vec![0u8; 512]);

Functions§

decrypt
Decrypt one sector in place (the method-0x8000 diffuser order): Diffuser B, then Diffuser A, then XOR the 32-byte sector key. The exact inverse of encrypt. Operates on a sector of any length and never panics.
encrypt
Encrypt one sector in place — the exact inverse of decrypt: XOR the 32-byte sector key, then Diffuser A, then Diffuser B. Operates on a sector of any length and never panics.