mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Security: ensure that XTS primary key is different from secondary key when creating volumes
This is unlikely to happen thanks to random generator properties but we much add this check to prevent an attack described in page 3 of https://csrc.nist.gov/csrc/media/Projects/crypto-publication-review-project/documents/initial-comments/sp800-38e-initial-public-comments-2021.pdf
This commit is contained in:
@@ -909,6 +909,15 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
|
|||||||
retVal = ERR_CIPHER_INIT_WEAK_KEY;
|
retVal = ERR_CIPHER_INIT_WEAK_KEY;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check that first half of keyInfo.master_keydata is different from the second half. If they are the same return error
|
||||||
|
// cf CCSS,NSA comment at page 3: https://csrc.nist.gov/csrc/media/Projects/crypto-publication-review-project/documents/initial-comments/sp800-38e-initial-public-comments-2021.pdf
|
||||||
|
if (memcmp (keyInfo.master_keydata, &keyInfo.master_keydata[bytesNeeded/2], bytesNeeded/2) == 0)
|
||||||
|
{
|
||||||
|
crypto_close (cryptoInfo);
|
||||||
|
retVal = ERR_CIPHER_INIT_WEAK_KEY;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -298,6 +298,11 @@ namespace VeraCrypt
|
|||||||
// Master data key
|
// Master data key
|
||||||
MasterKey.Allocate (options->EA->GetKeySize() * 2);
|
MasterKey.Allocate (options->EA->GetKeySize() * 2);
|
||||||
RandomNumberGenerator::GetData (MasterKey);
|
RandomNumberGenerator::GetData (MasterKey);
|
||||||
|
// check that first half of MasterKey is different from its second half. If they are the same, through an exception
|
||||||
|
// cf CCSS,NSA comment at page 3: https://csrc.nist.gov/csrc/media/Projects/crypto-publication-review-project/documents/initial-comments/sp800-38e-initial-public-comments-2021.pdf
|
||||||
|
if (memcmp (MasterKey.Ptr(), MasterKey.Ptr() + MasterKey.Size() / 2, MasterKey.Size() / 2) == 0)
|
||||||
|
throw AssertionFailed (SRC_POS);
|
||||||
|
|
||||||
headerOptions.DataKey = MasterKey;
|
headerOptions.DataKey = MasterKey;
|
||||||
|
|
||||||
// PKCS5 salt
|
// PKCS5 salt
|
||||||
|
|||||||
Reference in New Issue
Block a user