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

Enable RDRAND for all x86_64 except known prohibitively slow CPU models #2135

Conversation

torben-hansen
Copy link
Contributor

Description of changes:

Remove the need to have a "fast" rdrand. Instead flip the model to exclude known prohibitively slow rdrand implementations. In particular, this includes the AMD Zen1 and Zen2 generation microarchitectures. See q/VxC3AiwXpAjJ for some data on that.

This change is made to increase the usage of prediction resistance.

Testing:

To test the new family detection, I patched like this:

$ git diff
diff --git a/crypto/fipsmodule/cpucap/cpu_intel.c b/crypto/fipsmodule/cpucap/cpu_intel.c
index 8504ec3c4..96bdb6199 100644
--- a/crypto/fipsmodule/cpucap/cpu_intel.c
+++ b/crypto/fipsmodule/cpucap/cpu_intel.c
@@ -242,7 +242,10 @@ void OPENSSL_cpuid_setup(void) {
     }
 
     if (amd_rdrand_maybe_apply_restrictions(family, model) != 0) {
+      printf("amd_rdrand_maybe_apply_restrictions() returned 1\n");
       ecx &= ~(1u << 30);
+    } else {
+      printf("amd_rdrand_maybe_apply_restrictions() returned 0\n");
     }
   }

and ran the code on both a c5a and c6a instance. The former is Zen2 based, the latter is Zen3 based.

c5a:

$ ./tool/bssl version
amd_rdrand_maybe_apply_restrictions() returned 1

c6a:

$ ./tool/bssl version
amd_rdrand_maybe_apply_restrictions() returned 0

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

@torben-hansen torben-hansen requested a review from a team as a code owner January 23, 2025 20:49
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.73%. Comparing base (2637eda) to head (a8bb430).

Files with missing lines Patch % Lines
crypto/fipsmodule/cpucap/cpu_intel.c 71.42% 2 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           randomness_generation    #2135      +/-   ##
=========================================================
+ Coverage                  78.71%   78.73%   +0.01%     
=========================================================
  Files                        608      608              
  Lines                     102793   102800       +7     
  Branches                   14586    14586              
=========================================================
+ Hits                       80917    80939      +22     
+ Misses                     21167    21146      -21     
- Partials                     709      715       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crypto/fipsmodule/cpucap/cpu_intel.c Show resolved Hide resolved
@@ -498,7 +498,7 @@ static std::vector<Event> TestFunctionPRNGModel(unsigned flags) {
const size_t kPersonalizationStringLength = CTR_DRBG_ENTROPY_LEN;
const size_t kPassiveEntropyWithWhitenFactor = PASSIVE_ENTROPY_LOAD_LENGTH;
const bool kHaveRdrand = have_hw_rng_x86_64();
const bool kHaveFastRdrand = have_hw_rng_x86_64_fast();
const bool kHaveFastRdrand = have_hw_rng_x86_64();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should just remove kHaveFastRdrand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh correct. Will do when re-writing the tests.

@torben-hansen torben-hansen merged commit d1bfc44 into aws:randomness_generation Jan 24, 2025
110 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants