1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Linux/MacOSX: Enhance performance by implementing the possibility to choose the correct hash algorithm of volumes during various operations (mount, change password...), both using the GUI and the command line.

This commit is contained in:
Mounir IDRASSI
2014-12-19 18:18:23 +01:00
parent 18dc75ee62
commit 07156b6c09
26 changed files with 160 additions and 36 deletions

8
src/Core/CoreBase.cpp Normal file → Executable file
View File

@@ -68,9 +68,9 @@ namespace VeraCrypt
} }
} }
void CoreBase::ChangePassword (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf, int wipeCount) const void CoreBase::ChangePassword (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf, int wipeCount) const
{ {
shared_ptr <Volume> volume = OpenVolume (volumePath, preserveTimestamps, password, keyfiles); shared_ptr <Volume> volume = OpenVolume (volumePath, preserveTimestamps, password, kdf, keyfiles);
ChangePassword (volume, newPassword, newKeyfiles, newPkcs5Kdf, wipeCount); ChangePassword (volume, newPassword, newKeyfiles, newPkcs5Kdf, wipeCount);
} }
@@ -242,10 +242,10 @@ namespace VeraCrypt
return GetMountedVolume (volumePath); return GetMountedVolume (volumePath);
} }
shared_ptr <Volume> CoreBase::OpenVolume (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr <KeyfileList> protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) const shared_ptr <Volume> CoreBase::OpenVolume (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr<Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr<Pkcs5Kdf> protectionKdf, shared_ptr <KeyfileList> protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) const
{ {
make_shared_auto (Volume, volume); make_shared_auto (Volume, volume);
volume->Open (*volumePath, preserveTimestamps, password, keyfiles, protection, protectionPassword, protectionKeyfiles, sharedAccessAllowed, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); volume->Open (*volumePath, preserveTimestamps, password, kdf, keyfiles, protection, protectionPassword, protectionKdf, protectionKeyfiles, sharedAccessAllowed, volumeType, useBackupHeaders, partitionInSystemEncryptionScope);
return volume; return volume;
} }

4
src/Core/CoreBase.h Normal file → Executable file
View File

