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

delete some terrible code that was written to work around cargo bugs #2503

Merged
merged 3 commits into from
Sep 13, 2022

Conversation

cbeck88
Copy link
Contributor

@cbeck88 cbeck88 commented Sep 10, 2022

many years ago, we encountered this bug:
rust-lang/cargo#6571

This bug meant that if we wanted to have a single Rng type that worked on all platforms, including SGX, then it could not use the standard library on any platform, because cargo would evaluate dependencies without respect to what platform you are on.

However, it was really important for our code that we had such an abstraction layer. This was important for writing enclave impl code that could run in SGX and also in unit tests for instance.

The way we solved this issue was that, we took the current version of ThreadRng which is the generically recommendable cryptographic RNG type from rand crate, and made the smallest possible changes to it until it would build without the standard library. The main change was replacing std::thread_local! with the #[thread_local] attribute, which turned out to be straightforward. However, it creates an annoying maintenance burden on us, and there has been a lot of churn in the rand crate since then.

Since the resolver = 2 stuff was stabilized, the original problem is no longer the case. It's fine to have crates that pull in std in one platform but not another. So we can now just use ThreadRng as the no-RDRAND fallback, like we wanted all along.

Copy link
Collaborator

@nick-mobilecoin nick-mobilecoin left a comment

Choose a reason for hiding this comment

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

👍 love the detail in the commit message/description

🔧 Should crytpo/rand/src/lib.rs remove these lines too?

// The fallback code needs the unstable [thread_local] attribute
#![cfg_attr(not(target_feature = "rdrand"), feature(thread_local))]

@nick-mobilecoin nick-mobilecoin requested a review from a team September 10, 2022 17:13
Base automatically changed from eran/wasm-experiment to master September 11, 2022 19:08
@eranrund
Copy link
Contributor

Can you please rebase this?

many years ago, we encountered this bug:
rust-lang/cargo#6571

This bug meant that if we wanted to have a single Rng type that worked
on all platforms, including SGX, then it could not use the standard
library on any platform, because cargo would evaluate dependencies
without respect to what platform you are on.

However, it was really important for our code that we had such an
abstraction layer. This was important for writing enclave impl code
that could run in SGX and also in unit tests for instance.

The way we solved this issue was that, we took the current version
of `ThreadRng` which is the generically recommendable cryptographic
RNG type from `rand` crate, and made the smallest possible changes
to it until it would build without the standard library. The main
change was replacing `std::thread_local!` with the `#[thread_local]`
attribute, which turned out to be straightforward. However, it creates
an annoying maintenance burden on us, and there has been a lot of
churn in the rand crate since then.

Since the `resolver = 2` stuff was stabilized, the original problem
is no longer the case. It's fine to have crates that pull in `std`
in one platform but not another. So we can now just use `ThreadRng`
as the no-RDRAND fallback, like we wanted all along.
@cbeck88 cbeck88 force-pushed the crypto-rand-cleanup branch from 0c108d7 to ce0929f Compare September 13, 2022 06:22
@cbeck88 cbeck88 merged commit 6ecd1a3 into master Sep 13, 2022
@cbeck88 cbeck88 deleted the crypto-rand-cleanup branch September 13, 2022 19:46
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.

3 participants