Skip to content

Commit 27204c8

Browse files
committed
Fixed memory leak in TDECPasswordHash.DoDone. Reenabled all BCrypt Crypt/BSD style tests again. IsValidPassword is still a stub.
1 parent 05ddfad commit 27204c8

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

Source/DECHash.pas

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,26 +5237,15 @@ class function THash_BCrypt.GetCryptHash(
52375237
Format : TDECFormatClass): string;
52385238
var
52395239
Hash : THash_BCrypt;
5240-
B: TBytes;
52415240
begin
52425241
Hash := THash_BCrypt.Create;
52435242
try
52445243
Hash.Cost := StrToInt(string(Params));
52455244
Hash.Salt := Salt;
52465245

52475246
// BCrypt leaves off the $ in front of the actual password hash value
5248-
// Result := TEncoding.ASCII.GetString(//Hash.CalcBytes(TEncoding.UTF8.GetBytes(Password)));
5249-
// Format.Encode(Hash.CalcBytes(TEncoding.UTF8.GetBytes(Password))));
5250-
5251-
// b:= TEncoding.UTF8.GetBytes(Password);
5252-
5253-
// b := Format.Encode([85, 126, 148, 243, 75, 242, 134, 232, 113, 154, 38, 190, 148, 172, 30, 22, 217, 94, 249, 248, 25, 222, 224]);
5254-
b := Hash.CalcBytes(b);
5255-
b := Format.Encode(b);
5256-
5257-
Result := TEncoding.ASCII.GetString(b);
5258-
// [85, 126, 148, 243, 75, 242, 134, 232, 113, 154, 38, 190, 148, 172, 30, 22, 217, 94, 249, 248, 25, 222, 224];
5259-
// //Hash.CalcBytes(TEncoding.UTF8.GetBytes(Password))));
5247+
Result := TEncoding.ASCII.GetString(Format.Encode(Hash.CalcBytes(
5248+
TEncoding.UTF8.GetBytes(Password))));
52605249
finally
52615250
Hash.Free;
52625251
end;
@@ -5281,7 +5270,8 @@ class function THash_BCrypt.GetCryptParams(
52815270
class function THash_BCrypt.IsValidPassword(const Password,
52825271
CryptData: string): Boolean;
52835272
begin
5284-
5273+
{ TODO : To be implemented }
5274+
Result := false;
52855275
end;
52865276

52875277
procedure THash_BCrypt.BF_Encrypt(const BI: TBFBlock; var BO: TBFBlock);

Source/DECHashAuthentication.pas

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ procedure TDECPasswordHash.DoDone;
15581558
begin
15591559
inherited;
15601560

1561-
ProtectBuffer(FSalt, SizeOf(FSalt));
1561+
ProtectBuffer(FSalt[0], SizeOf(FSalt));
15621562
SetLength(FSalt, 0);
15631563
end;
15641564

@@ -1590,19 +1590,12 @@ class function TDECPasswordHash.GetDigestInCryptFormat(
15901590
if SaltIsRaw then
15911591
SaltBytes := TEncoding.UTF8.GetBytes(Salt)
15921592
else
1593-
SaltBytes := [20, 75, 61, 105, 26, 123, 78, 207, 57, 207, 115, 92, 127, 167, 167, 156]; //Format.Decode(TEncoding.UTF8.GetBytes(Salt));
1594-
1595-
// Mal noch mehr mocken um einzugrenzen welche Nutzung von Salt das Leck verursacht
1596-
// Result := Result + GetCryptParams(Params, Format) +
1597-
// GetCryptSalt(SaltBytes, Format) +
1598-
// GetCryptHash(Password, Params, SaltBytes, Format);
1593+
SaltBytes := Format.Decode(TEncoding.UTF8.GetBytes(Salt));
15991594

16001595
Result := Result + GetCryptParams(Params, Format) +
16011596
GetCryptSalt(SaltBytes, Format) +
16021597
GetCryptHash(Password, Params, SaltBytes, Format);
16031598
end;
1604-
1605-
SetLength(SaltBytes, 0);
16061599
end;
16071600

16081601
class function TDECPasswordHash.IsValidPassword(const Password : string;

Unit Tests/Tests/TestDECHash.pas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6365,10 +6365,9 @@ TPair = record
63656365
i : Integer;
63666366
SplitData : TBCryptBSDTestData;
63676367
begin
6368-
for i := Low(TestData) to 1 do //High(TestData) do
6368+
for i := Low(TestData) to High(TestData) do
63696369
begin
63706370
SplitData := SplitTestVector(TestData[i].bs);
6371-
// Fix memory leaks we get
63726371
Result := string(THash_BCrypt.GetDigestInCryptFormat(
63736372
Passwords[TestData[i].pn],
63746373
SplitData.Cost.ToString,

0 commit comments

Comments
 (0)