@@ -29,7 +29,7 @@ namespace VeraCrypt
virtual ~CoreBase (); virtual ~CoreBase ();
virtual void ChangePassword (shared_ptr <Volume> openVolume, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf = shared_ptr <Pkcs5Kdf> (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const; virtual void ChangePassword (shared_ptr <Volume> openVolume, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf = shared_ptr <Pkcs5Kdf> (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const;
virtual void ChangePassword (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf = shared_ptr <Pkcs5Kdf> (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const; virtual void ChangePassword (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Pkcs5Kdf> newPkcs5Kdf = shared_ptr <Pkcs5Kdf> (), int wipeCount = PRAND_HEADER_WIPE_PASSES) const;
virtual void CheckFilesystem (shared_ptr <VolumeInfo> mountedVolume, bool repair = false) const = 0; virtual void CheckFilesystem (shared_ptr <VolumeInfo> mountedVolume, bool repair = false) const = 0;
virtual void CoalesceSlotNumberAndMountPoint (MountOptions &options) const; virtual void CoalesceSlotNumberAndMountPoint (MountOptions &options) const;
virtual void CreateKeyfile (const FilePath &keyfilePath) const; virtual void CreateKeyfile (const FilePath &keyfilePath) const;
@@ -64,7 +64,7 @@ namespace VeraCrypt
virtual bool IsVolumeMounted (const VolumePath &volumePath) const; virtual bool IsVolumeMounted (const VolumePath &volumePath) const;
virtual VolumeSlotNumber MountPointToSlotNumber (const DirectoryPath &mountPoint) const = 0; virtual VolumeSlotNumber MountPointToSlotNumber (const DirectoryPath &mountPoint) const = 0;
virtual shared_ptr <VolumeInfo> MountVolume (MountOptions &options) = 0; virtual shared_ptr <VolumeInfo> MountVolume (MountOptions &options) = 0;
virtual shared_ptr <Volume> OpenVolume (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false) const; virtual shared_ptr <Volume> OpenVolume (shared_ptr <VolumePath> volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr<Pkcs5Kdf> Kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr<Pkcs5Kdf> protectionKdf = shared_ptr<Pkcs5Kdf> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false) const;
virtual void RandomizeEncryptionAlgorithmKey (shared_ptr <EncryptionAlgorithm> encryptionAlgorithm) const; virtual void RandomizeEncryptionAlgorithmKey (shared_ptr <EncryptionAlgorithm> encryptionAlgorithm) const;
virtual void ReEncryptVolumeHeaderWithNewSalt (const BufferPtr &newHeaderBuffer, shared_ptr <VolumeHeader> header, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles) const; virtual void ReEncryptVolumeHeaderWithNewSalt (const BufferPtr &newHeaderBuffer, shared_ptr <VolumeHeader> header, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles) const;
virtual void SetAdminPasswordCallback (shared_ptr <GetStringFunctor> functor) { } virtual void SetAdminPasswordCallback (shared_ptr <GetStringFunctor> functor) { }

35
src/Core/MountOptions.cpp Normal file → Executable file
View File

@@ -26,11 +26,21 @@ namespace VeraCrypt
TC_CLONE (NoHardwareCrypto); TC_CLONE (NoHardwareCrypto);
TC_CLONE (NoKernelCrypto); TC_CLONE (NoKernelCrypto);
TC_CLONE_SHARED (VolumePassword, Password); TC_CLONE_SHARED (VolumePassword, Password);
if (other.Kdf)
{
Kdf.reset(other.Kdf->Clone());
}
else
Kdf.reset();
TC_CLONE_SHARED (VolumePath, Path); TC_CLONE_SHARED (VolumePath, Path);
TC_CLONE (PartitionInSystemEncryptionScope); TC_CLONE (PartitionInSystemEncryptionScope);
TC_CLONE (PreserveTimestamps); TC_CLONE (PreserveTimestamps);
TC_CLONE (Protection); TC_CLONE (Protection);
TC_CLONE_SHARED (VolumePassword, ProtectionPassword); TC_CLONE_SHARED (VolumePassword, ProtectionPassword);
if (other.ProtectionKdf)
ProtectionKdf.reset(other.ProtectionKdf->Clone());
else
ProtectionKdf.reset();
TC_CLONE_SHARED (KeyfileList, ProtectionKeyfiles); TC_CLONE_SHARED (KeyfileList, ProtectionKeyfiles);
TC_CLONE (Removable); TC_CLONE (Removable);
TC_CLONE (SharedAccessAllowed); TC_CLONE (SharedAccessAllowed);
@@ -41,6 +51,7 @@ namespace VeraCrypt
void MountOptions::Deserialize (shared_ptr <Stream> stream) void MountOptions::Deserialize (shared_ptr <Stream> stream)
{ {
Serializer sr (stream); Serializer sr (stream);
wstring nameValue;
sr.Deserialize ("CachePassword", CachePassword); sr.Deserialize ("CachePassword", CachePassword);
sr.Deserialize ("FilesystemOptions", FilesystemOptions); sr.Deserialize ("FilesystemOptions", FilesystemOptions);
@@ -61,6 +72,14 @@ namespace VeraCrypt
Password = Serializable::DeserializeNew <VolumePassword> (stream); Password = Serializable::DeserializeNew <VolumePassword> (stream);
else else
Password.reset(); Password.reset();
if (!sr.DeserializeBool ("KdfNull"))
{
sr.Deserialize ("Kdf", nameValue);
Kdf = Pkcs5Kdf::GetAlgorithm (nameValue);
}
else
Kdf.reset();
if (!sr.DeserializeBool ("PathNull")) if (!sr.DeserializeBool ("PathNull"))
Path.reset (new VolumePath (sr.DeserializeWString ("Path"))); Path.reset (new VolumePath (sr.DeserializeWString ("Path")));
@@ -77,6 +96,14 @@ namespace VeraCrypt
else else
ProtectionPassword.reset(); ProtectionPassword.reset();
if (!sr.DeserializeBool ("ProtectionKdfNull"))
{
sr.Deserialize ("ProtectionKdf", nameValue);
ProtectionKdf = Pkcs5Kdf::GetAlgorithm (nameValue);
}
else
ProtectionKdf.reset();
ProtectionKeyfiles = Keyfile::DeserializeList (stream, "ProtectionKeyfiles"); ProtectionKeyfiles = Keyfile::DeserializeList (stream, "ProtectionKeyfiles");
sr.Deserialize ("Removable", Removable); sr.Deserialize ("Removable", Removable);
sr.Deserialize ("SharedAccessAllowed", SharedAccessAllowed); sr.Deserialize ("SharedAccessAllowed", SharedAccessAllowed);
@@ -106,6 +133,10 @@ namespace VeraCrypt
if (Password) if (Password)
Password->Serialize (stream); Password->Serialize (stream);
sr.Serialize ("KdfNull", Kdf == nullptr);
if (Kdf)
sr.Serialize ("Kdf", Kdf->GetName());
sr.Serialize ("PathNull", Path == nullptr); sr.Serialize ("PathNull", Path == nullptr);
if (Path) if (Path)
sr.Serialize ("Path", wstring (*Path)); sr.Serialize ("Path", wstring (*Path));
@@ -118,6 +149,10 @@ namespace VeraCrypt
if (ProtectionPassword) if (ProtectionPassword)
ProtectionPassword->Serialize (stream); ProtectionPassword->Serialize (stream);
sr.Serialize ("ProtectionKdfNull", ProtectionKdf == nullptr);
if (ProtectionKdf)
sr.Serialize ("ProtectionKdf", ProtectionKdf->GetName());
Keyfile::SerializeList (stream, "ProtectionKeyfiles", ProtectionKeyfiles); Keyfile::SerializeList (stream, "ProtectionKeyfiles", ProtectionKeyfiles);
sr.Serialize ("Removable", Removable); sr.Serialize ("Removable", Removable);
sr.Serialize ("SharedAccessAllowed", SharedAccessAllowed); sr.Serialize ("SharedAccessAllowed", SharedAccessAllowed);

2
src/Core/MountOptions.h Normal file → Executable file
View File

@@ -51,11 +51,13 @@ namespace VeraCrypt
bool NoHardwareCrypto; bool NoHardwareCrypto;
bool NoKernelCrypto; bool NoKernelCrypto;
shared_ptr <VolumePassword> Password; shared_ptr <VolumePassword> Password;
shared_ptr <Pkcs5Kdf> Kdf;
bool PartitionInSystemEncryptionScope; bool PartitionInSystemEncryptionScope;
shared_ptr <VolumePath> Path; shared_ptr <VolumePath> Path;
bool PreserveTimestamps; bool PreserveTimestamps;
VolumeProtection::Enum Protection; VolumeProtection::Enum Protection;
shared_ptr <VolumePassword> ProtectionPassword; shared_ptr <VolumePassword> ProtectionPassword;
shared_ptr <Pkcs5Kdf> ProtectionKdf;
shared_ptr <KeyfileList> ProtectionKeyfiles; shared_ptr <KeyfileList> ProtectionKeyfiles;
bool Removable; bool Removable;
bool SharedAccessAllowed; bool SharedAccessAllowed;

2
src/Core/Unix/CoreUnix.cpp Normal file → Executable file
View File

@@ -409,9 +409,11 @@ namespace VeraCrypt
options.Path, options.Path,
options.PreserveTimestamps, options.PreserveTimestamps,
options.Password, options.Password,
options.Kdf,
options.Keyfiles, options.Keyfiles,
options.Protection, options.Protection,
options.ProtectionPassword, options.ProtectionPassword,
options.ProtectionKdf,
options.ProtectionKeyfiles, options.ProtectionKeyfiles,
options.SharedAccessAllowed, options.SharedAccessAllowed,
VolumeType::Unknown, VolumeType::Unknown,

View File

@@ -36,6 +36,7 @@ namespace VeraCrypt
parser.AddSwitch (L"C", L"change", _("Change password or keyfiles")); parser.AddSwitch (L"C", L"change", _("Change password or keyfiles"));
parser.AddSwitch (L"c", L"create", _("Create new volume")); parser.AddSwitch (L"c", L"create", _("Create new volume"));
parser.AddSwitch (L"", L"create-keyfile", _("Create new keyfile")); parser.AddSwitch (L"", L"create-keyfile", _("Create new keyfile"));
parser.AddOption (L"", L"current-hash", _("Current hash algorithm for change password/keyfiles operation"));
parser.AddSwitch (L"", L"delete-token-keyfiles", _("Delete security token keyfiles")); parser.AddSwitch (L"", L"delete-token-keyfiles", _("Delete security token keyfiles"));
parser.AddSwitch (L"d", L"dismount", _("Dismount volume")); parser.AddSwitch (L"d", L"dismount", _("Dismount volume"));
parser.AddSwitch (L"", L"display-password", _("Display password while typing")); parser.AddSwitch (L"", L"display-password", _("Display password while typing"));
@@ -61,6 +62,7 @@ namespace VeraCrypt
parser.AddSwitch (L"", L"non-interactive", _("Do not interact with user")); parser.AddSwitch (L"", L"non-interactive", _("Do not interact with user"));
parser.AddOption (L"p", L"password", _("Password")); parser.AddOption (L"p", L"password", _("Password"));
parser.AddOption (L"", L"protect-hidden", _("Protect hidden volume")); parser.AddOption (L"", L"protect-hidden", _("Protect hidden volume"));
parser.AddOption (L"", L"protection-hash", _("Hash algorithm for protected hidden volume"));
parser.AddOption (L"", L"protection-keyfiles", _("Keyfiles for protected hidden volume")); parser.AddOption (L"", L"protection-keyfiles", _("Keyfiles for protected hidden volume"));
parser.AddOption (L"", L"protection-password", _("Password for protected hidden volume")); parser.AddOption (L"", L"protection-password", _("Password for protected hidden volume"));
parser.AddOption (L"", L"random-source", _("Use file as source of random data")); parser.AddOption (L"", L"random-source", _("Use file as source of random data"));
@@ -306,6 +308,20 @@ namespace VeraCrypt
throw_err (LangString["UNKNOWN_OPTION"] + L": " + str); throw_err (LangString["UNKNOWN_OPTION"] + L": " + str);
} }
if (parser.Found (L"current-hash", &str))
{
ArgCurrentHash.reset();
foreach (shared_ptr <Hash> hash, Hash::GetAvailableAlgorithms())
{
if (wxString (hash->GetName()).IsSameAs (str, false))
ArgCurrentHash = hash;
}
if (!ArgCurrentHash)
throw_err (LangString["UNKNOWN_OPTION"] + L": " + str);
}
if (parser.Found (L"keyfiles", &str)) if (parser.Found (L"keyfiles", &str))
ArgKeyfiles = ToKeyfileList (str); ArgKeyfiles = ToKeyfileList (str);
@@ -377,6 +393,22 @@ namespace VeraCrypt
ArgMountOptions.Protection = VolumeProtection::HiddenVolumeReadOnly; ArgMountOptions.Protection = VolumeProtection::HiddenVolumeReadOnly;
} }
if (parser.Found (L"protection-hash", &str))
{
bool bHashFound = false;
foreach (shared_ptr <Hash> hash, Hash::GetAvailableAlgorithms())
{
if (wxString (hash->GetName()).IsSameAs (str, false))
{
bHashFound = true;
ArgMountOptions.ProtectionKdf = Pkcs5Kdf::GetAlgorithm (*hash);
}
}
if (!bHashFound)
throw_err (LangString["UNKNOWN_OPTION"] + L": " + str);
}
ArgQuick = parser.Found (L"quick"); ArgQuick = parser.Found (L"quick");
if (parser.Found (L"random-source", &str)) if (parser.Found (L"random-source", &str))

View File

@@ -61,6 +61,7 @@ namespace VeraCrypt
VolumeCreationOptions::FilesystemType::Enum ArgFilesystem; VolumeCreationOptions::FilesystemType::Enum ArgFilesystem;
bool ArgForce; bool ArgForce;
shared_ptr <Hash> ArgHash; shared_ptr <Hash> ArgHash;
shared_ptr <Hash> ArgCurrentHash;
shared_ptr <KeyfileList> ArgKeyfiles; shared_ptr <KeyfileList> ArgKeyfiles;
MountOptions ArgMountOptions; MountOptions ArgMountOptions;
shared_ptr <DirectoryPath> ArgMountPoint; shared_ptr <DirectoryPath> ArgMountPoint;

4
src/Main/Forms/ChangePasswordDialog.cpp Normal file → Executable file
View File

@@ -47,7 +47,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
} }
CurrentPasswordPanel = new VolumePasswordPanel (this, password, keyfiles); CurrentPasswordPanel = new VolumePasswordPanel (this, password, keyfiles, false, true, true, false, true, true);
CurrentPasswordPanel->UpdateEvent.Connect (EventConnector <ChangePasswordDialog> (this, &ChangePasswordDialog::OnPasswordPanelUpdate)); CurrentPasswordPanel->UpdateEvent.Connect (EventConnector <ChangePasswordDialog> (this, &ChangePasswordDialog::OnPasswordPanelUpdate));
CurrentPasswordPanelSizer->Add (CurrentPasswordPanel, 1, wxALL | wxEXPAND); CurrentPasswordPanelSizer->Add (CurrentPasswordPanel, 1, wxALL | wxEXPAND);
@@ -125,7 +125,7 @@ namespace VeraCrypt
#endif #endif
wxBusyCursor busy; wxBusyCursor busy;
Core->ChangePassword (Path, Gui->GetPreferences().DefaultMountOptions.PreserveTimestamps, Core->ChangePassword (Path, Gui->GetPreferences().DefaultMountOptions.PreserveTimestamps,
CurrentPasswordPanel->GetPassword(), CurrentPasswordPanel->GetKeyfiles(), CurrentPasswordPanel->GetPassword(), CurrentPasswordPanel->GetPkcs5Kdf(), CurrentPasswordPanel->GetKeyfiles(),
newPassword, newKeyfiles, NewPasswordPanel->GetPkcs5Kdf(), NewPasswordPanel->GetHeaderWipeCount()); newPassword, newKeyfiles, NewPasswordPanel->GetPkcs5Kdf(), NewPasswordPanel->GetHeaderWipeCount());
} }

