Skip to content

Build from source

Building (Multi-OS)

Important

This library integrates the following cryptographic primitives and dependencies:

Note

Dependency source of truth: third-party source is vendored under vendor/. Built dependency headers and libraries are normalized under build/deps/<platform>/; the top level of that directory contains only include/ and lib/ after a successful dependency build.

For maintainer-only upstream Git histories and update commands, see vendor/README.md. Source stays vendored; ordinary clones do not require submodule initialization.

1. Clone the repository

git clone https://github.com/WanThinnn/Hybrid-PQ-CP-ABE.git
cd Hybrid-PQ-CP-ABE

Required toolchains include CMake, Rust/Cargo, GNU Make, and a native C/C++ compiler with C++17 support (the default native build standard). Use the Go version declared in the TKN20 module and check the Vault module when building the plugin. Windows also requires the MSVC x64 build tools and MinGW-w64 gcc for Go CGO/TKN20.

The root VERSION file holds the official version used by the website and release packaging. Native and WASM builds use it by default. To build the development version, select VERSION-DEV with the VERSION_FILE environment variable or a Make command-line variable:

:: Windows: x64 Native Tools Command Prompt
set VERSION_FILE=VERSION-DEV
make -j8
:: Return to the official version in this session:
set VERSION_FILE=
$env:VERSION_FILE = 'VERSION-DEV'
make -j8
Remove-Item Env:VERSION_FILE
# Linux/macOS/WSL: applies only to this command
VERSION_FILE=VERSION-DEV make -j8
# Also works for WASM:
make wasm VERSION_FILE=VERSION-DEV -j8

make VERSION_FILE=VERSION-DEV -j8 also works in Windows cmd or PowerShell. Make generates include/hybrid_pq_cp_abe/version.h and embeds the selected value in the library and CLI. Switching version files works even when the selected file is older than the header; unchanged values preserve the header timestamp. The version is fixed at build time, so deployed binaries do not read either version file or the environment variable at runtime. This option selects the compiled version only; release packaging continues to use the official VERSION file.

Linux native builds probe stack protector, stack-clash protection, glibc FORTIFY and PIE/linker support before compiling. FORTIFY uses level 3 when the selected compiler/libc support it, then level 2; the probe emits the actual flags in the dependency build log. Core libraries retain PIC, while the CLI uses PIE. ELF shared libraries and the CLI use a non-executable stack and full RELRO/NOW. The core export map preserves the declared C and C++ APIs. CET is not enabled.

Windows native builds enable GS and CFG with explicit ASLR/NX/high-entropy linker flags. SDL applies to C/C++ builds except covercrypt.cpp, whose existing getenv calls fail under MSVC SDL (C4996); no diagnostic is globally suppressed. Rust MSVC dependencies enable CFG; the Go/MinGW TKN20 DLL uses its own GNU PE linker flags and is not claimed to have CFG. CET is not enabled. Full ABI, wheel and runtime regression validation is performed separately from these build settings.

2. Configure for your machine

The single configure file checks the host toolchain without installing or downloading anything. Missing tools produce a nonzero exit status. Use --install explicitly to install missing tools; OS installers may request administrator access or interactive completion.

Check-only does not create activation scripts. If the check passes and the current terminal already has the tools on PATH, continue directly to the build steps. Do not source/call a missing activation file. If tools are missing, or configure finds them but your terminal cannot run them, use the install command to generate activation, then activate in this same terminal. Installation only adds tools that are missing or too old.

Linux / macOS

Run these commands in a Unix shell from the repository root. No Make or Python installation is needed to start the check:

chmod +x configure
./configure

If the check passes and your shell can run the tools, continue to step 3. Otherwise, install missing tools and generate activation:

./configure --install
. ./build/tools/activate.sh

For a custom Linux/macOS toolchain with an explicitly controlled PATH, use HCPABE_CONFIGURE_DISCOVER_PATHS=0 ./configure. This disables automatic search paths for bundled Go, Cargo and Homebrew; ordinary checks retain discovery by default. Configure tests use this mode so runner-installed tools cannot hide the missing/old tool versions being tested.

Linux installation supports apt, dnf, pacman and zypper. Go is downloaded from the official Go release metadata with SHA256 verification when needed. macOS uses Apple Command Line Tools and Homebrew; finish any Apple installer dialog and rerun configure --install if prompted. Rust uses the official rustup installer. After installation, run subsequent make commands in the same activated shell. Activation adds local tools to this shell's PATH.

