Skip to content

Commit

Permalink
Merge pull request #669 from pq-code-package/poly_compress
Browse files Browse the repository at this point in the history
Add C-only multi-level build with shared common code
  • Loading branch information
hanno-becker authored Jan 20, 2025
2 parents c79b97a + 5fadf03 commit 412ff2d
Show file tree
Hide file tree
Showing 79 changed files with 2,214 additions and 2,165 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ jobs:
- name: monolithic_build_multilevel
run: |
make run -C examples/monolithic_build_multilevel
- name: multilevel_build
run: |
make run -C examples/multilevel_build
build_kat:
needs: [quickcheck, quickcheck-windows, quickcheck-c90, quickcheck-lib, examples, lint, lint-markdown-link]
strategy:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ clean:
-make clean -C examples/mlkem_native_as_code_package >/dev/null
-make clean -C examples/monolithic_build >/dev/null
-make clean -C examples/monolithic_build_multilevel >/dev/null
-make clean -C examples/multilevel_build >/dev/null
23 changes: 17 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@

# Usage examples

This directory contains minimal examples demonstrating how to use mlkem-native.
This directory contains minimal examples demonstrating how you can use mlkem-native.

## Using unmodified mlkem-native as a code package
## Single-level build

See [mlkem_native_as_code_package](mlkem_native_as_code_package).
See [mlkem_native_as_code_package](mlkem_native_as_code_package) for a basic example of how to build a single instance
of mlkem-native.

## Using mlkem-native as a code package, bring your own FIPS-202
## Multi-level build

See [multilevel_build](multilevel_build) for an example of how to build one instance of mlkem-native per security level,
in such a way that level-independent code is shared.

## Custom FIPS202 implementation

See [bring_your_own_fips202](bring_your_own_fips202) for an example of how to use mlkem-native with your own FIPS-202
implementation.

## Using mlkem-native as a code package, custom config + custom FIPS-202 backend
## Custom config + custom FIPS-202 backend

See [custom_backend](custom_backend) for an example of how to use mlkem-native with a custom configuration file and a
custom FIPS-202 backend.

## Building mlkem-native with a single compilation unit
## Monobuild

See [monolithic_build](monolithic_build) for an example of how to build mlkem-native (with C backend) from a single
auto-generated compilation unit.

## Multi-level monobuild

See [monolithic_build_multilevel](monolithic_build_multilevel) for an example of how to build all security levels of
mlkem-native (with C backend) inside a single compilation unit, sharing the level-independent code.
2 changes: 1 addition & 1 deletion examples/monolithic_build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Single-level mlkem-native in a single compilation unit

This directory contains a minimal example for how to build a single instance of mlkem-native in a single compilation
unit.
unit. Only the C-backend is exercised.

The auto-generated source file [mlkem_native_monobuild.c](mlkem_native_monobuild.c) includes all mlkem-native C source
files. Moreover, it clears all `#define`s clauses set by mlkem-native at the end, and is hence amenable to multiple
Expand Down
Loading

18 comments on commit 412ff2d

@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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 29080 cycles 29046 cycles 1.00
ML-KEM-512 encaps 35434 cycles 35405 cycles 1.00
ML-KEM-512 decaps 45903 cycles 45880 cycles 1.00
ML-KEM-768 keypair 49300 cycles 49365 cycles 1.00
ML-KEM-768 encaps 55591 cycles 55567 cycles 1.00
ML-KEM-768 decaps 70356 cycles 70328 cycles 1.00
ML-KEM-1024 keypair 72019 cycles 72056 cycles 1.00
ML-KEM-1024 encaps 80739 cycles 80837 cycles 1.00
ML-KEM-1024 decaps 100646 cycles 100700 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)

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 13517 cycles 13956 cycles 0.97
ML-KEM-512 encaps 17266 cycles 17291 cycles 1.00
ML-KEM-512 decaps 22791 cycles 23181 cycles 0.98
ML-KEM-768 keypair 22537 cycles 22560 cycles 1.00
ML-KEM-768 encaps 24540 cycles 24504 cycles 1.00
ML-KEM-768 decaps 32550 cycles 32450 cycles 1.00
ML-KEM-1024 keypair 31535 cycles 31395 cycles 1.00
ML-KEM-1024 encaps 34867 cycles 34968 cycles 1.00
ML-KEM-1024 decaps 45809 cycles 45831 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 33267 cycles 33077 cycles 1.01
ML-KEM-512 encaps 38680 cycles 38822 cycles 1.00
ML-KEM-512 decaps 50063 cycles 50806 cycles 0.99
ML-KEM-768 keypair 54067 cycles 54897 cycles 0.98
ML-KEM-768 encaps 61066 cycles 60738 cycles 1.01
ML-KEM-768 decaps 75782 cycles 75882 cycles 1.00
ML-KEM-1024 keypair 82432 cycles 81820 cycles 1.01
ML-KEM-1024 encaps 92941 cycles 91788 cycles 1.01
ML-KEM-1024 decaps 111525 cycles 111489 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 14893 cycles 14920 cycles 1.00
ML-KEM-512 encaps 19708 cycles 19650 cycles 1.00
ML-KEM-512 decaps 26576 cycles 26315 cycles 1.01
ML-KEM-768 keypair 25613 cycles 25586 cycles 1.00
ML-KEM-768 encaps 28157 cycles 28096 cycles 1.00
ML-KEM-768 decaps 37835 cycles 37908 cycles 1.00
ML-KEM-1024 keypair 35590 cycles 35215 cycles 1.01
ML-KEM-1024 encaps 40336 cycles 40027 cycles 1.01
ML-KEM-1024 decaps 53879 cycles 53472 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.

