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

refactor: use EVP_MD_fetch() if available #5116

Merged
merged 6 commits into from
Feb 19, 2025

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Feb 14, 2025

Release Summary:

Resolved issues:

related to #5105

Description of changes:

openssl-3.0 "fetches" implementations of algorithms from "providers". To make that more efficient, you're encouraged to "pre-fetch" and store the implementations you use frequently. Additionally, if we want to influence which provider is chosen for the algorithm, we have to provide a "property query string". Here, we're using a string that tells openssl to ignore any default query for fips that was set for MD5.

Basically, this PR should just be a performance improvement for openssl-3.0 (although I didn't actually test that) and is required for openssl-3.0-fips.

I also felt very silly writing EVP_MD *evp_mds[S2N_HASH_SENTINEL], so I renamed S2N_HASH_SENTINEL to S2N_HASH_ALGS_COUNT. That's how it's used almost everywhere in the code, except for like one very old test (s2n_connection_test.c) that really treats it as a sentinel. If that complicates the PR too much, I can revert the rename.

Testing:

We have existing tests for s2n_hash. I added them to the openssl build job.
I also added s2n_openssl_test and s2n_init_test to the openssl build job. I think that's all the really relevant tests.

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 Feb 14, 2025
@lrstewart lrstewart force-pushed the openssl3fips_evp_2a branch 5 times, most recently from 16dfb2a to 0433ba4 Compare February 14, 2025 09:55
@lrstewart lrstewart marked this pull request as ready for review February 14, 2025 20:19
@lrstewart lrstewart requested a review from dougch as a code owner February 14, 2025 20:19
Comment on lines +345 to +370
const EVP_MD *md = s2n_hash_alg_to_evp_md(alg);
POSIX_ENSURE(md, S2N_ERR_HASH_INVALID_ALGORITHM);
POSIX_GUARD_OSSL(EVP_DigestInit_ex(state->digest.high_level.evp.ctx, md, NULL),
S2N_ERR_HASH_INIT_FAILED);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't cause more/less failures, it just makes the reason for failures more explicit. It seemed worth adding the S2N_ERR_HASH_INVALID_ALGORITHM here since hash_init is the place we actually kind of expect to discover a hash isn't allowed.

@lrstewart lrstewart mentioned this pull request Feb 14, 2025
9 tasks
@@ -61,5 +62,10 @@ int main(int argc, char** argv)
EXPECT_FALSE(s2n_supports_custom_rand());
}

/* We expect openssl-3.0 to support providers */
if (strstr(env_libcrypto, "openssl") && strstr(env_libcrypto, "3")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is there a reason we can't just do openssl-3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh not really? I guess I'm just paranoid after seeing all the different ways people format "OpenSSL 3". And openssl-1.0.2 and openssl-1.1.1 don't have "3"s, and it's not like we're going to add another pre-3.0 version.

Comment on lines +65 to +68
/* We expect openssl-3.0 to support providers */
if (strstr(env_libcrypto, "openssl") && strstr(env_libcrypto, "3")) {
EXPECT_TRUE(s2n_libcrypto_supports_providers());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should buildspec_openssl3fips.yml set S2N_LIBCRYPTO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it should D: I must have forgotten a negative CI test when I added the spec!

Here's a negative CI test now: https://us-west-2.console.aws.amazon.com/codesuite/codebuild/024603541914/projects/Openssl3fipsWIP/build/Openssl3fipsWIP%3Ac4c1670b-9b51-40a6-96e5-2328ad81a548?region=us-west-2 I ran against a change that broke s2n_build_test only for openssl-3.0-fips: 9319bb3

@lrstewart lrstewart enabled auto-merge February 19, 2025 18:08
@lrstewart lrstewart added this pull request to the merge queue Feb 19, 2025
Merged via the queue into aws:main with commit 493248b Feb 19, 2025
46 checks passed
@lrstewart lrstewart deleted the openssl3fips_evp_2a branch February 19, 2025 20:24
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.

4 participants