Skip to content

Commit

Permalink
Port 0.7.3 to SGX
Browse files Browse the repository at this point in the history
  • Loading branch information
dingelish committed Jan 26, 2020
1 parent 074cb6a commit e7e72f1
Show file tree
Hide file tree
Showing 22 changed files with 337 additions and 26 deletions.
101 changes: 101 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
kind: pipeline
name: rand-sgx-xargo-1604-release

steps:
- name: release-compile
image: baiduxlab/sgx-rust:1604-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release

---

kind: pipeline
name: rand-sgx-xargo-1604-debug

steps:
- name: debug-compile
image: baiduxlab/sgx-rust:1604-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx

---

kind: pipeline
name: rand-sgx-xargo-1804-release

steps:
- name: release-compile
image: baiduxlab/sgx-rust:1804-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release

---

kind: pipeline
name: rand-sgx-xargo-1804-debug

steps:
- name: debug-compile
image: baiduxlab/sgx-rust:1804-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx

---

kind: pipeline
name: rand-sgx-1604-release

steps:
- name: release-compile
image: baiduxlab/sgx-rust:1604-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- cargo build --release

---

kind: pipeline
name: rand-sgx-1604-hw-debug

steps:
- name: debug-compile
image: baiduxlab/sgx-rust:1604-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- cargo build

---

kind: pipeline
name: rand-sgx-1804-release

steps:
- name: release-compile
image: baiduxlab/sgx-rust:1804-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- cargo build --release

---

kind: pipeline
name: rand-sgx-1804-debug

