chantra / rpms / tpm2-tss

Forked from rpms/tpm2-tss 2 years ago
Clone

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

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