Debian Codegraph @

crt/aws-c-common/verification/cbmc/stubs/hash_table_generators.c

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 #include <aws/common/private/hash_table_impl.h>
7 #include <proof_helpers/make_common_data_structures.h>
8 #include <proof_helpers/nondet.h>
9
10 /* This file contains generators useful in hash-table stubs. See
11 * aws_hash_table_non_slots_override.c and aws_hash_iter_overrides.c for how these are used
12 */
13
14 /**
15 * The common case for the hash-table is that it maps strings to strings. This generates
16 * fully non-deterministic strings for both key and value
17 */
18 void hash_iterator_string_string_generator(struct aws_hash_iter *new_iter, const struct aws_hash_iter *old_iter) {
19 (void)old_iter;
20 if (new_iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE) {
21 new_iter->element.key = ensure_string_is_allocated_nondet_length();
22 __CPROVER_assume(aws_string_is_valid(new_iter->element.key));
23 new_iter->element.value = ensure_string_is_allocated_nondet_length();
24 __CPROVER_assume(aws_string_is_valid(new_iter->element.value));
25 }
26 }
27
28 /**
29 * The common case for the hash-table is that it maps strings to strings. This generates
30 * fully non-deterministic strings for both key and value
31 */
32 void hash_find_string_string_generator(
33 const struct aws_hash_table *map,
34 const void *key,
35 struct aws_hash_element *p_elem) {
36 if (p_elem) {
37 p_elem->key = ensure_string_is_allocated_nondet_length();
38 __CPROVER_assume(aws_string_is_valid(p_elem->key));
39 p_elem->value = ensure_string_is_allocated_nondet_length();
40 __CPROVER_assume(aws_string_is_valid(p_elem->value));
41 }
42 }
43
44 /**
45 * The common case for the hash-table is that it maps strings to strings.
46 * Some code (for e.g. the aws_cryptosdk_enc_ctx_size() function in the ESDK uses the string header
47 * but not the actual string itself. So this allocates the header, but not the string.
48 * This ensures that no successful proof CAN use the bytes of the string.
49 */
50 void hash_iterator_unbacked_string_string_generator(
51 struct aws_hash_iter *new_iter,
52 const struct aws_hash_iter *old_iter) {
53 (void)old_iter;
54 if (new_iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE) {
55 new_iter->element.key = malloc(sizeof(struct aws_string));
56 new_iter->element.value = malloc(sizeof(struct aws_string));
57 }
58 }
59
60 /**
61 * The common case for the hash-table is that it maps strings to strings.
62 * Some code (for e.g. the aws_cryptosdk_enc_ctx_size() function in the ESDK uses the string header
63 * but not the actual string itself. So this allocates the header, but not the string.
64 * This ensures that no successful proof CAN use the bytes of the string.
65 */
66 void hash_find_unbacked_string_string_generator(
67 const struct aws_hash_table *map,
68 const void *key,
69 struct aws_hash_element *p_elem) {
70 p_elem->key = malloc(sizeof(struct aws_string));
71 p_elem->value = malloc(sizeof(struct aws_string));
72 }