Debian Codegraph @

crt/s2n/tests/cbmc/proofs/s2n_stuffer_reserve/s2n_stuffer_reserve_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 #include <cbmc_proof/nondet.h>
20
21 #include "api/s2n.h"
22 #include "stuffer/s2n_stuffer.h"
23 #include "utils/s2n_mem.h"
24
25 int s2n_stuffer_reserve(struct s2n_stuffer *, struct s2n_stuffer_reservation *, const uint8_t);
26
27 void s2n_stuffer_reserve_harness()
28 {
29 /* Non-deterministic inputs. */
30 struct s2n_stuffer *stuffer = cbmc_allocate_s2n_stuffer();
31 __CPROVER_assume(s2n_result_is_ok(s2n_stuffer_validate(stuffer)));
32 struct s2n_stuffer_reservation *reservation = cbmc_allocate_s2n_stuffer_reservation();
33 const uint8_t length;
34
35 /* Non-deterministically set initialized (in s2n_mem) to true. */
36 if (nondet_bool()) { s2n_mem_init(); }
37
38 /* Save previous state from stuffer. */
39 struct s2n_stuffer old_stuffer = *stuffer;
40 /* Store a byte from the stuffer to compare */
41 struct store_byte_from_buffer old_byte_from_stuffer;
42 save_byte_from_blob(&stuffer->blob, &old_byte_from_stuffer);
43
44 /* Operation under verification. */
45 if (s2n_stuffer_reserve(stuffer, reservation, length) == S2N_SUCCESS) {
46 assert(stuffer->write_cursor == old_stuffer.write_cursor + length);
47 assert(stuffer->high_water_mark == S2N_MAX(old_stuffer.write_cursor + length, old_stuffer.high_water_mark));
48 assert(reservation->length == length);
49 if (old_stuffer.blob.size > 0 && reservation->length > 0) {
50 size_t idx;
51 __CPROVER_assume(idx >= reservation->write_cursor
52 && idx < (reservation->write_cursor + reservation->length));
53 assert(stuffer->blob.data[ idx ] == S2N_WIPE_PATTERN);
54 assert(reservation->stuffer->blob.data[ idx ] == S2N_WIPE_PATTERN);
55 }
56 assert(stuffer == reservation->stuffer);
57 assert(s2n_result_is_ok(s2n_stuffer_validate(stuffer)));
58 assert(s2n_result_is_ok(s2n_stuffer_reservation_validate(reservation)));
59 } else {
60 assert(stuffer->read_cursor == old_stuffer.read_cursor);
61 assert(stuffer->alloced == old_stuffer.alloced);
62 assert(stuffer->growable == old_stuffer.growable);
63 assert(stuffer->tainted == old_stuffer.tainted);
64 }
65 }