@@ -1102,6 +1102,24 @@ THash_BCrypt = class(TDECPasswordHash)
11021102 IncProc : TBFIncProc;
11031103 end ;
11041104
1105+ // / <summary>
1106+ // / Parts of the BSD/Crypt style password storage for BCrypt
1107+ // / </summary>
1108+ TBCryptBSDData = record
1109+ // / <summary>
1110+ // / Algorithm ID
1111+ // / </summary>
1112+ ID : string;
1113+ // / <summary>
1114+ // / Salt in Crypt encoding
1115+ // / </summary>
1116+ Salt : string;
1117+ // / <summary>
1118+ // / Cost factor
1119+ // / </summary>
1120+ Cost : UInt8;
1121+ end ;
1122+
11051123 var
11061124 // / <summary>
11071125 // / The calculated hash value
@@ -1175,6 +1193,11 @@ THash_BCrypt = class(TDECPasswordHash)
11751193 // / Block to store the result in
11761194 // / </param>
11771195 procedure BF_XorBlock (const B1, B2: TBFBlock; var B3: TBFBlock);
1196+
1197+ // / <summary>
1198+ // / Splits a given Crypt/BSD style password record into its parts
1199+ // / </summary>
1200+ function SplitTestVector (const Vector: string):TBCryptBSDData;
11781201 strict protected
11791202 procedure DoInit ; override;
11801203 procedure DoTransform (Buffer: PUInt32Array); override;
@@ -1261,6 +1284,23 @@ THash_BCrypt = class(TDECPasswordHash)
12611284 // / </summary>
12621285 class function MaxCost :UInt8;
12631286
1287+ // / <summary>
1288+ // / Checks whether a given password is the correct one for a password
1289+ // / storage "record"/entry in Crypt/BSD format.
1290+ // / </summary>
1291+ // / <param name="Password">
1292+ // / Password to check for validity
1293+ // / </param>
1294+ // / <param name="CryptData">
1295+ // / The data needed to "compare" the password against in Crypt/BSD like
1296+ // / format: $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
1297+ // / </param>
1298+ // / <returns>
1299+ // / True if the password given is correct.
1300+ // / </returns>
1301+ class function IsValidPassword (const Password : string;
1302+ const CryptData : string): Boolean; override;
1303+
12641304 // / <summary>
12651305 // / Processes one chunk of data to be hashed.
12661306 // / </summary>
@@ -5238,6 +5278,12 @@ class function THash_BCrypt.GetCryptParams(
52385278 Result := ' $' + Result;
52395279end ;
52405280
5281+ class function THash_BCrypt.IsValidPassword (const Password,
5282+ CryptData: string): Boolean;
5283+ begin
5284+
5285+ end ;
5286+
52415287procedure THash_BCrypt.BF_Encrypt (const BI: TBFBlock; var BO: TBFBlock);
52425288var
52435289 xl, xr : UInt32;
@@ -5356,6 +5402,16 @@ procedure THash_BCrypt.SetCost(const Value: UInt8);
53565402 raise EDECHashException.CreateFmt(sCostFactorInvalid, [MinCost, MaxCost]);
53575403end ;
53585404
5405+ function THash_BCrypt.SplitTestVector (const Vector: string): TBCryptBSDData;
5406+ var
5407+ Parts : TArray<string>;
5408+ begin
5409+ Parts := Vector.Split([' $' ], TStringSplitOptions.ExcludeEmpty);
5410+ Result.ID := Parts[0 ];
5411+ Result.Cost := Copy(Parts[1 ], Low(Parts[1 ]), Length(Parts[1 ])).ToInteger;
5412+ Result.Salt := Copy(Parts[2 ], Low(Parts[2 ]), 22 );
5413+ end ;
5414+
53595415{ $IFDEF RESTORE_RANGECHECKS}{ $R+}{ $ENDIF}
53605416{ $IFDEF RESTORE_OVERFLOWCHECKS}{ $Q+}{ $ENDIF}
53615417
0 commit comments