← Back to section · Tutorials & Labs

Building liboqs from Source: A Walkthrough of the Build Options

Skip the distribution packages and compile liboqs yourself with CMake: what the algorithm-selection, distribution-build and OpenSSL options actually do, and how to validate the result with the library's own tests.

Published 22 November 2026 · 5 min read · PQ Frontier

Building liboqs from Source: A Walkthrough of the Build Options
AI-generated site artwork
Video explainer · Using PQC libraries: install and go

In the previous hands-on lab we called liboqs through its Python binding. But where does the C library underneath come from, and why does the same source tree produce binaries that behave slightly differently on different machines? Building liboqs from source is worth a walkthrough in its own right: the library treats every algorithm as a pluggable module, and CMake options decide which algorithms and which implementation paths get compiled in. This tutorial goes through the key options one by one and ends with a validation routine. One caveat up front: liboqs is a research and prototyping library — its own documentation says it is not a production-grade cryptographic library — so we build it for learning, evaluation and integration experiments.

Preparation and the basic flow

Building liboqs requires CMake (the Ninja generator is recommended), a C compiler (GCC, Clang or MSVC all work) and optionally the OpenSSL development files. On a Debian-based system the typical preparation is installing packages such as build-essential, cmake, ninja-build and libssl-dev. One step that is easily skipped when fetching the source: pin the version. After cloning the official repository, check out a formal release tag before building instead of staying on the ever-moving main branch — the main branch adds and removes algorithms and adjusts interfaces continuously, so a command that builds today may fail tomorrow. Record the version together with the build command and base every experiment on that same source snapshot; this is both a reproducibility requirement and the first thing to check when a colleague’s machine refuses to build. With the source cloned from the Open Quantum Safe project’s official repository and pinned, the standard flow is just three steps: create a build subdirectory, run cmake -GNinja .. inside it to configure, then ninja to compile, and finally ninja install to place headers and libraries on the system path (usually /usr/local by default). The flow is deliberately plain: every tunable behaviour is funnelled into CMake configuration variables, so understanding the options is the same as understanding the build.

Selecting algorithms: OQS_ALGS_ENABLED and minimal builds

liboqs contains many algorithms, and compiling all of them is slow and produces a bloated library. The OQS_ALGS_ENABLED option accepts a filter expression with several common settings: All enables everything; STD enables only algorithms that are standardized or on the way to standardization; settings such as NIST_R4 select the candidate set of a particular round of the NIST competition. For single-algorithm experiments you can go further with OQS_MINIMAL_BUILD, narrowing the expression down to one algorithm and one parameter set — only ML-KEM-768, say — which cuts compile times from minutes to seconds and shrinks the resulting library considerably. Pruning is about more than speed: knowing exactly what is inside the library prevents test code from accidentally calling an algorithm you never intended to study, and a single minimal-build command is far more reproducible for others than a long list of defaults. Note that after changing selection options you should wipe the build directory and configure from scratch; switching incrementally often leaves stale object files behind and produces baffling symbol conflicts.

Distribution builds and implementation paths: OQS_DIST_BUILD

The same C source can produce very different machine code for different CPUs. Many liboqs algorithms ship optimized implementation paths for instruction sets such as AVX2, and by default the build system optimizes for the machine doing the building. That is fine for benchmarking on your own box, but the resulting binary may simply crash on an older machine. OQS_DIST_BUILD exists for exactly this case: with it enabled, the build stops optimizing aggressively for the build machine and instead compiles multiple implementation paths in, dispatching at runtime according to CPU capabilities — which yields a distributable artefact. A companion option lets you pin the optimization target to a specific microarchitecture. The rule of thumb: leave it off for local benchmarks where you want peak performance; turn it on for anything you ship, put into a container image, or produce in continuous integration. Recording the build machine’s model in your experiment notes is also the most commonly forgotten step when trying to reproduce someone else’s performance numbers.

The OpenSSL relationship: OQS_USE_OPENSSL

Some internal components of liboqs — certain hash function implementation paths, for example — can borrow the system OpenSSL’s libcrypto, or use the library’s own implementations throughout; OQS_USE_OPENSSL controls this. Turning it on reuses maintained, possibly hardware-accelerated hashing from the system and builds faster; turning it off produces a fully self-contained library whose behaviour does not depend on the system OpenSSL’s version or configuration and is therefore more predictable. Neither choice is universally better, but the choice must be written into your build record: comparing benchmark numbers across the two configurations can attribute differences to the hash implementation rather than the algorithm, one of the most common hidden flaws in evaluation reports. Also note that liboqs depending on OpenSSL is an implementation-level borrowing only — a completely different matter from plugging algorithms into the OpenSSL protocol stack with oqs-provider, covered in another article in this series.

After the build: run the built-in tests before your own code

Once ninja finishes, resist the urge to write calling code immediately. liboqs ships its own test programs: from the build tree you can run the KAT (known-answer tests) to verify that every enabled algorithm reproduces the standard test vectors byte for byte, run the speed test programs to get key generation, encapsulation, signing and verification timings on your machine, and use the hash and randomness tests to confirm the basic components are healthy. The value of this step is a clean line of responsibility: if the KATs pass, the build artefact itself is trustworthy, and wrong results later point at your own calling code; if a KAT fails, suspect the compiler version, optimization flags or pruning configuration before suspecting the algorithm implementations. Making “self-test first, experiment second” a habit saves hours of aimless debugging. Finally, record the full cmake command line together with the compiler and OS versions — that is your environment specification, more precise than any verbal description when you need to reproduce a result or ask for help.

Tags: liboqsCMakesource build