6
src/Main/Forms/MountOptionsDialog.cpp Normal file → Executable file
View File

@@ -30,7 +30,7 @@ namespace VeraCrypt
if (disableMountOptions) if (disableMountOptions)
OptionsButton->Show (false); OptionsButton->Show (false);
PasswordPanel = new VolumePasswordPanel (this, options.Password, options.Keyfiles, !disableMountOptions); PasswordPanel = new VolumePasswordPanel (this, options.Password, options.Keyfiles, !disableMountOptions, true, true, false, true, true);
PasswordPanel->SetCacheCheckBoxValidator (wxGenericValidator (&Options.CachePassword)); PasswordPanel->SetCacheCheckBoxValidator (wxGenericValidator (&Options.CachePassword));
PasswordSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND); PasswordSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND);
@@ -61,7 +61,7 @@ namespace VeraCrypt
OptionsButton->SetLabel (OptionsButtonLabel + L" >"); OptionsButton->SetLabel (OptionsButtonLabel + L" >");
OptionsPanel->Show (false); OptionsPanel->Show (false);
ProtectionPasswordPanel = new VolumePasswordPanel (OptionsPanel, options.ProtectionPassword, options.ProtectionKeyfiles, false, true, true, false, false, _("P&assword to hidden volume:")); ProtectionPasswordPanel = new VolumePasswordPanel (OptionsPanel, options.ProtectionPassword, options.ProtectionKeyfiles, false, true, true, false, true, true, _("P&assword to hidden volume:"));
ProtectionPasswordSizer->Add (ProtectionPasswordPanel, 1, wxALL | wxEXPAND); ProtectionPasswordSizer->Add (ProtectionPasswordPanel, 1, wxALL | wxEXPAND);
UpdateDialog(); UpdateDialog();
@@ -85,6 +85,7 @@ namespace VeraCrypt
TransferDataFromWindow(); TransferDataFromWindow();
Options.Password = PasswordPanel->GetPassword(); Options.Password = PasswordPanel->GetPassword();
Options.Kdf = PasswordPanel->GetPkcs5Kdf();
Options.Keyfiles = PasswordPanel->GetKeyfiles(); Options.Keyfiles = PasswordPanel->GetKeyfiles();
if (ReadOnlyCheckBox->IsChecked()) if (ReadOnlyCheckBox->IsChecked())
@@ -95,6 +96,7 @@ namespace VeraCrypt
{ {
Options.Protection = VolumeProtection::HiddenVolumeReadOnly; Options.Protection = VolumeProtection::HiddenVolumeReadOnly;
Options.ProtectionPassword = ProtectionPasswordPanel->GetPassword(); Options.ProtectionPassword = ProtectionPasswordPanel->GetPassword();
Options.ProtectionKdf = ProtectionPasswordPanel->GetPkcs5Kdf();
Options.ProtectionKeyfiles = ProtectionPasswordPanel->GetKeyfiles(); Options.ProtectionKeyfiles = ProtectionPasswordPanel->GetKeyfiles();
} }
else else