Windows

Prerequisite: install the Microsoft C++ build tools and use an x64 Native Tools Command Prompt for all native make commands.

  1. Download Build Tools for Visual Studio or Visual Studio from the official Microsoft downloads page. In Visual Studio Installer, select Desktop development with C++, including the MSVC x64/x86 build tools and a Windows SDK. If these components are already installed, keep your existing installation. See Microsoft's command-line setup guide for details.

  2. Open the Start menu, search for x64 Native Tools Command Prompt, and open the shortcut for your installed Visual Studio version (for example, x64 Native Tools Command Prompt for VS 2022 or VS 2026). Use this one cmd session for setup, activation, build and tests.

  3. From that x64 cmd, enter your repository directory:

    cd /d D:\path\to\Hybrid-PQ-CP-ABE
    

    Check only — report missing tools without installing or generating an activation script:

    powershell.exe -NoProfile -Command ^
        "$text = Get-Content .\configure -Raw;" ^
        "$setup = [scriptblock]::Create(($text -split '(?m)^# WINDOWS CONFIGURE\r?$', 2)[1]);" ^
        "& $setup"
    

    If the check passes and tools are already on this cmd session's PATH, continue to step 3 without activation. A missing activate.cmd is expected after check-only. Configure can discover tools in its child process that are not yet on the parent cmd's PATH; in that case, generate activation below.

    Install missing tools and generate activation — use this when setup or activation is needed:

    powershell.exe -NoProfile -Command ^
        "$text = Get-Content .\configure -Raw;" ^
        "$setup = [scriptblock]::Create(($text -split '(?m)^# WINDOWS CONFIGURE\r?$', 2)[1]);" ^
        "& $setup -Install"
    

    Both commands run PowerShell as a child process and return to the same cmd. The ^ characters continue the command across lines in cmd; copy the whole block. The install command uses WinGet and MSYS2's package manager for MSYS2/Make/CMake/MinGW, Go and Rust. If WinGet is missing, install Microsoft App Installer first.

    Only after successful install/script generation, activate in the same cmd:

    call build\tools\activate.cmd
    

    If using generated activation, run it in each new build session. It adds Windows system utilities, MSYS2/Make, Go and Rust to PATH and prepares MSVC x64. The MSYS2 location comes from configure (MSYS2_ROOT, or C:\msys64 by default).

    To verify linker priority:

    where.exe cl.exe
    where.exe link.exe
    

    The first link.exe result must be the MSVC linker under your Visual Studio installation. Activation preserves existing MSVC tool paths ahead of MSYS2.

Continue with steps 3–5 in the same x64 cmd session, using its existing environment or the activation generated above.

WebAssembly (both platforms): Use sh ./configure --wasm to check, or sh ./configure --wasm --install to install missing WASM tools, including Emscripten and Rust nightly. If the check passes in an already configured shell, build directly. After install, activate the generated activate-wasm.sh (Unix/MSYS2) or activate-wasm.cmd (cmd) before building. See the WebAssembly guide for the full command sequence.

3. Build native dependencies

make deps -j8
This builds Crypto++, liboqs, the SDK-owned AC17 CP-ABE bridge, CIRCL, CoverCrypt and the PDF/CMS bridge. liboqs is configured as a minimal ML-KEM + ML-DSA build only: ML-KEM-512/768/1024 and ML-DSA-44/65/87. The -jN budget is distributed across the dependency builds without oversubscribing the requested total.

Dependency output

build/deps/<platform>/
├── include/
│   ├── cryptopp/
│   ├── liboqs/
│   ├── rabe/
│   └── tkn20/
└── lib/
    ├── cryptopp/
    ├── liboqs/
    ├── rabe/
    └── tkn20/
Temporary CMake/Cargo/Go/Crypto++ build trees are removed after success. Fingerprint metadata is kept inside each lib/<dep>/ directory so unchanged dependencies can be skipped on the next build.

4. Build the Hybrid-CP-ABE native core

make -j8
The core consumes headers and libraries directly from build/deps/<platform>/. Every native make -jN checks dependency input fingerprints and staged-output SHA-256 records before compiling the core. Unchanged dependencies retain their outputs and timestamps. Source, configuration, flags or toolchain changes rebuild the affected dependencies; missing or modified staged files also invalidate the cache. Python 3 is required (python on Windows, python3 on Linux/macOS).

