Merge remote-tracking branch 'origin/master' and update changelog
diff --git a/.travis.yml b/.travis.yml
index 6a32e3b..b41e681 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -137,6 +137,7 @@
         - rustup target add wasm32-unknown-emscripten
         - nvm install 9
         - ./utils/ci/install_cargo_web.sh
+        - cargo web prepare-emscripten
         - cargo web -V
       addons:
         chrome: stable
@@ -211,7 +212,11 @@
 
 after_script: set +e
 
-cache: cargo
+cache:
+  cargo: true
+  directories:
+    - .local/share/cargo-web
+
 before_cache:
   # Travis can't cache files that are not readable by "others"
   - chmod -R a+r $HOME/.cargo
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6aa0a24..cf701f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,9 @@
 
 
 ## [0.6.4] - 2019-01-08
+### Additions
+- Add support for x86_64-fortanix-unknown-sgx target (#670)
+
 ### Fixes
 - Move wasm-bindgen shims to correct crate (#686)
 - Make `wasm32-unknown-unknown` compile but fail at run-time if missing bindingsg (#686)
diff --git a/Cargo.toml b/Cargo.toml
index 8f3c374..d802d36 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -79,3 +79,6 @@
 
 [package.metadata.docs.rs]
 all-features = true
+
+[patch.crates-io]
+rand_core = { path = "rand_core", version = "0.3", default-features = false }
diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml
index 723a49a..3adca38 100644
--- a/rand_os/Cargo.toml
+++ b/rand_os/Cargo.toml
@@ -33,3 +33,6 @@
 [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"
diff --git a/rand_os/src/lib.rs b/rand_os/src/lib.rs
index 752303a..67b0dfe 100644
--- a/rand_os/src/lib.rs
+++ b/rand_os/src/lib.rs
@@ -142,6 +142,8 @@
           feature = "stdweb"))]
 #[macro_use] extern crate stdweb;
 
+#[cfg(target_env = "sgx")]
+extern crate rdrand;
 
 #[cfg(not(feature = "log"))]
 #[macro_use]
@@ -310,6 +312,7 @@
 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(
@@ -376,6 +379,7 @@
     target_os = "solaris",
     windows,
     target_arch = "wasm32",
+    target_env = "sgx"
 )))]
 compile_error!("OS RNG support is not available for this platform");
 
diff --git a/rand_os/src/sgx.rs b/rand_os/src/sgx.rs
new file mode 100644
index 0000000..43ae0ef
--- /dev/null
+++ b/rand_os/src/sgx.rs
@@ -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;
+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()
+    }
+}