From b430663219d81c094ffbdc93379ab948344d8e7d Mon Sep 17 00:00:00 2001 From: Vlad Gheorghiu Date: Sat, 30 Mar 2024 17:40:34 -0400 Subject: [PATCH] Fix --- README.md | 12 ++++++------ oqs/oqs.py | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6b5c064..0965539 100644 --- a/README.md +++ b/README.md @@ -150,12 +150,12 @@ import oqs ``` liboqs-python defines two main classes: `KeyEncapsulation` and `Signature`, -providing post-quantum key encapsulation and signture mechanisms, respectively. -Each must be instantiated with a string identifying one of mechanisms supported -by liboqs; these can be enumerated using the `get_enabled_KEM_mechanisms()` and -`get_enabled_sig_mechanisms()` functions. The files in `examples/` demonstrate -the wrapper's API. Support for alternative RNGs is provided via the -`randombytes_*()` functions. +providing post-quantum key encapsulation and signature mechanisms, +respectively. Each must be instantiated with a string identifying one of +mechanisms supported by liboqs; these can be enumerated using the +`get_enabled_KEM_mechanisms()` and `get_enabled_sig_mechanisms()` functions. +The files in `examples/` demonstrate the wrapper's API. Support for alternative +RNGs is provided via the `randombytes_*()` functions. The liboqs-python project should be in the `PYTHONPATH`. To ensure this on UNIX-like systems, execute diff --git a/oqs/oqs.py b/oqs/oqs.py index 522584e..36a81c1 100644 --- a/oqs/oqs.py +++ b/oqs/oqs.py @@ -20,6 +20,8 @@ OQS_SUCCESS = 0 OQS_ERROR = -1 +OQS_VERSION = "0.10.0" + def _load_shared_obj(name, additional_searching_paths=None): """Attempts to load shared library.""" @@ -51,19 +53,24 @@ def _load_shared_obj(name, additional_searching_paths=None): for path in paths: if path: - lib = dll.LoadLibrary(path) - return lib + try: + lib = dll.LoadLibrary(path) + return lib + except OSError: + pass raise RuntimeError("No " + name + " shared libraries found") -def _install_liboqs(directory): +def _install_liboqs(directory, oqs_version): """Install liboqs in $HOME/directory.""" with tempfile.TemporaryDirectory() as tmpdirname: oqs_install_str = ( "cd " + tmpdirname - + " && git clone https://github.com/open-quantum-safe/liboqs --depth 1 && cmake -S liboqs -B liboqs/build -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=" + + " && git clone https://github.com/open-quantum-safe/liboqs --branch " + + oqs_version + + " --depth 1 && cmake -S liboqs -B liboqs/build -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=" + directory + " && cmake --build liboqs/build --parallel 4 && cmake --build liboqs/build --target install" ) @@ -74,14 +81,14 @@ def _install_liboqs(directory): home_dir = os.path.expanduser("~") -oqs_install_dir = os.path.abspath(home_dir + os.path.sep + "oqs") -oqs_lib_dir = os.path.abspath(oqs_install_dir + os.path.sep + "lib") +oqs_install_dir = os.path.abspath(home_dir + os.path.sep + "oqs") # $HOME/oqs +oqs_lib_dir = os.path.abspath(oqs_install_dir + os.path.sep + "lib") # $HOME/oqs/lib try: _liboqs = _load_shared_obj(name="oqs", additional_searching_paths=[oqs_lib_dir]) assert _liboqs except RuntimeError: # We don't have liboqs, so we try to install it automatically in $HOME/oqs - _install_liboqs(oqs_install_dir) + _install_liboqs(directory=oqs_install_dir, oqs_version=OQS_VERSION) # Try loading it again try: _liboqs = _load_shared_obj(name="oqs", additional_searching_paths=[oqs_lib_dir])