Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add additional EC key validation for FIPS #4452

Merged
merged 6 commits into from
Mar 18, 2024

Conversation

goatgoose
Copy link
Contributor

@goatgoose goatgoose commented Mar 6, 2024

Description of changes:

The EC_KEY_check_key libcrypto API is used in s2n-tls to validate the public key received from the peer. Some libcryptos, such as AWS-LC, provide another API: EC_KEY_check_fips, which includes the validation performed by EC_KEY_check_key as well as additional validation for FIPS.

This PR calls the EC_KEY_check_fips API instead of EC_KEY_check_key when s2n-tls is operating in FIPS mode.

Call-outs:

EC_KEY_check_fips isn't defined in all libcryptos, so a new feature probe was added.

Testing:

A new test was added to ensure that the feature probe is working correctly.

Performance:

I ran benchmarks to determine the performance impact of this change with AWS-LC-FIPS-2022. I used this s2n_perf unit test to get results. I ran each operation for 10 minutes.

While this change did significantly impact the performance of s2n_ecc_evp_compute_shared_secret_from_params, this is such a small part of the handshake that there wasn't really a noticeable change.

operation op time before change (us) op time after change (us) % slower
s2n_ecc_evp_compute_shared_secret_from_params 69.14 156.76 126.72%
TLS 1.3 handshake with secp256 1,461.52 1,464.08 0.17%

generate vs compute_shared_secret comparison:

operation op time before change (us) op time after change (us)
s2n_ecc_evp_generate_ephemeral_key 108.37 108.37
s2n_ecc_evp_compute_shared_secret_from_params 69.14 156.76
% of time checking vs generating 38.95% 59.12%

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Mar 6, 2024
@goatgoose goatgoose force-pushed the fips-ec-check branch 2 times, most recently from 3cf7a0e to 7a48299 Compare March 12, 2024 18:28
@goatgoose goatgoose marked this pull request as ready for review March 12, 2024 18:57
@goatgoose goatgoose requested review from lrstewart and jmayclin March 12, 2024 18:58
@goatgoose goatgoose requested a review from lrstewart March 13, 2024 22:26
crypto/s2n_ecc_evp.c Outdated Show resolved Hide resolved
Comment on lines 480 to 484
if (s2n_is_in_fips_mode() && s2n_libcrypto_supports_ec_key_check_fips()) {
EXPECT_FAILURE_WITH_ERRNO(ret, S2N_ERR_ECDHE_INVALID_PUBLIC_KEY_FIPS);
} else {
EXPECT_FAILURE_WITH_ERRNO(ret, S2N_ERR_ECDHE_INVALID_PUBLIC_KEY);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't know that I love this trick, but it does work?

Copy link
Contributor Author

@goatgoose goatgoose Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I'm not really sure it's worth it. If you think it's better without it let me know and I will remove it. I think the test itself is worth keeping either way though, since the call to EC_KEY_check_key isn't currently being tested.

Unfortunately the debug line hack won't work either, since it requires different builds (AWS-LC vs AWS-LC-FIPS), so we can't compare the two line numbers.

crypto/s2n_ecc_evp.c Outdated Show resolved Hide resolved
@goatgoose goatgoose enabled auto-merge (squash) March 18, 2024 16:46
@goatgoose goatgoose merged commit ee58f34 into aws:main Mar 18, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants