encrypted-file: Extend magic numbers in try_password().
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Jan 2019 20:14:36 +0000 (12:14 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Jan 2019 00:59:37 +0000 (16:59 -0800)
The three-byte magic numbers would match 1 in about every 16 million
guessed passwords, which is too frequent for exhaustive testing.  The new
7- and 10-byte magic numbers should not have the same problem.

src/data/encrypted-file.c

index f1074b4c1d159d4ad805ea9b887f40400114e20f..27bfe2e3f09c62c89b8f8089b3cf6659ef5efd27 100644 (file)
@@ -348,7 +348,12 @@ try_password(struct encrypted_file *f, const char *password)
   rijndaelDecrypt (f->rk, f->Nr,
                    CHAR_CAST (const char *, f->ciphertext),
                    CHAR_CAST (char *, f->plaintext));
-  return !memcmp (f->plaintext, f->type == SYSTEM ? "$FL" : "* E", 3);
+
+  const char *magic = f->type == SYSTEM ? "$FL?@(#)" : "* Encoding";
+  for (int i = 0; magic[i]; i++)
+    if (magic[i] != '?' && f->plaintext[i] != magic[i])
+      return false;
+  return true;
 }
 
 static bool