steps:
- name: debug-compile
image: baiduxlab/sgx-rust:1804-1.1.0
commands:
- . /opt/sgxsdk/environment
- . /root/.cargo/env
- cargo build
5 changes: 5 additions & 0 deletions .github/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "1"
rules:
- base: master
upstream: rust-random:master
mergeMethod: none
29 changes: 16 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Random number generators and other randomness functionality.
"""
keywords = ["random", "rng"]
categories = ["algorithms", "no-std"]
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"]
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore", "/sgx/*"]
autobenches = true
edition = "2018"

Expand All @@ -21,20 +21,21 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[features]
default = ["std", "mesalock_sgx"] # without "std" rand uses libcore
# Meta-features:
default = ["std"] # without "std" rand uses libcore
nightly = ["simd_support"] # enables all features requiring nightly rust
serde1 = [] # does nothing, deprecated

# Optional dependencies:
std = ["rand_core/std", "rand_chacha/std", "alloc", "getrandom", "libc"]
std = ["rand_core/std", "rand_core/mesalock_sgx", "rand_chacha/std", "rand_chacha/mesalock_sgx", "alloc", "getrandom"]
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
# re-export optional WASM dependencies to avoid breakage:
# Warning: wasm-bindgen and stdweb features will be removed in rand 0.8;
# recommended to activate via the getrandom crate instead.
wasm-bindgen = ["getrandom_package/wasm-bindgen"]
stdweb = ["getrandom_package/stdweb"]
#wasm-bindgen = ["getrandom_package/wasm-bindgen"]
#stdweb = ["getrandom_package/stdweb"]
getrandom = ["getrandom_package", "rand_core/getrandom"]
mesalock_sgx = ["sgx_tstd"]

# Configuration:
simd_support = ["packed_simd"] # enables SIMD support
Expand All @@ -47,7 +48,7 @@ members = [
"rand_chacha",
"rand_hc",
"rand_pcg",
"tests/wasm_bindgen",
#"tests/wasm_bindgen",
]

[dependencies]
Expand All @@ -56,8 +57,9 @@ rand_pcg = { path = "rand_pcg", version = "0.2", optional = true }
# Do not depend on 'getrandom_package' directly; use the 'getrandom' feature!
# This is a dependency because: we forward wasm feature flags
# This is renamed because: we need getrandom to depend on rand_core/getrandom
getrandom_package = { version = "0.1.1", package = "getrandom", optional = true }
log = { version = "0.4.4", optional = true }
getrandom_package = { git = "https://github.com/mesalock-linux/getrandom-sgx.git", package = "getrandom", optional = true }
log = { git = "https://github.com/mesalock-linux/log-sgx.git", optional = true }
sgx_tstd = { version = "1.0", rev = "v1.1.0", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }

[dependencies.packed_simd]
# NOTE: so far no version works reliably due to dependence on unstable features
Expand All @@ -68,19 +70,20 @@ features = ["into_bits"]

[target.'cfg(unix)'.dependencies]
# Used for fork protection (reseeding.rs)
libc = { version = "0.2.22", optional = true, default-features = false }
# SGX does not provide fork. No need for fork protection
#libc = { version = "0.2.22", optional = true, default-features = false }

# Emscripten does not support 128-bit integers, which are used by ChaCha code.
# We work around this by using a different RNG.
[target.'cfg(not(target_os = "emscripten"))'.dependencies]
rand_chacha = { path = "rand_chacha", version = "0.2.1", default-features = false }
[target.'cfg(target_os = "emscripten")'.dependencies]
rand_hc = { path = "rand_hc", version = "0.2" }
#[target.'cfg(target_os = "emscripten")'.dependencies]
#rand_hc = { path = "rand_hc", version = "0.2" }

[dev-dependencies]
rand_pcg = { path = "rand_pcg", version = "0.2" }
#rand_pcg = { path = "rand_pcg", version = "0.2" }
# Only for benches:
rand_hc = { path = "rand_hc", version = "0.2" }
#rand_hc = { path = "rand_hc", version = "0.2" }

[package.metadata.docs.rs]
all-features = true
95 changes: 95 additions & 0 deletions Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
[dependencies]
alloc = {}

[dependencies.sgx_types]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 1

[dependencies.sgx_alloc]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 1

[dependencies.sgx_unwind]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 1

[dependencies.sgx_demangle]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 1

[dependencies.panic_abort]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 1

[dependencies.sgx_libc]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 2

[dependencies.sgx_tkey_exchange]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 2

[dependencies.sgx_tservice]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 2

[dependencies.sgx_tse]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 2

[dependencies.sgx_tcrypto]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 2

[dependencies.sgx_trts]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 3

[dependencies.sgx_backtrace_sys]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 3

[dependencies.panic_unwind]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 3

[dependencies.sgx_tdh]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 4

[dependencies.sgx_tseal]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 4

[dependencies.sgx_tprotected_fs]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 4

[dependencies.std]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
features = ["backtrace", "net"]
stage = 5

[dependencies.sgx_no_tstd]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 5

[dependencies.sgx_rand]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 6

[dependencies.sgx_serialize]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 6

[dependencies.sgx_tunittest]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 6

[dependencies.sgx_backtrace]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 7

[dependencies.sgx_cov]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
stage = 7
10 changes: 6 additions & 4 deletions rand_chacha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ appveyor = { repository = "rust-random/rand" }

[dependencies]
rand_core = { path = "../rand_core", version = "0.5" }
c2-chacha = { version = "0.2.2", default-features = false, features = ["simd"] }
c2-chacha = { git = "https://github.com/mesalock-linux/cryptocorrosion-sgx" }
sgx_tstd = { rev = "v1.1.0", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }

[features]
default = ["std", "simd"]
std = ["c2-chacha/std"]
simd = [] # deprecated
default = ["std", "simd", "mesalock_sgx"]
std = ["c2-chacha/simd"]
simd = []
mesalock_sgx = ["sgx_tstd"]
7 changes: 6 additions & 1 deletion rand_chacha/src/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
//! The ChaCha random number generator.
#[cfg(not(feature = "std"))] use core;
#[cfg(feature = "std")] use std as core;
#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))]
use std as core;

#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
use core::fmt;
#[cfg(all(feature = "mesalock_sgx", target_env = "sgx"))]
use self::core::fmt;
use c2_chacha::guts::ChaCha;
use rand_core::block::{BlockRng, BlockRngCore};
Expand Down Expand Up @@ -56,6 +60,7 @@ where T: Copy + Default
new
}
}

impl<T> fmt::Debug for Array64<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Array64 {{}}")
Expand Down
8 changes: 8 additions & 0 deletions rand_chacha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#![cfg_attr(not(feature = "std"), no_std)]

#![cfg_attr(all(feature = "mesalock_sgx",
not(target_env = "sgx")), no_std)]
#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))]

#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
#[macro_use]
extern crate sgx_tstd as std;

pub use rand_core;

mod chacha;
Expand Down
8 changes: 5 additions & 3 deletions rand_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ travis-ci = { repository = "rust-random/rand" }
appveyor = { repository = "rust-random/rand" }

[features]
std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug
std = ["alloc", "getrandom", "getrandom/std", "mesalock_sgx"] # use std library; should be default but for above bug
alloc = [] # enables Vec and Box support without std
serde1 = ["serde"] # enables serde for BlockRng wrapper
mesalock_sgx = ["alloc", "sgx_tstd"]

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.1", optional = true }
serde = { git = "https://github.com/mesalock-linux/serde-sgx.git", features = ["derive"], optional = true }
getrandom = { git = "https://github.com/mesalock-linux/getrandom-sgx", optional = true }
sgx_tstd = { rev = "v1.1.0", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }

[package.metadata.docs.rs]
all-features = true
5 changes: 4 additions & 1 deletion rand_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
//! Error types
use core::fmt;
use core::num::NonZeroU32;

#[cfg(all(feature="std", feature="mesalock_sgx", not(target_env="sgx")))]
use std::prelude::v1::*;

use core::num::NonZeroU32;

/// Error type of random number generators
///
Expand Down
17 changes: 17 additions & 0 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
#![allow(clippy::unreadable_literal)]
#![cfg_attr(not(feature = "std"), no_std)]

#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
#![cfg_attr(any(not(feature = "std"),
all(feature = "mesalock_sgx", not(target_env = "sgx"))),
no_std)]
#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))]
#![allow(clippy::unreadable_literal)]

#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
#[macro_use]
extern crate sgx_tstd as std;

#[cfg(all(feature="mesalock_sgx", not(target_env="sgx")))]
use std::prelude::v1::*;

#[cfg(any(all(feature="std", not(feature="mesalock_sgx")),
target_env = "sgx"))]
extern crate core;

use core::convert::AsMut;
use core::default::Default;
Expand Down
Loading

0 comments on commit e7e72f1

Please sign in to comment.