-
Notifications
You must be signed in to change notification settings - Fork 12
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
Demonstrate use of CBMC in example of (de)compression routines #46
Conversation
@mkannwischer @potsrevennil I have issues running astyle $(git ls-files "*.c" "*.h") --options=.astylerc --formatted on I'm using Astyle 3.4.16 ( |
Different versions of Astyle are incompatible to each other. Like this: PQClean/PQClean#520 |
Ah, thank you @cothan! I will see if I can get the specific version used by CI. |
@cothan Yes, that works, thank you 🙏 Unfortunately, |
3c03a48
to
d68a755
Compare
@cothan @potsrevennil @mkannwischer Is there a way to run the nix CI tasks locally to avoid pushing lots of revisions until the CI is appeased? |
4301678
to
93c1a16
Compare
People use https://github.com/nektos/act run GitHub action locally. Because we have openssf, it generates a lot of noise. |
d2b6094
to
f37dcb7
Compare
@mkannwischer @potsrevennil @cothan I'll stop here for the initial CBMC PR and leave further harnesses and proofs for separate PRs. I am overall quite happy how easy things are once the tool is setup, and think we will be able to roll it out more broadly for the verification of the C code in MLKEM-C-{Generic, AArch64, Embedded}. |
Thanks @hanno-becker , it's look very good. Regards to the boilerplate from CBMC starter, I think we can reduce LoC (although it's not very important) by deleting them. P/S: Do you know why the CBMC check these functions 3 times? |
C code in MLKEM-C-AArch64 should be free of undefined behaviour. The C Bounded Model Checker (CBMC) is a tool which can prove absence of various classes of undefined behaviour. This commit is a first step towards using CBMC to harden MLKEM-C-AArch64. - Setup CBMC boilerplate using cbmc-starter-kit: All proof harnesses, scripts and Makefiles needed to run CBMC are in the `cbmc/` directory. Harnesses are organized by the (main) function to which they apply, and stored in separate directories with the name of the function. - Demonstrate the use of CBMC in the example of the decompression funcion `poly_decompress`: Specify (in natural language, in a function contract, and in the test harness) that the coefficients in the output polynomial of this function are unsigned canonical. - Guided by CBMC, make smaller changes to `poly_decompress` to avoid integer truncation warnings. The previous code did _not_ trigger undefined behaviour to my understanding (signed -> unsigned conversions are always defined), but it is arguably still better style to make truncations explicit. To run the `poly_decompress` proofs along: ``` cd cbmc/proofs/poly_decompress make ``` To run all CBMC tests (only `poly_decompress` so far, but more will hopefully be added) and print a summary, ``` cd cbmc/proofs KYBER_K={2,3,4} run-cbmc-proofs.py --summarize ``` Signed-off-by: Hanno Becker <[email protected]>
Signed-off-by: Hanno Becker <[email protected]>
Signed-off-by: Hanno Becker <[email protected]>
Signed-off-by: Hanno Becker <[email protected]>
Rebased after merge of #44. |
@cothan It's for KYBER_K=2,3,4 |
Depends on: #44 by @potsrevennilC code in MLKEM-C-AArch64 should be free of undefined behaviour. The C Bounded Model Checker (CBMC) is a tool which can prove absence of various classes of undefined behaviour.
This commit is a first step towards using CBMC to harden MLKEM-C-AArch64.
cbmc/
directory. Harnesses are organized by the (main) function to which they apply, and stored in separate directories with the name of the function.poly_decompress
andpoly_compress
: Specify (in natural language, in a function contract, and in the test harness) that the coefficients in the output polynomial of this function are unsigned canonical. Hoist out scalar (de)compression routines as separate functionsscalar_[de]compress_q_[16|32]
for independent verification.poly_decompress
to avoid integer truncation warnings. The previous code did not trigger undefined behaviour to my understanding (signed -> unsigned conversions are always defined), but it is arguably still better style to make truncations explicit.Note that CBMC blasts through the Barrett reduction to show that it's a genuine rounded division, which is pretty cool.
To run the
poly_decompress
proofs alone:To run all CBMC tests (only
poly_decompress
so far, but more will hopefully be added) and print a summary,