This repository documents the process of building the Python extension of liboqs library.
Pip, Python Hatch, cmake, ninja, and a C compiler (e.g. gcc) are required to build the extension.
- Clone this repository
- If you already have libOQS repository on the system, specify its location by
export LIBOQS_ROOT=/path/to/liboqs - Run
build.shto build dependencies and python package - Run
pip install --upgrade --force-reinstall dist/oqspython-*.whlto install the package into your pip environment from oqs import oqspythonin your Python code (based on where it is located relative to the Python file)
Should be visible in IDE when oqspython is imported. Otherwise, see oqspython.i or oqspython.py.
from oqs import oqspython sig = oqspython.OQS_SIGNATURE(oqspython.OQS_SIG_alg_dilithium_5) public_key = bytes(sig.length_public_key) private_key = bytes(sig.length_private_key) message = b"This is the message to sign" result = sig.keypair(public_key, private_key) assert result == oqspython.OQS_SUCCESS signature = bytes(sig.length_signature) result = sig.sign(signature, message, len(message), private_key) assert result == oqspython.OQS_SUCCESS result = sig.verify(message, len(message), signature, public_key) assert result == oqspython.OQS_SUCCESS kem = oqspython.OQS_KEYENCAPSULATION(oqspython.OQS_KEM_alg_kyber_1024) public_key = bytes(kem.length_public_key) private_key = bytes(kem.length_private_key) result = kem.keypair(public_key, private_key) assert result == oqspython.OQS_SUCCESS shared_secret = bytes(kem.length_shared_secret) ciphertext = bytes(kem.length_ciphertext) result = kem.encapsulate(ciphertext, shared_secret, public_key) assert result == oqspython.OQS_SUCCESS shared_secret2 = bytes(kem.length_shared_secret) result = kem.decapsulate(shared_secret2, ciphertext, private_key) assert result == oqspython.OQS_SUCCESS assert shared_secret == shared_secret2 print("Finished successfully")