aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2017-05-12 07:24:28 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-05-12 07:24:28 +0000
commit9fd55d37d099d0edbfad9654d422724a54ca1532 (patch)
treec0ffc44c5863a99b1c3324c0943b4d5526496031
parentadb03ede1d577eececce5ea7366673adea2e038c (diff)
parent98b0e9b9f49ad6087119c61ac63adb971de13f7e (diff)
downloadtpm2-9fd55d37d099d0edbfad9654d422724a54ca1532.tar.gz
Rewrite MemoryEqual() to be constant-time. am: e760ff57b9 am: a71795a2cd am: 07a9435803 am: 19237091e3
am: 98b0e9b9f4 Change-Id: If08baa76ab20307f1690ffad345152e7f6616faf
-rw-r--r--MemoryLib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/MemoryLib.c b/MemoryLib.c
index 7beac63..178848e 100644
--- a/MemoryLib.c
+++ b/MemoryLib.c
@@ -75,15 +75,15 @@ MemoryEqual(
UINT32 size // IN: size of bytes being compared
)
{
- BOOL equal = TRUE;
+ BOOL diff = FALSE;
const BYTE *b1, *b2;
b1 = (BYTE *)buffer1;
b2 = (BYTE *)buffer2;
// Compare all bytes so that there is no leakage of information
// due to timing differences.
for(; size > 0; size--)
- equal = (*b1++ == *b2++) && equal;
- return equal;
+ diff |= *b1++ ^ *b2++;
+ return !diff;
}
//
//