View File

@@ -699,6 +699,7 @@ namespace VeraCrypt
{ {
VolumePasswordWizardPage *page = dynamic_cast <VolumePasswordWizardPage *> (GetCurrentPage()); VolumePasswordWizardPage *page = dynamic_cast <VolumePasswordWizardPage *> (GetCurrentPage());
Password = page->GetPassword(); Password = page->GetPassword();
Kdf = page->GetPkcs5Kdf();
Keyfiles = page->GetKeyfiles(); Keyfiles = page->GetKeyfiles();
if (forward && Password && !Password->IsEmpty()) if (forward && Password && !Password->IsEmpty())
@@ -937,7 +938,7 @@ namespace VeraCrypt
}); });
#endif #endif
shared_ptr <Volume> outerVolume = Core->OpenVolume (make_shared <VolumePath> (SelectedVolumePath), true, Password, Keyfiles, VolumeProtection::ReadOnly); shared_ptr <Volume> outerVolume = Core->OpenVolume (make_shared <VolumePath> (SelectedVolumePath), true, Password, Kdf, Keyfiles, VolumeProtection::ReadOnly);
MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume); MaxHiddenVolumeSize = Core->GetMaxHiddenVolumeSize (outerVolume);
// Add a reserve (in case the user mounts the outer volume and creates new files // Add a reserve (in case the user mounts the outer volume and creates new files

View File

@@ -73,6 +73,7 @@ namespace VeraCrypt
VolumeHostType::Enum SelectedVolumeHostType; VolumeHostType::Enum SelectedVolumeHostType;
VolumeType::Enum SelectedVolumeType; VolumeType::Enum SelectedVolumeType;
shared_ptr <VolumePassword> Password; shared_ptr <VolumePassword> Password;
shared_ptr <Pkcs5Kdf> Kdf;
uint32 SectorSize; uint32 SectorSize;
shared_ptr <Hash> SelectedHash; shared_ptr <Hash> SelectedHash;
uint64 VolumeSize; uint64 VolumeSize;

14
src/Main/Forms/VolumePasswordPanel.cpp Normal file → Executable file
View File

