Skip to content

Include constant-time analysis framework#2449

Draft
pablo-gf wants to merge 1 commit into
open-quantum-safe:mainfrom
pablo-gf:ct-tooling
Draft

Include constant-time analysis framework#2449
pablo-gf wants to merge 1 commit into
open-quantum-safe:mainfrom
pablo-gf:ct-tooling

Conversation

@pablo-gf
Copy link
Copy Markdown
Contributor

This PR includes the constant-time testing framework developed throughout the course of the LFX Mentorship project supervised by @bhess. These are the main features of this framework:

  • It is based on two dynamic analysis tools: Valgrind's memcheck with the Kyberslash patch (renamed to Valgrind-Varlat), and Clang's MemSanitizer (MemSan) to detect possible sources (warnigns) of non-constant-time behavior.
  • Provides unified scripts for running constant-time checks both in the CI pipeline and locally.
  • Includes a script that aggregates analysis outputs and generates visual graphs to identify and track constant-time warning trends.
  • Includes several documentation files outlining the installation, setup, and usage process.

I would be happy to walk through the details of any of these features either here or during a status call. You can also find detailed guides in the documentation files I’ve added under tests/ct_tooling and its subdirectories. Feel free to throw any feedback or comments so that we can move this from draft to "ready for review"!

  • Does this PR change the input/output behaviour of a cryptographic algorithm (i.e., does it change known answer test values)? (If so, a version bump will be required from x.y.z to x.(y+1).0.)
  • Does this PR change the list of algorithms available -- either adding, removing, or renaming? Does this PR otherwise change an API? (If so, PRs in fully supported downstream projects dependent on these, i.e., oqs-provider will also need to be ready for review and merge by the time this is merged. Also, make sure to update the list of algorithms in the continuous benchmarking files: .github/workflows/kem-bench.yml and sig-bench.yml)

AI assistance was used to generate documentation and minor editing. The resulting code was reviewed, edited and verified for accuracy.

steps:
- name: Example Interactive Inputs Step
id: interactive-inputs
uses: boasiHQ/interactive-inputs@v2
steps:
- name: Example Interactive Inputs Step
id: interactive-inputs
uses: boasiHQ/interactive-inputs@v2
Signed-off-by: Pablo Gutiérrez <pablogf@uma.es>
@coveralls
Copy link
Copy Markdown

coveralls commented May 29, 2026

Coverage Status

Coverage is 82.191%pablo-gf:ct-tooling into open-quantum-safe:main. No base build found for open-quantum-safe:main.

Copy link
Copy Markdown
Member

@bhess bhess left a comment

Choose a reason for hiding this comment

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

Thank you @pablo-gf for this work on improving the constant‑time tooling in liboqs, this is an important step towards more exhaustive ct-testing in liboqs.

I’ve left a few initial comments inline.

I would be happy to walk through the details of any of these features either here or during a status call.

That would be excellent. @dstebila / @RodriM11: could we allocate some time in an upcoming status call for @pablo-gf to walk us through this contribution? I think a walkthrough would be very valuable.

workflow_dispatch:

jobs:
interactive-inputs:
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.

My understanding is that this job requires interactive input to select the algorithms. Is that correct? If so, what is the intended usage, and can it be configured to run non‑interactively (e.g., for inclusion in the weekly CI runs)?

display: Select the algorithm(s) to execute valgrind-varlat constant-time testing on
type: multiselect
choices:
- "BIKE-L1"
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.

My concern with this list is maintainability: if the set of algorithms in liboqs changes, the list would need to be updated manually. Is there a way to generate this list dynamically based on the algorithms currently available?

@@ -0,0 +1,396 @@
// SPDX-License-Identifier: MIT
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.

The test_sig.c / test_kem.c files and the corresponding CMakeLists.txt appear to be largely copied from the versions in the /tests directory. Could we avoid duplicating these files and instead reuse the originals with additional macro definitions (e.g., to disable signature verification during ct-testing)? Or is there a specific reason why maintaining separate copies is necessary here?

@@ -0,0 +1,15 @@
fun:PQCP_MLKEM_NATIVE_MLKEM*_C_poly_decompress_d*
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.

I really like this approach, having an allowlist mechanism similar to the Valgrind one makes a lot of sense.

INSTALL_PREFIX="$PWD/valgrind_varlat"

echo "Cloning Valgrind's source code"
git clone git://sourceware.org/git/valgrind.git valgrind_varlat_src> /dev/null 2>&1 || true
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.

The statements with || true would silently fail.

@RodriM11
Copy link
Copy Markdown
Member

That would be excellent. @dstebila / @RodriM11: could we allocate some time in an upcoming status call for @pablo-gf to walk us through this contribution? I think a walkthrough would be very valuable.

For sure. Next week is TSC meeting, so we could do it the 9th of June, if @pablo-gf is available.

done

# Create backup files of the original tests files
mv "$LIBOQS_DIR/tests/CMakeLists.txt" "$LIBOQS_DIR/tests/CMakeLists.txt.bak"
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.

This looks brittle since it makes assumptions about the liboqs file structure. IMO avoiding replacing the original files and instead work CT-specific macros in the original files would be more robust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants