Debian Codegraph @

crt/s2n/tests/unit/s2n_dh_pad_shared_secret_test.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 "s2n_test.h"
17
18 /* Include the .c file directly to access the static helper */
19 #include "crypto/s2n_dhe.c"
20
21 int main(int argc, char **argv)
22 {
23 BEGIN_TEST();
24
25 /* No padding needed when computed_size == expected_size */
26 {
27 uint8_t data[] = { 0xAA, 0xBB, 0xCC, 0xDD };
28 struct s2n_blob key = { 0 };
29 EXPECT_SUCCESS(s2n_blob_init(&key, data, sizeof(data)));
30
31 s2n_dh_pad_shared_secret(&key, 4, 4);
32 EXPECT_EQUAL(key.size, 4);
33 EXPECT_EQUAL(data[0], 0xAA);
34 EXPECT_EQUAL(data[1], 0xBB);
35 EXPECT_EQUAL(data[2], 0xCC);
36 EXPECT_EQUAL(data[3], 0xDD);
37 };
38
39 /* Padding needed when computed_size < expected_size */
40 {
41 uint8_t data[8] = { 0xAA, 0xBB, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00 };
42 struct s2n_blob key = { 0 };
43 EXPECT_SUCCESS(s2n_blob_init(&key, data, 3));
44
45 s2n_dh_pad_shared_secret(&key, 3, 8);
46 EXPECT_EQUAL(key.size, 8);
47 /* First 5 bytes should be zero padding */
48 for (int i = 0; i < 5; i++) {
49 EXPECT_EQUAL(data[i], 0x00);
50 }
51 /* Last 3 bytes should be the original data */
52 EXPECT_EQUAL(data[5], 0xAA);
53 EXPECT_EQUAL(data[6], 0xBB);
54 EXPECT_EQUAL(data[7], 0xCC);
55 };
56
57 END_TEST();
58 }