Debian Codegraph @

crt/s2n/tests/cbmc/proofs/s2n_dup/s2n_dup_harness.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include <assert.h>
17 #include <cbmc_proof/cbmc_utils.h>
18 #include <cbmc_proof/make_common_datastructures.h>
19
20 #include "api/s2n.h"
21 #include "utils/s2n_blob.h"
22
23 /*
24 * There's unreachable code in the CBMC output because s2n_dup calls
25 * s2n_alloc, which itself calls s2n_realloc. Since the to blob must
26 * be size 0 with a null data pointer to pass the first checks in s2n_dup,
27 * many branches of s2n_realloc cannot be executed. This is intentional behavior.
28 */
29
30 void s2n_dup_harness()
31 {
32 struct s2n_blob *from = cbmc_allocate_s2n_blob();
33 struct s2n_blob *to = cbmc_allocate_s2n_blob();
34 __CPROVER_assume(s2n_result_is_ok(s2n_blob_validate(from)));
35 __CPROVER_assume(s2n_result_is_ok(s2n_blob_validate(to)));
36 const struct s2n_blob old_from = *from;
37 const struct s2n_blob old_to = *to;
38 struct store_byte_from_buffer old_byte;
39 save_byte_from_blob(from, &old_byte);
40
41 nondet_s2n_mem_init();
42
43 if (s2n_dup(from, to) == S2N_SUCCESS) {
44 assert(old_from.size != 0);
45 assert(old_from.data != NULL);
46 assert(old_to.size == 0);
47 assert(old_to.data == NULL);
48 assert(to->size == from->size);
49
50 uint32_t idx;
51 __CPROVER_assume(idx < from->size);
52 assert(from->data[ idx ] == to->data[ idx ]);
53 }
54 assert(s2n_result_is_ok(s2n_blob_validate(from)));
55 assert(s2n_result_is_ok(s2n_blob_validate(to)));
56 assert_blob_equivalence(from, &old_from, &old_byte);
57 }