diff options
Diffstat (limited to 'src/Volume/Keyfile.cpp')
-rw-r--r-- | src/Volume/Keyfile.cpp | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/Volume/Keyfile.cpp b/src/Volume/Keyfile.cpp index d171458c..24b40709 100644 --- a/src/Volume/Keyfile.cpp +++ b/src/Volume/Keyfile.cpp @@ -12,13 +12,13 @@ #include "Platform/Serializer.h" #include "Common/SecurityToken.h" +#include "Common/EMVToken.h" #include "Crc32.h" #include "Keyfile.h" #include "VolumeException.h" - namespace VeraCrypt { - void Keyfile::Apply (const BufferPtr &pool) const + void Keyfile::Apply (const BufferPtr &pool, bool emvSupportEnabled) const { if (Path.IsDirectory()) throw ParameterIncorrect (SRC_POS); @@ -32,22 +32,22 @@ namespace VeraCrypt SecureBuffer keyfileBuf (File::GetOptimalReadSize()); - if (SecurityToken::IsKeyfilePathValid (Path)) + if (Token::IsKeyfilePathValid (Path, emvSupportEnabled)) { // Apply keyfile generated by a security token vector <byte> keyfileData; - SecurityToken::GetKeyfileData (SecurityTokenKeyfile (wstring (Path)), keyfileData); + Token::getTokenKeyfile(wstring(Path))->GetKeyfileData(keyfileData); if (keyfileData.size() < MinProcessedLength) - throw InsufficientData (SRC_POS, Path); + throw InsufficientData(SRC_POS, Path); for (size_t i = 0; i < keyfileData.size(); i++) { - uint32 crc = crc32.Process (keyfileData[i]); + uint32 crc = crc32.Process(keyfileData[i]); - pool[poolPos++] += (byte) (crc >> 24); - pool[poolPos++] += (byte) (crc >> 16); - pool[poolPos++] += (byte) (crc >> 8); + pool[poolPos++] += (byte)(crc >> 24); + pool[poolPos++] += (byte)(crc >> 16); + pool[poolPos++] += (byte)(crc >> 8); pool[poolPos++] += (byte) crc; if (poolPos >= pool.Size()) @@ -57,8 +57,9 @@ namespace VeraCrypt break; } - burn (&keyfileData.front(), keyfileData.size()); - goto done; + + burn(&keyfileData.front(), keyfileData.size()); + goto done; } file.Open (Path, File::OpenRead, File::ShareRead); @@ -67,26 +68,24 @@ namespace VeraCrypt { for (size_t i = 0; i < readLength; i++) { - uint32 crc = crc32.Process (keyfileBuf[i]); - - pool[poolPos++] += (byte) (crc >> 24); - pool[poolPos++] += (byte) (crc >> 16); - pool[poolPos++] += (byte) (crc >> 8); + uint32 crc = crc32.Process(keyfileBuf[i]); + pool[poolPos++] += (byte)(crc >> 24); + pool[poolPos++] += (byte)(crc >> 16); + pool[poolPos++] += (byte)(crc >> 8); pool[poolPos++] += (byte) crc; - if (poolPos >= pool.Size()) poolPos = 0; - if (++totalLength >= MaxProcessedLength) goto done; } } -done: + done: + if (totalLength < MinProcessedLength) throw InsufficientData (SRC_POS, Path); } - shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password) + shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password, bool emvSupportEnabled) { if (!password) password.reset (new VolumePassword); @@ -143,7 +142,7 @@ done: // Apply all keyfiles foreach_ref (const Keyfile &k, keyfilesExp) { - k.Apply (keyfilePool); + k.Apply (keyfilePool, emvSupportEnabled); } newPassword->Set (keyfilePool); |