-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CBMC: Add contract for native
rej_uniform
and prove fallback logic
This commit adds a contract for the rejection sampling backend and proves the C implementation correct on the basis of that contract. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
- Loading branch information
1 parent
1b2db0c
commit 801ac78
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include ../Makefile_params.common | ||
|
||
HARNESS_ENTRY = harness | ||
HARNESS_FILE = rej_uniform_native_harness | ||
|
||
# This should be a unique identifier for this proof, and will appear on the | ||
# Litani dashboard. It can be human-readable and contain spaces if you wish. | ||
PROOF_UID = rej_uniform_native | ||
|
||
DEFINES += -DMLKEM_USE_NATIVE_BACKEND_ARITH -DMLKEM_NATIVE_ARITH_BACKEND_FILE="\"dummy_backend.h\"" | ||
INCLUDES += | ||
|
||
REMOVE_FUNCTION_BODY += | ||
UNWINDSET += | ||
|
||
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c | ||
PROJECT_SOURCES += $(SRCDIR)/mlkem/sampling.c | ||
|
||
CHECK_FUNCTION_CONTRACTS=$(MLKEM_NAMESPACE)rej_uniform | ||
USE_FUNCTION_CONTRACTS=rej_uniform_native $(MLKEM_NAMESPACE)rej_uniform_scalar | ||
APPLY_LOOP_CONTRACTS=on | ||
USE_DYNAMIC_FRAMES=1 | ||
|
||
# Disable any setting of EXTERNAL_SAT_SOLVER, and choose SMT backend instead | ||
EXTERNAL_SAT_SOLVER= | ||
CBMCFLAGS=--bitwuzla | ||
|
||
#CBMCFLAGS += --no-array-field-sensitivity --arrays-uf-always --slice-formula | ||
|
||
FUNCTION_NAME = rej_uniform_native | ||
|
||
# If this proof is found to consume huge amounts of RAM, you can set the | ||
# EXPENSIVE variable. With new enough versions of the proof tools, this will | ||
# restrict the number of EXPENSIVE CBMC jobs running at once. See the | ||
# documentation in Makefile.common under the "Job Pools" heading for details. | ||
# EXPENSIVE = true | ||
|
||
# This function is large enough to need... | ||
CBMC_OBJECT_BITS = 8 | ||
|
||
# If you require access to a file-local ("static") function or object to conduct | ||
# your proof, set the following (and do not include the original source file | ||
# ("mlkem/poly.c") in PROJECT_SOURCES). | ||
# REWRITTEN_SOURCES = $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i | ||
# include ../Makefile.common | ||
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_SOURCE = $(SRCDIR)/mlkem/poly.c | ||
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_FUNCTIONS = foo bar | ||
# $(PROOFDIR)/<__SOURCE_FILE_BASENAME__>.i_OBJECTS = baz | ||
# Care is required with variables on the left-hand side: REWRITTEN_SOURCES must | ||
# be set before including Makefile.common, but any use of variables on the | ||
# left-hand side requires those variables to be defined. Hence, _SOURCE, | ||
# _FUNCTIONS, _OBJECTS is set after including Makefile.common. | ||
|
||
include ../Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# This file marks this directory as containing a CBMC proof. |
19 changes: 19 additions & 0 deletions
19
proofs/cbmc/rej_uniform_native/rej_uniform_native_harness.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2024 The mlkem-native project authors | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT-0 | ||
|
||
#include <stdint.h> | ||
#include "cbmc.h" | ||
|
||
#define rej_uniform MLKEM_NAMESPACE(rej_uniform) | ||
unsigned int rej_uniform(int16_t *r, unsigned int target, unsigned int offset, | ||
const uint8_t *buf, unsigned int buflen); | ||
|
||
void harness(void) | ||
{ | ||
unsigned int target, offset, inlen; | ||
int16_t *r; | ||
uint8_t *buf; | ||
|
||
rej_uniform(r, target, offset, buf, inlen); | ||
} |