Simplify passwordToHistoryHash()

When processing the password and salt, just use update() instead of
concatenating them into an array.  No change in behavior, as verified by
LockscreenCredentialTest.testPasswordToHistoryHash().

Test: atest LockscreenCredentialTest
Change-Id: I92e240dbe4df6c30fe35444b1452bb003421243b
This commit is contained in:
Eric Biggers
2022-07-28 19:24:55 +00:00
parent 7dab5f7694
commit ebcd3fd445

View File

@@ -278,11 +278,8 @@ public class LockscreenCredential implements Parcelable, AutoCloseable {
try {
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
sha256.update(hashFactor);
byte[] saltedPassword = Arrays.copyOf(passwordToHash, passwordToHash.length
+ salt.length);
System.arraycopy(salt, 0, saltedPassword, passwordToHash.length, salt.length);
sha256.update(saltedPassword);
Arrays.fill(saltedPassword, (byte) 0);
sha256.update(passwordToHash);
sha256.update(salt);
return new String(HexEncoding.encode(sha256.digest()));
} catch (NoSuchAlgorithmException e) {
throw new AssertionError("Missing digest algorithm: ", e);