@@ -14,7 +14,7 @@
namespace VeraCrypt namespace VeraCrypt
{ {
VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, const wxString &passwordLabel) VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, bool isMountPassword, const wxString &passwordLabel)
: VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList) : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList)
{ {
if (keyfiles) if (keyfiles)
@@ -63,14 +63,20 @@ namespace VeraCrypt
Pkcs5PrfStaticText->Show (enablePkcs5Prf); Pkcs5PrfStaticText->Show (enablePkcs5Prf);
Pkcs5PrfChoice->Show (enablePkcs5Prf); Pkcs5PrfChoice->Show (enablePkcs5Prf);
HeaderWipeCountText->Show (enablePkcs5Prf); HeaderWipeCountText->Show (enablePkcs5Prf && !isMountPassword);
HeaderWipeCount->Show (enablePkcs5Prf); HeaderWipeCount->Show (enablePkcs5Prf && !isMountPassword);
if (enablePkcs5Prf) if (enablePkcs5Prf)
{ {
if (isMountPassword)
{
// case of password for mounting
Pkcs5PrfChoice->Delete (0);
Pkcs5PrfChoice->Append (LangString["AUTODETECTION"]);
}
foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms()) foreach_ref (const Pkcs5Kdf &kdf, Pkcs5Kdf::GetAvailableAlgorithms())
{ {
if (!kdf.IsDeprecated()) if (!kdf.IsDeprecated() || isMountPassword)
Pkcs5PrfChoice->Append (kdf.GetName()); Pkcs5PrfChoice->Append (kdf.GetName());
} }
Pkcs5PrfChoice->Select (0); Pkcs5PrfChoice->Select (0);

2
src/Main/Forms/VolumePasswordPanel.h Normal file → Executable file
View File

@@ -18,7 +18,7 @@ namespace VeraCrypt
class VolumePasswordPanel : public VolumePasswordPanelBase class VolumePasswordPanel : public VolumePasswordPanelBase
{ {
public: public:
VolumePasswordPanel (wxWindow* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableCache = false, bool enablePassword = true, bool enableKeyfiles = true, bool enableConfirmation = false, bool enablePkcs5Prf = false, const wxString &passwordLabel = wxString()); VolumePasswordPanel (wxWindow* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableCache = false, bool enablePassword = true, bool enableKeyfiles = true, bool enableConfirmation = false, bool enablePkcs5Prf = false, bool isMountPassword = false, const wxString &passwordLabel = wxString());
virtual ~VolumePasswordPanel (); virtual ~VolumePasswordPanel ();
void AddKeyfile (shared_ptr <Keyfile> keyfile); void AddKeyfile (shared_ptr <Keyfile> keyfile);

2
src/Main/Forms/VolumePasswordWizardPage.cpp Normal file → Executable file
View File

@@ -15,7 +15,7 @@ namespace VeraCrypt
VolumePasswordWizardPage::VolumePasswordWizardPage (wxPanel* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableConfirmation) VolumePasswordWizardPage::VolumePasswordWizardPage (wxPanel* parent, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, bool enableConfirmation)
: VolumePasswordWizardPageBase (parent), ConfirmationMode (enableConfirmation) : VolumePasswordWizardPageBase (parent), ConfirmationMode (enableConfirmation)
{ {
PasswordPanel = new VolumePasswordPanel (this, password, keyfiles, false, true, true, enableConfirmation); PasswordPanel = new VolumePasswordPanel (this, password, keyfiles, false, true, true, enableConfirmation, !enableConfirmation, !enableConfirmation);
PasswordPanel->UpdateEvent.Connect (EventConnector <VolumePasswordWizardPage> (this, &VolumePasswordWizardPage::OnPasswordPanelUpdate)); PasswordPanel->UpdateEvent.Connect (EventConnector <VolumePasswordWizardPage> (this, &VolumePasswordWizardPage::OnPasswordPanelUpdate));
PasswordPanelSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND); PasswordPanelSizer->Add (PasswordPanel, 1, wxALL | wxEXPAND);

View File

@@ -22,6 +22,7 @@ namespace VeraCrypt
shared_ptr <KeyfileList> GetKeyfiles () const { return PasswordPanel->GetKeyfiles(); } shared_ptr <KeyfileList> GetKeyfiles () const { return PasswordPanel->GetKeyfiles(); }
shared_ptr <VolumePassword> GetPassword () const { return PasswordPanel->GetPassword(); } shared_ptr <VolumePassword> GetPassword () const { return PasswordPanel->GetPassword(); }
shared_ptr <Pkcs5Kdf> GetPkcs5Kdf () const { return PasswordPanel->GetPkcs5Kdf(); }
bool IsValid (); bool IsValid ();
void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); } void SetMaxStaticTextWidth (int width) { InfoStaticText->Wrap (width); }
void SetPageText (const wxString &text) { InfoStaticText->SetLabel (text); } void SetPageText (const wxString &text) { InfoStaticText->SetLabel (text); }

6
src/Main/GraphicUserInterface.cpp Normal file → Executable file
View File

@@ -177,9 +177,11 @@ namespace VeraCrypt
options->Path, options->Path,
options->PreserveTimestamps, options->PreserveTimestamps,
options->Password, options->Password,
options->Kdf,
options->Keyfiles, options->Keyfiles,
options->Protection, options->Protection,
options->ProtectionPassword, options->ProtectionPassword,
options->ProtectionKdf,
options->ProtectionKeyfiles, options->ProtectionKeyfiles,
true, true,
volumeType, volumeType,
@@ -1261,9 +1263,11 @@ namespace VeraCrypt
options.Path, options.Path,
options.PreserveTimestamps, options.PreserveTimestamps,
options.Password, options.Password,
options.Kdf,
options.Keyfiles, options.Keyfiles,
options.Protection, options.Protection,
options.ProtectionPassword, options.ProtectionPassword,
options.ProtectionKdf,
options.ProtectionKeyfiles, options.ProtectionKeyfiles,
options.SharedAccessAllowed, options.SharedAccessAllowed,
VolumeType::Unknown, VolumeType::Unknown,
@@ -1373,7 +1377,7 @@ namespace VeraCrypt
// Decrypt header // Decrypt header
shared_ptr <VolumePassword> passwordKey = Keyfile::ApplyListToPassword (options.Keyfiles, options.Password); shared_ptr <VolumePassword> passwordKey = Keyfile::ApplyListToPassword (options.Keyfiles, options.Password);
if (layout->GetHeader()->Decrypt (headerBuffer, *passwordKey, layout->GetSupportedKeyDerivationFunctions(), layout->GetSupportedEncryptionAlgorithms(), layout->GetSupportedEncryptionModes())) if (layout->GetHeader()->Decrypt (headerBuffer, *passwordKey, options.Kdf, layout->GetSupportedKeyDerivationFunctions(), layout->GetSupportedEncryptionAlgorithms(), layout->GetSupportedEncryptionModes()))
{ {
decryptedLayout = layout; decryptedLayout = layout;
break; break;

2
src/Main/GraphicUserInterface.h Normal file → Executable file
View File

@@ -29,7 +29,7 @@ namespace VeraCrypt
virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const; virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const;
virtual void BeginBusyState () const { wxBeginBusyCursor(); } virtual void BeginBusyState () const { wxBeginBusyCursor(); }
virtual void BeginInteractiveBusyState (wxWindow *window); virtual void BeginInteractiveBusyState (wxWindow *window);
virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const { ThrowTextModeRequired(); } virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <Hash> currentHash = shared_ptr <Hash>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const { ThrowTextModeRequired(); }
wxHyperlinkCtrl *CreateHyperlink (wxWindow *parent, const wxString &linkUrl, const wxString &linkText) const; wxHyperlinkCtrl *CreateHyperlink (wxWindow *parent, const wxString &linkUrl, const wxString &linkText) const;
virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const; virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const;
virtual void CreateVolume (shared_ptr <VolumeCreationOptions> options) const { ThrowTextModeRequired(); } virtual void CreateVolume (shared_ptr <VolumeCreationOptions> options) const { ThrowTextModeRequired(); }

30
src/Main/TextUserInterface.cpp Normal file → Executable file
View File

@@ -244,6 +244,12 @@ namespace VeraCrypt
#endif #endif
ShowInfo ("EXTERNAL_VOL_HEADER_BAK_FIRST_INFO"); ShowInfo ("EXTERNAL_VOL_HEADER_BAK_FIRST_INFO");
shared_ptr <Pkcs5Kdf> kdf;
if (CmdLine->ArgHash)
{
kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash);
}
shared_ptr <Volume> normalVolume; shared_ptr <Volume> normalVolume;
shared_ptr <Volume> hiddenVolume; shared_ptr <Volume> hiddenVolume;
@@ -274,9 +280,11 @@ namespace VeraCrypt
options->Path, options->Path,
options->PreserveTimestamps, options->PreserveTimestamps,
options->Password, options->Password,
kdf,
options->Keyfiles, options->Keyfiles,
options->Protection, options->Protection,
options->ProtectionPassword, options->ProtectionPassword,
options->ProtectionKdf,
options->ProtectionKeyfiles, options->ProtectionKeyfiles,
true, true,
volumeType, volumeType,
@@ -359,7 +367,7 @@ namespace VeraCrypt
ShowInfo ("VOL_HEADER_BACKED_UP"); ShowInfo ("VOL_HEADER_BACKED_UP");
} }
void TextUserInterface::ChangePassword (shared_ptr <VolumePath> volumePath, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Hash> newHash) const void TextUserInterface::ChangePassword (shared_ptr <VolumePath> volumePath, shared_ptr <VolumePassword> password, shared_ptr <Hash> currentHash, shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> newPassword, shared_ptr <KeyfileList> newKeyfiles, shared_ptr <Hash> newHash) const
{ {
shared_ptr <Volume> volume; shared_ptr <Volume> volume;
@@ -378,6 +386,12 @@ namespace VeraCrypt
bool passwordInteractive = !password.get(); bool passwordInteractive = !password.get();
bool keyfilesInteractive = !keyfiles.get(); bool keyfilesInteractive = !keyfiles.get();
shared_ptr<Pkcs5Kdf> kdf;
if (currentHash)
{
kdf = Pkcs5Kdf::GetAlgorithm (*currentHash);
}
while (true) while (true)
{ {
// Current password // Current password
@@ -406,7 +420,7 @@ namespace VeraCrypt
try try
{ {
keyfiles.reset (new KeyfileList); keyfiles.reset (new KeyfileList);
volume = Core->OpenVolume (volumePath, Preferences.DefaultMountOptions.PreserveTimestamps, password, keyfiles); volume = Core->OpenVolume (volumePath, Preferences.DefaultMountOptions.PreserveTimestamps, password, kdf, keyfiles);
} }
catch (PasswordException&) catch (PasswordException&)
{ {
@@ -416,7 +430,7 @@ namespace VeraCrypt
} }
if (!volume.get()) if (!volume.get())
volume = Core->OpenVolume (volumePath, Preferences.DefaultMountOptions.PreserveTimestamps, password, keyfiles); volume = Core->OpenVolume (volumePath, Preferences.DefaultMountOptions.PreserveTimestamps, password, kdf, keyfiles);
} }
catch (PasswordException &e) catch (PasswordException &e)
{ {
@@ -1285,6 +1299,12 @@ namespace VeraCrypt
// Ask whether to restore internal or external backup // Ask whether to restore internal or external backup
bool restoreInternalBackup; bool restoreInternalBackup;
shared_ptr <Pkcs5Kdf> kdf;
if (CmdLine->ArgHash)
{
kdf = Pkcs5Kdf::GetAlgorithm (*CmdLine->ArgHash);
}
ShowInfo (LangString["HEADER_RESTORE_EXTERNAL_INTERNAL"]); ShowInfo (LangString["HEADER_RESTORE_EXTERNAL_INTERNAL"]);
ShowInfo (L"\n1) " + LangString["HEADER_RESTORE_INTERNAL"]); ShowInfo (L"\n1) " + LangString["HEADER_RESTORE_INTERNAL"]);
ShowInfo (L"2) " + LangString["HEADER_RESTORE_EXTERNAL"] + L"\n"); ShowInfo (L"2) " + LangString["HEADER_RESTORE_EXTERNAL"] + L"\n");
@@ -1325,9 +1345,11 @@ namespace VeraCrypt
options.Path, options.Path,
options.PreserveTimestamps, options.PreserveTimestamps,
options.Password, options.Password,
kdf,
options.Keyfiles, options.Keyfiles,
options.Protection, options.Protection,
options.ProtectionPassword, options.ProtectionPassword,
options.ProtectionKdf,
options.ProtectionKeyfiles, options.ProtectionKeyfiles,
options.SharedAccessAllowed, options.SharedAccessAllowed,
VolumeType::Unknown, VolumeType::Unknown,
@@ -1432,7 +1454,7 @@ namespace VeraCrypt
// Decrypt header // Decrypt header
shared_ptr <VolumePassword> passwordKey = Keyfile::ApplyListToPassword (options.Keyfiles, options.Password); shared_ptr <VolumePassword> passwordKey = Keyfile::ApplyListToPassword (options.Keyfiles, options.Password);
if (layout->GetHeader()->Decrypt (headerBuffer, *passwordKey, layout->GetSupportedKeyDerivationFunctions(), layout->GetSupportedEncryptionAlgorithms(), layout->GetSupportedEncryptionModes())) if (layout->GetHeader()->Decrypt (headerBuffer, *passwordKey, kdf, layout->GetSupportedKeyDerivationFunctions(), layout->GetSupportedEncryptionAlgorithms(), layout->GetSupportedEncryptionModes()))
{ {
decryptedLayout = layout; decryptedLayout = layout;
break; break;

2
src/Main/TextUserInterface.h Normal file → Executable file
View File

@@ -30,7 +30,7 @@ namespace VeraCrypt
virtual bool AskYesNo (const wxString &message, bool defaultYes = false, bool warning = false) const; virtual bool AskYesNo (const wxString &message, bool defaultYes = false, bool warning = false) const;
virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const; virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const;
virtual void BeginBusyState () const { } virtual void BeginBusyState () const { }
virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const; virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <Hash> currentHash = shared_ptr <Hash>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const;
virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const; virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const;
virtual void CreateVolume (shared_ptr <VolumeCreationOptions> options) const; virtual void CreateVolume (shared_ptr <VolumeCreationOptions> options) const;
virtual void DeleteSecurityTokenKeyfiles () const; virtual void DeleteSecurityTokenKeyfiles () const;

7
src/Main/UserInterface.cpp Normal file → Executable file
View File

@@ -883,6 +883,11 @@ namespace VeraCrypt
cmdLine.ArgMountOptions.Password = cmdLine.ArgPassword; cmdLine.ArgMountOptions.Password = cmdLine.ArgPassword;
cmdLine.ArgMountOptions.Keyfiles = cmdLine.ArgKeyfiles; cmdLine.ArgMountOptions.Keyfiles = cmdLine.ArgKeyfiles;
cmdLine.ArgMountOptions.SharedAccessAllowed = cmdLine.ArgForce; cmdLine.ArgMountOptions.SharedAccessAllowed = cmdLine.ArgForce;
if (cmdLine.ArgHash)
{
cmdLine.ArgMountOptions.Kdf = Pkcs5Kdf::GetAlgorithm (*cmdLine.ArgHash);
}
VolumeInfoList mountedVolumes; VolumeInfoList mountedVolumes;
switch (cmdLine.ArgCommand) switch (cmdLine.ArgCommand)
@@ -965,7 +970,7 @@ namespace VeraCrypt
return true; return true;
case CommandId::ChangePassword: case CommandId::ChangePassword:
ChangePassword (cmdLine.ArgVolumePath, cmdLine.ArgPassword, cmdLine.ArgKeyfiles, cmdLine.ArgNewPassword, cmdLine.ArgNewKeyfiles, cmdLine.ArgHash); ChangePassword (cmdLine.ArgVolumePath, cmdLine.ArgPassword, cmdLine.ArgCurrentHash, cmdLine.ArgKeyfiles, cmdLine.ArgNewPassword, cmdLine.ArgNewKeyfiles, cmdLine.ArgHash);
return true; return true;
case CommandId::CreateKeyfile: case CommandId::CreateKeyfile:

2
src/Main/UserInterface.h Normal file → Executable file
View File

@@ -29,7 +29,7 @@ namespace VeraCrypt
virtual bool AskYesNo (const wxString &message, bool defaultYes = false, bool warning = false) const = 0; virtual bool AskYesNo (const wxString &message, bool defaultYes = false, bool warning = false) const = 0;
virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const = 0; virtual void BackupVolumeHeaders (shared_ptr <VolumePath> volumePath) const = 0;
virtual void BeginBusyState () const = 0; virtual void BeginBusyState () const = 0;
virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const = 0; virtual void ChangePassword (shared_ptr <VolumePath> volumePath = shared_ptr <VolumePath>(), shared_ptr <VolumePassword> password = shared_ptr <VolumePassword>(), shared_ptr <Hash> currentHash = shared_ptr <Hash>(), shared_ptr <KeyfileList> keyfiles = shared_ptr <KeyfileList>(), shared_ptr <VolumePassword> newPassword = shared_ptr <VolumePassword>(), shared_ptr <KeyfileList> newKeyfiles = shared_ptr <KeyfileList>(), shared_ptr <Hash> newHash = shared_ptr <Hash>()) const = 0;
virtual void CheckRequirementsForMountingVolume () const; virtual void CheckRequirementsForMountingVolume () const;
virtual void CloseExplorerWindows (shared_ptr <VolumeInfo> mountedVolume) const; virtual void CloseExplorerWindows (shared_ptr <VolumeInfo> mountedVolume) const;
virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const = 0; virtual void CreateKeyfile (shared_ptr <FilePath> keyfilePath = shared_ptr <FilePath>()) const = 0;

View File

@@ -31,6 +31,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const = 0; virtual shared_ptr <Hash> GetHash () const = 0;
virtual int GetIterationCount () const = 0; virtual int GetIterationCount () const = 0;
virtual wstring GetName () const = 0; virtual wstring GetName () const = 0;
virtual Pkcs5Kdf* Clone () const = 0;
virtual bool IsDeprecated () const { return GetHash()->IsDeprecated(); } virtual bool IsDeprecated () const { return GetHash()->IsDeprecated(); }
protected: protected:
@@ -53,6 +54,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); }
virtual int GetIterationCount () const { return 655331; } virtual int GetIterationCount () const { return 655331; }
virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; } virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacRipemd160(); }
private: private:
Pkcs5HmacRipemd160 (const Pkcs5HmacRipemd160 &); Pkcs5HmacRipemd160 (const Pkcs5HmacRipemd160 &);
@@ -69,6 +71,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); }
virtual int GetIterationCount () const { return 327661; } virtual int GetIterationCount () const { return 327661; }
virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; } virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacRipemd160_1000(); }
private: private:
Pkcs5HmacRipemd160_1000 (const Pkcs5HmacRipemd160_1000 &); Pkcs5HmacRipemd160_1000 (const Pkcs5HmacRipemd160_1000 &);
@@ -85,6 +88,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); }
virtual int GetIterationCount () const { return 200000; } virtual int GetIterationCount () const { return 200000; }
virtual wstring GetName () const { return L"HMAC-SHA-256"; } virtual wstring GetName () const { return L"HMAC-SHA-256"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha256_Boot(); }
private: private:
Pkcs5HmacSha256_Boot (const Pkcs5HmacSha256_Boot &); Pkcs5HmacSha256_Boot (const Pkcs5HmacSha256_Boot &);
@@ -101,6 +105,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha256); }
virtual int GetIterationCount () const { return 500000; } virtual int GetIterationCount () const { return 500000; }
virtual wstring GetName () const { return L"HMAC-SHA-256"; } virtual wstring GetName () const { return L"HMAC-SHA-256"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha256(); }
private: private:
Pkcs5HmacSha256 (const Pkcs5HmacSha256 &); Pkcs5HmacSha256 (const Pkcs5HmacSha256 &);
@@ -117,6 +122,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha512); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha512); }
virtual int GetIterationCount () const { return 500000; } virtual int GetIterationCount () const { return 500000; }
virtual wstring GetName () const { return L"HMAC-SHA-512"; } virtual wstring GetName () const { return L"HMAC-SHA-512"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacSha512(); }
private: private:
Pkcs5HmacSha512 (const Pkcs5HmacSha512 &); Pkcs5HmacSha512 (const Pkcs5HmacSha512 &);
@@ -133,6 +139,7 @@ namespace VeraCrypt
virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Whirlpool); } virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Whirlpool); }
virtual int GetIterationCount () const { return 500000; } virtual int GetIterationCount () const { return 500000; }
virtual wstring GetName () const { return L"HMAC-Whirlpool"; } virtual wstring GetName () const { return L"HMAC-Whirlpool"; }
virtual Pkcs5Kdf* Clone () const { return new Pkcs5HmacWhirlpool; }
private: private:
Pkcs5HmacWhirlpool (const Pkcs5HmacWhirlpool &); Pkcs5HmacWhirlpool (const Pkcs5HmacWhirlpool &);

