Przeglądaj źródła

Optimization

(cherry picked from commit 4cc84446887c4d987ac59f2cfb240ff46345dbea)

Source commit: 2b785517022dfc6533bfa859f0d374a02ef36bf4
Martin Prikryl 4 lat temu
rodzic
commit
9887ac9205
2 zmienionych plików z 8 dodań i 8 usunięć
  1. 8 7
      source/core/Security.cpp
  2. 0 1
      source/core/Security.h

+ 8 - 7
source/core/Security.cpp

@@ -11,13 +11,15 @@
 #define PWALG_SIMPLE_INTERNAL 0x00
 #define PWALG_SIMPLE_EXTERNAL 0x01
 #define PWALG_SIMPLE_INTERNAL2 0x02
+RawByteString PWALG_SIMPLE_STRING("0123456789ABCDEF");
 //---------------------------------------------------------------------------
 RawByteString SimpleEncryptChar(unsigned char Ch)
 {
   Ch = (unsigned char)((~Ch) ^ PWALG_SIMPLE_MAGIC);
-  return
-    PWALG_SIMPLE_STRING.SubString(((Ch & 0xF0) >> 4) + 1, 1) +
-    PWALG_SIMPLE_STRING.SubString(((Ch & 0x0F) >> 0) + 1, 1);
+  RawByteString Result("..");
+  Result[1] = PWALG_SIMPLE_STRING[((Ch & 0xF0) >> 4) + 1];
+  Result[2] = PWALG_SIMPLE_STRING[((Ch & 0x0F) >> 0) + 1];
+  return Result;
 }
 //---------------------------------------------------------------------------
 unsigned char SimpleDecryptNextChar(RawByteString &Str)
@@ -38,8 +40,7 @@ RawByteString EncryptPassword(UnicodeString UnicodePassword, UnicodeString Unico
   UTF8String Password = UnicodePassword;
   UTF8String Key = UnicodeKey;
 
-  RawByteString Result("");
-  int Index;
+  RawByteString Result;
 
   if (!RandSeed) Randomize();
   Password = Key + Password;
@@ -62,9 +63,9 @@ RawByteString EncryptPassword(UnicodeString UnicodePassword, UnicodeString Unico
     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++)
+  for (int Index = 0; Index < Shift; Index++)
     Result += SimpleEncryptChar((unsigned char)random(256));
-  for (Index = 0; Index < Password.Length(); Index++)
+  for (int Index = 0; Index < Password.Length(); Index++)
     Result += SimpleEncryptChar(Password.c_str()[Index]);
   while (Result.Length() < PWALG_SIMPLE_MAXLEN * 2)
     Result += SimpleEncryptChar((unsigned char)random(256));

+ 0 - 1
source/core/Security.h

@@ -4,7 +4,6 @@
 //---------------------------------------------------------------------------
 #define PWALG_SIMPLE 1
 #define PWALG_SIMPLE_MAGIC 0xA3
-#define PWALG_SIMPLE_STRING ((RawByteString)"0123456789ABCDEF")
 #define PWALG_SIMPLE_MAXLEN 50
 #define PWALG_SIMPLE_FLAG 0xFF
 RawByteString EncryptPassword(UnicodeString Password, UnicodeString Key, Integer Algorithm = PWALG_SIMPLE);