Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .github/workflows/ct-tooling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: ct-tooling

permissions:
contents: read

on:
workflow_dispatch:
inputs:
algorithms:
description: 'Algorithms to execute CT testing on (comma-separated)'
required: true
type: string
default: 'ML-KEM-512,ML-KEM-768,ML-KEM-1024'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does this mean only these algs are CT-tested now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CI, yes. That is correct.


workflow_call:
inputs:
algorithms:
required: true
type: string

jobs:
resolve-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.algs.outputs.matrix }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
- run: python -m pip install --require-hashes -r .github/workflows/requirements.txt
- name: Resolve algorithm list
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
id: algs
env:
ALGORITHMS_INPUT: ${{ inputs.algorithms }}
run: |
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
python3 - <<'PY'
import os, sys, json
sys.path.insert(0, 'tests')
import helpers
requested = os.environ["ALGORITHMS_INPUT"].strip()
all_algs = helpers.available_kems_by_name() + helpers.available_sigs_by_name()
requested_set = { a.strip() for a in requested.split(',')}
invalid_algorithms = requested_set - set(all_algs)
if invalid_algorithms:
print(f"Invalid algorithms: {invalid_algorithms}", file=sys.stderr)
sys.exit(1)
selected_algorithms = [a for a in all_algs if a in requested_set]
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"matrix={json.dumps(selected_algorithms)}\n")
PY

valgrind-varlat:
needs: [resolve-matrix]
runs-on: ubuntu-latest
container:
image: openquantumsafe/ci-ubuntu-latest:latest
strategy:
matrix:
algorithm: ${{ fromJson(needs.resolve-matrix.outputs.matrix) }}
compiler: [gcc, clang]
liboqs_build: [generic, auto]
opt_flag: [-O0, -O1, -O2, -O3, -Os, -Ofast, "-O2 -fno-tree-vectorize", "-O3 -fno-tree-vectorize", "-O2 -fno-vectorize", "-O3 -fno-vectorize"]
exclude:
- compiler: clang
opt_flag: "-O2 -fno-tree-vectorize"
- compiler: clang
opt_flag: "-O3 -fno-tree-vectorize"
- compiler: gcc
opt_flag: "-O2 -fno-vectorize"
- compiler: gcc
opt_flag: "-O3 -fno-vectorize"
max-parallel: 5
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4

- name: Run valgrind_varlat tests
shell: bash
env:
OPT_FLAG: ${{ matrix.opt_flag }}
ALGORITHM: ${{ matrix.algorithm }}
run: |
set -eu -o pipefail
cd "$GITHUB_WORKSPACE/tests/ct_tooling"
chmod +x ct_test.sh
./ct_test.sh valgrind-varlat ${{ matrix.compiler }} ${{ matrix.liboqs_build }} "$OPT_FLAG" "$ALGORITHM"

