Skip to content

Commit

Permalink
Merge pull request #458 from pq-code-package/cbmc_formatting
Browse files Browse the repository at this point in the history
CBMC: Make CBMC annotations more readable
  • Loading branch information
hanno-becker authored Nov 28, 2024
2 parents f3b81a3 + 19e11b9 commit d297d86
Show file tree
Hide file tree
Showing 117 changed files with 2,220 additions and 1,650 deletions.
10 changes: 6 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
#
# clang-format style file for MLKEM-C
#
# This is based on the style for for AWS-LC
# clang-format style file for mlkem-native
#
BasedOnStyle: Google
MaxEmptyLinesToKeep: 3
Expand All @@ -17,4 +15,8 @@ IncludeBlocks: Preserve

# Designate CBMC contracts/macros that appear in .h files
# as "attributes" so they don't get increasingly indented line after line
AttributeMacros: ['REQUIRES', 'ENSURES', 'ASSIGNS', 'INVARIANT']
BreakBeforeBraces: Allman
WhitespaceSensitiveMacros: ['__contract__', '__loop__' ]
Macros:
- __contract__(x)={} void foo()
- __loop__(x)={}
3 changes: 2 additions & 1 deletion cbmc/proofs/barrett_reduce/barrett_reduce_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t a;
int16_t r;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/basemul_cached/basemul_cached_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t *a, *b, *r, b_cached;

basemul_cached(r, a, b, b_cached);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/cmov/cmov_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *x, *y;
size_t len;
uint8_t b;
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/cmov_int16/cmov_int16_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint16_t b;
int16_t *r, v;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/crypto_kem_dec/crypto_kem_dec_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c;
crypto_kem_dec(a, b, c);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/crypto_kem_enc/crypto_kem_enc_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c;
crypto_kem_enc(a, b, c);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c, *d;
crypto_kem_enc_derand(a, b, c, d);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/crypto_kem_keypair/crypto_kem_keypair_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b;
crypto_kem_keypair(a, b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c;
crypto_kem_keypair_derand(a, b, c);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/fqmul/fqmul_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t a, b, r;

r = fqmul(a, b);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/gen_matrix/gen_matrix_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
polyvec *a;
uint8_t *seed;
int transposed;
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/gen_matrix_entry/gen_matrix_entry_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void gen_matrix_entry(poly *entry, uint8_t seed[MLKEM_SYMBYTES + 16]);
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *out;
uint8_t *seed;
gen_matrix_entry(out, seed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void gen_matrix_entry_x4(poly vec[4], uint8_t *seed[4]);
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly out[4];
uint8_t *seed[4];
gen_matrix_entry_x4(out, seed);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/indcpa_dec/indcpa_dec_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *m, *c, *sk;
indcpa_dec(m, c, sk);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/indcpa_enc/indcpa_enc_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c, *d;
indcpa_enc(a, b, c, d);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *a, *b, *c;
indcpa_keypair_derand(a, b, c);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/invntt_layer/invntt_layer_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void invntt_layer(int16_t *p, int len, int layer);
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t *a;
int len, layer;
invntt_layer(a, len, layer);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/matvec_mul/matvec_mul_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ void matvec_mul(polyvec *out, polyvec const *a, polyvec const *v,
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
polyvec *out, *a, *v;
polyvec_mulcache *vc;
matvec_mul(out, a, v, vc);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/montgomery_reduce/montgomery_reduce_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int32_t a;
int16_t r;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ void ntt_butterfly_block(int16_t *r, int16_t root, int start, int len,
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t *r, root;
int start, stride, bound;
ntt_butterfly_block(r, root, start, stride, bound);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/ntt_layer/ntt_layer_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void ntt_layer(int16_t *p, int len, int layer);
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
int16_t *a;
int len, layer;
ntt_layer(a, len, layer);
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_add/poly_add_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r, *b;
poly_add(r, b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r, *a, *b;
poly_mulcache *b_cached;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_cbd_eta1/poly_cbd_eta1_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *buf;
poly *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_cbd_eta2/poly_cbd_eta2_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *buf;
poly *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_compress_du/poly_compress_du_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r;
uint8_t *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_compress_dv/poly_compress_dv_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r;
uint8_t *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_decompress_du/poly_decompress_du_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r;
uint8_t *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_decompress_dv/poly_decompress_dv_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *r;
uint8_t *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_frombytes/poly_frombytes_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *a;
uint8_t *r;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_frommsg/poly_frommsg_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *a;
uint8_t *msg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *seed;
poly *r0, *r1, *r2, *r3;
uint8_t nonce0, nonce1, nonce2, nonce3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *seed;
poly *r0, *r1, *r2, *r3;
uint8_t nonce0, nonce1, nonce2, nonce3;
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_getnoise_eta2/poly_getnoise_eta2_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
uint8_t *seed;
poly *r;
uint8_t nonce;
Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_invntt_tomont/poly_invntt_tomont_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *p;
poly_invntt_tomont(p);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly_mulcache *x;
poly *a;

Expand Down
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_ntt/poly_ntt_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *a;
poly_ntt(a);
}
3 changes: 2 additions & 1 deletion cbmc/proofs/poly_reduce/poly_reduce_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* @brief Starting point for formal analysis
*
*/
void harness(void) {
void harness(void)
{
poly *a;

/* Contracts for this function are in poly.h */
Expand Down
Loading

0 comments on commit d297d86

Please sign in to comment.