Debian Codegraph @

crt/aws-c-common/verification/cbmc/include/proof_helpers/utils.h

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #pragma once
7
8 #include <aws/common/array_list.h>
9 #include <aws/common/byte_buf.h>
10 #include <proof_helpers/nondet.h>
11 #include <stddef.h>
12 #include <stdint.h>
13
14 /**
15 * CBMC has an internal representation in which each object has an index and a (signed) offset
16 * A buffer cannot be larger than the max size of the offset
17 * The Makefile is expected to set CBMC_OBJECT_BITS to the value of --object-bits
18 */
19 #define MAX_MALLOC (SIZE_MAX >> (CBMC_OBJECT_BITS + 1))
20
21 // The magical name __CPROVER_uninterpreted_* causes CBMC to give us an
22 // uninterpreted function
23 uint64_t __CPROVER_uninterpreted_hasher(void *);
24
25 #define IMPLIES(a, b) (!(a) || (b))
26
27 struct store_byte_from_buffer {
28 size_t index;
29 uint8_t byte;
30 };
31
32 /**
33 * Asserts whether all bytes from two arrays of same length match.
34 */
35 void assert_bytes_match(const uint8_t *const a, const uint8_t *const b, const size_t len);
36
37 /**
38 * Asserts whether all bytes from an array are equal to c.
39 */
40 void assert_all_bytes_are(const uint8_t *const a, const uint8_t c, const size_t len);
41
42 /**
43 * Asserts whether all bytes from an array are equal to 0.
44 */
45 void assert_all_zeroes(const uint8_t *const a, const size_t len);
46
47 /**
48 * Asserts whether the byte in storage correspond to the byte in the same position in buffer.
49 */
50 void assert_byte_from_buffer_matches(const uint8_t *const buffer, const struct store_byte_from_buffer *const b);
51
52 /**
53 * Nondeterministically selects a byte from array and stores it into a store_array_list_byte
54 * structure. Afterwards, one can prove using the assert_array_list_equivalence function
55 * whether no byte in the array has changed.
56 */
57 void save_byte_from_array(const uint8_t *const array, const size_t size, struct store_byte_from_buffer *const storage);
58
59 /**
60 * Asserts two aws_array_list structures are equivalent. Prior to using this function,
61 * it is necessary to select a non-deterministic byte from the rhs aws_array_list structure
62 * (use save_byte_from_array function), so it can properly assert all bytes match.
63 */
64 void assert_array_list_equivalence(
65 const struct aws_array_list *const lhs,
66 const struct aws_array_list *const rhs,
67 const struct store_byte_from_buffer *const rhs_byte);
68
69 /**
70 * Asserts two aws_byte_buf structures are equivalent. In order to be considered equivalent,
71 * all member from both structures must match (i.e., len, *buffer, capacity, and *allocator),
72 * including all bytes from its underlying buffers. Prior to using this function,
73 * it is necessary to select a non-deterministic byte from the rhs aws_byte_buf structure
74 * (use save_byte_from_array function), so it can properly assert all bytes match.
75 */
76 void assert_byte_cursor_equivalence(
77 const struct aws_byte_cursor *const lhs,
78 const struct aws_byte_cursor *const rhs,
79 const struct store_byte_from_buffer *const rhs_byte);
80
81 /**
82 * Asserts two aws_byte_cursor structures are equivalent. Prior to using this function,
83 * it is necessary to select a non-deterministic byte from the rhs aws_byte_cursor structure
84 * (use save_byte_from_array function), so it can properly assert all bytes match.
85 */
86 void assert_byte_buf_equivalence(
87 const struct aws_byte_buf *const lhs,
88 const struct aws_byte_buf *const rhs,
89 const struct store_byte_from_buffer *const rhs_byte);
90
91 /**
92 * Nondeterministically selects a byte from a hash_table implementation and stores it into a
93 * store_array_list_byte structure.
94 */
95 void save_byte_from_hash_table(const struct aws_hash_table *map, struct store_byte_from_buffer *storage);
96
97 /**
98 * Checks that a no bytes in the hash_table have changed from when "storage" was stored.
99 */
100 void check_hash_table_unchanged(const struct aws_hash_table *map, const struct store_byte_from_buffer *storage);
101
102 /**
103 * Standard stub function to compare two items.
104 */
105 int nondet_compare(const void *const a, const void *const b);
106
107 /**
108 * Standard stub function to compare two items.
109 */
110 int uninterpreted_compare(const void *const a, const void *const b);
111
112 /**
113 * Standard stub function to compare two items.
114 */
115 bool nondet_equals(const void *const a, const void *const b);
116
117 /**
118 * Standard stub function to compare two items.
119 * Also enforces uninterpreted_hasher() to be equal for equal values.
120 */
121 bool uninterpreted_equals(const void *const a, const void *const b);
122
123 /**
124 * uninterpreted_equals(), but with an extra assertion that a and b are both not null
125 */
126 bool uninterpreted_equals_assert_inputs_nonnull(const void *const a, const void *const b);
127
128 /**
129 * Standard stub function to hash one item.
130 */
131 uint64_t nondet_hasher(const void *a);
132
133 /**
134 * Standard stub function to hash one item.
135 */
136 uint64_t uninterpreted_hasher(const void *a);
137
138 /**
139 * Standard stub function of a predicate
140 */
141 bool uninterpreted_predicate_fn(uint8_t value);