> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apich.org/llms.txt
> Use this file to discover all available pages before exploring further.

# ensia

> Next-generation LLVM 21+ compiler obfuscation framework with 15 interleaved passes in a 12-stage cascade.

**Ensia (OLLVM-Next)** is an LLVM-based compiler obfuscation framework rebuilt for modern LLVM toolchains (**LLVM 21, 22, and 23+**), continuing the Hikari lineage for C, C++, Objective-C/Swift, and Rust binaries.

> [!WARNING]
>
> **Dual-Use Tooling Notice:** Ensia is a high-strength compiler protection framework. Read [ETHICS.md](https://github.com/Apich-Organization/ensia/blob/main/ETHICS.md) and [LEGAL.md](https://github.com/Apich-Organization/ensia/blob/main/LEGAL.md) before use.

> [card] [Usage & Integration](https://github.com/Apich-Organization/ensia#usage--integration)
>
> Clang `-fpass-plugin`, `rustc -Z llvm-plugins`, and `ensia.toml` reference on GitHub.

> [card] [Project Homepage](https://apich.org/projects/ensia/)
>
> Pass summary, benchmark tables, and Open Collective budget on apich.org.

> [card] [GitHub Repository](https://github.com/Apich-Organization/ensia)
>
> C++ pass sources, 8 cryptographic benchmark domains, and the CTF crackme suite.

> [card] [Zenodo DOI](https://doi.org/10.5281/zenodo.20149843)
>
> Persistent citation (`10.5281/zenodo.20149843`) and Software Heritage archive.

## Core Philosophy: No Single Point of Failure

Traditional VM-based obfuscators wrap logic inside a central bytecode interpreter loop. Once an analyst recovers the opcode dispatch table, all protected routines collapse at once. Ensia rejects central interpreters and instead interleaves **15 passes across a 12-stage non-linear cascade**, forcing symbolic solvers and dynamic taint analysis into state-space explosion.

```mermaid theme={null}
flowchart TB
    S1["1–4. AntiHooking · FunctionWrapper · FCO · AntiDebugging"] --> S5["5–6. StringEncryption (GF(2^8)) · ConstantEncryption (Phase 1)"]
    S5 --> Loop["7. Per-Function Loop: Sub -> MBA -> Split -> BCF -> CSM/CFF -> Vec"]
    Loop --> S8["8–9. ConstantEncryption (Phase 2) · IndirectBranch (Knuth Hash)"]
    S8 --> S10["10–12. Cleanup Markers · FeatureElimination · LTO Evasion (noinline optnone)"]
```

## Repository Structure & Pass Suite

| Path | Role |
| - | - |
| `obfuscation/Obfuscation.cpp` & `ObfConfig.cpp` | 12-stage cascading pipeline, `ensia.toml` parser, presets, and regex policy engine |
| `obfuscation/ChaosStateMachine.cpp` & `Flattening.cpp` | Q32 fixed-point logistic-map Chaos State Machine (`2³²` states) and branchless CFF fallback |
| `obfuscation/MBAObfuscation.cpp` & `Substitution.cpp` | 42 multivariate non-linear MBA identities over `Z/(2^n)Z` and algebraic substitution |
| `obfuscation/AntiHooking.cpp` & `AntiDebugging.cpp` | Entry prologue guards, direct raw syscalls, hardware debug registers (`DR0-7`), data-flow entanglement |
| `obfuscation/StringEncryption.cpp` & `ConstantEncryption.cpp` | Vernam OTP + Rijndael `GF(2^8)` string stubs with exit zeroization; 2-phase MBA/Feistel constants |
| `obfuscation/VectorObfuscation.cpp` & `IndirectBranch.cpp` | 128/256/512-bit SIMD lifting and Knuth multiplicative encrypted jump tables |
| `obfuscation/RustCompat.cpp` & `compat/llvm22..23/` | Rust frontend plugin compatibility and multi-version LLVM 21–23+ shims |
| `benchmark/` & `ctf/` | 8 cryptographic benchmark domains, 3 evaluation harnesses, and official crackme challenge |

## Support Tiers & Presets

| Tier | Operating Systems | Architectures | Status |
| - | - | - | - |
| **Tier 0** | Linux, Windows (MSVC, `clang-cl`, MinGW) | `x86_64`, `AArch64` | Full support & release blocker |
| **Tier 1** | macOS, FreeBSD | `x86_64`, `AArch64` | Full support (non-blocker) |
| **Tier 2** | OpenBSD, iOS, Android | `RISC-V`, `i386` | Best-effort / issue response |

Presets scale from **`low`** (fast compile, minimal bloat) through **`mid`** (recommended production balance) and **`high`** (all passes including CSM, Feistel constants, AntiHook, AntiDebug, FCO) up to **`max`** (512-bit SIMD lifting, nested 2-level CSM dispatch, 3-round wrappers).

## Benchmarks

![Ensia binary size expansion by cryptographic domain](https://mintcdn.com/apich-organization/-dwr41T2xn7sv5RT/images/bench/size_expansion_light.svg?fit=max\&auto=format\&n=-dwr41T2xn7sv5RT\&q=85\&s=b31f7854973e8ff9405d2478e7af861b)

Mean binary code size expansion under the max profile across 8 cryptographic domains (5.6× PQC to 103.6× asymmetric PKC).

![Ensia symbolic crackme resilience chart](https://mintcdn.com/apich-organization/-dwr41T2xn7sv5RT/images/bench/symbolic_crackme_resilience_light.svg?fit=max\&auto=format\&n=-dwr41T2xn7sv5RT\&q=85\&s=2f47b823cd14c5dc5d5cea61d85d79bb)

Symbolic execution resilience across 79 crackme benchmark targets.

## Integration & Configuration

```toml ensia.toml theme={null}
[global]
preset = "mid"

[passes.bcf]
enabled = true
probability = 60
entropy_chain = true

[passes.string_encryption]
enabled = true
anti_dump = true

[passes.chaos_state_machine]
enabled = true
warmup = 128
```

```bash Clang theme={null}
ENSIA_CONFIG=ensia.toml \
clang -fpass-plugin=/path/to/libEnsia.so -O2 main.c -o main
```

```bash Rust (cargo) theme={null}
ENSIA_CONFIG=ensia.toml RUSTC_BOOTSTRAP=1 \
RUSTFLAGS="-Z llvm-plugins=/path/to/libEnsia_rust.so -C passes=ensia" \
cargo build --release
```


## Related topics

- [Quickstart](https://docs.apich.org/quickstart.md)
- [Security Policy & Release Standards](https://docs.apich.org/guides/security-and-releases.md)
- [Stack Architecture & Project Map](https://docs.apich.org/guides/architecture.md)
- [Apich Organization Documentation](https://docs.apich.org/index.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.