Debian Codegraph @

crt/s2n/tests/cbmc/proofs/s2n_align_to/s2n_align_to_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/make_common_datastructures.h>
18
19 #include "api/s2n.h"
20 #include "utils/s2n_safety.h"
21
22 int s2n_align_to_harness()
23 {
24 const uint32_t initial;
25 const uint32_t alignment;
26 /* Division and modulo are too slow in CBMC to perform all necessary checks,
27 * so relevant assertions that can't be used currently have been left in comments. */
28 uint32_t *out = malloc(sizeof(uint32_t));
29 /* uint64_t result = (uint64_t) alignment * ((((uint64_t) initial - 1) / (uint64_t) alignment) + 1); */
30
31 if (s2n_align_to(initial, alignment, out) == S2N_SUCCESS) {
32 if (initial == 0) {
33 assert(*out == 0);
34 } else {
35 /* assert(*out >= initial); */
36 /* assert(*out < (uint64_t) initial + (uint64_t) alignment); */
37 /* assert(result <= UINT32_MAX); */
38 /* assert(*out % alignment == 0); */
39 }
40 } else {
41 /* assert(*out % alignment != 0 || out == NULL); */
42 /* assert(result > UINT32_MAX || out == NULL); */
43 }
44 }