mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-10-22 14:22:36 +00:00
Tests: verify that CRYPTOPP_ALIGN_DATA delivers the requested alignment (#1844)
The macro expands to nothing for compilers that are neither MSVC nor GCC/Clang, and the SIMD backends issue aligned loads against buffers declared with it, so a silent expansion to nothing would fault at run time. Nothing verified this so far. Add TC_IS_ALIGNED next to the existing alignment constants and check both of them from the platform self-test suites. The probe buffers stay below the alignment under test because the ABI already aligns larger objects by itself, which would make the check pass vacuously. The check is skipped in the Windows driver: a failing self-test there reaches TC_BUG_CHECK and would bugcheck the machine.
This commit is contained in:
@@ -70,10 +70,30 @@ namespace VeraCrypt
|
||||
|
||||
void EncryptionTest::TestAll ()
|
||||
{
|
||||
TestAlignment();
|
||||
TestAll (false);
|
||||
TestAll (true);
|
||||
}
|
||||
|
||||
// Must stay smaller than the alignment under test: the ABI aligns larger objects by itself.
|
||||
#define TC_ALIGNMENT_PROBE_SIZE 4
|
||||
|
||||
// Verifies that CRYPTOPP_ALIGN_DATA actually delivers the alignment it requests.
|
||||
// It expands to nothing for compilers that are neither MSVC nor GCC/Clang (see
|
||||
// Crypto/config.h), and the SIMD backends issue aligned loads against buffers
|
||||
// declared with it, so a silent expansion to nothing would fault at run time.
|
||||
void EncryptionTest::TestAlignment ()
|
||||
{
|
||||
static CRYPTOPP_ALIGN_DATA(TC_DERIVED_KEY_BUFFER_ALIGNMENT) uint8 derivedKeyProbe[TC_ALIGNMENT_PROBE_SIZE];
|
||||
static CRYPTOPP_ALIGN_DATA(TC_KEY_INFO_BUFFER_ALIGNMENT) uint8 keyInfoProbe[TC_ALIGNMENT_PROBE_SIZE];
|
||||
|
||||
if (!TC_IS_ALIGNED (derivedKeyProbe, TC_DERIVED_KEY_BUFFER_ALIGNMENT))
|
||||
throw TestFailed (SRC_POS);
|
||||
|
||||
if (!TC_IS_ALIGNED (keyInfoProbe, TC_KEY_INFO_BUFFER_ALIGNMENT))
|
||||
throw TestFailed (SRC_POS);
|
||||
}
|
||||
|
||||
void EncryptionTest::TestAll (bool enableCpuEncryptionSupport)
|
||||
{
|
||||
bool hwSupportEnabled = Cipher::IsHwSupportEnabled();
|
||||
|
||||
Reference in New Issue
Block a user