Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Added sgx feature for rand with
no-std
#764Added sgx feature for rand with
no-std
#764Changes from all commits
6669766
9bd37dd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a good idea? I looked at the source code for
sgx_raed_rand
in the Intel SGX SDK. It does feature detection using CPUID to try to detect whether RDRAND is available, and falls back torand()
if feature detection says RDRAND isn't available. But, feature detection like that isn't secure in SGX because theCPUID
has to be executed outside the enclave.In #738, @akash-fortanix and @jethrogb suggested to just hard-code the use of
RDRAND
, i.e. requireRDRAND
be available within SGX, since in practice it seems like all SGX-capable CPUs include RDRAND, despite Intel's warnings. That seems more secure to me. What do you think?Importantly, I'd rather avoid having two different implementations for this for the two different SGX targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like you're saying that Intel's secure randomness isn't really secure.
Assembly is out of my yard.
@dingelish What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Brian, as far as I know,
RDRAND
is always enabled in CPU supporting SGX. The feature detection is only enabled in simulation mode and the fallback only works on sim+oldcpu (no rdrand) combinations.I don't know if you are considering to support the simulation mode of SGX. I would like to recommend to just hard code it for simplification. I would like to say that users needs to add additional stuffs to claim that this is a simulation mode (currently it is defined by env
SGX_MODE=SW
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BoringSSL already has the assembly language code that ring can import, so don't worry about writing assembly language code for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not dug into the randomness of
RDRAND
much. What I know is that people choose to trust it or not.Technically the randomness of
RDRAND
seems good enough.Update: a proof of RDRAND 'bug' caused by bad impl of urandom.
https://cr.yp.to/talks/2014.01.09/slides-dan+tanja-20140109-4x3.pdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dingelish Whether or not RDRAND is secure, both of these approaches ultimately use RDRAND, right? That is, the
sgx_read_rand
function uses RDRAND under the hood, right? The main questoin is whether it is better to use thesgx_read_rand
wrapper or whether it's better to just directly useRDRAND
, right?I have to say, I don't understand the Intel SDK source code at all. My concern was already raised as a bug at intel/linux-sgx#111. It is confusing to have two different implementations of the function (if I understand correctly): the one you pointed me to and the one at https://github.com/intel/linux-sgx/blob/master/common/src/sgx_read_rand.cpp.
This makes me lean in favor of just using RDRAND directly for all SGX targets. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes everything will ultimately use RDRAND. I believe in foreseeable future this is the only randomness source in SGX.
You can forget about
sgx_read_rand
, a function exported by Intel SGX SDK, because ring does not need to depends on Intel SGX SDK. Simply wrapRDRAND
or just use intrinsic functions and that'll be 100% fine for SGX enclave.Yes. There are two implementations of
sgx_read_rand
. One is for the untrusted side, and another is for the trusted side (SGX Enclave). The code snipped he referred to is used in the untrusted side.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dingelish Thanks for the explanation. I agree that we should just more directly use RDRAND and avoid
sgx_read_rand
.