Skip to content

Commit

Permalink
rust: bump tiny-keccak from 1.5.0 to 2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Sep 9, 2020
1 parent 518a104 commit baa2b44
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ updates:
- dependency-name: serde_cbor
- dependency-name: sha2
- dependency-name: snow
- dependency-name: tiny-keccak
15 changes: 12 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion keymanager-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ io-context = "0.2.0"
rand = "0.7.3"
sgx-isa = { version = "0.3.2", features = ["sgxstd"] }
sp800-185 = "0.2.0"
tiny-keccak = "1.4.2"
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
x25519-dalek = "1.1.0"
zeroize = "1.1"
9 changes: 7 additions & 2 deletions keymanager-lib/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
use anyhow::Result;
use lazy_static::lazy_static;
use sgx_isa::Keypolicy;
use tiny_keccak::sha3_256;
use tiny_keccak::{Hasher, Sha3};

use oasis_core_keymanager_api_common::*;
use oasis_core_runtime::{
Expand Down Expand Up @@ -209,10 +209,15 @@ impl CachedPolicy {
let policy = untrusted_policy.verify()?;

let mut cached_policy = Self::default();
cached_policy.checksum = sha3_256(&raw).to_vec();
cached_policy.serial = policy.serial;
cached_policy.runtime_id = policy.id;

let mut sha3 = Sha3::v256();
sha3.update(&raw);
let mut k = [0; 32];
sha3.finalize(&mut k);
cached_policy.checksum = k.to_vec();

// Convert the policy into a cached one.
//
// TODO: Need a mock enclave identity for non-sgx builds if we want to
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ io-context = "0.2.0"
x25519-dalek = "1.1.0"
ed25519-dalek = "1.0.0-pre.3"
deoxysii = { git = "https://github.com/oasisprotocol/deoxysii-rust" }
tiny-keccak = "1.4.2"
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
sp800-185 = "0.2.0"
zeroize = "1.1"
intrusive-collections = "0.8"
Expand Down
19 changes: 8 additions & 11 deletions runtime/src/common/sgx/egetkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ use sp800_185::KMac;
#[cfg(target_env = "sgx")]
use sgx_isa::{Keyname, Keyrequest};
#[cfg(target_env = "sgx")]
use tiny_keccak::sha3_256;

// This crate is not portable due to dependencies, even when using the mock
// key derivation:
//
// * sp800_185 relies on tiny_keccak, which as of 1.4.2, will produce
// incorrect results on big endian targets, and will crash on any
// architecture that requires aligned 64 bit loads and stores.
#[cfg(not(target_arch = "x86_64"))]
error!("Only x86_64 is supported");
use tiny_keccak::{Hasher, Sha3};

#[cfg(not(target_env = "sgx"))]
const MOCK_MRENCLAVE_KEY: &[u8] = b"Ekiden Test MRENCLAVE KEY";
Expand All @@ -32,7 +23,13 @@ fn egetkey_impl(key_policy: Keypolicy, context: &[u8]) -> [u8; 16] {

req.keyname = Keyname::Seal as u16;
req.keypolicy = key_policy;
req.keyid = sha3_256(context);

let mut sha3 = Sha3::v256();
sha3.update(context);
let mut k = [0; 32];
sha3.finalize(&mut k);
req.keyid = k.into();

// Fucking sgx_isa::Attributes doesn't have a -> [u64;2].
req.attributemask[0] = 1 | 2 | 4; // SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG | SGX_FLAGS_MODE64BIT
req.attributemask[1] = 3; // SGX_XFRM_LEGACY
Expand Down

0 comments on commit baa2b44

Please sign in to comment.