VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Volume/Keyfile.cpp
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2023-06-29 00:06:20 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2023-06-29 00:06:20 +0200
commit034b64f4153550cbe5849bcbfc27e187377cc512 (patch)
treed831496163c3891031765010bf1934406b0c4a3c /src/Volume/Keyfile.cpp
parent502ab9112a7624dbd7c1c90c2e12ed45512b8b3c (diff)
downloadVeraCrypt-034b64f4153550cbe5849bcbfc27e187377cc512.tar.gz
VeraCrypt-034b64f4153550cbe5849bcbfc27e187377cc512.zip
EMV keyfile support: Overall code improvements and bug fixes
Diffstat (limited to 'src/Volume/Keyfile.cpp')
-rw-r--r--src/Volume/Keyfile.cpp81
1 files changed, 42 insertions, 39 deletions
diff --git a/src/Volume/Keyfile.cpp b/src/Volume/Keyfile.cpp
index 9527fd11..24b40709 100644
--- a/src/Volume/Keyfile.cpp
+++ b/src/Volume/Keyfile.cpp
@@ -18,7 +18,7 @@
#include "VolumeException.h"
namespace VeraCrypt
{
- void Keyfile::Apply (const BufferPtr &pool, bool EMVOption) const
+ void Keyfile::Apply (const BufferPtr &pool, bool emvSupportEnabled) const
{
if (Path.IsDirectory())
throw ParameterIncorrect (SRC_POS);
@@ -32,57 +32,60 @@ namespace VeraCrypt
SecureBuffer keyfileBuf (File::GetOptimalReadSize());
- std::wcout << wstring (Path) << std::endl;
- if (Token::IsKeyfilePathValid (Path, EMVOption)) {
- // Apply keyfile generated by a security token
- vector <byte> keyfileData;
- Token::getTokenKeyfile(wstring(Path))->GetKeyfileData(keyfileData);
+ if (Token::IsKeyfilePathValid (Path, emvSupportEnabled))
+ {
+ // Apply keyfile generated by a security token
+ vector <byte> keyfileData;
+ Token::getTokenKeyfile(wstring(Path))->GetKeyfileData(keyfileData);
- if (keyfileData.size() < MinProcessedLength)
- throw InsufficientData(SRC_POS, Path);
+ if (keyfileData.size() < MinProcessedLength)
+ throw InsufficientData(SRC_POS, Path);
- for (size_t i = 0; i < keyfileData.size(); i++) {
- uint32 crc = crc32.Process(keyfileData[i]);
+ for (size_t i = 0; i < keyfileData.size(); 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;
+ 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 (poolPos >= pool.Size())
+ poolPos = 0;
- if (++totalLength >= MaxProcessedLength)
- break;
- }
+ if (++totalLength >= MaxProcessedLength)
+ break;
+ }
- burn(&keyfileData.front(), keyfileData.size());
- goto done;
- }
+ burn(&keyfileData.front(), keyfileData.size());
+ goto done;
+ }
- file.Open (Path, File::OpenRead, File::ShareRead);
+ file.Open (Path, File::OpenRead, File::ShareRead);
- while ((readLength = file.Read (keyfileBuf)) > 0) {
- 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);
- pool[poolPos++] += (byte) crc;
- if (poolPos >= pool.Size())
- poolPos = 0;
- if (++totalLength >= MaxProcessedLength)
- goto done;
- }
- }
- done:
+ while ((readLength = file.Read (keyfileBuf)) > 0)
+ {
+ 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);
+ pool[poolPos++] += (byte) crc;
+ if (poolPos >= pool.Size())
+ poolPos = 0;
+ if (++totalLength >= MaxProcessedLength)
+ goto done;
+ }
+ }
+ done:
if (totalLength < MinProcessedLength)
throw InsufficientData (SRC_POS, Path);
}
- shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password, bool EMVOption)
+ shared_ptr <VolumePassword> Keyfile::ApplyListToPassword (shared_ptr <KeyfileList> keyfiles, shared_ptr <VolumePassword> password, bool emvSupportEnabled)
{
if (!password)
password.reset (new VolumePassword);
@@ -139,7 +142,7 @@ namespace VeraCrypt
// Apply all keyfiles
foreach_ref (const Keyfile &k, keyfilesExp)
{
- k.Apply (keyfilePool, EMVOption);
+ k.Apply (keyfilePool, emvSupportEnabled);
}
newPassword->Set (keyfilePool);