diff options
author | nagendra modadugu <ngm@google.com> | 2017-05-12 00:36:08 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-12 00:36:08 +0000 |
commit | a71795a2cdc96cfd78508d8625f9a3b9efd5b117 (patch) | |
tree | c0ffc44c5863a99b1c3324c0943b4d5526496031 | |
parent | 44544398445dd5f5adbe13c5b551eb087781da64 (diff) | |
parent | e760ff57b9414578d8b29a328a02beb580fcbb63 (diff) | |
download | tpm2-a71795a2cdc96cfd78508d8625f9a3b9efd5b117.tar.gz |
Rewrite MemoryEqual() to be constant-time.
am: e760ff57b9
Change-Id: I21c094b84f345de24afde68875d0558148042374
-rw-r--r-- | MemoryLib.c | 6 |
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; } // // |