ocamba is a library to replace expressions (+, -, ^, &, |) by their MBA (Mixed-Boolean Arithmetics) equivalents. All of ocamba's work is done in compile time, via PPX.
ocamba's MBAs are Linear, not Polynomial.
To use ocamba, you must add it as a dependency in your project's dune file and register it as a preprocessor for the relevant executables or libraries.
(executable
(name main)
(preprocess (pps ocamba))
)
; Optionally you can see the transformed code after invoking "dune build", use:
; (flags :standard -source)Usage is exemplified within this project's main.ml.
The extension's structure follows:
[%mba ({N}, {E})]
Where {N} controls the recursion depth of the transformations, and {E} is the expression to be transformed.
An example of a transformed expression is:
let normal_add = x + y
let obfuscated_add =
((((((lnot x) land y) + (x land (lnot y))) + (2 * (x land y))) lor
((((lnot x) land y) + (x land (lnot y))) + (2 * (x land y))))
+ ((((lnot x) land y) + (x land (lnot y))) + (2 * (x land y))))
-
((lnot ((((lnot x) land y) + (x land (lnot y))) + (2 * (x land y)))) land
((((lnot x) land y) + (x land (lnot y))) + (2 * (x land y))))