| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "crypto/s2n_fips.h" |
| 17 |
#include "tls/s2n_cipher_suites.h" |
| 18 |
#include "tls/s2n_tls_parameters.h" |
| 19 |
#include "utils/s2n_result.h" |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
const s2n_hash_algorithm fips_hash_algs[] = { |
| 24 |
S2N_HASH_SHA224, |
| 25 |
S2N_HASH_SHA256, |
| 26 |
S2N_HASH_SHA384, |
| 27 |
S2N_HASH_SHA512, |
| 28 |
|
| 29 |
S2N_HASH_SHAKE256_64, |
| 30 |
}; |
| 31 |
S2N_RESULT s2n_fips_validate_hash_algorithm(s2n_hash_algorithm hash_alg, bool *valid) |
| 32 |
{ |
| 33 |
RESULT_ENSURE_REF(valid); |
| 34 |
*valid = false; |
| 35 |
for (size_t i = 0; i < s2n_array_len(fips_hash_algs); i++) { |
| 36 |
if (fips_hash_algs[i] == hash_alg) { |
| 37 |
*valid = true; |
| 38 |
return S2N_RESULT_OK; |
| 39 |
} |
| 40 |
} |
| 41 |
return S2N_RESULT_OK; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
const uint8_t fips_cipher_suite_ianas[][2] = { |
| 46 |
|
| 47 |
{ TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 }, |
| 48 |
{ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 }, |
| 49 |
{ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 }, |
| 50 |
{ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 }, |
| 51 |
{ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA }, |
| 52 |
{ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA }, |
| 53 |
|
| 54 |
|
| 55 |
{ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 }, |
| 56 |
{ TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 }, |
| 57 |
{ TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 }, |
| 58 |
{ TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 }, |
| 59 |
{ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 }, |
| 60 |
{ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 }, |
| 61 |
{ TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 }, |
| 62 |
{ TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 }, |
| 63 |
{ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA }, |
| 64 |
{ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA }, |
| 65 |
{ TLS_DHE_RSA_WITH_AES_128_CBC_SHA }, |
| 66 |
{ TLS_DHE_RSA_WITH_AES_256_CBC_SHA }, |
| 67 |
|
| 68 |
|
| 69 |
{ TLS_AES_128_GCM_SHA256 }, |
| 70 |
{ TLS_AES_256_GCM_SHA384 }, |
| 71 |
}; |
| 72 |
|
| 73 |
S2N_RESULT s2n_fips_validate_cipher_suite(const struct s2n_cipher_suite *cipher_suite, bool *valid) |
| 74 |
{ |
| 75 |
RESULT_ENSURE_REF(cipher_suite); |
| 76 |
RESULT_ENSURE_REF(valid); |
| 77 |
|
| 78 |
*valid = false; |
| 79 |
for (size_t i = 0; i < s2n_array_len(fips_cipher_suite_ianas); i++) { |
| 80 |
if (fips_cipher_suite_ianas[i][0] != cipher_suite->iana_value[0]) { |
| 81 |
continue; |
| 82 |
} |
| 83 |
if (fips_cipher_suite_ianas[i][1] != cipher_suite->iana_value[1]) { |
| 84 |
continue; |
| 85 |
} |
| 86 |
*valid = true; |
| 87 |
return S2N_RESULT_OK; |
| 88 |
} |
| 89 |
return S2N_RESULT_OK; |
| 90 |
} |
| 91 |
|
| 92 |
S2N_RESULT s2n_fips_validate_signature_scheme(const struct s2n_signature_scheme *sig_alg, bool *valid) |
| 93 |
{ |
| 94 |
RESULT_ENSURE_REF(sig_alg); |
| 95 |
RESULT_GUARD(s2n_fips_validate_hash_algorithm(sig_alg->hash_alg, valid)); |
| 96 |
return S2N_RESULT_OK; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
const struct s2n_ecc_named_curve *fips_curves[] = { |
| 101 |
&s2n_ecc_curve_secp256r1, |
| 102 |
&s2n_ecc_curve_secp384r1, |
| 103 |
&s2n_ecc_curve_secp521r1, |
| 104 |
}; |
| 105 |
S2N_RESULT s2n_fips_validate_curve(const struct s2n_ecc_named_curve *curve, bool *valid) |
| 106 |
{ |
| 107 |
RESULT_ENSURE_REF(curve); |
| 108 |
RESULT_ENSURE_REF(valid); |
| 109 |
*valid = false; |
| 110 |
for (size_t i = 0; i < s2n_array_len(fips_curves); i++) { |
| 111 |
if (fips_curves[i] == curve) { |
| 112 |
*valid = true; |
| 113 |
return S2N_RESULT_OK; |
| 114 |
} |
| 115 |
} |
| 116 |
return S2N_RESULT_OK; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
const struct s2n_kem *fips_kems[] = { |
| 121 |
&s2n_mlkem_768, |
| 122 |
&s2n_mlkem_1024 |
| 123 |
}; |
| 124 |
|
| 125 |
S2N_RESULT s2n_fips_validate_kem(const struct s2n_kem *kem, bool *valid) |
| 126 |
{ |
| 127 |
RESULT_ENSURE_REF(kem); |
| 128 |
RESULT_ENSURE_REF(valid); |
| 129 |
*valid = false; |
| 130 |
|
| 131 |
for (size_t i = 0; i < s2n_array_len(fips_kems); i++) { |
| 132 |
if (fips_kems[i] == kem) { |
| 133 |
*valid = true; |
| 134 |
return S2N_RESULT_OK; |
| 135 |
} |
| 136 |
} |
| 137 |
return S2N_RESULT_OK; |
| 138 |
} |
| 139 |
|
| 140 |
S2N_RESULT s2n_fips_validate_hybrid_group(const struct s2n_kem_group *hybrid_group, bool *valid) |
| 141 |
{ |
| 142 |
RESULT_ENSURE_REF(hybrid_group); |
| 143 |
RESULT_ENSURE_REF(valid); |
| 144 |
*valid = false; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
| T, |
| 149 |
the |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
if (hybrid_group->send_kem_first || hybrid_group->curve == &s2n_ecc_curve_none) { |
| 157 |
RESULT_GUARD(s2n_fips_validate_kem(hybrid_group->kem, valid)); |
| 158 |
} else { |
| 159 |
RESULT_GUARD(s2n_fips_validate_curve(hybrid_group->curve, valid)); |
| 160 |
} |
| 161 |
|
| 162 |
return S2N_RESULT_OK; |
| 163 |
} |
| 164 |
|
| 165 |
S2N_RESULT s2n_fips_validate_version(uint8_t version, bool *valid) |
| 166 |
{ |
| 167 |
RESULT_ENSURE_REF(valid); |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
*valid = (version >= S2N_TLS12); |
| 172 |
return S2N_RESULT_OK; |
| 173 |
} |