Skip to content

Commit

Permalink
Improved CPU extension handling and updated README. (open-quantum-saf…
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf authored Feb 20, 2020
1 parent f857b57 commit 56eece8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 77 deletions.
68 changes: 0 additions & 68 deletions .CMake/add-cpu-extension-flags.cmake

This file was deleted.

File renamed without changes.
15 changes: 15 additions & 0 deletions .CMake/cpu-extensions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TODO: Use cpu_features instead of list-cpu-extensions.c
if(ARCH STREQUAL "x86" OR
ARCH STREQUAL "x86_64")
try_run(RUN_RESULT COMPILE_RESULT
"${CMAKE_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/.CMake/list-cpu-extensions.c"
RUN_OUTPUT_VARIABLE RUN_OUTPUT)
foreach(CPU_EXTENSION ${RUN_OUTPUT})
set(USE_${CPU_EXTENSION}_INSTRUCTIONS TRUE)
endforeach()
if(USE_AVX512BW_INSTRUCTIONS AND
USE_AVX512DQ_INSTRUCTIONS AND
USE_AVX512F_INSTRUCTIONS)
set(USE_AVX512_INSTRUCTIONS ON)
endif()
endif()
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
xcode: "11.3.0"
environment:
#TODO: Make tests pass with Release build
CONFIGURE_ARGS: -DUSE_OPENSSL=OFF -DCMAKE_BUILD_TYPE=Debug
CONFIGURE_ARGS: -DUSE_OPENSSL=OFF
SKIP_TESTS: style
steps:
- checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ build/
__pycache__
.pytest_cache
.cache
.CMake/a.out

6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3")
else()
include(.CMake/add-cpu-extension-flags.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer")
include(.CMake/cpu-extensions.cmake)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fomit-frame-pointer -march=native")
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
Expand All @@ -51,7 +51,7 @@ if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif()

include(.CMake/config-oqs-alg-support.cmake)
include(.CMake/alg-support.cmake)

include(.CMake/sanitizers.cmake)

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ liboqs is an open source C library for quantum-safe cryptographic algorithms.
- [Quickstart](#quickstart)
* [Linux / macOS](#linuxmacOS)
* [Windows](#windows)
* [Others](#others)
* [Cross compilation](#cross-compilation)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -92,11 +92,15 @@ We realize some parties may want to deploy quantum-safe cryptography prior to th
cmake -GNinja ..
ninja

Various options can be passed to `cmake` to disable algorithms, use different implementations, specify whether to use OpenSSL, etc.. All supported options are listed in the `.CMake/alg-support.cmake` file, and can be viewed by running `cmake -LAH ..` in the `build` directory`. All subsequent instructions assume we are in this directory.
Various options can be passed to `cmake` to customize the build. Some of them include:

If the build fails on macOS, you might have to run `cmake -GNinja -DCMAKE_BUILD_TYPE="Debug .."` before calling `ninja`.
- `-DUSE_OPENSSL=<val>`: `<val>` can be `ON` or `OFF`; when `ON`, liboqs uses OpenSSL's AES, SHA-2, and SHA-3 implementations.
- `-DBUILD_SHARED_LIBS=<val>`: `<val>` can be `ON` or `OFF`; when `ON`, CMake generates instructions for building a shared library, otherwise it generates instructions for building a static library.
- `OPENSSL_ROOT_DIR=<dir>`: `<dir>` specifies the directory in which CMake will look for OpenSSL.

3. The main build result is `lib/liboqs.a`, a static library. There are also a variety of programs built under the `tests` directory:
All supported options are listed in the `.CMake/alg-support.cmake` file, and can be viewed by running `cmake -LAH ..` in the `build` directory. All subsequent instructions assume we are in `build`.

3. The main build result is `lib/liboqs.a`, a static library. The public headers are located in the `include` directory. There are also a variety of programs built under the `tests` directory:

- `test_kem`: Simple test harness for key encapsulation mechanisms
- `test_sig`: Simple test harness for key signature schemes
Expand All @@ -118,13 +122,15 @@ If the build fails on macOS, you might have to run `cmake -GNinja -DCMAKE_BUILD_

Then open `build/docs/doxygen/html/index.html` in your web browser.

4. Finally, `ninja install` can be run to install the built library and `include` files to a location of choice, which can be specified by passing the `-DCMAKE_INSTALL_PREFIX=<dir>` option to `cmake` at configure time.

### Windows

Binaries can be generated using Visual Studio 2019 with the [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) extension installed.

### Cross compilation

You can cross compile liboqs for various platform by supplying CMake with an appropriate [toolchain](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) file.
You can cross compile liboqs for various platform by supplying CMake with an appropriate [toolchain](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html) file.

For example, to cross compile for a Raspberry Pi from Ubuntu Bionic:

Expand Down

0 comments on commit 56eece8

Please sign in to comment.