浏览代码

Consistent length of encrypted password

Source commit: 5bf061de76d5a5aa0b8628f078e780c6af1744a6
Martin Prikryl 4 年之前
父节点
当前提交
376f4fa84b
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      source/core/Security.cpp

+ 6 - 3
source/core/Security.cpp

@@ -39,12 +39,10 @@ RawByteString EncryptPassword(UnicodeString UnicodePassword, UnicodeString Unico
   UTF8String Key = UnicodeKey;
 
   RawByteString Result("");
-  int Shift, Index;
+  int Index;
 
   if (!RandSeed) Randomize();
   Password = Key + Password;
-  Shift = (Password.Length() < PWALG_SIMPLE_MAXLEN) ?
-    (unsigned char)random(PWALG_SIMPLE_MAXLEN - Password.Length()) : 0;
   Result += SimpleEncryptChar((unsigned char)PWALG_SIMPLE_FLAG); // Flag
   int Len = Password.Length();
   if (Len > std::numeric_limits<unsigned char>::max())
@@ -58,6 +56,11 @@ RawByteString EncryptPassword(UnicodeString UnicodePassword, UnicodeString Unico
     Result += SimpleEncryptChar((unsigned char)PWALG_SIMPLE_INTERNAL);
     Result += SimpleEncryptChar((unsigned char)Len);
   }
+  int DataLen =
+    (Result.Length() / 2) +
+    1 + // Shift
+    Password.Length();
+  int Shift = (DataLen < PWALG_SIMPLE_MAXLEN) ? random(PWALG_SIMPLE_MAXLEN - DataLen) : 0;
   Result += SimpleEncryptChar((unsigned char)Shift);
   for (Index = 0; Index < Shift; Index++)
     Result += SimpleEncryptChar((unsigned char)random(256));