AMD EPYC 3rd gen (c6a)

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 18110 cycles 18094 cycles 1.00
ML-KEM-512 encaps 22994 cycles 22911 cycles 1.00
ML-KEM-512 decaps 30314 cycles 30205 cycles 1.00
ML-KEM-768 keypair 31107 cycles 31104 cycles 1.00
ML-KEM-768 encaps 33885 cycles 33887 cycles 1.00
ML-KEM-768 decaps 44610 cycles 44494 cycles 1.00
ML-KEM-1024 keypair 44396 cycles 44686 cycles 0.99
ML-KEM-1024 encaps 49543 cycles 49954 cycles 0.99
ML-KEM-1024 decaps 64077 cycles 64342 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 20354 cycles 20355 cycles 1.00
ML-KEM-512 encaps 26922 cycles 26954 cycles 1.00
ML-KEM-512 decaps 35737 cycles 35779 cycles 1.00
ML-KEM-768 keypair 34903 cycles 34905 cycles 1.00
ML-KEM-768 encaps 38190 cycles 38169 cycles 1.00
ML-KEM-768 decaps 50956 cycles 50951 cycles 1.00
ML-KEM-1024 keypair 48037 cycles 47981 cycles 1.00
ML-KEM-1024 encaps 53872 cycles 54176 cycles 0.99
ML-KEM-1024 decaps 71418 cycles 71674 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 18116 cycles 18117 cycles 1.00
ML-KEM-512 encaps 22180 cycles 22174 cycles 1.00
ML-KEM-512 decaps 28845 cycles 28829 cycles 1.00
ML-KEM-768 keypair 30552 cycles 30564 cycles 1.00
ML-KEM-768 encaps 33635 cycles 33626 cycles 1.00
ML-KEM-768 decaps 43159 cycles 43166 cycles 1.00
ML-KEM-1024 keypair 44155 cycles 44176 cycles 1.00
ML-KEM-1024 encaps 49644 cycles 49658 cycles 1.00
ML-KEM-1024 decaps 62630 cycles 62640 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 39396 cycles 39577 cycles 1.00
ML-KEM-512 encaps 45598 cycles 45619 cycles 1.00
ML-KEM-512 decaps 59080 cycles 59080 cycles 1
ML-KEM-768 keypair 64918 cycles 64519 cycles 1.01
ML-KEM-768 encaps 73199 cycles 72950 cycles 1.00
ML-KEM-768 decaps 91533 cycles 91111 cycles 1.00
ML-KEM-1024 keypair 96607 cycles 96073 cycles 1.01
ML-KEM-1024 encaps 107897 cycles 107206 cycles 1.01
ML-KEM-1024 decaps 131224 cycles 130548 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.

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

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 43442 cycles 43325 cycles 1.00
ML-KEM-512 encaps 51406 cycles 51813 cycles 0.99
ML-KEM-512 decaps 66702 cycles 67018 cycles 1.00
ML-KEM-768 keypair 71827 cycles 71608 cycles 1.00
ML-KEM-768 encaps 83304 cycles 82680 cycles 1.01
ML-KEM-768 decaps 103667 cycles 103114 cycles 1.01
ML-KEM-1024 keypair 107138 cycles 106742 cycles 1.00
ML-KEM-1024 encaps 122109 cycles 121052 cycles 1.01
ML-KEM-1024 decaps 147886 cycles 147326 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 51538 cycles 51405 cycles 1.00
ML-KEM-512 encaps 59634 cycles 59550 cycles 1.00
ML-KEM-512 decaps 76544 cycles 76537 cycles 1.00
ML-KEM-768 keypair 84288 cycles 84282 cycles 1.00
ML-KEM-768 encaps 95641 cycles 94962 cycles 1.01
ML-KEM-768 decaps 117943 cycles 117171 cycles 1.01
ML-KEM-1024 keypair 125363 cycles 124526 cycles 1.01
ML-KEM-1024 encaps 139482 cycles 138736 cycles 1.01
ML-KEM-1024 decaps 168180 cycles 167382 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 38052 cycles 37951 cycles 1.00
ML-KEM-512 encaps 43371 cycles 43322 cycles 1.00
ML-KEM-512 decaps 55552 cycles 55510 cycles 1.00
ML-KEM-768 keypair 63038 cycles 62975 cycles 1.00
ML-KEM-768 encaps 70440 cycles 70419 cycles 1.00
ML-KEM-768 decaps 86908 cycles 86890 cycles 1.00
ML-KEM-1024 keypair 94539 cycles 94481 cycles 1.00
ML-KEM-1024 encaps 105314 cycles 105197 cycles 1.00
ML-KEM-1024 decaps 126986 cycles 126506 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 29079 cycles 29041 cycles 1.00
ML-KEM-512 encaps 35455 cycles 35393 cycles 1.00
ML-KEM-512 decaps 45897 cycles 45891 cycles 1.00
ML-KEM-768 keypair 49316 cycles 49383 cycles 1.00
ML-KEM-768 encaps 55598 cycles 55591 cycles 1.00
ML-KEM-768 decaps 70388 cycles 70353 cycles 1.00
ML-KEM-1024 keypair 72026 cycles 72079 cycles 1.00
ML-KEM-1024 encaps 80761 cycles 80862 cycles 1.00
ML-KEM-1024 decaps 100670 cycles 100733 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 58337 cycles 58342 cycles 1.00
ML-KEM-512 encaps 65750 cycles 65810 cycles 1.00
ML-KEM-512 decaps 84524 cycles 84601 cycles 1.00
ML-KEM-768 keypair 98954 cycles 98963 cycles 1.00
ML-KEM-768 encaps 110343 cycles 110566 cycles 1.00
ML-KEM-768 decaps 136523 cycles 136500 cycles 1.00
ML-KEM-1024 keypair 150162 cycles 150087 cycles 1.00
ML-KEM-1024 encaps 166157 cycles 166550 cycles 1.00
ML-KEM-1024 decaps 202263 cycles 202797 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 60638 cycles 60765 cycles 1.00
ML-KEM-512 encaps 69777 cycles 69723 cycles 1.00
ML-KEM-512 decaps 88704 cycles 88788 cycles 1.00
ML-KEM-768 keypair 101743 cycles 102028 cycles 1.00
ML-KEM-768 encaps 115005 cycles 114142 cycles 1.01
ML-KEM-768 decaps 140654 cycles 139370 cycles 1.01
ML-KEM-1024 keypair 154323 cycles 153975 cycles 1.00
ML-KEM-1024 encaps 171473 cycles 169718 cycles 1.01
ML-KEM-1024 decaps 203985 cycles 202204 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.

