-
Notifications
You must be signed in to change notification settings - Fork 753
Include constant-time analysis framework #2449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bd47e84
e1874c3
017916a
0284430
3edf0de
e6c3a4c
ceadb8d
08435be
48f1063
483f44e
f7d078e
239a289
fa50488
6fc943b
925bc29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||
|
|
||
| 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 | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| id: algs | ||
| env: | ||
| ALGORITHMS_INPUT: ${{ inputs.algorithms }} | ||
| run: | | ||
|
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/** | ||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR | ||
| CMAKE_C_COMPILER_ID MATCHES "Clang") | ||
|
|
@@ -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}) | ||
|
|
@@ -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! | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.