diff options
author | nagendra modadugu <ngm@google.com> | 2017-05-12 02:11:33 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-12 02:11:33 +0000 |
commit | 19237091e3f57a9db0882bce942cb1ec56f9db2d (patch) | |
tree | c0ffc44c5863a99b1c3324c0943b4d5526496031 | |
parent | 9695b44f9a6d08f31e48a90e23605dccd8187317 (diff) | |
parent | 07a9435803fa7709313a94419a0b94d2fe8ae27a (diff) | |
download | tpm2-19237091e3f57a9db0882bce942cb1ec56f9db2d.tar.gz |
Rewrite MemoryEqual() to be constant-time. am: e760ff57b9 am: a71795a2cd
am: 07a9435803
Change-Id: I7c9ac4a9973aa33890034a544a5aec0cf3f5c8a2
-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; } // // |