C FFI binding for the rabe Rust Attribute-Based Encryption library. It supports both CP-ABE (Ciphertext-Policy) and KP-ABE (Key-Policy) encryption and decryption schemes, including AC17, BSW, AW11, BDABE, MKE08, LSW, and YCT14.
This library is fully updated to rabe 0.4.x (which includes AEAD authenticated encryption) and contains strict memory-safety fixes for robust production use.
Regardless of your operating system, the build process requires:
- Rust Toolchain (nightly): Required because the build script uses
cbindgen'swith_parse_expandfeature to generate C headers from macros. cargo-expand: Required bycbindgento expand Rust macros before generating the C header.- C/C++ Build Tools: MSVC on Windows, GCC/Clang on Linux/macOS.
First, install Rust via rustup, then set up the nightly toolchain and install cargo-expand:
rustup default nightly
cargo install cargo-expand- Install build essentials:
# Debian / Ubuntu sudo apt update && sudo apt install build-essential # Fedora / RHEL sudo dnf groupinstall "Development Tools"
- Clone and build:
git clone https://github.com/WanThinnn/librabe-ffi.git cd librabe-ffi cargo build --release - Output: You will find
librabe_ffi.so(dynamic library),librabe_ffi.a(static library) intarget/release/, andrabe.h(C header) in the project root.
- Install Xcode Command Line Tools:
xcode-select --install
- Clone and build:
git clone https://github.com/WanThinnn/librabe-ffi.git cd librabe-ffi cargo build --release - Output: You will find
librabe_ffi.dylib(dynamic library),librabe_ffi.a(static library) intarget/release/, andrabe.hin the project root.
- Install Visual Studio Build Tools. Ensure you select Desktop development with C++ during installation.
- Make sure you install Rust using PowerShell or CMD (do not use MSYS2/Git Bash to avoid mixing toolchains).
- Clone and build:
git clone https://github.com/WanThinnn/librabe-ffi.git cd librabe-ffi cargo build --release
- Output: You will find
rabe_ffi.dll(dynamic library),rabe_ffi.dll.lib(import library),rabe_ffi.lib(static library) intarget\release\, andrabe.hin the project root.
- Copy the dynamic library (
.so,.dylib, or.dll) to your project directory or system library path. On Windows, you also need the.dll.libfile for linking. - Copy
rabe.hto your project's include directory. - Include the header and link the library during compilation.
Example (AC17 scheme):
#include "rabe.h"
int main() {
Ac17SetupResult keys = rabe_ac17_init();
// ... use keys.public_key, keys.master_key ...
rabe_ac17_free_public_key(keys.public_key);
rabe_ac17_free_master_key(keys.master_key);
return 0;
}Note: For detailed usage of other schemes, refer to the unit tests in the Rust source code (src/cp_abe/ and src/kp_abe/).