Skip to content

Commit

Permalink
Merge pull request #788 from pq-code-package/pct_breakage_logic
Browse files Browse the repository at this point in the history
Add runtime option to break PCT
  • Loading branch information
hanno-becker authored Feb 19, 2025
2 parents 1923acf + e4eb6e0 commit 34872b3
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 1 deletion.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ jobs:
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: "MLK_KEYGEN_PCT"
- name: "PCT enabled"
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -479,6 +479,19 @@ jobs:
nistkat: false
kat: true
acvp: true
- name: "PCT enabled + broken"
run: |
make clean
CFLAGS='-DMLK_CONFIG_FILE=\"../test/break_pct_config.h\"' make func -j4
# PCT breakage is done at runtime via MLK_BREAK_PCT
make run_func # Should be OK
MLK_BREAK_PCT=0 make run_func # Should be OK
if (MLK_BREAK_PCT=1 make run_func 2>&1 >/dev/null); then
echo "PCT failure expected"
exit 1
else
echo "PCT failed as expected"
fi
- name: "MLKEM_GEN_MATRIX_NBLOCKS=1"
uses: ./.github/actions/multi-functest
with:
Expand Down
20 changes: 20 additions & 0 deletions mlkem/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@
*****************************************************************************/
/* #define MLK_KEYGEN_PCT */

/******************************************************************************
* Name: MLK_KEYGEN_PCT_BREAKAGE_TEST
*
* Description: If this option is set, the user must provide a runtime
* function `static inline int mlk_break_pct() { ... }` to
* indicate whether the PCT should be made fail.
*
* This option only has an effect if MLK_KEYGEN_PCT is set.
*
*****************************************************************************/
/* #define MLK_KEYGEN_PCT_BREAKAGE_TEST
#if !defined(__ASSEMBLER__)
#include "sys.h"
static MLK_INLINE int mlk_break_pct(void)
{
... return 0/1 depending on whether PCT should be broken ...
}
#endif
*/

/************************* Config internals ********************************/

/* Default namespace
Expand Down
8 changes: 8 additions & 0 deletions mlkem/kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ static int check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES],
goto cleanup;
}

#if defined(MLK_KEYGEN_PCT_BREAKAGE_TEST)
/* Deliberately break PCT for testing purposes */
if (mlk_break_pct())
{
ss_enc[0] = ~ss_enc[0];
}
#endif /* MLK_KEYGEN_PCT_BREAKAGE_TEST */

res = ct_memcmp(ss_enc, ss_dec, sizeof(ss_dec));

cleanup:
Expand Down
Loading

