Debian Codegraph @

crt/s2n/tests/unit/s2n_kem_preferences_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 "tls/s2n_kem_preferences.h"
17
18 #include "crypto/s2n_fips.h"
19 #include "crypto/s2n_pq.h"
20 #include "s2n_test.h"
21 #include "tls/s2n_tls_parameters.h"
22
23 int main(int argc, char **argv)
24 {
25 BEGIN_TEST();
26 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
27
28 EXPECT_FALSE(s2n_kem_preferences_includes_tls13_kem_group(&kem_preferences_null, TLS_PQ_KEM_GROUP_ID_SECP256R1_MLKEM_768));
29 EXPECT_FALSE(s2n_kem_preferences_includes_tls13_kem_group(&kem_preferences_null, TLS_PQ_KEM_GROUP_ID_X25519_MLKEM_768));
30 EXPECT_FALSE(s2n_kem_preferences_includes_tls13_kem_group(&kem_preferences_null, TLS_PQ_KEM_GROUP_ID_SECP384R1_MLKEM_1024));
31 EXPECT_FALSE(s2n_kem_preferences_includes_tls13_kem_group(&kem_preferences_null, TLS_PQ_KEM_GROUP_ID_MLKEM_1024));
32
33 {
34 const struct s2n_kem_preferences test_prefs = {
35 .kem_count = 0,
36 .kems = NULL,
37 .tls13_kem_group_count = S2N_KEM_GROUPS_COUNT,
38 .tls13_kem_groups = ALL_SUPPORTED_KEM_GROUPS,
39 };
40
41 EXPECT_TRUE(s2n_kem_preferences_includes_tls13_kem_group(&test_prefs, TLS_PQ_KEM_GROUP_ID_SECP256R1_MLKEM_768));
42 EXPECT_TRUE(s2n_kem_preferences_includes_tls13_kem_group(&test_prefs, TLS_PQ_KEM_GROUP_ID_X25519_MLKEM_768));
43 EXPECT_TRUE(s2n_kem_preferences_includes_tls13_kem_group(&test_prefs, TLS_PQ_KEM_GROUP_ID_SECP384R1_MLKEM_1024));
44 EXPECT_TRUE(s2n_kem_preferences_includes_tls13_kem_group(&test_prefs, TLS_PQ_KEM_GROUP_ID_MLKEM_1024));
45
46 if (s2n_libcrypto_supports_evp_kem()) {
47 if (s2n_libcrypto_supports_mlkem()) {
48 EXPECT_TRUE(s2n_kem_group_is_available(&s2n_secp256r1_mlkem_768));
49 EXPECT_TRUE(s2n_kem_group_is_available(&s2n_secp384r1_mlkem_1024));
50 EXPECT_TRUE(s2n_kem_group_is_available(&s2n_pure_mlkem_1024));
51 if (s2n_is_evp_apis_supported()) {
52 EXPECT_TRUE(s2n_kem_group_is_available(&s2n_x25519_mlkem_768));
53 } else {
54 EXPECT_FALSE(s2n_kem_group_is_available(&s2n_x25519_mlkem_768));
55 }
56 }
57 } else {
58 EXPECT_FALSE(s2n_kem_group_is_available(&s2n_secp256r1_mlkem_768));
59 EXPECT_FALSE(s2n_kem_group_is_available(&s2n_x25519_mlkem_768));
60 EXPECT_FALSE(s2n_kem_group_is_available(&s2n_secp384r1_mlkem_1024));
61 EXPECT_FALSE(s2n_kem_group_is_available(&s2n_pure_mlkem_1024));
62 }
63 };
64
65 END_TEST();
66 }