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

Add support for x86_64-fortanix-unknown-sgx target #670

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ autocfg = "0.1"

[package.metadata.docs.rs]
all-features = true

[patch.crates-io]
rand_core = { path = "rand_core", version = "0.3", default-features = false }
3 changes: 3 additions & 0 deletions rand_os/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ fuchsia-zircon = "0.3.2"
[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.12", optional = true }
stdweb = { version = "0.4", optional = true }

[target.'cfg(target_env = "sgx")'.dependencies]
rdrand = "0.4.0"
4 changes: 4 additions & 0 deletions rand_os/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ extern crate wasm_bindgen;
feature = "stdweb"))]
#[macro_use] extern crate stdweb;

#[cfg(target_env = "sgx")]
extern crate rdrand;

#[cfg(not(feature = "log"))]
#[macro_use]
Expand Down Expand Up @@ -310,6 +312,7 @@ mod_use!(cfg(target_os = "openbsd"), openbsd_bitrig);
mod_use!(cfg(target_os = "redox"), redox);
mod_use!(cfg(target_os = "solaris"), solaris);
mod_use!(cfg(windows), windows);
mod_use!(cfg(target_env = "sgx"), sgx);

mod_use!(
cfg(all(
Expand Down Expand Up @@ -356,5 +359,6 @@ compile_error!("enable either wasm_bindgen or stdweb feature");
target_os = "solaris",
windows,
target_arch = "wasm32",
target_env = "sgx"
)))]
compile_error!("OS RNG support is not available for this platform");
38 changes: 38 additions & 0 deletions rand_os/src/sgx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2018 Developers of the Rand project.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::OsRngImpl;
dhardy marked this conversation as resolved.
Show resolved Hide resolved
use Error;
use rdrand::RdRand;
use rand_core::RngCore;
use std::fmt::{Debug, Formatter, Result as FmtResult};

#[derive(Clone)]
pub struct OsRng{
gen: RdRand
}

impl OsRngImpl for OsRng {
fn new() -> Result<OsRng, Error> {
let rng = RdRand::new()?;
Ok(OsRng{ gen: rng })
}

fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> {
self.gen.try_fill_bytes(dest)
}

fn method_str(&self) -> &'static str { "RDRAND" }
}

impl Debug for OsRng {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
f.debug_struct("OsRng")
.finish()
}
}