Browse Source

Remove single line hash function

Vishnu Mohandas 4 years ago
parent
commit
5fffea1824
2 changed files with 4 additions and 8 deletions
  1. 4 4
      lib/core/configuration.dart
  2. 0 4
      lib/utils/crypto_util.dart

+ 4 - 4
lib/core/configuration.dart

@@ -66,10 +66,10 @@ class Configuration {
       String passphrase, KeyAttributes attributes) async {
     final kek = CryptoUtil.scrypt(
         utf8.encode(passphrase), base64.decode(attributes.kekSalt));
-    bool correctPassphrase = CryptoUtil.compareHash(
-        kek,
-        base64.decode(attributes.kekHash),
-        base64.decode(attributes.kekHashSalt));
+    final calculatedKekHash =
+        CryptoUtil.scrypt(kek, base64.decode(attributes.kekHashSalt));
+    bool correctPassphrase =
+        base64.encode(calculatedKekHash) == attributes.kekHash;
     if (!correctPassphrase) {
       throw Exception("Incorrect passphrase");
     }

+ 0 - 4
lib/utils/crypto_util.dart

@@ -20,10 +20,6 @@ class CryptoUtil {
         .hashBytes(salt: salt, input: plainText, len: 32);
   }
 
-  static bool compareHash(Uint8List plainText, Uint8List hash, Uint8List salt) {
-    return base64.encode(scrypt(plainText, salt)) == base64.encode(hash);
-  }
-
   static Uint8List aesEncrypt(
       Uint8List plainText, Uint8List key, Uint8List iv) {
     final encrypter = AES(Key(key), mode: AESMode.cbc);