Debian Codegraph @

crt/aws-c-common/include/aws/common/zero.h

raw symbols SCIP
1 #ifndef AWS_COMMON_ZERO_H
2 #define AWS_COMMON_ZERO_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/common/stdbool.h>
10 #include <aws/common/stdint.h>
11
12 #include <string.h>
13
14 AWS_PUSH_SANE_WARNING_LEVEL
15 AWS_EXTERN_C_BEGIN
16
17 /**
18 * Set each byte in the struct to zero.
19 */
20 #define AWS_ZERO_STRUCT(object) \
21 do { \
22 memset(&(object), 0, sizeof(object)); \
23 } while (0)
24
25 /**
26 * Set each byte in the array to zero.
27 * Does not work with arrays of unknown bound.
28 */
29 #define AWS_ZERO_ARRAY(array) memset((void *)(array), 0, sizeof(array))
30
31 /**
32 * Returns whether each byte in the object is zero.
33 */
34 #ifdef CBMC
35 /* clang-format off */
36 # define AWS_IS_ZEROED(object) \
37 __CPROVER_forall { \
38 int i; \
39 (i >= 0 && i < sizeof(object)) ==> ((const uint8_t *)&object)[i] == 0 \
40 }
41 /* clang-format on */
42 #else
43 # define AWS_IS_ZEROED(object) aws_is_mem_zeroed(&(object), sizeof(object))
44 #endif
45
46 /**
47 * Returns whether each byte is zero.
48 */
49 AWS_STATIC_IMPL
50 bool aws_is_mem_zeroed(const void *buf, size_t bufsize);
51
52 /**
53 * Securely zeroes a memory buffer. This function will attempt to ensure that
54 * the compiler will not optimize away this zeroing operation.
55 */
56 AWS_COMMON_API
57 void aws_secure_zero(void *pBuf, size_t bufsize);
58
59 AWS_EXTERN_C_END
60
61 #ifndef AWS_NO_STATIC_IMPL
62 # include <aws/common/zero.inl>
63 #endif /* AWS_NO_STATIC_IMPL */
64
65 AWS_POP_SANE_WARNING_LEVEL
66
67 #endif /* AWS_COMMON_ZERO_H */