Rewrite MemoryEqual() to be constant-time. am: e760ff57b9 am: a71795a2cd
am: 07a9435803

Change-Id: I7c9ac4a9973aa33890034a544a5aec0cf3f5c8a2
diff --git a/MemoryLib.c b/MemoryLib.c
index 7beac63..178848e 100644
--- a/MemoryLib.c
+++ b/MemoryLib.c
@@ -75,15 +75,15 @@
       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;
 }
 //
 //