12
src/Volume/Volume.cpp Normal file → Executable file
View File

@@ -62,7 +62,7 @@ namespace VeraCrypt
return EA->GetMode(); return EA->GetMode();
} }
void Volume::Open (const VolumePath &volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr <KeyfileList> protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) void Volume::Open (const VolumePath &volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr <Pkcs5Kdf> protectionKdf, shared_ptr <KeyfileList> protectionKeyfiles, bool sharedAccessAllowed, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope)
{ {
make_shared_auto (File, file); make_shared_auto (File, file);
@@ -93,10 +93,10 @@ namespace VeraCrypt
throw; throw;
} }
return Open (file, password, keyfiles, protection, protectionPassword, protectionKeyfiles, volumeType, useBackupHeaders, partitionInSystemEncryptionScope); return Open (file, password, kdf, keyfiles, protection, protectionPassword, protectionKdf,protectionKeyfiles, volumeType, useBackupHeaders, partitionInSystemEncryptionScope);
} }
void Volume::Open (shared_ptr <File> volumeFile, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr <KeyfileList> protectionKeyfiles, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope) void Volume::Open (shared_ptr <File> volumeFile, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection, shared_ptr <VolumePassword> protectionPassword, shared_ptr <Pkcs5Kdf> protectionKdf,shared_ptr <KeyfileList> protectionKeyfiles, VolumeType::Enum volumeType, bool useBackupHeaders, bool partitionInSystemEncryptionScope)
{ {
if (!volumeFile) if (!volumeFile)
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
@@ -189,7 +189,7 @@ namespace VeraCrypt
shared_ptr <VolumeHeader> header = layout->GetHeader(); shared_ptr <VolumeHeader> header = layout->GetHeader();
if (header->Decrypt (headerBuffer, *passwordKey, layout->GetSupportedKeyDerivationFunctions(), layoutEncryptionAlgorithms, layoutEncryptionModes)) if (header->Decrypt (headerBuffer, *passwordKey, kdf, layout->GetSupportedKeyDerivationFunctions(), layoutEncryptionAlgorithms, layoutEncryptionModes))
{ {
// Header decrypted // Header decrypted
@@ -238,9 +238,9 @@ namespace VeraCrypt
Volume protectedVolume; Volume protectedVolume;
protectedVolume.Open (VolumeFile, protectedVolume.Open (VolumeFile,
protectionPassword, protectionKeyfiles, protectionPassword, protectionKdf, protectionKeyfiles,
VolumeProtection::ReadOnly, VolumeProtection::ReadOnly,
shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> (), shared_ptr <VolumePassword> (), shared_ptr <Pkcs5Kdf> (),shared_ptr <KeyfileList> (),
VolumeType::Hidden, VolumeType::Hidden,
useBackupHeaders); useBackupHeaders);

4
src/Volume/Volume.h Normal file → Executable file
View File

@@ -89,8 +89,8 @@ namespace VeraCrypt
uint64 GetVolumeCreationTime () const { return Header->GetVolumeCreationTime(); } uint64 GetVolumeCreationTime () const { return Header->GetVolumeCreationTime(); }
bool IsHiddenVolumeProtectionTriggered () const { return HiddenVolumeProtectionTriggered; } bool IsHiddenVolumeProtectionTriggered () const { return HiddenVolumeProtectionTriggered; }
bool IsInSystemEncryptionScope () const { return SystemEncryption; } bool IsInSystemEncryptionScope () const { return SystemEncryption; }
void Open (const VolumePath &volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false); void Open (const VolumePath &volumePath, bool preserveTimestamps, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <Pkcs5Kdf> protectionKdf = shared_ptr <Pkcs5Kdf> (),shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false);
void Open (shared_ptr <File> volumeFile, shared_ptr <VolumePassword> password, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false); void Open (shared_ptr <File> volumeFile, shared_ptr <VolumePassword> password, shared_ptr <Pkcs5Kdf> kdf, shared_ptr <KeyfileList> keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr <VolumePassword> protectionPassword = shared_ptr <VolumePassword> (), shared_ptr <Pkcs5Kdf> protectionKdf = shared_ptr <Pkcs5Kdf> (), shared_ptr <KeyfileList> protectionKeyfiles = shared_ptr <KeyfileList> (), VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false);
void ReadSectors (const BufferPtr &buffer, uint64 byteOffset); void ReadSectors (const BufferPtr &buffer, uint64 byteOffset);
void ReEncryptHeader (bool backupHeader, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf); void ReEncryptHeader (bool backupHeader, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf);
void WriteSectors (const ConstBufferPtr &buffer, uint64 byteOffset); void WriteSectors (const ConstBufferPtr &buffer, uint64 byteOffset);

5
src/Volume/VolumeHeader.cpp Normal file → Executable file
View File

@@ -78,7 +78,7 @@ namespace VeraCrypt
EncryptNew (headerBuffer, options.Salt, options.HeaderKey, options.Kdf); EncryptNew (headerBuffer, options.Salt, options.HeaderKey, options.Kdf);
} }
bool VolumeHeader::Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) bool VolumeHeader::Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, shared_ptr <Pkcs5Kdf> kdf, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes)
{ {
if (password.Size() < 1) if (password.Size() < 1)
throw PasswordEmpty (SRC_POS); throw PasswordEmpty (SRC_POS);
@@ -89,6 +89,9 @@ namespace VeraCrypt
foreach (shared_ptr <Pkcs5Kdf> pkcs5, keyDerivationFunctions) foreach (shared_ptr <Pkcs5Kdf> pkcs5, keyDerivationFunctions)
{ {
if (kdf && (kdf->GetName() != pkcs5->GetName()))
continue;
pkcs5->DeriveKey (headerKey, password, salt); pkcs5->DeriveKey (headerKey, password, salt);
foreach (shared_ptr <EncryptionMode> mode, encryptionModes) foreach (shared_ptr <EncryptionMode> mode, encryptionModes)

2
src/Volume/VolumeHeader.h Normal file → Executable file
View File

@@ -56,7 +56,7 @@ namespace VeraCrypt
virtual ~VolumeHeader (); virtual ~VolumeHeader ();
void Create (const BufferPtr &headerBuffer, VolumeHeaderCreationOptions &options); void Create (const BufferPtr &headerBuffer, VolumeHeaderCreationOptions &options);
bool Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes); bool Decrypt (const ConstBufferPtr &encryptedData, const VolumePassword &password, shared_ptr <Pkcs5Kdf> kdf, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes);
void EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf); void EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf);
uint64 GetEncryptedAreaStart () const { return EncryptedAreaStart; } uint64 GetEncryptedAreaStart () const { return EncryptedAreaStart; }
uint64 GetEncryptedAreaLength () const { return EncryptedAreaLength; } uint64 GetEncryptedAreaLength () const { return EncryptedAreaLength; }