-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CBMC proof for default_cmm_generate_enc_materials (#656)
* Add proof files for default_cmm_generate_enc_materials * Move on_encrypt function to its own file * Add validator and allocator functions Change variable name and add comment for it on Makefile Merge changes from 'master' * Add and edit allocators for materials and cmm * Add missing file to Makefile (algorithm_is_known) * Remove unnecessary assumptions * Edit preconditions and postconditions * Fix style checks * Restore simpler precondition * Check that output remains unchanged (top-level check only) Do intial allocation as usual and pass output by reference Remove request_alg assertion in case of failure * Fix style issues * Use C-style comments and add space * Remove unneeded assumptions and use nondet values Replace precondition by false case in enc_request validator * Remove copyright year on Makefile
- Loading branch information
1 parent
6005f41
commit 7aaad97
Showing
10 changed files
with
297 additions
and
48 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
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
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
67 changes: 67 additions & 0 deletions
67
verification/cbmc/proofs/default_cmm_generate_enc_materials/Makefile
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,67 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
######### | ||
# if Makefile.local exists, use it. This provides a way to override the defaults | ||
sinclude ../Makefile.local | ||
#otherwise, use the default values | ||
include ../Makefile.local_default | ||
include ../Makefile.string | ||
######### | ||
# Local vars | ||
# Values are chosen for performance. Increasing them does not improve coverage. | ||
MAX_TABLE_SIZE ?= 1 | ||
# In OBJ_txt2nid, this value unwinds strcmp(s, "prime256v1") | ||
PRIME_STRING_LEN=10 | ||
######### | ||
PROOF_UID = default_cmm_generate_enc_materials | ||
HARNESS_ENTRY = $(PROOF_UID)_harness | ||
HARNESS_FILE = $(HARNESS_ENTRY).c | ||
|
||
CBMCFLAGS += | ||
|
||
DEFINES += -DMAX_TABLE_SIZE=$(MAX_TABLE_SIZE) | ||
|
||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/byte_buf.c | ||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/common.c | ||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/encoding.c | ||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/error.c | ||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/hash_table.c | ||
PROJECT_SOURCES += $(CBMC_ROOT)/aws-c-common/source/string.c | ||
PROJECT_SOURCES += $(PROOF_SOURCE)/openssl/bn_override.c | ||
PROJECT_SOURCES += $(PROOF_SOURCE)/openssl/ec_override.c | ||
PROJECT_SOURCES += $(PROOF_SOURCE)/openssl/evp_override.c | ||
PROJECT_SOURCES += $(PROOF_SOURCE)/openssl/objects_override.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/cipher.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/cipher_openssl.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/default_cmm.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/edk.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/header.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/keyring_trace.c | ||
PROJECT_SOURCES += $(SRCDIR)/source/materials.c | ||
|
||
PROOF_SOURCES += $(COMMON_PROOF_SOURCE)/make_common_data_structures.c | ||
PROOF_SOURCES += $(COMMON_PROOF_SOURCE)/proof_allocators.c | ||
PROOF_SOURCES += $(COMMON_PROOF_SOURCE)/utils.c | ||
PROOF_SOURCES += $(COMMON_PROOF_STUB)/aws_hash_table_no_slots_override.c | ||
PROOF_SOURCES += $(COMMON_PROOF_STUB)/aws_string_destroy_override.c | ||
PROOF_SOURCES += $(COMMON_PROOF_STUB)/error.c | ||
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE) | ||
PROOF_SOURCES += $(PROOF_SOURCE)/cbmc_invariants.c | ||
PROOF_SOURCES += $(PROOF_SOURCE)/make_common_data_structures.c | ||
PROOF_SOURCES += $(PROOF_STUB)/aws_base64_encode.c | ||
PROOF_SOURCES += $(PROOF_STUB)/on_encrypt_stub.c | ||
|
||
UNWINDSET += strcmp.0:$(call addone,$(PRIME_STRING_LEN)) | ||
########### | ||
include ../Makefile.common |
4 changes: 4 additions & 0 deletions
4
verification/cbmc/proofs/default_cmm_generate_enc_materials/cbmc-batch.yaml
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,4 @@ | ||
: | ||
This file marks this directory as containing a CBMC proof. This file | ||
is automatically clobbered in CI and replaced with parameters for | ||
running the proof. |
67 changes: 67 additions & 0 deletions
67
...mc/proofs/default_cmm_generate_enc_materials/default_cmm_generate_enc_materials_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,67 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not | ||
* use | ||
* this file except in compliance with the License. A copy of the License is | ||
* located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on | ||
* an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or | ||
* implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <aws/cryptosdk/default_cmm.h> | ||
#include <aws/cryptosdk/materials.h> | ||
#include <make_common_data_structures.h> | ||
|
||
int on_encrypt( | ||
struct aws_cryptosdk_keyring *keyring, | ||
struct aws_allocator *request_alloc, | ||
struct aws_byte_buf *unencrypted_data_key, | ||
struct aws_array_list *keyring_trace, | ||
struct aws_array_list *edks, | ||
const struct aws_hash_table *enc_ctx, | ||
enum aws_cryptosdk_alg_id alg); | ||
|
||
void default_cmm_generate_enc_materials_harness() { | ||
const struct aws_cryptosdk_keyring_vt vtable = { .vt_size = nondet_size_t(), | ||
.name = ensure_c_str_is_allocated(SIZE_MAX), | ||
.destroy = nondet_voidp(), | ||
.on_encrypt = nondet_bool() ? NULL : on_encrypt, | ||
.on_decrypt = nondet_voidp() }; | ||
/* Nondet input */ | ||
struct aws_cryptosdk_cmm *cmm = ensure_default_cmm_attempt_allocation(&vtable); | ||
struct aws_cryptosdk_enc_materials *output = ensure_enc_materials_attempt_allocation(); | ||
struct aws_cryptosdk_enc_request *request = ensure_enc_request_attempt_allocation(MAX_TABLE_SIZE); | ||
|
||
/* Assumptions */ | ||
__CPROVER_assume(aws_cryptosdk_default_cmm_is_valid(cmm)); | ||
|
||
__CPROVER_assume(output != NULL); | ||
|
||
__CPROVER_assume(aws_cryptosdk_enc_request_is_valid(request)); | ||
|
||
/* Save current state of the data structures */ | ||
struct store_byte_from_buffer old_output; | ||
save_byte_from_array((uint8_t *)output, sizeof(*output), &old_output); | ||
|
||
/* Operation under verification */ | ||
if (__CPROVER_file_local_default_cmm_c_default_cmm_generate_enc_materials(cmm, &output, request) == | ||
AWS_OP_SUCCESS) { | ||
assert(aws_cryptosdk_enc_materials_is_valid(output)); | ||
assert(aws_cryptosdk_algorithm_is_known(request->requested_alg)); | ||
} else { | ||
/* Note that we perform a top-level comparison here */ | ||
assert_byte_from_buffer_matches((uint8_t *)output, &old_output); | ||
} | ||
|
||
/* Postconditions */ | ||
assert(aws_cryptosdk_default_cmm_is_valid(cmm)); | ||
assert(aws_cryptosdk_enc_request_is_valid(request)); | ||
} |
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
Oops, something went wrong.