← Back to section · Software & Developer Tools
Inside liboqs: Two API Families, Compile-Time Assembly, and Language Bindings
A look at how liboqs organizes its KEM and signature interfaces, assembles algorithms at build time, and reaches other languages through bindings — and how to integrate it correctly as an evaluation platform.
If you could pick only one library to learn what post-quantum algorithms actually look like in code, liboqs would be the right starting point. It is the core library of the Open Quantum Safe (OQS) project, written in C, and it gathers more than a dozen post-quantum key encapsulation and signature algorithms under a single interface. Rather than repeating the usual list of which algorithms it covers, this article takes it apart: how the interface is organized, how algorithms are assembled, how bindings distribute it, and which path an integration into a real project should take.
Two families: one call shape for KEM and SIG
The interface design of liboqs has a distinctive trait: whether the underlying algorithm is lattice-, hash-, or code-based, it converges externally into two families. The key encapsulation family offers three operations — key generation, encapsulation, decapsulation; the signature family offers key generation, signing, and verification. A caller first obtains an algorithm object by name string, then performs operations through a uniform set of functions (the following is an illustrative sketch; consult the official documentation for exact names):
/* Illustrative: interface shape only; see the liboqs docs for details */
OQS_KEM *kem = OQS_KEM_new("ML-KEM-768");
OQS_KEM_keypair(kem, public_key, secret_key);
OQS_KEM_encaps(kem, ciphertext, shared_secret, public_key);
OQS_KEM_decaps(kem, shared_secret, ciphertext, secret_key);
This “same shape, different name” design is extremely friendly to evaluation work: one test harness can iterate over every algorithm and produce comparable figures for key sizes, ciphertext sizes, and timing. The price is weaker compile-time checking — a misspelled algorithm name only fails at runtime — so evaluation code should assert early that the algorithm object is non-null.
Compile-time assembly: algorithms as removable parts
liboqs is built with CMake, and its algorithms are organized as switchable modules: at build time you can enable only the algorithms you need, and choose whether platform-specific optimized implementations are compiled in. This matters on three levels. First, research setups can compile every candidate into a single binary for side-by-side comparison. Second, embedded or constrained environments can keep only the target algorithm and control the footprint. Third, a single algorithm often exists in the library both as a readability-first reference implementation and as an optimized variant for a particular instruction set, and the build options decide which one is used.
For integrators this means “the performance of liboqs” is not a fixed number but a function of the build configuration: compiler, target architecture, and enabled options can change results severalfold. Any benchmark figure based on liboqs should be quoted together with its build configuration, or it is not comparable.
Bindings: distributing a C interface to many languages
Few people write raw C calls in production code; most meet liboqs through a binding. The OQS project maintains several binding lines covering ecosystems such as C++, Go, Python, Rust, .NET, and Java (their maintenance status varies — check each repository’s current notes before relying on one). Bindings all do roughly the same work: they translate C-level buffer management into the host language’s idioms, for example wrapping public keys, secret keys, and shared secrets as native byte arrays or objects, and they take care of memory release.
The binding layer is also a risk layer: it decides how errors propagate, how long key material lingers in memory, and whether the host language’s garbage collector might copy sensitive buffers. When evaluating a binding, look beyond the algorithm list to whether its handling of key objects matches the security conventions of the host language.
The correct integration path: evaluate first, migrate second
The official documentation of liboqs is explicit about its positioning: the library is intended for research and prototyping, and direct dependence on it in production is not recommended. This is not modesty but engineering fact — its interface evolves with the algorithm evaluation process, and its compatibility promises between versions are weaker than those of production libraries. A sound integration path therefore has three steps: use liboqs to establish feasibility and rough performance magnitudes over the target algorithm set; map the selection conclusions onto a production-oriented library (for example, the implementation already integrated into your protocol stack); and carry away the test vectors and benchmarking methodology rather than the library itself.
For teaching and standards tracking, liboqs has one more unique value: new algorithms and parameter sets tend to become available here first, making it a window onto the standardization process. Mistaking the window for a door is the one misunderstanding to avoid when integrating it.
Reproducibility of evaluation experiments: record versions and configurations
One more engineering discipline is easily overlooked when evaluating with liboqs: conclusions must be reproducible. The algorithm set and implementation details of liboqs evolve between versions, and an algorithm’s parameters and performance can change across releases; layered on top are the configuration differences from compile-time assembly. A conclusion such as “algorithm A is this much faster than algorithm B” only means something once the library version, build options, compiler, and hardware are recorded. Sound practice is to freeze the evaluation environment into a rebuildable build script and to write algorithm names, parameter sets, and test-vector versions into the evaluation report, so that when standards or implementations move on, old conclusions can be re-run verbatim and compared item by item instead of being argued from memory.
This discipline also explains liboqs’s real place in industrial evaluation processes: what it produces is not final numbers that can be pasted into a procurement document, but a repeatable measurement method and order-of-magnitude judgements. Archive the method, and annotate figures with their provenance and environment, and evaluation results stay transferable between teams and fresh over time. It is also a deep difference in documentation culture between research and production libraries: the former assumes readers will re-run the experiments; the latter assumes readers will run the same binary for years.
The integration conclusion in one sentence
The whole article condenses into one operational conclusion: liboqs belongs in your evaluation lab, your teaching environment, and your standards-tracking list — not in a production system’s dependency list. Its interface uniformity makes algorithm comparison cheap, its compile-time assembly makes experimental configurations flexible, and its binding ecosystem lets teams in many languages start at low cost; all three are optimized for “finding out where things stand”, not for “running stably for years”. Keep those two optimization directions distinct and the integration decision cannot go wrong: use liboqs to settle the accounts of algorithms, parameters, and performance, then hand the conclusions to a library built for production to execute.
References
- Open Quantum Safe project and liboqs documentation: https://openquantumsafe.org/
- liboqs source repository and build instructions: https://github.com/open-quantum-safe/liboqs
- NIST post-quantum cryptography standardization project: https://csrc.nist.gov/projects/post-quantum-cryptography
Tags: liboqsOQSAPI designprototyping