This is an automated email from the ASF dual-hosted git repository.
dingyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git
The following commit(s) were added to refs/heads/master by this push:
new 806a301 Fix consttime_memequal integer overflow bug
new 04c8271 Merge pull request #253 from volcano0dr/master
806a301 is described below
commit 806a301d68137e148d591f2a8b4f482ff9df9827
Author: volcano <[email protected]>
AuthorDate: Tue Jun 30 11:50:19 2020 +0800
Fix consttime_memequal integer overflow bug
---
sgx_trts/src/memeq.rs | 6 +++---
sgx_ucrypto/src/util.rs | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/sgx_trts/src/memeq.rs b/sgx_trts/src/memeq.rs
index 05b3372..b3f1ff9 100644
--- a/sgx_trts/src/memeq.rs
+++ b/sgx_trts/src/memeq.rs
@@ -76,14 +76,14 @@ unsafe fn consttime_memequal(
b2: *const u8,
l: usize,
) -> i32 {
- let mut res: u32 = 0;
+ let mut res: i32 = 0;
let mut len = l;
let p1 = slice::from_raw_parts(b1, l);
let p2 = slice::from_raw_parts(b2, l);
while len > 0 {
len -= 1;
- res |= (p1[len] ^ p2[len]) as u32;
+ res |= (p1[len] ^ p2[len]) as i32;
}
/*
* Map 0 to 1 and [1, 256) to 0 using only constant-time
@@ -94,5 +94,5 @@ unsafe fn consttime_memequal(
* advantage of them, certain compilers generate branches on
* certain CPUs for `!res'.
*/
- (1 & ((res - 1) >> 8)) as i32
+ 1 & ((res - 1) >> 8)
}
diff --git a/sgx_ucrypto/src/util.rs b/sgx_ucrypto/src/util.rs
index 93b1c27..a7ea69b 100644
--- a/sgx_ucrypto/src/util.rs
+++ b/sgx_ucrypto/src/util.rs
@@ -47,14 +47,14 @@ pub unsafe extern "C" fn consttime_memequal(
b2: *const u8,
l: usize,
) -> i32 {
- let mut res: u32 = 0;
+ let mut res: i32 = 0;
let mut len = l;
let p1 = slice::from_raw_parts(b1, l);
let p2 = slice::from_raw_parts(b2, l);
while len > 0 {
len -= 1;
- res |= (p1[len] ^ p2[len]) as u32;
+ res |= (p1[len] ^ p2[len]) as i32;
}
/*
* Map 0 to 1 and [1, 256) to 0 using only constant-time
@@ -65,7 +65,7 @@ pub unsafe extern "C" fn consttime_memequal(
* advantage of them, certain compilers generate branches on
* certain CPUs for `!res'.
*/
- (1 & ((res - 1) >> 8)) as i32
+ 1 & ((res - 1) >> 8)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]