File: s2n_policy_defaults.c

package info (click to toggle)
aws-crt-python 0.28.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,428 kB
  • sloc: ansic: 437,955; python: 27,657; makefile: 5,855; sh: 4,289; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (128 lines) | stat: -rw-r--r-- 4,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

#include "tls/policy/s2n_policy_defaults.h"

#include "tls/s2n_security_policies.h"

/* clang-format off */
S2N_INLINE_SECURITY_POLICY_V1(
    default_policy_strict,
    S2N_TLS13,
    S2N_CIPHER_PREF_LIST(
        &s2n_tls13_aes_128_gcm_sha256,
        &s2n_tls13_aes_256_gcm_sha384,
    ),
    S2N_SIG_PREF_LIST(
        &s2n_mldsa44,
        &s2n_mldsa65,
        &s2n_mldsa87,
        &s2n_ecdsa_sha256,
        &s2n_ecdsa_sha384,
        &s2n_ecdsa_sha512,
        &s2n_rsa_pss_pss_sha256,
        &s2n_rsa_pss_pss_sha384,
        &s2n_rsa_pss_pss_sha512,
        &s2n_rsa_pss_rsae_sha256,
        &s2n_rsa_pss_rsae_sha384,
        &s2n_rsa_pss_rsae_sha512,
    ),
    S2N_CURVE_PREF_LIST(
        &s2n_ecc_curve_secp256r1,
        &s2n_ecc_curve_secp384r1,
        &s2n_ecc_curve_secp521r1,
    ),
    S2N_KEM_PREF_LIST(
        &s2n_secp256r1_mlkem_768,
        &s2n_x25519_mlkem_768,
        &s2n_secp384r1_mlkem_1024,
    )
);
/* clang-format on */

/* clang-format off */
S2N_INLINE_SECURITY_POLICY_V1(
    default_policy_compat,
    S2N_TLS12,
    S2N_CIPHER_PREF_LIST(
        &s2n_tls13_aes_128_gcm_sha256,
        &s2n_tls13_aes_256_gcm_sha384,
        &s2n_tls13_chacha20_poly1305_sha256,
        &s2n_ecdhe_ecdsa_with_aes_128_gcm_sha256,
        &s2n_ecdhe_rsa_with_aes_128_gcm_sha256,
        &s2n_ecdhe_ecdsa_with_aes_256_gcm_sha384,
        &s2n_ecdhe_rsa_with_aes_256_gcm_sha384,
        &s2n_ecdhe_ecdsa_with_chacha20_poly1305_sha256,
        &s2n_ecdhe_rsa_with_chacha20_poly1305_sha256,
        &s2n_ecdhe_ecdsa_with_aes_128_cbc_sha256,
        &s2n_ecdhe_rsa_with_aes_128_cbc_sha256,
        &s2n_ecdhe_ecdsa_with_aes_256_cbc_sha384,
        &s2n_ecdhe_rsa_with_aes_256_cbc_sha384,
    ),
    S2N_SIG_PREF_LIST(
        &s2n_mldsa44,
        &s2n_mldsa65,
        &s2n_mldsa87,
        &s2n_ecdsa_sha256,
        &s2n_ecdsa_sha384,
        &s2n_ecdsa_sha512,
        &s2n_rsa_pss_pss_sha256,
        &s2n_rsa_pss_pss_sha384,
        &s2n_rsa_pss_pss_sha512,
        &s2n_rsa_pss_rsae_sha256,
        &s2n_rsa_pss_rsae_sha384,
        &s2n_rsa_pss_rsae_sha512,
        &s2n_rsa_pkcs1_sha256,
        &s2n_rsa_pkcs1_sha384,
        &s2n_rsa_pkcs1_sha512,
    ),
    S2N_CURVE_PREF_LIST(
        &s2n_ecc_curve_secp256r1,
        &s2n_ecc_curve_x25519,
        &s2n_ecc_curve_secp384r1,
        &s2n_ecc_curve_secp521r1,
    ),
    S2N_KEM_PREF_LIST(
        &s2n_secp256r1_mlkem_768,
        &s2n_x25519_mlkem_768,
        &s2n_secp384r1_mlkem_1024,
    )
);
/* clang-format on */

const struct s2n_security_policy *default_policies[S2N_MAX_DEFAULT_POLICIES][S2N_MAX_POLICY_VERSIONS] = {
    [S2N_POLICY_STRICT] = {
            [S2N_STRICT_2025_08_20] = &default_policy_strict,
    },
    [S2N_POLICY_COMPATIBLE] = {
            [S2N_COMPAT_2025_08_20] = &default_policy_compat,
    },
};

const struct s2n_security_policy *s2n_security_policy_get(s2n_policy_name policy, uint64_t version)
{
    /* The uint64_t cast here is required for some older compilers to avoid a
     * "tautological-constant-out-of-range-compare" error. That error assumes
     * "policy" will be a valid s2n_default_policy, but that is not guaranteed by
     * the standard.
     */
    PTR_ENSURE((uint64_t) policy < S2N_MAX_DEFAULT_POLICIES, S2N_ERR_INVALID_SECURITY_POLICY);
    PTR_ENSURE(version < S2N_MAX_POLICY_VERSIONS, S2N_ERR_INVALID_SECURITY_POLICY);

    const struct s2n_security_policy *match = default_policies[policy][version];
    PTR_ENSURE(match, S2N_ERR_INVALID_SECURITY_POLICY);

    return match;
}