Debian Codegraph @

crt/s2n/tests/sidetrail/working/s2n-cbc/cbc.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 <stdint.h>
17
18 #include "crypto/s2n_hmac.h"
19
20 #include "tls/s2n_record.h"
21 #include "tls/s2n_prf.h"
22 #include "tls/s2n_connection.h"
23
24 #include <smack.h>
25 #include <smack-contracts.h>
26 #include "ct-verif.h"
27 #include "sidetrail.h"
28
29 int simple_cbc_wrapper(int currently_in_hash_block, int size, int *xor_pad, int * digest_pad)
30 {
31 /* Even after code balancing, there is a small remaining leakage, because s2n forces an extra hash-compression
32 * round by copying an extra hash block's worth of data into the hash. This has extra cost of memcopy one
33 * hash block (of data already in cache). This could potentially be reduced by finding a better way to trigger
34 * the extra hash-compression round.
35 * Note that the 68 here is in LLVM time model units, which roughly correspond to cycles
36 */
37 __VERIFIER_ASSERT_MAX_LEAKAGE(68);
38
39 public_in(__SMACK_value(currently_in_hash_block));
40 __VERIFIER_assume(currently_in_hash_block >= 0);
41 __VERIFIER_assume(currently_in_hash_block < BLOCK_SIZE);
42
43 struct s2n_hmac_state hmac = {
44 .alg = S2N_HMAC_SHA1,
45 .hash_block_size = BLOCK_SIZE,
46 .currently_in_hash_block = 0,
47 .digest_size = SHA_DIGEST_LENGTH,
48 .xor_pad_size = BLOCK_SIZE,
49 .inner.alg = S2N_HASH_SHA1,
50 .inner.currently_in_hash_block = 0,
51 .inner_just_key.alg = S2N_HASH_SHA1,
52 .inner_just_key.currently_in_hash_block = 0,
53 .outer.alg = S2N_HASH_SHA1,
54 .outer.currently_in_hash_block = 0,
55 .outer_just_key.alg = S2N_HASH_SHA1,
56 .outer_just_key.currently_in_hash_block = 0,
57 .xor_pad = *xor_pad,
58 //xor_pad is an array
59 .digest_pad = *digest_pad
60 };
61
62
63 struct s2n_crypto_parameters client;
64 struct s2n_connection conn = {
65 .client = &client,
66 .mode = S2N_SERVER,
67 .extension_requests_sent = { 0 },
68 .extension_requests_received = { 0 },
69 .extension_responses_received = { 0 }
70 };
71
72 /* Data represents the decrypted data handed to the process.
73 * Intentionally left non-deterministic so that the proof can handle all possible values in the buffer
74 */
75 //cppcheck-suppress unassignedVariable
76 int data[MAX_SIZE];
77 public_in(__SMACK_value(size));
78 __VERIFIER_assume(size >= 0);
79 __VERIFIER_assume(size <= MAX_SIZE);
80
81 struct s2n_blob decrypted = {
82 .data = data,
83 .size = size,
84 .allocated = 1,
85 };
86
87 return s2n_verify_cbc(&conn, &hmac, &decrypted);
88 }