Skip to content

Commit e2c391d

Browse files
committed
cpuid not supported in sgx environment
1 parent afc167f commit e2c391d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sha2/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ opaque-debug = "0.3"
2121
cfg-if = "0.1"
2222
sha2-asm = { version = "0.5", optional = true }
2323

24-
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]
24+
[target.'cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(target_env = "sgx")))'.dependencies]
2525
cpuid-bool = "0.1"
2626

2727
[target.'cfg(all(target_arch = "aarch64", target_os = "linux"))'.dependencies]

sha2/src/sha256/x86.rs

+16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ unsafe fn digest_blocks(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
9595
_mm_storeu_si128(state_ptr_mut.add(1), hgef);
9696
}
9797

98+
#[cfg(feature = "cpuid_bool")]
9899
pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
99100
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725
100101
// after stabilization
@@ -106,3 +107,18 @@ pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
106107
super::soft::compress(state, blocks);
107108
}
108109
}
110+
111+
/// Just use `std::is_x86_feature_detected` in sgx environment
112+
#[cfg(not(feature = "cpuid_bool"))]
113+
pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
114+
if std::is_x86_feature_detected!("sse2")
115+
|| std::is_x86_feature_detected!("ssse3")
116+
|| std::is_x86_feature_detected!("sse4.1")
117+
{
118+
unsafe {
119+
digest_blocks(state, blocks);
120+
}
121+
} else {
122+
super::soft::compress(state, blocks);
123+
}
124+
}

0 commit comments

Comments
 (0)