Blame SOURCES/0001-esys_iutil-use-memcmp-in-byte-array-comparison.patch

28cd4a
From 0bf42a4489973005ddd912a800dfb92eff2806e8 Mon Sep 17 00:00:00 2001
28cd4a
From: William Roberts <william.c.roberts@intel.com>
28cd4a
Date: Mon, 16 Sep 2019 17:12:23 -0700
28cd4a
Subject: [PATCH] esys_iutil: use memcmp in byte array comparison
28cd4a
28cd4a
Rather than a byte for byte forloop, use memcmp() so the compiler can
28cd4a
use architectural optimizations.
28cd4a
28cd4a
Signed-off-by: William Roberts <william.c.roberts@intel.com>
28cd4a
---
28cd4a
 src/tss2-esys/esys_iutil.c | 27 +++++----------------------
28cd4a
 1 file changed, 5 insertions(+), 22 deletions(-)
28cd4a
28cd4a
diff --git a/src/tss2-esys/esys_iutil.c b/src/tss2-esys/esys_iutil.c
28cd4a
index 94d0332c5b7d..08a9b7dffcbd 100644
28cd4a
--- a/src/tss2-esys/esys_iutil.c
28cd4a
+++ b/src/tss2-esys/esys_iutil.c
28cd4a
@@ -35,23 +35,6 @@ cmp_UINT16(const UINT16 * in1, const UINT16 * in2)
28cd4a
     }
28cd4a
 }
28cd4a
 
28cd4a
-/**
28cd4a
- * Compare variables of type BYTE.
28cd4a
- * @param[in] in1 Variable to be compared with:
28cd4a
- * @param[in] in2
28cd4a
- */
28cd4a
-static bool
28cd4a
-cmp_BYTE(const BYTE * in1, const BYTE * in2)
28cd4a
-{
28cd4a
-    LOG_TRACE("call");
28cd4a
-    if (*in1 == *in2)
28cd4a
-        return true;
28cd4a
-    else {
28cd4a
-        LOG_TRACE("cmp false");
28cd4a
-        return false;
28cd4a
-    }
28cd4a
-}
28cd4a
-
28cd4a
 /**
28cd4a
  * Compare two arrays of type BYTE.
28cd4a
  * @param[in] in1 array to be compared with:.
28cd4a
@@ -65,12 +48,12 @@ cmp_BYTE_array(const BYTE * in1, size_t count1, const BYTE * in2, size_t count2)
28cd4a
         LOG_TRACE("cmp false");
28cd4a
         return false;
28cd4a
     }
28cd4a
-    for (size_t i = 0; i < count1; i++) {
28cd4a
-        if (!cmp_BYTE(&in1[i], &in2[i])) {
28cd4a
-            LOG_TRACE("cmp false");
28cd4a
-            return false;
28cd4a
-        }
28cd4a
+
28cd4a
+    if (memcmp(in1, in2, count2) != 0) {
28cd4a
+        LOG_TRACE("cmp false");
28cd4a
+        return false;
28cd4a
     }
28cd4a
+
28cd4a
     return true;
28cd4a
 }
28cd4a
 
28cd4a
-- 
28cd4a
2.27.0
28cd4a