LCOV - code coverage report
Current view: top level - tls/policy - s2n_policy_defaults.c (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 7 7 100.0 %
Date: 2025-09-30 07:28:05 Functions: 1 1 100.0 %
Branches: 9 12 75.0 %

           Branch data     Line data    Source code
       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/policy/s2n_policy_defaults.h"
      17                 :            : 
      18                 :            : #include "tls/s2n_security_policies.h"
      19                 :            : 
      20                 :            : /* clang-format off */
      21                 :            : S2N_INLINE_SECURITY_POLICY_V1(
      22                 :            :     default_policy_strict,
      23                 :            :     S2N_TLS13,
      24                 :            :     S2N_CIPHER_PREF_LIST(
      25                 :            :         &s2n_tls13_aes_128_gcm_sha256,
      26                 :            :         &s2n_tls13_aes_256_gcm_sha384,
      27                 :            :     ),
      28                 :            :     S2N_SIG_PREF_LIST(
      29                 :            :         &s2n_mldsa44,
      30                 :            :         &s2n_mldsa65,
      31                 :            :         &s2n_mldsa87,
      32                 :            :         &s2n_ecdsa_sha256,
      33                 :            :         &s2n_ecdsa_sha384,
      34                 :            :         &s2n_ecdsa_sha512,
      35                 :            :         &s2n_rsa_pss_pss_sha256,
      36                 :            :         &s2n_rsa_pss_pss_sha384,
      37                 :            :         &s2n_rsa_pss_pss_sha512,
      38                 :            :         &s2n_rsa_pss_rsae_sha256,
      39                 :            :         &s2n_rsa_pss_rsae_sha384,
      40                 :            :         &s2n_rsa_pss_rsae_sha512,
      41                 :            :     ),
      42                 :            :     S2N_CURVE_PREF_LIST(
      43                 :            :         &s2n_ecc_curve_secp256r1,
      44                 :            :         &s2n_ecc_curve_secp384r1,
      45                 :            :         &s2n_ecc_curve_secp521r1,
      46                 :            :     ),
      47                 :            :     S2N_KEM_PREF_LIST(
      48                 :            :         &s2n_secp256r1_mlkem_768,
      49                 :            :         &s2n_x25519_mlkem_768,
      50                 :            :         &s2n_secp384r1_mlkem_1024,
      51                 :            :     )
      52                 :            : );
      53                 :            : /* clang-format on */
      54                 :            : 
      55                 :            : /* clang-format off */
      56                 :            : S2N_INLINE_SECURITY_POLICY_V1(
      57                 :            :     default_policy_compat,
      58                 :            :     S2N_TLS12,
      59                 :            :     S2N_CIPHER_PREF_LIST(
      60                 :            :         &s2n_tls13_aes_128_gcm_sha256,
      61                 :            :         &s2n_tls13_aes_256_gcm_sha384,
      62                 :            :         &s2n_tls13_chacha20_poly1305_sha256,
      63                 :            :         &s2n_ecdhe_ecdsa_with_aes_128_gcm_sha256,
      64                 :            :         &s2n_ecdhe_rsa_with_aes_128_gcm_sha256,
      65                 :            :         &s2n_ecdhe_ecdsa_with_aes_256_gcm_sha384,
      66                 :            :         &s2n_ecdhe_rsa_with_aes_256_gcm_sha384,
      67                 :            :         &s2n_ecdhe_ecdsa_with_chacha20_poly1305_sha256,
      68                 :            :         &s2n_ecdhe_rsa_with_chacha20_poly1305_sha256,
      69                 :            :         &s2n_ecdhe_ecdsa_with_aes_128_cbc_sha256,
      70                 :            :         &s2n_ecdhe_rsa_with_aes_128_cbc_sha256,
      71                 :            :         &s2n_ecdhe_ecdsa_with_aes_256_cbc_sha384,
      72                 :            :         &s2n_ecdhe_rsa_with_aes_256_cbc_sha384,
      73                 :            :     ),
      74                 :            :     S2N_SIG_PREF_LIST(
      75                 :            :         &s2n_mldsa44,
      76                 :            :         &s2n_mldsa65,
      77                 :            :         &s2n_mldsa87,
      78                 :            :         &s2n_ecdsa_sha256,
      79                 :            :         &s2n_ecdsa_sha384,
      80                 :            :         &s2n_ecdsa_sha512,
      81                 :            :         &s2n_rsa_pss_pss_sha256,
      82                 :            :         &s2n_rsa_pss_pss_sha384,
      83                 :            :         &s2n_rsa_pss_pss_sha512,
      84                 :            :         &s2n_rsa_pss_rsae_sha256,
      85                 :            :         &s2n_rsa_pss_rsae_sha384,
      86                 :            :         &s2n_rsa_pss_rsae_sha512,
      87                 :            :         &s2n_rsa_pkcs1_sha256,
      88                 :            :         &s2n_rsa_pkcs1_sha384,
      89                 :            :         &s2n_rsa_pkcs1_sha512,
      90                 :            :     ),
      91                 :            :     S2N_CURVE_PREF_LIST(
      92                 :            :         &s2n_ecc_curve_secp256r1,
      93                 :            :         &s2n_ecc_curve_x25519,
      94                 :            :         &s2n_ecc_curve_secp384r1,
      95                 :            :         &s2n_ecc_curve_secp521r1,
      96                 :            :     ),
      97                 :            :     S2N_KEM_PREF_LIST(
      98                 :            :         &s2n_secp256r1_mlkem_768,
      99                 :            :         &s2n_x25519_mlkem_768,
     100                 :            :         &s2n_secp384r1_mlkem_1024,
     101                 :            :     )
     102                 :            : );
     103                 :            : /* clang-format on */
     104                 :            : 
     105                 :            : const struct s2n_security_policy *default_policies[S2N_MAX_DEFAULT_POLICIES][S2N_MAX_POLICY_VERSIONS] = {
     106                 :            :     [S2N_POLICY_STRICT] = {
     107                 :            :             [S2N_STRICT_2025_08_20] = &default_policy_strict,
     108                 :            :     },
     109                 :            :     [S2N_POLICY_COMPATIBLE] = {
     110                 :            :             [S2N_COMPAT_2025_08_20] = &default_policy_compat,
     111                 :            :     },
     112                 :            : };
     113                 :            : 
     114                 :            : const struct s2n_security_policy *s2n_security_policy_get(s2n_policy_name policy, uint64_t version)
     115                 :      65061 : {
     116                 :            :     /* The uint64_t cast here is required for some older compilers to avoid a
     117                 :            :      * "tautological-constant-out-of-range-compare" error. That error assumes
     118                 :            :      * "policy" will be a valid s2n_default_policy, but that is not guaranteed by
     119                 :            :      * the standard.
     120                 :            :      */
     121 [ +  - ][ +  + ]:      65061 :     PTR_ENSURE((uint64_t) policy < S2N_MAX_DEFAULT_POLICIES, S2N_ERR_INVALID_SECURITY_POLICY);
     122 [ +  - ][ +  + ]:        801 :     PTR_ENSURE(version < S2N_MAX_POLICY_VERSIONS, S2N_ERR_INVALID_SECURITY_POLICY);
     123                 :            : 
     124                 :         66 :     const struct s2n_security_policy *match = default_policies[policy][version];
     125 [ +  + ][ +  - ]:         66 :     PTR_ENSURE(match, S2N_ERR_INVALID_SECURITY_POLICY);
     126                 :            : 
     127                 :         38 :     return match;
     128                 :         66 : }

Generated by: LCOV version 1.14