Graviton3

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 18950 cycles 18967 cycles 1.00
ML-KEM-512 encaps 23573 cycles 23560 cycles 1.00
ML-KEM-512 decaps 30675 cycles 30694 cycles 1.00
ML-KEM-768 keypair 32341 cycles 32313 cycles 1.00
ML-KEM-768 encaps 35900 cycles 35896 cycles 1.00
ML-KEM-768 decaps 46041 cycles 46038 cycles 1.00
ML-KEM-1024 keypair 46586 cycles 46621 cycles 1.00
ML-KEM-1024 encaps 52470 cycles 52443 cycles 1.00
ML-KEM-1024 decaps 66239 cycles 66278 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: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 39349 cycles 39348 cycles 1.00
ML-KEM-512 encaps 45352 cycles 45455 cycles 1.00
ML-KEM-512 decaps 57395 cycles 57377 cycles 1.00
ML-KEM-768 keypair 65864 cycles 65850 cycles 1.00
ML-KEM-768 encaps 73715 cycles 73802 cycles 1.00
ML-KEM-768 decaps 89700 cycles 89876 cycles 1.00
ML-KEM-1024 keypair 98984 cycles 98993 cycles 1.00
ML-KEM-1024 encaps 109964 cycles 110056 cycles 1.00
ML-KEM-1024 decaps 130729 cycles 130883 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.

Bananapi bpi-f3 benchmarks

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 331562 cycles 334938 cycles 0.99
ML-KEM-512 encaps 440510 cycles 443581 cycles 0.99
ML-KEM-512 decaps 588870 cycles 591786 cycles 1.00
ML-KEM-768 keypair 548593 cycles 559178 cycles 0.98
ML-KEM-768 encaps 687637 cycles 697637 cycles 0.99
ML-KEM-768 decaps 879374 cycles 889082 cycles 0.99
ML-KEM-1024 keypair 809108 cycles 828079 cycles 0.98
ML-KEM-1024 encaps 981068 cycles 1000643 cycles 0.98
ML-KEM-1024 decaps 1215369 cycles 1231971 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.

Arm Cortex-A72 (Raspberry Pi 4) benchmarks

Benchmark suite Current: 412ff2d Previous: 5e3033e Ratio
ML-KEM-512 keypair 52445 cycles 51776 cycles 1.01
ML-KEM-512 encaps 58898 cycles 58359 cycles 1.01
ML-KEM-512 decaps 75192 cycles 74228 cycles 1.01
ML-KEM-768 keypair 88768 cycles 87850 cycles 1.01
ML-KEM-768 encaps 96913 cycles 96467 cycles 1.00
ML-KEM-768 decaps 119344 cycles 119522 cycles 1.00
ML-KEM-1024 keypair 132166 cycles 131631 cycles 1.00
ML-KEM-1024 encaps 144492 cycles 145213 cycles 1.00
ML-KEM-1024 decaps 175903 cycles 177906 cycles 0.99

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

Please sign in to comment.