mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Calculate key transformation at least one time
This commit is contained in:
parent
50af183b70
commit
15c0c27e79
2 changed files with 35 additions and 6 deletions
|
|
@ -84,6 +84,7 @@ object frmMasterKey: TfrmMasterKey
|
|||
Width = 456
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 6
|
||||
Caption = 'Key transformation'
|
||||
ChildSizing.LeftRightSpacing = 12
|
||||
ChildSizing.TopBottomSpacing = 12
|
||||
|
|
@ -274,6 +275,7 @@ object frmMasterKey: TfrmMasterKey
|
|||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
OKButton.Enabled = False
|
||||
OKButton.OnClick = OKButtonClick
|
||||
HelpButton.Name = 'HelpButton'
|
||||
HelpButton.DefaultCaption = True
|
||||
CloseButton.Name = 'CloseButton'
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ type
|
|||
pnlMemory: TPanel;
|
||||
procedure btnTestClick(Sender: TObject);
|
||||
procedure edtPasswordChange(Sender: TObject);
|
||||
procedure OKButtonClick(Sender: TObject);
|
||||
private
|
||||
FTest: Boolean;
|
||||
function Test(Finish: Boolean): Boolean;
|
||||
end;
|
||||
|
||||
function CreateMasterKey(Short: Boolean; out Password: String; out ArgonType: Targon2_type; var M: UInt32; var T, P: UInt16): Boolean;
|
||||
|
|
@ -58,6 +62,7 @@ begin
|
|||
seMemory.Value:= M div 1024;
|
||||
gbMasterKey.Visible:= not Short;
|
||||
pnlButtons.OKButton.Enabled:= Short;
|
||||
pnlButtons.OKButton.ModalResult:= mrNone;
|
||||
|
||||
Result:= (ShowModal = mrOK);
|
||||
|
||||
|
|
@ -80,13 +85,16 @@ end;
|
|||
|
||||
{ TfrmMasterKey }
|
||||
|
||||
procedure TfrmMasterKey.btnTestClick(Sender: TObject);
|
||||
function TfrmMasterKey.Test(Finish: Boolean): Boolean;
|
||||
const
|
||||
HASH_LEN = 88;
|
||||
SALT = 'a5abbcdd86a5d7f9c8a76ea7d0197ed1';
|
||||
Buttons: array[Boolean] of TMsgDlgButtons = ([mbOK], [mbOK, mbCancel]);
|
||||
var
|
||||
Res: Integer;
|
||||
Ret: Integer;
|
||||
Delay: Double;
|
||||
StartTime: QWord;
|
||||
Res: TModalResult;
|
||||
ArgonType: Targon2_type;
|
||||
t_cost, m_cost, parallelism: UInt32;
|
||||
Hash: array[0..Pred(HASH_LEN)] of Byte;
|
||||
|
|
@ -102,14 +110,25 @@ begin
|
|||
end;
|
||||
StartTime:= GetTickCount64;
|
||||
|
||||
Res:= argon2_kdf(t_cost, m_cost, parallelism, 'password', 8,
|
||||
Ret:= argon2_kdf(t_cost, m_cost, parallelism, 'password', 8,
|
||||
SALT, Length(SALT), @Hash[0], HASH_LEN, ArgonType);
|
||||
|
||||
if (Res <> ARGON2_OK) then
|
||||
ShowMessage(Format(rsMsgKeyTransformError, [Res]))
|
||||
FTest:= (Ret = ARGON2_OK);
|
||||
|
||||
if (not FTest) then
|
||||
MessageDlg(Format(rsMsgKeyTransformError, [Ret]), mtError, [mbOK], 0)
|
||||
else begin
|
||||
ShowMessage(Format(rsMsgKeyTransformTime, [Double(GetTickCount64 - StartTime) / 1000]));
|
||||
Delay:= Double(GetTickCount64 - StartTime) / 1000;
|
||||
Res:= MessageDlg(Format(rsMsgKeyTransformTime, [Delay]), mtInformation, Buttons[Finish], 0);
|
||||
if Finish and (Res <> mrOK) then FTest:= False;
|
||||
end;
|
||||
|
||||
Result:= FTest;
|
||||
end;
|
||||
|
||||
procedure TfrmMasterKey.btnTestClick(Sender: TObject);
|
||||
begin
|
||||
Test(False);
|
||||
end;
|
||||
|
||||
procedure TfrmMasterKey.edtPasswordChange(Sender: TObject);
|
||||
|
|
@ -117,5 +136,13 @@ begin
|
|||
pnlButtons.OKButton.Enabled:= (Length(edtPassword.Text) > 0) and (edtPassword.Text = edtRepeat.Text);
|
||||
end;
|
||||
|
||||
procedure TfrmMasterKey.OKButtonClick(Sender: TObject);
|
||||
begin
|
||||
if FTest or Test(True) then
|
||||
begin
|
||||
ModalResult:= mrOK;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue