From 5c6294ae7bf10ca9fac33afde649a8aee1b97572 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Fri, 14 Jun 2019 03:47:37 -0700 Subject: [PATCH] Add error for sgx && !rdrand --- src/rdrand.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rdrand.rs b/src/rdrand.rs index 6c60796..4753507 100644 --- a/src/rdrand.rs +++ b/src/rdrand.rs @@ -31,13 +31,14 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> { Err(Error::UNKNOWN) } +#[cfg(and(target_env = "sgx", not(target_feature = "rdrand")))] +compile_error!("SGX targets must enable RDRAND to get randomness"); + // TODO use is_x86_feature_detected!("rdrand") when that works in core. See: // https://github.com/rust-lang-nursery/stdsimd/issues/464 fn is_rdrand_supported() -> bool { if cfg!(target_feature = "rdrand") { true - } else if cfg!(target_env = "sgx") { - false // No CPUID in SGX enclaves } else { // SAFETY: All x86_64 CPUs support CPUID leaf 1 const FLAG: u32 = 1 << 30;