- name: Upload valgrind_varlat logs
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # pin@v4
with:
name: valgrind_varlat_${{ matrix.compiler }}_${{ matrix.liboqs_build }}_${{ matrix.opt_flag }}_logs
path: |
tests/ct_tooling/tools/valgrind_varlat/logs/**

memsan:
needs: [resolve-matrix]
runs-on: ubuntu-latest
container:
image: openquantumsafe/ci-ubuntu-latest:latest
strategy:
matrix:
algorithm: ${{ fromJson(needs.resolve-matrix.outputs.matrix) }}
compiler: [clang]
liboqs_build: [generic, auto]
opt_flag: [-O1, -O2, -O3, -Os, -Ofast, "-O2 -fno-vectorize", "-O3 -fno-vectorize"]
max-parallel: 5
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4

- name: Run memsan tests
shell: bash
env:
OPT_FLAG: ${{ matrix.opt_flag }}
ALGORITHM: ${{ matrix.algorithm }}
run: |
set -eu -o pipefail
cd "$GITHUB_WORKSPACE/tests/ct_tooling"
chmod +x ct_test.sh
./ct_test.sh memsan ${{ matrix.compiler }} ${{ matrix.liboqs_build }} "$OPT_FLAG" "$ALGORITHM"

- name: Upload memsan logs
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba # pin@v4
with:
name: memsan_${{ matrix.compiler }}_${{matrix.liboqs_build}}_${{ matrix.opt_flag }}_logs
path: |
tests/ct_tooling/tools/memsan/logs/**
9 changes: 8 additions & 1 deletion .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ jobs:
sig-continuous-benchmarking:
uses: ./.github/workflows/sig-bench.yml
permissions:
contents: write
contents: write

ct-tooling:
uses: ./.github/workflows/ct-tooling.yml
permissions:
contents: read
with:
algorithms: 'ML-KEM-512,ML-KEM-768,ML-KEM-1024'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tags
# CMake & testing
/build*
/tmp*
/CMakeFiles/

# MSVC
.vs
Expand Down Expand Up @@ -38,4 +39,4 @@ __pycache__
compile_commands.json

# Generated by Nix flake
result/
result/
15 changes: 10 additions & 5 deletions CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ The following options can be passed to CMake before the build file generation pr
- [OQS_SPEED_USE_ARM_PMU](#OQS_SPEED_USE_ARM_PMU)
- [USE_COVERAGE](#USE_COVERAGE)
- [USE_SANITIZER](#USE_SANITIZER)
- [OQS_ENABLE_TEST_CONSTANT_TIME](#OQS_ENABLE_TEST_CONSTANT_TIME)
- [OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND](#OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND)
- [OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN](#OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN)
- [OQS_STRICT_WARNINGS](#OQS_STRICT_WARNINGS)
- [OQS_EMBEDDED_BUILD](#OQS_EMBEDDED_BUILD)
- [OQS_MEMOPT_BUILD](#OQS_MEMOPT_BUILD)
Expand Down Expand Up @@ -238,16 +239,20 @@ This has an effect when the compiler is Clang and when [CMAKE_BUILD_TYPE](#CMAKE

**Default**: Unset.

## OQS_ENABLE_TEST_CONSTANT_TIME
## OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND

This is used in conjunction with `tests/test_constant_time.py` to use Valgrind to look for instances of secret-dependent control flow. liboqs must also be compiled with [CMAKE_BUILD_TYPE](#CMAKE_BUILD_TYPE) set to `Debug`.

See the documentation in [`tests/test_constant_time.py`](https://github.com/open-quantum-safe/liboqs/blob/main/tests/test_constant_time.py) for more usage information.
This is used in conjunction with `tests/test_constant_time.py` to use Valgrind to look for instances of secret-dependent control flow. liboqs must also be compiled with [CMAKE_BUILD_TYPE](#CMAKE_BUILD_TYPE) set to `Debug`.

When this option is set to `ON`, the additional option `OQS_ENABLE_TEST_CONSTANT_TIME_OPTIMIZED` is made available to control whether liboqs is built using `-O3` optimization, as in a release build, or using the default "Debug" profile. By default, `OQS_ENABLE_TEST_CONSTANT_TIME_OPTIMIZED` is `OFF`.

**Default**: `OFF`.

## OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN

Similar to [`OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND`](#OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND), this option enables constant-time testing using Clang's MemorySanitizer.

**Default**: `OFF`.

## OQS_STRICT_WARNINGS

Can be `ON` or `OFF`. When `ON`, all compiler warnings are enabled and treated as errors. This setting is recommended to be enabled prior to submission of a Pull Request as CI runs with this setting active. When `OFF`, significantly fewer compiler warnings are enabled such as to avoid undue build errors triggered by (future) compiler warning features/unknown at the development time of this library.
Expand Down
16 changes: 12 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: MIT

option(OQS_ENABLE_TEST_CONSTANT_TIME "Build test suite with support for Valgrind-based detection of non-constant time behaviour." OFF)
option(OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND "Build test suite with support for Valgrind-based detection of non-constant time behaviour." OFF)
option(OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN "Build test suite with support for MemorySanitizer-based detection of non-constant time behaviour." OFF)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we introduce a variable to enable memsan-only testing and define the previous variable to be Valgrind only testing, users get confused: Does setting "OQS_ENABLE_TEST_CONSTANT_TIME" enable all CT testing or just Valgrind-based testing? Wouldn't it be more sensible to add also a OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND option and re-define OQS_ENABLE_TEST_CONSTANT_TIME to enable both OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND and OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is a better approach too. In this case, each tool requires a mutually exclusive testing environment since they rely on different compilation and execution frameworks to flag uninitialized secret data, so we would stay with OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND and OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN only. I have updated this in the latest version and documented it in CONFIGURE.md too.


if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
Expand Down Expand Up @@ -107,6 +108,7 @@ target_link_libraries(speed_kem PRIVATE ${TEST_DEPS})

set(KEM_TESTS example_kem kat_kem test_kem test_kem_mem speed_kem vectors_kem)


# SIG API tests
add_executable(example_sig example_sig.c)
target_link_libraries(example_sig PRIVATE ${TEST_DEPS})
Expand Down Expand Up @@ -225,9 +227,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND BUILD_SHARED_LIBS)
endif()

# Enable Valgrind-based timing side-channel analysis for test_kem and test_sig
if(OQS_ENABLE_TEST_CONSTANT_TIME AND NOT OQS_DEBUG_BUILD)
message(WARNING "OQS_ENABLE_TEST_CONSTANT_TIME is incompatible with CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}.")
set(OQS_ENABLE_TEST_CONSTANT_TIME OFF)
if(OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND AND NOT OQS_DEBUG_BUILD)
message(WARNING "OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND is incompatible with CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}.")
set(OQS_ENABLE_TEST_CONSTANT_TIME_VALGRIND OFF)
endif()

# Enable MemSan-based timing side-channel analysis for test_kem and test_sig
if(OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN AND NOT OQS_DEBUG_BUILD)
message(WARNING "OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN is incompatible with CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}.")
set(OQS_ENABLE_TEST_CONSTANT_TIME_MEMSAN OFF)
endif()

# Record compile options -- from target speed_kem - don't set any options only for speed_kem!
Expand Down
35 changes: 0 additions & 35 deletions tests/constant_time/kem/issues.json

This file was deleted.

35 changes: 0 additions & 35 deletions tests/constant_time/kem/passes.json

This file was deleted.

35 changes: 0 additions & 35 deletions tests/constant_time/kem/passes/kyber

This file was deleted.

5 changes: 0 additions & 5 deletions tests/constant_time/kem/passes/sntrup

This file was deleted.

Loading