build/deps/<platform>/lib/.ready is written atomically only after all five dependencies have valid output records (including the separate Crypto++ DLL on Windows). The marker is unchanged on a cache hit. The .integrity.json records are local cache checks, not signed provenance or protection against someone who can replace both a binary and its checksum record. Existing caches without these records rebuild once.

5. Run tests

make test -j8

On Windows, run these commands in the x64 Native Tools Command Prompt prepared in step 2. Windows uses the MSVC x64 ABI; the SDK RABE bridge targets x86_64-pc-windows-msvc, while CIRCL uses Go/MinGW only behind a C ABI DLL plus an MSVC import .lib.

The native C++ library, Crypto++, and liboqs use the dynamic MSVC runtime (/MD). Crypto++ still links as a static .lib. The dependency builder removes byte-identical duplicate archive members from the Rust static library while preserving its symbols and COFF linker indexes.

After make, the build prints the exact include, dependency-library, native-library, shared-library, runtime-DLL, and CLI output paths. include/ and lib/ at the repository root are project-only: include/hybrid_pq_cp_abe/ contains the public Hybrid-CP-ABE API, while lib/ contains the project static and shared libraries side by side. All third-party headers/libraries stay exclusively under build/deps/<platform>/.

Normal core builds are incremental. Use make clean only to remove the project core/object output. Use make clean-deps to remove the complete dependency output for the current platform.

Run built Windows artifacts

The configured x64 developer shell is required for the source-build commands above, including make test, which can compile test executables. It is not required to run the resulting CLI or an application linked against the SDK.

After building, you can close the developer shell and use ordinary CMD, PowerShell or Git Bash. Keep the required runtime DLLs beside the executable and ensure the Microsoft Visual C++ x64 runtime is installed. Headers and .lib files are build/link inputs, not runtime files. For shell-specific examples, see running the Windows file-encryption example and running the prebuilt CLI.

Windows C compiler setup

This section concerns applications using the prebuilt SDK, not rebuilding the SDK itself. A normal PowerShell, CMD, Git Bash or MSYS2 shell can compile a C application when a suitable compiler is available. The shell does not decide which compiler you must use.

For the PowerShell example, make Windows GCC available as gcc. If necessary, install a native Windows GCC toolchain following MSYS2's installation instructions. Use a 64-bit Windows compiler, not a Linux/WSL compiler or the MSYS /usr/bin/gcc.

If you already have the tested MINGW64 compiler in C:\msys64\mingw64\bin, add it to this PowerShell session and check its version:

$env:Path = "C:\msys64\mingw64\bin;$env:Path"
gcc --version

Adjust that directory if your compiler is installed elsewhere. MSYS2 also provides other compiler environments; the concrete compatibility checks below used MINGW64.

Tested C application compatibility

The downloaded Windows v6.1.0 SDK was tested with the documentation's demo.c, the packaged headers, libhybrid-pq-cp-abe_dll.lib, and its two runtime DLLs. Every successful check compiled the application, ran AC17 setup, key generation, encryption and decryption, and compared the recovered file byte for byte. The library itself was not rebuilt.

Shell Compiler Compile and file round trip
Ordinary CMD MSYS2 MinGW-w64 GCC 15.2.0 Passed
Windows PowerShell 5.1 Same GCC Passed
PowerShell 7 Same GCC Passed
Git Bash Same GCC, compiler directory first in PATH Passed
MSYS2 MINGW64 Bash Same GCC Passed
CMD with the MSVC developer environment initialized MSVC x64 Passed

GCC linked directly to the SDK's existing DLL import .lib; generating a different import library was not necessary for this C example. These checks cover the public C API with shared-library linking. They do not establish compatibility with the SDK's static C++ archive or every third-party compiler.

For Git Bash, put the compiler directory first inside the shell before compiling, so Git's bundled tools do not take precedence:

export PATH="/c/msys64/mingw64/bin:$PATH"
gcc --version

With the SDK path assigned to SDK, the corresponding C compilation command is:

gcc -std=c17 -DUSE_DLL -I"$SDK/include" demo.c "$SDK/lib/libhybrid-pq-cp-abe_dll.lib" -o demo.exe

