-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coeff_signed_to_unsigned() functions and its proof
Signed-off-by: Rod Chapman <[email protected]>
- Loading branch information
1 parent
124e510
commit 6446621
Showing
7 changed files
with
175 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
include ../Makefile_params.common | ||
|
||
HARNESS_ENTRY = harness | ||
HARNESS_FILE = coeff_signed_to_unsigned_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 = coeff_signed_to_unsigned | ||
|
||
DEFINES += | ||
INCLUDES += | ||
|
||
REMOVE_FUNCTION_BODY += | ||
UNWINDSET += | ||
|
||
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c | ||
PROJECT_SOURCES += $(SRCDIR)/mlkem/poly.c | ||
|
||
CHECK_FUNCTION_CONTRACTS=coeff_signed_to_unsigned | ||
USE_FUNCTION_CONTRACTS= | ||
APPLY_LOOP_CONTRACTS=on | ||
USE_DYNAMIC_FRAMES=1 | ||
|
||
CBMCFLAGS=--smt2 | ||
|
||
# Uncomment this to see what commands litani is running... | ||
#VERBOSE=on | ||
|
||
# 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 | ||
|
||
# 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,14 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
coeff_signed_to_unsigned proof | ||
============== | ||
|
||
This directory contains a memory safety proof for coeff_signed_to_unsigned. | ||
|
||
To run the proof. | ||
------------- | ||
* Follow these [tool installation instructions](https://github.com/awslabs/aws-templates-for-cbmc-proofs/wiki/Installation) to install cbmc and cbmc-viewer. | ||
* Add `cbmc`, `goto-cc`, `goto-instrument`, `goto-analyzer`, and `cbmc-viewer` | ||
to your path. | ||
* Run `make`. | ||
* Open `report/html/index.html` in a web browser. |
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. |
30 changes: 30 additions & 0 deletions
30
cbmc/proofs/coeff_signed_to_unsigned/coeff_signed_to_unsigned_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,30 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* | ||
* Insert copyright notice | ||
*/ | ||
|
||
/** | ||
* @file coeff_signed_to_unsigned.c | ||
* @brief Implements the proof harness for coeff_signed_to_unsigned function. | ||
*/ | ||
|
||
/* | ||
* Insert project header files that | ||
* - include the declaration of the function | ||
* - include the types needed to declare function arguments | ||
*/ | ||
#include <poly.h> | ||
|
||
/** | ||
* @brief Starting point for formal analysis | ||
* | ||
*/ | ||
void harness(void) | ||
{ | ||
int16_t u; | ||
|
||
/* Contracts for this function are in poly.h */ | ||
uint16_t d = coeff_signed_to_unsigned(u); | ||
} |
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,27 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
FILE = ../../../mlkem/poly | ||
HARNESS_FILE = coeff_signed_to_unsigned_harness | ||
TARGET ?= coeff_signed_to_unsigned | ||
|
||
CHECKS=--bounds-check --pointer-check \ | ||
--memory-cleanup-check --div-by-zero-check --signed-overflow-check \ | ||
--unsigned-overflow-check --pointer-overflow-check --conversion-check \ | ||
--undefined-shift-check --enum-range-check --pointer-primitive-check | ||
|
||
all: clean $(TARGET) | ||
|
||
coeff_signed_to_unsigned: $(FILE)_contracts.goto results_smt | ||
|
||
|
||
results_smt: $(FILE)_contracts.goto | ||
cbmc --verbosity 6 --object-bits 8 $(CHECKS) --smt2 $< | ||
|
||
$(FILE)_contracts.goto: $(FILE).goto | ||
goto-instrument --dfcc harness --apply-loop-contracts --enforce-contract $(TARGET) $< $@ | ||
|
||
$(FILE).goto: $(FILE).c $(HARNESS_FILE).c | ||
goto-cc --function harness -DCBMC -I../../../fips202 -I../../../mlkem -o $@ $^ | ||
|
||
clean: | ||
rm -f *.goto |
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