From bdfc1cabaf2adbd2ac6722b9b35e220475726bbd Mon Sep 17 00:00:00 2001 From: Yu Ding Date: Tue, 16 Jul 2019 07:05:38 -0700 Subject: [PATCH] Add SGX --- .drone.yml | 101 ++++++++++++++++++++++++++++++++++ .github/pull.yml | 5 ++ Xargo.toml | 90 ++++++++++++++++++++++++++++++ block-cipher-trait/Cargo.toml | 6 +- block-cipher-trait/src/dev.rs | 4 +- block-cipher-trait/src/lib.rs | 9 ++- crypto-mac/Cargo.toml | 6 +- crypto-mac/src/dev.rs | 4 +- crypto-mac/src/lib.rs | 11 ++++ digest/Cargo.toml | 8 ++- digest/src/dev.rs | 4 +- digest/src/lib.rs | 8 ++- stream-cipher/Cargo.toml | 6 +- stream-cipher/src/dev.rs | 20 ++++--- stream-cipher/src/lib.rs | 5 +- x86_64-unknown-linux-sgx.json | 31 +++++++++++ 16 files changed, 288 insertions(+), 30 deletions(-) create mode 100644 .drone.yml create mode 100644 .github/pull.yml create mode 100644 Xargo.toml create mode 100644 x86_64-unknown-linux-sgx.json diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 000000000..4ec1c8b01 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,101 @@ +kind: pipeline +name: rustcrypto-traits-sgx-xargo-1604-release + +steps: +- name: release-compile + image: baiduxlab/sgx-rust:1604-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-xargo-1604-debug + +steps: +- name: debug-compile + image: baiduxlab/sgx-rust:1604-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-xargo-1804-release + +steps: +- name: release-compile + image: baiduxlab/sgx-rust:1804-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx --release + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-xargo-1804-debug + +steps: +- name: debug-compile + image: baiduxlab/sgx-rust:1804-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - RUST_TARGET_PATH=`pwd` xargo build --target x86_64-unknown-linux-sgx + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-1604-release + +steps: +- name: release-compile + image: baiduxlab/sgx-rust:1604-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - cargo build --release + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-1604-hw-debug + +steps: +- name: debug-compile + image: baiduxlab/sgx-rust:1604-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - cargo build + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-1804-release + +steps: +- name: release-compile + image: baiduxlab/sgx-rust:1804-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - cargo build --release + +--- + +kind: pipeline +name: rustcrypto-traits-sgx-1804-debug + +steps: +- name: debug-compile + image: baiduxlab/sgx-rust:1804-1.0.9 + commands: + - . /opt/sgxsdk/environment + - . /root/.cargo/env + - cargo build diff --git a/.github/pull.yml b/.github/pull.yml new file mode 100644 index 000000000..e2a107537 --- /dev/null +++ b/.github/pull.yml @@ -0,0 +1,5 @@ +version: "1" +rules: + - base: master + upstream: RustCrypto:master + mergeMethod: none diff --git a/Xargo.toml b/Xargo.toml new file mode 100644 index 000000000..ae57fb6de --- /dev/null +++ b/Xargo.toml @@ -0,0 +1,90 @@ +[dependencies] +alloc = {} + +[dependencies.sgx_types] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 1 + +[dependencies.sgx_demangle] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 1 + +[dependencies.panic_abort] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 1 + +[dependencies.sgx_libc] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 2 + +[dependencies.sgx_tkey_exchange] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 2 + +[dependencies.sgx_tservice] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 2 + +[dependencies.sgx_tse] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 2 + +[dependencies.sgx_tcrypto] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 2 + +[dependencies.sgx_trts] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 3 + +[dependencies.sgx_backtrace_sys] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 3 + +[dependencies.sgx_unwind] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 4 + +[dependencies.sgx_tdh] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 4 + +[dependencies.sgx_tseal] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 4 + +[dependencies.sgx_tprotected_fs] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 4 + +[dependencies.sgx_alloc] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 4 + +[dependencies.panic_unwind] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 5 + +[dependencies.std] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 6 + +[dependencies.sgx_rand] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 7 + +[dependencies.sgx_serialize] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 7 + +[dependencies.sgx_tunittest] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 7 + +[dependencies.sgx_backtrace] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 8 + +[dependencies.sgx_cov] +git = "https://github.com/baidu/rust-sgx-sdk.git" +stage = 8 diff --git a/block-cipher-trait/Cargo.toml b/block-cipher-trait/Cargo.toml index 267798e1d..91b6cd9fe 100644 --- a/block-cipher-trait/Cargo.toml +++ b/block-cipher-trait/Cargo.toml @@ -11,11 +11,13 @@ categories = ["cryptography", "no-std"] [dependencies] generic-array = "0.12" -blobby = { version = "0.1", optional = true } +blobby = { git = "https://github.com/mesalock-linux/rustcrypto-utils-sgx", optional = true } +sgx_tstd = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git", optional = true } [features] -std = [] +std = ["mesalock_sgx"] dev = ["blobby"] +mesalock_sgx = ["sgx_tstd"] [badges] travis-ci = { repository = "RustCrypto/traits" } diff --git a/block-cipher-trait/src/dev.rs b/block-cipher-trait/src/dev.rs index 938df6869..17652ed25 100644 --- a/block-cipher-trait/src/dev.rs +++ b/block-cipher-trait/src/dev.rs @@ -1,8 +1,8 @@ #[macro_export] macro_rules! new_test { ($name:ident, $test_name:expr, $cipher:ty) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use block_cipher_trait::blobby::Blob3Iterator; use block_cipher_trait::generic_array::typenum::Unsigned; use block_cipher_trait::generic_array::GenericArray; diff --git a/block-cipher-trait/src/lib.rs b/block-cipher-trait/src/lib.rs index 497287fd7..611816333 100644 --- a/block-cipher-trait/src/lib.rs +++ b/block-cipher-trait/src/lib.rs @@ -2,14 +2,19 @@ //! block ciphers. #![no_std] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] +#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))] #[cfg(feature = "dev")] pub extern crate blobby; pub extern crate generic_array; -#[cfg(feature = "std")] + +#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))] extern crate std; +#[cfg(all(feature = "std", feature = "mesalock_sgx", not(target_env = "sgx")))] +extern crate sgx_tstd as std; + +use generic_array::{GenericArray, ArrayLength}; use generic_array::typenum::Unsigned; -use generic_array::{ArrayLength, GenericArray}; #[cfg(feature = "dev")] pub mod dev; diff --git a/crypto-mac/Cargo.toml b/crypto-mac/Cargo.toml index 51af928cd..f2a12258f 100644 --- a/crypto-mac/Cargo.toml +++ b/crypto-mac/Cargo.toml @@ -12,11 +12,13 @@ categories = ["cryptography", "no-std"] [dependencies] generic-array = "0.12" subtle = { version = "2", default-features = false } -blobby = { version = "0.1", optional = true } +blobby = { git = "https://github.com/mesalock-linux/rustcrypto-utils-sgx", optional = true } +sgx_tstd = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git", optional = true } [features] dev = ["blobby"] -std = [] +std = ["mesalock_sgx"] +mesalock_sgx = ["sgx_tstd"] [badges] travis-ci = { repository = "RustCrypto/traits" } diff --git a/crypto-mac/src/dev.rs b/crypto-mac/src/dev.rs index 9eb4b6b75..16bc90208 100644 --- a/crypto-mac/src/dev.rs +++ b/crypto-mac/src/dev.rs @@ -1,8 +1,8 @@ #[macro_export] macro_rules! new_test { ($name:ident, $test_name:expr, $mac:ty) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use crypto_mac::blobby::Blob3Iterator; use crypto_mac::Mac; diff --git a/crypto-mac/src/lib.rs b/crypto-mac/src/lib.rs index 70779cf7e..88656cd0c 100644 --- a/crypto-mac/src/lib.rs +++ b/crypto-mac/src/lib.rs @@ -1,9 +1,15 @@ //! This crate provides trait for Message Authentication Code (MAC) algorithms. #![no_std] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] +#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))] pub extern crate generic_array; extern crate subtle; +#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))] +extern crate std; +#[cfg(all(feature = "std", feature = "mesalock_sgx", not(target_env = "sgx")))] +extern crate sgx_tstd as std; + #[cfg(feature = "dev")] pub extern crate blobby; #[cfg(feature = "std")] @@ -92,6 +98,11 @@ where pub fn code(self) -> GenericArray { self.code } + + /// Added by @dingelish, to provide backward compatibility + pub fn code_ref(&self) -> &GenericArray { + &self.code + } } impl ConstantTimeEq for MacResult diff --git a/digest/Cargo.toml b/digest/Cargo.toml index 5825ca0ab..9a759795d 100644 --- a/digest/Cargo.toml +++ b/digest/Cargo.toml @@ -11,14 +11,16 @@ categories = ["cryptography", "no-std"] [dependencies] generic-array = "0.12" -blobby = { version = "0.1", optional = true } +blobby = { git = "https://github.com/mesalock-linux/rustcrypto-utils-sgx", optional = true } +sgx_tstd = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git", optional = true } [features] -std = [] +std = ["mesalock_sgx"] dev = ["blobby"] +mesalock_sgx = ["sgx_tstd"] [badges] travis-ci = { repository = "RustCrypto/traits" } [package.metadata.docs.rs] -features = ["std"] \ No newline at end of file +features = ["std"] diff --git a/digest/src/dev.rs b/digest/src/dev.rs index f4d79e71e..1b6ed74b8 100644 --- a/digest/src/dev.rs +++ b/digest/src/dev.rs @@ -4,8 +4,8 @@ use core::fmt::Debug; #[macro_export] macro_rules! new_test { ($name:ident, $test_name:expr, $hasher:ty, $test_func:ident) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use digest::blobby::Blob2Iterator; let data = include_bytes!(concat!("data/", $test_name, ".blb")); diff --git a/digest/src/lib.rs b/digest/src/lib.rs index 3d2e06757..2103a9a47 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -14,10 +14,12 @@ //! The `Digest` trait is the most commonly used trait. #![no_std] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] +#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))] pub extern crate generic_array; -#[cfg(feature = "std")] -#[macro_use] -extern crate std; +#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))] +#[macro_use] extern crate std; +#[cfg(all(feature = "std", feature = "mesalock_sgx", not(target_env = "sgx")))] +#[macro_use] extern crate sgx_tstd as std; #[cfg(feature = "dev")] pub extern crate blobby; use generic_array::{ArrayLength, GenericArray}; diff --git a/stream-cipher/Cargo.toml b/stream-cipher/Cargo.toml index 7e0d1196f..229cbd08c 100644 --- a/stream-cipher/Cargo.toml +++ b/stream-cipher/Cargo.toml @@ -11,11 +11,13 @@ categories = ["cryptography", "no-std"] [dependencies] generic-array = "0.12" -blobby = { version = "0.1", optional = true } +blobby = { git = "https://github.com/mesalock-linux/rustcrypto-utils-sgx", optional = true } +sgx_tstd = { rev = "v1.0.9", git = "https://github.com/baidu/rust-sgx-sdk.git", optional = true } [features] -std = [] +std = ["mesalock_sgx"] dev = ["blobby"] +mesalock_sgx = ["sgx_tstd"] [badges] travis-ci = { repository = "RustCrypto/traits" } diff --git a/stream-cipher/src/dev.rs b/stream-cipher/src/dev.rs index ee66a72d9..d23042e4c 100644 --- a/stream-cipher/src/dev.rs +++ b/stream-cipher/src/dev.rs @@ -2,11 +2,11 @@ #[macro_export] macro_rules! new_sync_test { ($name:ident, $cipher:ty, $test_name:expr) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use stream_cipher::blobby::Blob4Iterator; use stream_cipher::generic_array::GenericArray; - use stream_cipher::{NewStreamCipher, SyncStreamCipher}; + use stream_cipher::{SyncStreamCipher, NewStreamCipher}; let data = include_bytes!(concat!("data/", $test_name, ".blb")); for (i, row) in Blob4Iterator::new(data).unwrap().enumerate() { @@ -41,11 +41,13 @@ macro_rules! new_sync_test { #[macro_export] macro_rules! new_seek_test { ($name:ident, $cipher:ty, $test_name:expr) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use stream_cipher::blobby::Blob4Iterator; use stream_cipher::generic_array::GenericArray; - use stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; + use stream_cipher::{ + SyncStreamCipher, SyncStreamCipherSeek, NewStreamCipher + }; const MAX_SEEK: usize = 512; @@ -83,11 +85,11 @@ macro_rules! new_seek_test { #[macro_export] macro_rules! new_async_test { ($name:ident, $test_name:expr, $cipher:ty) => { - #[test] - fn $name() { + //#[test] + pub fn $name() { use stream_cipher::blobby::Blob4Iterator; use stream_cipher::generic_array::GenericArray; - use stream_cipher::{NewStreamCipher, StreamCipher}; + use stream_cipher::{StreamCipher, NewStreamCipher}; fn run_test( key: &[u8], diff --git a/stream-cipher/src/lib.rs b/stream-cipher/src/lib.rs index e973c39a0..fd596b91d 100644 --- a/stream-cipher/src/lib.rs +++ b/stream-cipher/src/lib.rs @@ -5,11 +5,14 @@ //! for ciphers implementation. #![no_std] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] +#![cfg_attr(all(target_env = "sgx", target_vendor = "mesalock"), feature(rustc_private))] #[cfg(feature = "dev")] pub extern crate blobby; pub extern crate generic_array; -#[cfg(feature = "std")] +#[cfg(all(feature = "std", feature = "mesalock_sgx", target_env = "sgx"))] extern crate std; +#[cfg(all(feature = "std", feature = "mesalock_sgx", not(target_env = "sgx")))] +extern crate sgx_tstd as std; use generic_array::typenum::Unsigned; use generic_array::{ArrayLength, GenericArray}; diff --git a/x86_64-unknown-linux-sgx.json b/x86_64-unknown-linux-sgx.json new file mode 100644 index 000000000..10d37a749 --- /dev/null +++ b/x86_64-unknown-linux-sgx.json @@ -0,0 +1,31 @@ +{ + "arch": "x86_64", + "cpu": "x86-64", + "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", + "dynamic-linking": true, + "env": "sgx", + "exe-allocation-crate": "alloc_system", + "executables": true, + "has-elf-tls": true, + "has-rpath": true, + "linker-flavor": "gcc", + "linker-is-gnu": true, + "llvm-target": "x86_64-unknown-linux-gnu", + "max-atomic-width": 64, + "os": "linux", + "position-independent-executables": true, + "pre-link-args": { + "gcc": [ + "-Wl,--as-needed", + "-Wl,-z,noexecstack", + "-m64" + ] + }, + "relro-level": "full", + "stack-probes": true, + "target-c-int-width": "32", + "target-endian": "little", + "target-family": "unix", + "target-pointer-width": "64", + "vendor": "mesalock" +}