Use a Bash SDK path such as /c/Users/alex/Downloads/..., and keep the two packaged DLLs beside the executable. In ordinary CMD the same GCC command works with %SDK% in place of $SDK. MSVC remains another option in a configured developer shell; the native library source build above continues to use MSVC on Windows.

Choose the C++ standard

The native Makefile defaults to CXX_STANDARD ?= c++17. Override it on the command line or through the environment to select a standard supported by your compiler. For example, to build and test with C++20 on Linux, macOS, or Windows:

make clean
make -j8 CXX_STANDARD=c++20
make test -j8 CXX_STANDARD=c++20

Pass the same value to each build and test invocation. Run make clean when changing standards because Make does not track compiler flag changes; existing objects would otherwise be reused. This only requires rebuilding the native core, so you can keep the staged dependencies.

CXX_STANDARD supplies -std=c++20 to GCC/Clang or /std:c++20 to MSVC in the example above. It controls the native core, CLI, and C++ tests; dependency and WebAssembly builds use their own settings. Prefer this variable when changing only the standard: setting CXXFLAGS on the Make command line replaces the complete default flag list, including include paths and optimization flags.

The C header compatibility check in make test compiles crypto_params.c as C and filters C++ standard flags from that command. Choosing C++17, C++20, or another C++ standard therefore does not pass an incompatible C++ flag to the C compiler mode.

See build/README.md for the output layout. Keep logs under build/logs/, local reports under build/reports/, and temporary fixtures under build/tmp/. Reusable diagnostic scripts live in scripts/diagnostics/.

Available Make Commands

  • make deps -j8: Build/check the five native dependencies and print their final include/library layout.
  • make -j8: Check the dependency cache, rebuild dependencies as needed, then build the native C++ core incrementally.
  • make clean-deps: Remove build/deps/<platform>/.
  • make static: Build only the project static library.
  • make shared: Build only the project shared library.
  • make executable: Build only the CLI executable.
  • make test -j8: Incrementally build and run the tests.
  • make tests -j8: Alias for make test -j8.
  • make install: Install the CLI, public headers, and native static/shared libraries to the system. On Windows, the default prefix is %LOCALAPPDATA%\Programs\pq-cp-abe with bin/, include/, and lib/ subdirectories.
  • make vault -j8: Build the Vault plugin on Linux against the current shared core.
  • make test-vault -j8: Build/test on Linux, then run HTTP tests with only the Vault service in Docker.
  • make clean-vault: Remove only the Linux Vault plugin output under build/artifacts/linux/vault/.
  • make abi-info: Show the platform ABI/toolchain policy.
  • make clean: Remove only project core/object output.

If installed, sccache is used automatically where supported. liboqs prefers Ninja when available.

On Windows, make deps builds Crypto++ as both a static library and an ordinary, non-FIPS DLL with the upstream DLL API. build/deps/windows/lib/cryptopp/ contains libcryptopp.lib (static), cryptopp.dll, and cryptopp.lib (DLL import library). DLL consumers include cryptopp/dll.h first and link cryptopp.lib.

Repository Layout

src/                    C++ core implementation only
include/                Public C/C++ API
bindings/python/        Python binding
bindings/ffi/circl/           Project-owned Go/C bridge for CIRCL TKN20
plugins/vault/          Optional HashiCorp Vault plugin
bindings/wasm/                WebAssembly SDK
bindings/npm/                 npm package distribution
bindings/ffi/covercrypt/      Native Rust/C bridge for CoverCrypt
bindings/ffi/pqc-underskrift/   Native Rust/C bridge for PDF/CMS
vendor/cryptopp/        Vendored Crypto++ source
vendor/liboqs/          Vendored Open Quantum Safe source
vendor/rabe/            MIT-licensed RABE backend
bindings/ffi/rabe/      SDK-owned AC17 CP-ABE-only bridge
vendor/circl/           Vendored Cloudflare CIRCL v1.6.4 source
vendor/cover_crypt/     Vendored Cosmian CoverCrypt source
lib/                    Generated/prebuilt native libraries
tests/cpp/              Native test suite
build/artifacts/        Core build output grouped by platform

src/ is intentionally reserved for the project's C++ implementation. Optional integrations, bindings, and third-party source live outside it. Core build artifacts are grouped under build/artifacts/<platform>/; dependency output remains under build/deps/<platform>/.