Skip to content

Commit 635ce54

Browse files
committed
Port 0.7.3 to SGX
1 parent 074cb6a commit 635ce54

File tree

22 files changed

+338
-26
lines changed

22 files changed

+338
-26
lines changed

.drone.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
kind: pipeline
2+
name: rand-sgx-xargo-1604-release
3+
4+
steps:
5+
- name: release-compile
6+
image: baiduxlab/sgx-rust:1604-1.1.0
7+
commands:
8+
- . /opt/sgxsdk/environment
9+
- . /root/.cargo/env
10+
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release
11+
12+
---
13+
14+
kind: pipeline
15+
name: rand-sgx-xargo-1604-debug
16+
17+
steps:
18+
- name: debug-compile
19+
image: baiduxlab/sgx-rust:1604-1.1.0
20+
commands:
21+
- . /opt/sgxsdk/environment
22+
- . /root/.cargo/env
23+
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx
24+
25+
---
26+
27+
kind: pipeline
28+
name: rand-sgx-xargo-1804-release
29+
30+
steps:
31+
- name: release-compile
32+
image: baiduxlab/sgx-rust:1804-1.1.0
33+
commands:
34+
- . /opt/sgxsdk/environment
35+
- . /root/.cargo/env
36+
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release
37+
38+
---
39+
40+
kind: pipeline
41+
name: rand-sgx-xargo-1804-debug
42+
43+
steps:
44+
- name: debug-compile
45+
image: baiduxlab/sgx-rust:1804-1.1.0
46+
commands:
47+
- . /opt/sgxsdk/environment
48+
- . /root/.cargo/env
49+
- RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx
50+
51+
---
52+
53+
kind: pipeline
54+
name: rand-sgx-1604-release
55+
56+
steps:
57+
- name: release-compile
58+
image: baiduxlab/sgx-rust:1604-1.1.0
59+
commands:
60+
- . /opt/sgxsdk/environment
61+
- . /root/.cargo/env
62+
- cargo build --release
63+
64+
---
65+
66+
kind: pipeline
67+
name: rand-sgx-1604-hw-debug
68+
69+
steps:
70+
- name: debug-compile
71+
image: baiduxlab/sgx-rust:1604-1.1.0
72+
commands:
73+
- . /opt/sgxsdk/environment
74+
- . /root/.cargo/env
75+
- cargo build
76+
77+
---
78+
79+
kind: pipeline
80+
name: rand-sgx-1804-release
81+
82+
steps:
83+
- name: release-compile
84+
image: baiduxlab/sgx-rust:1804-1.1.0
85+
commands:
86+
- . /opt/sgxsdk/environment
87+
- . /root/.cargo/env
88+
- cargo build --release
89+
90+
---
91+
92+
kind: pipeline
93+
name: rand-sgx-1804-debug
94+
95+
steps:
96+
- name: debug-compile
97+
image: baiduxlab/sgx-rust:1804-1.1.0
98+
commands:
99+
- . /opt/sgxsdk/environment
100+
- . /root/.cargo/env
101+
- cargo build

.github/pull.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: "1"
2+
rules:
3+
- base: master
4+
upstream: rust-random:master
5+
mergeMethod: none

