Skip to content

Commit 34872b3

Browse files
authored
Merge pull request #788 from pq-code-package/pct_breakage_logic
Add runtime option to break PCT
2 parents 1923acf + e4eb6e0 commit 34872b3

File tree

4 files changed

+383
-1
lines changed

4 files changed

+383
-1
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ jobs:
469469
runs-on: ${{ matrix.target.runner }}
470470
steps:
471471
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
472-
- name: "MLK_KEYGEN_PCT"
472+
- name: "PCT enabled"
473473
uses: ./.github/actions/multi-functest
474474
with:
475475
gh_token: ${{ secrets.GITHUB_TOKEN }}
@@ -479,6 +479,19 @@ jobs:
479479
nistkat: false
480480
kat: true
481481
acvp: true
482+
- name: "PCT enabled + broken"
483+
run: |
484+
make clean
485+
CFLAGS='-DMLK_CONFIG_FILE=\"../test/break_pct_config.h\"' make func -j4
486+
# PCT breakage is done at runtime via MLK_BREAK_PCT
487+
make run_func # Should be OK
488+
MLK_BREAK_PCT=0 make run_func # Should be OK
489+
if (MLK_BREAK_PCT=1 make run_func 2>&1 >/dev/null); then
490+
echo "PCT failure expected"
491+
exit 1
492+
else
493+
echo "PCT failed as expected"
494+
fi
482495
- name: "MLKEM_GEN_MATRIX_NBLOCKS=1"
483496
uses: ./.github/actions/multi-functest
484497
with:

mlkem/config.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,26 @@
293293
*****************************************************************************/
294294
/* #define MLK_KEYGEN_PCT */
295295

296+
/******************************************************************************
297+
* Name: MLK_KEYGEN_PCT_BREAKAGE_TEST
298+
*
299+
* Description: If this option is set, the user must provide a runtime
300+
* function `static inline int mlk_break_pct() { ... }` to
301+
* indicate whether the PCT should be made fail.
302+
*
303+
* This option only has an effect if MLK_KEYGEN_PCT is set.
304+
*
305+
*****************************************************************************/
306+
/* #define MLK_KEYGEN_PCT_BREAKAGE_TEST
307+
#if !defined(__ASSEMBLER__)
308+
#include "sys.h"
309+
static MLK_INLINE int mlk_break_pct(void)
310+
{
311+
... return 0/1 depending on whether PCT should be broken ...
312+
}
313+
#endif
314+
*/
315+
296316
/************************* Config internals ********************************/
297317

298318
/* Default namespace

mlkem/kem.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ static int check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
145145
goto cleanup;
146146
}
147147

148+
#if defined(MLK_KEYGEN_PCT_BREAKAGE_TEST)
149+
/* Deliberately break PCT for testing purposes */
150+
if (mlk_break_pct())
151+
{
152+
ss_enc[0] = ~ss_enc[0];
153+
}
154+
#endif /* MLK_KEYGEN_PCT_BREAKAGE_TEST */
155+
148156
res = ct_memcmp(ss_enc, ss_dec, sizeof(ss_dec));
149157

150158
cleanup:

0 commit comments

Comments
 (0)