Weaver: use Util.arrayCompare() to compare keys.
It is constant time compare so safe to use for the key comparison.
Test: libese-app-weaver-test
Bug: 37697859
Change-Id: I338e42781287c31ff64b484288b7f40c58e908d1
diff --git a/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java b/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
index 29e4841..c81ea0d 100644
--- a/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
+++ b/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
@@ -139,11 +139,9 @@
}
// Check the key matches in constant time and copy out the value if it does
- byte difference = 0;
- for (short i = 0; i < Consts.SLOT_KEY_BYTES; ++i) {
- difference |= keyBuffer[(short) (keyOffset + i)] ^ mKey[i];
- }
- final byte result = (difference == 0) ? Consts.READ_SUCCESS : Consts.READ_WRONG_KEY;
+ final byte result = (Util.arrayCompare(
+ keyBuffer, keyOffset, mKey, (short) 0, Consts.SLOT_KEY_BYTES) == 0) ?
+ Consts.READ_SUCCESS : Consts.READ_WRONG_KEY;
// Keep track of the number of failures
if (result == Consts.READ_WRONG_KEY) {