Cargo.toml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Random number generators and other randomness functionality.
1212
"""
1313
keywords = ["random", "rng"]
1414
categories = ["algorithms", "no-std"]
15-
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"]
15+
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore", "/sgx/*"]
1616
autobenches = true
1717
edition = "2018"
1818

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

2323
[features]
24+
default = ["std", "mesalock_sgx"] # without "std" rand uses libcore
2425
# Meta-features:
25-
default = ["std"] # without "std" rand uses libcore
2626
nightly = ["simd_support"] # enables all features requiring nightly rust
2727
serde1 = [] # does nothing, deprecated
2828

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

3940
# Configuration:
4041
simd_support = ["packed_simd"] # enables SIMD support
@@ -47,7 +48,7 @@ members = [
4748
"rand_chacha",
4849
"rand_hc",
4950
"rand_pcg",
50-
"tests/wasm_bindgen",
51+
#"tests/wasm_bindgen",
5152
]
5253

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

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

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

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

8083
[dev-dependencies]
81-
rand_pcg = { path = "rand_pcg", version = "0.2" }
84+
#rand_pcg = { path = "rand_pcg", version = "0.2" }
8285
# Only for benches:
83-
rand_hc = { path = "rand_hc", version = "0.2" }
86+
#rand_hc = { path = "rand_hc", version = "0.2" }
8487

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

Xargo.toml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
[dependencies]
2+
alloc = {}
3+
4+
[dependencies.sgx_types]
5+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
6+
stage = 1
7+
8+
[dependencies.sgx_alloc]
9+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
10+
stage = 1
11+
12+
[dependencies.sgx_unwind]
13+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
14+
stage = 1
15+
16+
[dependencies.sgx_demangle]
17+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
18+
stage = 1
19+
20+
[dependencies.panic_abort]
21+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
22+
stage = 1
23+
24+
[dependencies.sgx_libc]
25+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
26+
stage = 2
27+
28+
[dependencies.sgx_tkey_exchange]
29+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
30+
stage = 2
31+
32+
[dependencies.sgx_tservice]
33+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
34+
stage = 2
35+
36+
[dependencies.sgx_tse]
37+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
38+
stage = 2
39+
40+
[dependencies.sgx_tcrypto]
41+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
42+
stage = 2
43+
44+
[dependencies.sgx_trts]
45+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
46+
stage = 3
47+
48+
[dependencies.sgx_backtrace_sys]
49+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
50+
stage = 3
51+
52+
[dependencies.panic_unwind]
53+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
54+
stage = 3
55+
56+
[dependencies.sgx_tdh]
57+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
58+
stage = 4
59+
60+
[dependencies.sgx_tseal]
61+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
62+
stage = 4
63+
64+
[dependencies.sgx_tprotected_fs]
65+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
66+
stage = 4
67+
68+
[dependencies.std]
69+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
70+
features = ["backtrace", "net"]
71+
stage = 5
72+
73+
[dependencies.sgx_no_tstd]
74+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
75+
stage = 5
76+
77+
[dependencies.sgx_rand]
78+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
79+
stage = 6
80+
81+
[dependencies.sgx_serialize]
82+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
83+
stage = 6
84+
85+
[dependencies.sgx_tunittest]
86+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
87+
stage = 6
88+
89+
[dependencies.sgx_backtrace]
90+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
91+
stage = 7
92+
93+
[dependencies.sgx_cov]
94+
git = "https://github.com/apache/teaclave-sgx-sdk.git"
95+
stage = 7

rand_chacha/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ appveyor = { repository = "rust-random/rand" }
2020

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

2526
[features]
26-
default = ["std", "simd"]
27-
std = ["c2-chacha/std"]
28-
simd = [] # deprecated
27+
default = ["std", "simd", "mesalock_sgx"]
28+
std = ["c2-chacha/simd"]
29+
simd = []
30+
mesalock_sgx = ["sgx_tstd"]

rand_chacha/src/chacha.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
//! The ChaCha random number generator.
1010
1111
#[cfg(not(feature = "std"))] use core;
12-
#[cfg(feature = "std")] use std as core;
12+
#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))]
13+
use std as core;
1314

15+
#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
16+
use core::fmt;
17+
#[cfg(all(feature = "mesalock_sgx", target_env = "sgx"))]
1418
use self::core::fmt;
1519
use c2_chacha::guts::ChaCha;
1620
use rand_core::block::{BlockRng, BlockRngCore};
@@ -56,6 +60,7 @@ where T: Copy + Default
5660
new
5761
}
5862
}
63+
5964
impl<T> fmt::Debug for Array64<T> {
6065
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6166
write!(f, "Array64 {{}}")

rand_chacha/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
1919
#![cfg_attr(not(feature = "std"), no_std)]
2020

21+
#![cfg_attr(all(feature = "mesalock_sgx",
22+
not(target_env = "sgx")), no_std)]
23+
#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))]
24+
25+
#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
26+
#[macro_use]
27+
extern crate sgx_tstd as std;
28+
2129
pub use rand_core;
2230

2331
mod chacha;

rand_core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ travis-ci = { repository = "rust-random/rand" }
1919
appveyor = { repository = "rust-random/rand" }
2020

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

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

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

rand_core/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
//! Error types
1010
1111
use core::fmt;
12-
use core::num::NonZeroU32;
1312

13+
#[cfg(all(feature="std", feature="mesalock_sgx", not(target_env="sgx")))]
14+
use std::prelude::v1::*;
15+
16+
use core::num::NonZeroU32;
1417

1518
/// Error type of random number generators
1619
///

rand_core/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@
3838
#![allow(clippy::unreadable_literal)]
3939
#![cfg_attr(not(feature = "std"), no_std)]
4040

41+
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
42+
#![cfg_attr(any(not(feature = "std"),
43+
all(feature = "mesalock_sgx", not(target_env = "sgx"))),
44+
no_std)]
45+
#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))]
46+
#![allow(clippy::unreadable_literal)]
47+
48+
#[cfg(all(feature = "mesalock_sgx", not(target_env = "sgx")))]
49+
#[macro_use]
50+
extern crate sgx_tstd as std;
51+
52+
#[cfg(all(feature="mesalock_sgx", not(target_env="sgx")))]
53+
use std::prelude::v1::*;
54+
55+
#[cfg(any(all(feature="std", not(feature="mesalock_sgx")),
56+
target_env = "sgx"))]
57+
extern crate core;
4158

4259
use core::convert::AsMut;
4360
use core::default::Default;

0 commit comments

Comments
 (0)