18 comments on commit 34872b3

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Intel Xeon 4th gen (c7i)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 9519 cycles 9572 cycles 0.99
ML-KEM-512 encaps 11479 cycles 11363 cycles 1.01
ML-KEM-512 decaps 15162 cycles 15371 cycles 0.99
ML-KEM-768 keypair 16453 cycles 16349 cycles 1.01
ML-KEM-768 encaps 17922 cycles 17847 cycles 1.00
ML-KEM-768 decaps 23832 cycles 23552 cycles 1.01
ML-KEM-1024 keypair 22333 cycles 22090 cycles 1.01
ML-KEM-1024 encaps 24186 cycles 24114 cycles 1.00
ML-KEM-1024 decaps 31835 cycles 31669 cycles 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Arm Cortex-A76 (Raspberry Pi 5) benchmarks

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 29507 cycles 29507 cycles 1
ML-KEM-512 encaps 35114 cycles 35112 cycles 1.00
ML-KEM-512 decaps 45736 cycles 45733 cycles 1.00
ML-KEM-768 keypair 50349 cycles 50347 cycles 1.00
ML-KEM-768 encaps 55795 cycles 55794 cycles 1.00
ML-KEM-768 decaps 70732 cycles 70724 cycles 1.00
ML-KEM-1024 keypair 73381 cycles 73381 cycles 1
ML-KEM-1024 encaps 82191 cycles 82196 cycles 1.00
ML-KEM-1024 decaps 102431 cycles 102438 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Intel Xeon 4th gen (c7i) (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 28665 cycles 28652 cycles 1.00
ML-KEM-512 encaps 34592 cycles 34562 cycles 1.00
ML-KEM-512 decaps 43774 cycles 43737 cycles 1.00
ML-KEM-768 keypair 48107 cycles 48348 cycles 1.00
ML-KEM-768 encaps 55794 cycles 55774 cycles 1.00
ML-KEM-768 decaps 66991 cycles 66991 cycles 1
ML-KEM-1024 keypair 71651 cycles 71645 cycles 1.00
ML-KEM-1024 encaps 82670 cycles 82783 cycles 1.00
ML-KEM-1024 decaps 97882 cycles 98022 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

AMD EPYC 3rd gen (c6a)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 17264 cycles 17272 cycles 1.00
ML-KEM-512 encaps 19054 cycles 19069 cycles 1.00
ML-KEM-512 decaps 24512 cycles 24553 cycles 1.00
ML-KEM-768 keypair 29886 cycles 29452 cycles 1.01
ML-KEM-768 encaps 30737 cycles 30720 cycles 1.00
ML-KEM-768 decaps 38308 cycles 38469 cycles 1.00
ML-KEM-1024 keypair 43108 cycles 43293 cycles 1.00
ML-KEM-1024 encaps 44787 cycles 44853 cycles 1.00
ML-KEM-1024 decaps 55086 cycles 55115 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

AMD EPYC 4th gen (c7a)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 11478 cycles 11477 cycles 1.00
ML-KEM-512 encaps 13128 cycles 13139 cycles 1.00
ML-KEM-512 decaps 17992 cycles 17985 cycles 1.00
ML-KEM-768 keypair 20084 cycles 20041 cycles 1.00
ML-KEM-768 encaps 21235 cycles 21183 cycles 1.00
ML-KEM-768 decaps 28173 cycles 28117 cycles 1.00
ML-KEM-1024 keypair 26688 cycles 26678 cycles 1.00
ML-KEM-1024 encaps 28831 cycles 28929 cycles 1.00
ML-KEM-1024 decaps 38381 cycles 38389 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Intel Xeon 3rd gen (c6i)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 16115 cycles 16142 cycles 1.00
ML-KEM-512 encaps 18383 cycles 18408 cycles 1.00
ML-KEM-512 decaps 24897 cycles 24943 cycles 1.00
ML-KEM-768 keypair 27846 cycles 28459 cycles 0.98
ML-KEM-768 encaps 29475 cycles 29529 cycles 1.00
ML-KEM-768 decaps 38888 cycles 38979 cycles 1.00
ML-KEM-1024 keypair 37590 cycles 37643 cycles 1.00
ML-KEM-1024 encaps 40568 cycles 40626 cycles 1.00
ML-KEM-1024 decaps 53140 cycles 53241 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

AMD EPYC 3rd gen (c6a) (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 39833 cycles 39834 cycles 1.00
ML-KEM-512 encaps 48320 cycles 48322 cycles 1.00
ML-KEM-512 decaps 62590 cycles 62608 cycles 1.00
ML-KEM-768 keypair 64848 cycles 64867 cycles 1.00
ML-KEM-768 encaps 75484 cycles 75470 cycles 1.00
ML-KEM-768 decaps 94523 cycles 94513 cycles 1.00
ML-KEM-1024 keypair 96140 cycles 96163 cycles 1.00
ML-KEM-1024 encaps 109708 cycles 109771 cycles 1.00
ML-KEM-1024 decaps 133411 cycles 133335 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

AMD EPYC 4th gen (c7a) (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 36407 cycles 36391 cycles 1.00
ML-KEM-512 encaps 42878 cycles 42931 cycles 1.00
ML-KEM-512 decaps 55892 cycles 55993 cycles 1.00
ML-KEM-768 keypair 58972 cycles 58976 cycles 1.00
ML-KEM-768 encaps 67366 cycles 67366 cycles 1
ML-KEM-768 decaps 84353 cycles 84342 cycles 1.00
ML-KEM-1024 keypair 88236 cycles 88201 cycles 1.00
ML-KEM-1024 encaps 98774 cycles 98785 cycles 1.00
ML-KEM-1024 decaps 120522 cycles 120401 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton2

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 29510 cycles 29513 cycles 1.00
ML-KEM-512 encaps 35117 cycles 35119 cycles 1.00
ML-KEM-512 decaps 45744 cycles 45747 cycles 1.00
ML-KEM-768 keypair 50364 cycles 50366 cycles 1.00
ML-KEM-768 encaps 55794 cycles 55795 cycles 1.00
ML-KEM-768 decaps 70708 cycles 70708 cycles 1
ML-KEM-1024 keypair 73426 cycles 73398 cycles 1.00
ML-KEM-1024 encaps 82261 cycles 82226 cycles 1.00
ML-KEM-1024 decaps 102525 cycles 102475 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton3

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 19151 cycles 19151 cycles 1
ML-KEM-512 encaps 22843 cycles 22843 cycles 1
ML-KEM-512 decaps 30154 cycles 30151 cycles 1.00
ML-KEM-768 keypair 32895 cycles 32892 cycles 1.00
ML-KEM-768 encaps 36462 cycles 36464 cycles 1.00
ML-KEM-768 decaps 46910 cycles 46913 cycles 1.00
ML-KEM-1024 keypair 47344 cycles 47345 cycles 1.00
ML-KEM-1024 encaps 53338 cycles 53338 cycles 1
ML-KEM-1024 decaps 67300 cycles 67305 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Intel Xeon 3rd gen (c6i) (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 47221 cycles 47285 cycles 1.00
ML-KEM-512 encaps 55862 cycles 55914 cycles 1.00
ML-KEM-512 decaps 71442 cycles 71549 cycles 1.00
ML-KEM-768 keypair 76741 cycles 76837 cycles 1.00
ML-KEM-768 encaps 87459 cycles 87576 cycles 1.00
ML-KEM-768 decaps 108169 cycles 108356 cycles 1.00
ML-KEM-1024 keypair 112337 cycles 112405 cycles 1.00
ML-KEM-1024 encaps 126625 cycles 126622 cycles 1.00
ML-KEM-1024 decaps 152983 cycles 153038 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton4

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 18005 cycles 18008 cycles 1.00
ML-KEM-512 encaps 21444 cycles 21446 cycles 1.00
ML-KEM-512 decaps 28146 cycles 28150 cycles 1.00
ML-KEM-768 keypair 31055 cycles 31054 cycles 1.00
ML-KEM-768 encaps 34011 cycles 34013 cycles 1.00
ML-KEM-768 decaps 43873 cycles 43872 cycles 1.00
ML-KEM-1024 keypair 44873 cycles 44871 cycles 1.00
ML-KEM-1024 encaps 50302 cycles 50300 cycles 1.00
ML-KEM-1024 decaps 63198 cycles 63194 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton3 (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 39006 cycles 39006 cycles 1
ML-KEM-512 encaps 44887 cycles 44892 cycles 1.00
ML-KEM-512 decaps 56722 cycles 56725 cycles 1.00
ML-KEM-768 keypair 64403 cycles 64394 cycles 1.00
ML-KEM-768 encaps 71976 cycles 71963 cycles 1.00
ML-KEM-768 decaps 87842 cycles 87829 cycles 1.00
ML-KEM-1024 keypair 96101 cycles 96099 cycles 1.00
ML-KEM-1024 encaps 106194 cycles 106192 cycles 1.00
ML-KEM-1024 decaps 127274 cycles 127262 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton2 (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 59704 cycles 59681 cycles 1.00
ML-KEM-512 encaps 68302 cycles 68298 cycles 1.00
ML-KEM-512 decaps 87026 cycles 87016 cycles 1.00
ML-KEM-768 keypair 99422 cycles 99399 cycles 1.00
ML-KEM-768 encaps 110584 cycles 110588 cycles 1.00
ML-KEM-768 decaps 135307 cycles 135310 cycles 1.00
ML-KEM-1024 keypair 148951 cycles 149094 cycles 1.00
ML-KEM-1024 encaps 164545 cycles 164678 cycles 1.00
ML-KEM-1024 decaps 195815 cycles 196029 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Graviton4 (no-opt)

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 35792 cycles 35814 cycles 1.00
ML-KEM-512 encaps 40762 cycles 40769 cycles 1.00
ML-KEM-512 decaps 52095 cycles 52103 cycles 1.00
ML-KEM-768 keypair 59152 cycles 59164 cycles 1.00
ML-KEM-768 encaps 66728 cycles 66735 cycles 1.00
ML-KEM-768 decaps 81272 cycles 81279 cycles 1.00
ML-KEM-1024 keypair 88940 cycles 88952 cycles 1.00
ML-KEM-1024 encaps 98866 cycles 98876 cycles 1.00
ML-KEM-1024 decaps 117714 cycles 117726 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Arm Cortex-A55 (Snapdragon 888) benchmarks

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 59407 cycles 59446 cycles 1.00
ML-KEM-512 encaps 67054 cycles 67106 cycles 1.00
ML-KEM-512 decaps 86151 cycles 86552 cycles 1.00
ML-KEM-768 keypair 100993 cycles 101117 cycles 1.00
ML-KEM-768 encaps 112029 cycles 112175 cycles 1.00
ML-KEM-768 decaps 139351 cycles 139182 cycles 1.00
ML-KEM-1024 keypair 153557 cycles 153523 cycles 1.00
ML-KEM-1024 encaps 169944 cycles 173409 cycles 0.98
ML-KEM-1024 decaps 207085 cycles 208260 cycles 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

SpacemiT K1 8 (Banana Pi F3) benchmarks

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 226547 cycles 226408 cycles 1.00
ML-KEM-512 encaps 271436 cycles 271232 cycles 1.00
ML-KEM-512 decaps 345412 cycles 345098 cycles 1.00
ML-KEM-768 keypair 375017 cycles 374843 cycles 1.00
ML-KEM-768 encaps 433760 cycles 433446 cycles 1.00
ML-KEM-768 decaps 531773 cycles 531194 cycles 1.00
ML-KEM-1024 keypair 557978 cycles 557561 cycles 1.00
ML-KEM-1024 encaps 633571 cycles 633277 cycles 1.00
ML-KEM-1024 decaps 756977 cycles 755659 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

Choose a reason for hiding this comment

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

Arm Cortex-A72 (Raspberry Pi 4) benchmarks

Benchmark suite Current: 34872b3 Previous: 1923acf Ratio
ML-KEM-512 keypair 52760 cycles 52692 cycles 1.00
ML-KEM-512 encaps 61151 cycles 60842 cycles 1.01
ML-KEM-512 decaps 78428 cycles 77332 cycles 1.01
ML-KEM-768 keypair 90980 cycles 90338 cycles 1.01
ML-KEM-768 encaps 98991 cycles 98375 cycles 1.01
ML-KEM-768 decaps 122810 cycles 123632 cycles 0.99
ML-KEM-1024 keypair 135042 cycles 135516 cycles 1.00
ML-KEM-1024 encaps 147553 cycles 148493 cycles 0.99
ML-KEM-1024 decaps 180822 cycles 181493 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.