Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoftco committed Mar 30, 2024
1 parent 8fdda36 commit b430663
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions oqs/oqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"
)
Expand All @@ -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])
Expand Down

0 comments on commit b430663

Please sign in to comment.