diff options
author | nagendra modadugu <ngm@google.com> | 2017-05-12 00:44:19 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-12 00:44:19 +0000 |
commit | 07a9435803fa7709313a94419a0b94d2fe8ae27a (patch) | |
tree | c0ffc44c5863a99b1c3324c0943b4d5526496031 | |
parent | c8ea94480d7073d71506509f88f045d249672b4d (diff) | |
parent | a71795a2cdc96cfd78508d8625f9a3b9efd5b117 (diff) | |
download | tpm2-07a9435803fa7709313a94419a0b94d2fe8ae27a.tar.gz |
Rewrite MemoryEqual() to be constant-time. am: e760ff57b9
am: a71795a2cd
Change-Id: I4b54efeedb0e6835491ac40d29a47af9bcc24a7d
-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; } // // |