Debian Codegraph @

crt/s2n/tests/unit/s2n_stream_cipher_null_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 "crypto/s2n_stream_cipher_null.c"
17
18 #include "api/s2n.h"
19 #include "s2n_test.h"
20
21 int main(int argc, char **argv)
22 {
23 BEGIN_TEST();
24 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
25
26 /* Test that in and out being the same size succeeds */
27 {
28 uint8_t array[9] = { 0 };
29 struct s2n_blob in = { 0 };
30 EXPECT_SUCCESS(s2n_blob_init(&in, array, 9));
31 struct s2n_blob out = { 0 };
32 EXPECT_SUCCESS(s2n_blob_init(&out, array, 9));
33 struct s2n_session_key session_key = { 0 };
34 EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
35 };
36
37 /* Test that in size > out size fails */
38 {
39 uint8_t array[9] = { 0 };
40 struct s2n_blob in = { 0 };
41 EXPECT_SUCCESS(s2n_blob_init(&in, array, 9));
42 struct s2n_blob out = { 0 };
43 EXPECT_SUCCESS(s2n_blob_init(&out, array, 8));
44 struct s2n_session_key session_key = { 0 };
45 EXPECT_FAILURE(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
46 };
47
48 /* Test that in is copied to out when they are different */
49 {
50 uint8_t in_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
51 uint8_t out_array[9] = { 0 };
52 struct s2n_blob in = { 0 };
53 EXPECT_SUCCESS(s2n_blob_init(&in, in_array, 9));
54 struct s2n_blob out = { 0 };
55 EXPECT_SUCCESS(s2n_blob_init(&out, out_array, 9));
56 EXPECT_BYTEARRAY_NOT_EQUAL(in_array, out_array, out.size);
57 struct s2n_session_key session_key = { 0 };
58 EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
59 EXPECT_BYTEARRAY_EQUAL(in_array, out_array, out.size);
60 };
61
62 /* Test that null cipher is always available */
63 {
64 EXPECT_TRUE(s2n_stream_cipher_null_available());
65 };
66
67 /* Test that get_key always returns success */
68 {
69 struct s2n_blob in = { 0 };
70 struct s2n_session_key session_key = { 0 };
71 EXPECT_OK(s2n_stream_cipher_null_get_key(&session_key, &in));
72 };
73
74 /* Test that destroy_key always returns success */
75 {
76 struct s2n_session_key session_key = { 0 };
77 EXPECT_OK(s2n_stream_cipher_null_destroy_key(&session_key));
78 };
79
80 /* Test that init always returns success */
81 {
82 struct s2n_session_key session_key = { 0 };
83 EXPECT_OK(s2n_stream_cipher_null_init(&session_key));
84 };
85
86 END_TEST();
87 }