VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume
diff options
context:
space:
mode:
Diffstat (limited to 'src/Volume')
-rw-r--r--src/Volume/EncryptionTest.cpp2
-rw-r--r--src/Volume/VolumePassword.cpp96
-rw-r--r--src/Volume/VolumePassword.h13
3 files changed, 10 insertions, 101 deletions
diff --git a/src/Volume/EncryptionTest.cpp b/src/Volume/EncryptionTest.cpp
index 0d9a0e03..cd94a09c 100644
--- a/src/Volume/EncryptionTest.cpp
+++ b/src/Volume/EncryptionTest.cpp
@@ -790,7 +790,7 @@ namespace VeraCrypt
void EncryptionTest::TestPkcs5 ()
{
- VolumePassword password ("password", 8);
+ VolumePassword password ((byte*) "password", 8);
static const byte saltData[] = { 0x12, 0x34, 0x56, 0x78 };
ConstBufferPtr salt (saltData, sizeof (saltData));
Buffer derivedKey (4);
diff --git a/src/Volume/VolumePassword.cpp b/src/Volume/VolumePassword.cpp
index c36f910d..c6d27a67 100644
--- a/src/Volume/VolumePassword.cpp
+++ b/src/Volume/VolumePassword.cpp
@@ -16,31 +16,11 @@
namespace VeraCrypt
{
- VolumePassword::VolumePassword () : PasswordSize (0), Unportable (false)
+ VolumePassword::VolumePassword () : PasswordSize (0)
{
AllocateBuffer ();
}
- VolumePassword::VolumePassword (const char *password, size_t size)
- {
- Set ((const byte *) password, size);
- }
-
- VolumePassword::VolumePassword (const byte *password, size_t size)
- {
- Set (password, size);
- }
-
- VolumePassword::VolumePassword (const wchar_t *password, size_t charCount)
- {
- Set (password, charCount);
- }
-
- VolumePassword::VolumePassword (const wstring &password)
- {
- Set (password.c_str(), password.size());
- }
-
VolumePassword::~VolumePassword ()
{
}
@@ -51,12 +31,6 @@ namespace VeraCrypt
PasswordBuffer.Allocate (MaxSize);
}
- void VolumePassword::CheckPortability () const
- {
- if (Unportable || !IsPortable())
- throw UnportablePassword (SRC_POS);
- }
-
void VolumePassword::Deserialize (shared_ptr <Stream> stream)
{
Serializer sr (stream);
@@ -69,16 +43,6 @@ namespace VeraCrypt
sr.Deserialize ("WipeData", wipeBuffer);
}
- bool VolumePassword::IsPortable () const
- {
- for (size_t i = 0; i < PasswordSize; i++)
- {
- if (PasswordBuffer[i] >= 0x7f || PasswordBuffer[i] < 0x20)
- return false;
- }
- return true;
- }
-
void VolumePassword::Serialize (shared_ptr <Stream> stream) const
{
Serializable::Serialize (stream);
@@ -98,62 +62,12 @@ namespace VeraCrypt
if (size > MaxSize)
throw PasswordTooLong (SRC_POS);
-
- PasswordBuffer.CopyFrom (ConstBufferPtr (password, size));
- PasswordSize = size;
- Unportable = !IsPortable();
- }
-
- void VolumePassword::Set (const wchar_t *password, size_t charCount)
- {
- if (charCount > MaxSize)
- throw PasswordTooLong (SRC_POS);
+ PasswordBuffer.Erase ();
+ if (size > 0)
+ PasswordBuffer.CopyFrom (ConstBufferPtr (password, size));
- union Conv
- {
- byte b[sizeof (wchar_t)];
- wchar_t c;
- };
-
- Conv conv;
- conv.c = L'A';
-
- int lsbPos = -1;
- for (size_t i = 0; i < sizeof (conv.b); ++i)
- {
- if (conv.b[i] == L'A')
- {
- lsbPos = i;
- break;
- }
- }
-
- if (lsbPos == -1)
- throw ParameterIncorrect (SRC_POS);
-
- bool unportable = false;
- byte passwordBuf[MaxSize];
- for (size_t i = 0; i < charCount; ++i)
- {
- conv.c = password[i];
- passwordBuf[i] = conv.b[lsbPos];
- for (int j = 0; j < (int) sizeof (wchar_t); ++j)
- {
- if (j != lsbPos && conv.b[j] != 0)
- unportable = true;
- }
- }
-
- Set (passwordBuf, charCount);
-
- if (unportable)
- Unportable = true;
- }
-
- void VolumePassword::Set (const ConstBufferPtr &password)
- {
- Set (password, password.Size());
+ PasswordSize = size;
}
void VolumePassword::Set (const VolumePassword &password)
diff --git a/src/Volume/VolumePassword.h b/src/Volume/VolumePassword.h
index bf10eb98..ff7479a5 100644
--- a/src/Volume/VolumePassword.h
+++ b/src/Volume/VolumePassword.h
@@ -22,10 +22,8 @@ namespace VeraCrypt
{
public:
VolumePassword ();
- VolumePassword (const byte *password, size_t size);
- VolumePassword (const char *password, size_t size);
- VolumePassword (const wchar_t *password, size_t charCount);
- VolumePassword (const wstring &password);
+ VolumePassword (const byte *password, size_t size) { Set (password, size); }
+ VolumePassword (const SecureBuffer &password) { Set (password.Ptr (), password.Size ()); }
VolumePassword (const VolumePassword &password) { Set (password); }
virtual ~VolumePassword ();
@@ -35,13 +33,10 @@ namespace VeraCrypt
operator BufferPtr () const { return BufferPtr (PasswordBuffer); }
- void CheckPortability () const;
byte *DataPtr () const { return PasswordBuffer; }
bool IsEmpty () const { return PasswordSize == 0; }
size_t Size () const { return PasswordSize; }
void Set (const byte *password, size_t size);
- void Set (const wchar_t *password, size_t charCount);
- void Set (const ConstBufferPtr &password);
void Set (const VolumePassword &password);
TC_SERIALIZABLE (VolumePassword);
@@ -51,12 +46,10 @@ namespace VeraCrypt
protected:
void AllocateBuffer ();
- bool IsPortable () const;
SecureBuffer PasswordBuffer;
size_t PasswordSize;
- bool Unportable;
};
struct PasswordException : public Exception
@@ -86,6 +79,8 @@ namespace VeraCrypt
TC_EXCEPTION_NODECL (ProtectionPasswordKeyfilesIncorrect); \
TC_EXCEPTION (PasswordEmpty); \
TC_EXCEPTION (PasswordTooLong); \
+ TC_EXCEPTION (PasswordUTF8TooLong); \
+ TC_EXCEPTION (PasswordUTF8Invalid); \
TC_EXCEPTION (UnportablePassword);
TC_EXCEPTION_SET;