mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-10-05 16:46:35 -05:00
Crypto: fix portable C code on big-endian CPUs (#1899)
* Crypto: fix portable C code on big-endian CPUs On big-endian CPUs (e.g. MIPS and PowerPC) the portable C code of several algorithms assumes a little-endian host, so ciphertext, hashes and derived keys are wrong and "veracrypt --text --test" fails: - Twofish: the key-dependent S-box bytes are read back from 32-bit words through a union, and blocks are loaded/stored as native words. - Camellia: blocks and keys are always byte-swapped to big-endian. - Kuznyechik: keys and blocks are loaded/stored as native 64-bit words while the tables expect the little-endian interpretation. - SHA-256/SHA-512: message words, length and digest are always byte-swapped. - BLAKE2s: the parameter block and message words are read as native little-endian data. The parameter block is now built from its fields, so it is right for any parameters, not only the ones VeraCrypt uses. - Streebog: the existing big-endian code path is never enabled, and BSWAP64 used by it is not defined (its buffer512 initializer also has one pair of braces too many). Its add512() also differs from the little-endian one, which drops a carry on purpose (existing volumes depend on it); do the same limb arithmetic on big-endian. - misc.h: the rotate-based bswap_32 (non-Linux, non-Apple, non-MSVC builds) lacks outer parentheses, so "bswap_32(a) ^ b" is parsed wrongly, and the fallback bswap_64 does not parenthesise its argument. - PBKDF2: the block number is always byte-swapped. Swap only where the host byte order differs from the data, and enable the Streebog big-endian path. On big-endian hosts the message words, keys and blocks of SHA-2, BLAKE2s, Twofish and Kuznyechik are read and written byte-wise (new VcLoad*/VcStore* inline helpers in misc.h), so these paths also work on misaligned buffers on strict-alignment CPUs. On little-endian CPUs the code is unchanged: the object files of all touched sources are byte-identical before and after this change (checked on x86_64, aarch64 and mipsel). With it, all self-tests pass on mips (big-endian) under qemu. Signed-off-by: Ville Takio <ville+git@takio.fi> * Volume: avoid unaligned 64-bit header and test vector accesses The volume header (de)serialisation and TestXtsAES read and write 64-bit fields through casted pointers into byte buffers at offsets that are only 4-byte aligned (e.g. the header field at offset 12). CPUs that trap on misaligned access without kernel fix-up (SPARC, MIPS64 on some systems, qemu-user) then fail with SIGBUS in "veracrypt --test" and when creating or opening any volume. Use memcpy instead, and have DeserializeEntryAt check that the whole entry, not only its start, lies inside the header. The XTS code also accesses its local byte arrays (whitening values, data unit number) through uint64 pointers; declare them 8-byte aligned instead of relying on the compiler's stack layout. Signed-off-by: Ville Takio <ville+git@takio.fi> * Volume: test multi-block PBKDF2 output and the Streebog carry case The PBKDF2 self-tests only check the first 4 bytes of each derivation, so the block counter of the second and later output blocks is never checked. Also compare the complete output of a 192-byte derivation for every PRF, which covers the later blocks and how they are joined, and hash a message whose block sum hits the carry case of Streebog's add512(), which has to stay bit-compatible across CPUs. The message buffer is 8-byte aligned, as the portable Streebog code reads it as 64-bit words. The expected values are those of the existing little-endian code, and match independent implementations for all five PRFs (Python hashlib/hmac, OpenSSL for Whirlpool, gostcrypto for Streebog). Signed-off-by: Ville Takio <ville+git@takio.fi> --------- Signed-off-by: Ville Takio <ville+git@takio.fi>
This commit is contained in:
1 parent
ce72be65bb
commit
425cea6c9c
11 files changed
+353
-72
No files matched your search
@@ -70,9 +70,9 @@ namespace VeraCrypt
|
||||
void EncryptionModeXTS::EncryptBufferXTS (const Cipher &cipher, const Cipher &secondaryCipher, uint8 *buffer, uint64 length, uint64 startDataUnitNo, unsigned int startCipherBlockNo) const
|
||||
{
|
||||
uint8 finalCarry;
|
||||
uint8 whiteningValues [ENCRYPTION_DATA_UNIT_SIZE];
|
||||
uint8 whiteningValue [BYTES_PER_XTS_BLOCK];
|
||||
uint8 byteBufUnitNo [BYTES_PER_XTS_BLOCK];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 whiteningValues [ENCRYPTION_DATA_UNIT_SIZE];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 whiteningValue [BYTES_PER_XTS_BLOCK];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 byteBufUnitNo [BYTES_PER_XTS_BLOCK];
|
||||
uint64 *whiteningValuesPtr64 = (uint64 *) whiteningValues;
|
||||
uint64 *whiteningValuePtr64 = (uint64 *) whiteningValue;
|
||||
uint64 *bufPtr = (uint64 *) buffer;
|
||||
@@ -249,9 +249,9 @@ namespace VeraCrypt
|
||||
void EncryptionModeXTS::DecryptBufferXTS (const Cipher &cipher, const Cipher &secondaryCipher, uint8 *buffer, uint64 length, uint64 startDataUnitNo, unsigned int startCipherBlockNo) const
|
||||
{
|
||||
uint8 finalCarry;
|
||||
uint8 whiteningValues [ENCRYPTION_DATA_UNIT_SIZE];
|
||||
uint8 whiteningValue [BYTES_PER_XTS_BLOCK];
|
||||
uint8 byteBufUnitNo [BYTES_PER_XTS_BLOCK];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 whiteningValues [ENCRYPTION_DATA_UNIT_SIZE];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 whiteningValue [BYTES_PER_XTS_BLOCK];
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 byteBufUnitNo [BYTES_PER_XTS_BLOCK];
|
||||
uint64 *whiteningValuesPtr64 = (uint64 *) whiteningValues;
|
||||
uint64 *whiteningValuePtr64 = (uint64 *) whiteningValue;
|
||||
uint64 *bufPtr = (uint64 *) buffer;
|
||||
|
||||
@@ -511,7 +511,8 @@ namespace VeraCrypt
|
||||
|
||||
memcpy (p, XtsTestVectors[i].plaintext, sizeof (p));
|
||||
|
||||
dataUnitNo = Endian::Big (*((uint64 *) XtsTestVectors[i].dataUnitNo));
|
||||
memcpy (&dataUnitNo, XtsTestVectors[i].dataUnitNo, sizeof (dataUnitNo));
|
||||
dataUnitNo = Endian::Big (dataUnitNo);
|
||||
|
||||
aes.EncryptSectors (p, dataUnitNo, sizeof (p) / ENCRYPTION_DATA_UNIT_SIZE, ENCRYPTION_DATA_UNIT_SIZE);
|
||||
|
||||
@@ -1200,6 +1201,147 @@ namespace VeraCrypt
|
||||
if (memcmp (derivedKey.Ptr(), "\xd0\x53\xa2\x30", 4) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
|
||||
// Output longer than one hash block: PBKDF2 block counters 2 and up,
|
||||
// and how the output blocks are joined (password "password", salt
|
||||
// 0x12345678, 5 iterations, 192 bytes).
|
||||
static const uint8 longKeyBlake2s[192] =
|
||||
{
|
||||
0x8d, 0x51, 0xfa, 0x31, 0x46, 0x25, 0x37, 0x67, 0xa3, 0x29, 0x6b, 0x3c,
|
||||
0x6b, 0xc1, 0x5d, 0xb2, 0xee, 0xe1, 0x6c, 0x28, 0x00, 0x26, 0xea, 0x08,
|
||||
0x65, 0x9c, 0x12, 0xf1, 0x07, 0xde, 0x0d, 0xb9, 0x9b, 0x4f, 0x39, 0xfa,
|
||||
0xc6, 0x80, 0x26, 0xb1, 0x8f, 0x8e, 0x48, 0x89, 0x85, 0x2d, 0x24, 0x2d,
|
||||
0xbd, 0x63, 0x72, 0x4a, 0x6c, 0xc6, 0x19, 0x7e, 0xc3, 0x1a, 0x5d, 0xf7,
|
||||
0x61, 0xdc, 0x0d, 0xc8, 0x16, 0x3d, 0xd1, 0x1b, 0x02, 0x9b, 0x84, 0xd1,
|
||||
0xc1, 0xee, 0x73, 0xf7, 0x1a, 0x36, 0x82, 0x50, 0xd0, 0xe7, 0x57, 0x16,
|
||||
0x2b, 0x27, 0x00, 0x97, 0xee, 0x6e, 0xa1, 0x55, 0x44, 0x55, 0x19, 0x4f,
|
||||
0x1f, 0xea, 0xe4, 0x48, 0x30, 0xfd, 0xaa, 0xa1, 0xe6, 0x9e, 0x1e, 0x3c,
|
||||
0x5c, 0x43, 0x56, 0x10, 0x29, 0x4f, 0x72, 0x57, 0x3a, 0x14, 0x15, 0x77,
|
||||
0xa6, 0x0a, 0x56, 0xd2, 0x7b, 0xfa, 0x86, 0x22, 0x20, 0x65, 0xd8, 0xc2,
|
||||
0x64, 0x24, 0x68, 0x95, 0xc5, 0x52, 0x0d, 0x22, 0x33, 0x3c, 0xa6, 0x7c,
|
||||
0x89, 0x17, 0xde, 0x0b, 0xc9, 0x62, 0xaf, 0x52, 0x2b, 0xda, 0x14, 0x24,
|
||||
0xb0, 0x3d, 0xe1, 0x2b, 0xea, 0x23, 0x3c, 0xd8, 0xca, 0x8a, 0xe3, 0x7a,
|
||||
0xa7, 0x6f, 0xdd, 0x4a, 0x2c, 0x31, 0x46, 0xa2, 0xeb, 0x3e, 0x2a, 0x07,
|
||||
0xf2, 0x08, 0x21, 0x42, 0xb3, 0xde, 0x03, 0x53, 0x36, 0xb5, 0xff, 0x24
|
||||
};
|
||||
static const uint8 longKeySha512[192] =
|
||||
{
|
||||
0x13, 0x64, 0xae, 0xf8, 0x0d, 0xf5, 0x57, 0x6c, 0x30, 0xd5, 0x71, 0x4c,
|
||||
0xa7, 0x75, 0x3f, 0xfd, 0x00, 0xe5, 0x25, 0x8b, 0x39, 0xc7, 0x44, 0x7f,
|
||||
0xce, 0x23, 0x3d, 0x08, 0x75, 0xe0, 0x2f, 0x48, 0xd6, 0x30, 0xd7, 0x00,
|
||||
0xb6, 0x24, 0xdb, 0xe0, 0x5a, 0xd7, 0x47, 0xef, 0x52, 0xca, 0xa6, 0x34,
|
||||
0x83, 0x47, 0xe5, 0xcb, 0xe9, 0x87, 0xf1, 0x20, 0x59, 0x6a, 0xe6, 0xa9,
|
||||
0xcf, 0x51, 0x78, 0xc6, 0xb6, 0x23, 0xa6, 0x74, 0x0d, 0xe8, 0x91, 0xbe,
|
||||
0x1a, 0xd0, 0x28, 0xcc, 0xce, 0x16, 0x98, 0x9a, 0xbe, 0xfb, 0xdc, 0x78,
|
||||
0xc9, 0xe1, 0x7d, 0x72, 0x67, 0xce, 0xe1, 0x61, 0x56, 0x5f, 0x96, 0x68,
|
||||
0xe6, 0xe1, 0xdd, 0xf4, 0xbf, 0x1b, 0x80, 0xe0, 0x19, 0x1c, 0xf4, 0xc4,
|
||||
0xd3, 0xdd, 0xd5, 0xd5, 0x57, 0x2d, 0x83, 0xc7, 0xa3, 0x37, 0x87, 0xf4,
|
||||
0x4e, 0xe0, 0xf6, 0xd8, 0x6d, 0x65, 0xdc, 0xa0, 0x52, 0xa3, 0x13, 0xbe,
|
||||
0x81, 0xfc, 0x30, 0xbe, 0x7d, 0x69, 0x58, 0x34, 0xb6, 0xdd, 0x41, 0xc6,
|
||||
0x21, 0x50, 0xf5, 0x60, 0x44, 0xf9, 0x87, 0x69, 0xfd, 0x75, 0x75, 0xcb,
|
||||
0x10, 0xe5, 0xe0, 0xfd, 0xf0, 0x7d, 0x3f, 0x79, 0xe2, 0xa0, 0x68, 0xb5,
|
||||
0xbf, 0xd1, 0x76, 0x91, 0xc8, 0x68, 0x67, 0xd9, 0x01, 0x00, 0x4c, 0x1b,
|
||||
0xfc, 0x1a, 0xd3, 0x39, 0x7b, 0x9d, 0x3d, 0x88, 0x71, 0xfc, 0x55, 0x1a
|
||||
};
|
||||
static const uint8 longKeyWhirlpool[192] =
|
||||
{
|
||||
0x50, 0x7c, 0x36, 0x6f, 0xee, 0x10, 0x2e, 0x9a, 0xe2, 0x8a, 0xd5, 0x82,
|
||||
0x72, 0x7d, 0x27, 0x0f, 0xe8, 0x4d, 0x7f, 0x68, 0x7a, 0xcf, 0xb5, 0xe7,
|
||||
0x43, 0x67, 0xaa, 0x98, 0x93, 0x52, 0x2b, 0x09, 0x6e, 0x42, 0xdf, 0x2c,
|
||||
0x59, 0x4a, 0x91, 0x6d, 0x7e, 0x10, 0xae, 0xb2, 0x1a, 0x89, 0x8f, 0xb9,
|
||||
0x8f, 0xe6, 0x31, 0xa9, 0xd8, 0x9f, 0x98, 0x26, 0xf4, 0xda, 0xcd, 0x7d,
|
||||
0x65, 0x65, 0xde, 0x10, 0x95, 0x91, 0xb4, 0x84, 0x26, 0xae, 0x43, 0xa1,
|
||||
0x00, 0x5b, 0x1e, 0xb8, 0x38, 0x97, 0xa4, 0x1e, 0x4b, 0xd2, 0x65, 0x64,
|
||||
0xbc, 0xfa, 0x1f, 0x35, 0x85, 0xdb, 0x4f, 0x97, 0x65, 0x6f, 0xbd, 0x24,
|
||||
0xd4, 0xe2, 0x28, 0x89, 0xec, 0xcf, 0x3a, 0xa4, 0x1b, 0x56, 0xe9, 0x61,
|
||||
0xa3, 0x1f, 0x6f, 0xd6, 0xac, 0x9b, 0x92, 0xf4, 0xe6, 0xc2, 0x26, 0xbc,
|
||||
0xd4, 0x99, 0x45, 0xf2, 0xcd, 0x46, 0xd0, 0x57, 0x44, 0xc7, 0x4b, 0x5d,
|
||||
0xed, 0x17, 0x8e, 0x68, 0x0a, 0x6d, 0x5d, 0xbe, 0x72, 0xf4, 0x6d, 0xc6,
|
||||
0x9e, 0x19, 0xcc, 0x09, 0xaa, 0x90, 0xb0, 0xcb, 0x40, 0xa3, 0x61, 0xd1,
|
||||
0xe5, 0x1b, 0x90, 0xfb, 0x82, 0x5d, 0xec, 0xd6, 0xb9, 0x11, 0x9b, 0xe9,
|
||||
0xa3, 0x70, 0xe5, 0x9a, 0x2e, 0x9c, 0x3a, 0x35, 0x25, 0xcd, 0x15, 0xe3,
|
||||
0xfc, 0x1a, 0x00, 0x40, 0xa5, 0x71, 0x11, 0xfc, 0x82, 0x74, 0xe3, 0x90
|
||||
};
|
||||
static const uint8 longKeySha256[192] =
|
||||
{
|
||||
0xf2, 0xa0, 0x4f, 0xb2, 0xd3, 0xe9, 0xa5, 0xd8, 0x51, 0x0b, 0x5c, 0x06,
|
||||
0xdf, 0x70, 0x8e, 0x24, 0xe9, 0xc7, 0xd9, 0x15, 0x3d, 0x22, 0xcd, 0xde,
|
||||
0xb8, 0xa6, 0xdb, 0xfd, 0x71, 0x85, 0xc6, 0x99, 0x32, 0xc0, 0xee, 0x37,
|
||||
0x27, 0xf7, 0x24, 0xcf, 0xea, 0xa6, 0xac, 0x73, 0xa1, 0x4c, 0x4e, 0x52,
|
||||
0x9b, 0x94, 0xf3, 0x54, 0x06, 0xfc, 0x04, 0x65, 0xa1, 0x0a, 0x24, 0xfe,
|
||||
0xf0, 0x98, 0x1d, 0xa6, 0x22, 0x28, 0xeb, 0x24, 0x55, 0x74, 0xce, 0x6a,
|
||||
0x3a, 0x28, 0xe2, 0x04, 0x3a, 0x59, 0x13, 0xec, 0x3f, 0xf2, 0xdb, 0xcf,
|
||||
0x58, 0xdd, 0x53, 0xd9, 0xf9, 0x17, 0xf6, 0xda, 0x74, 0x06, 0x3c, 0x0b,
|
||||
0x66, 0xf5, 0x0f, 0xf5, 0x58, 0xa3, 0x27, 0x52, 0x8c, 0x5b, 0x07, 0x91,
|
||||
0xd0, 0x81, 0xeb, 0xb6, 0xbc, 0x30, 0x69, 0x42, 0x71, 0xf2, 0xd7, 0x18,
|
||||
0x42, 0xbe, 0xe8, 0x02, 0x93, 0x70, 0x66, 0xad, 0x35, 0x65, 0xbc, 0xf7,
|
||||
0x96, 0x8e, 0x64, 0xf1, 0xc6, 0x92, 0xda, 0xe0, 0xdc, 0x1f, 0xb5, 0xf4,
|
||||
0x15, 0xe8, 0xda, 0x2b, 0xb8, 0xd5, 0x96, 0x06, 0x50, 0x0e, 0xdb, 0xd7,
|
||||
0xbf, 0x5d, 0x14, 0x7e, 0x16, 0x3c, 0xbd, 0x69, 0x29, 0x11, 0x45, 0x25,
|
||||
0xaa, 0xc1, 0x7c, 0x6f, 0x0e, 0xcb, 0xe6, 0x86, 0x83, 0x77, 0xf0, 0xf4,
|
||||
0x66, 0xbb, 0x34, 0x82, 0x3a, 0x84, 0x88, 0xde, 0xda, 0x8e, 0xce, 0x85
|
||||
};
|
||||
static const uint8 longKeyStreebog[192] =
|
||||
{
|
||||
0xd0, 0x53, 0xa2, 0x30, 0x6f, 0x45, 0x81, 0xeb, 0xbc, 0x06, 0x81, 0xc5,
|
||||
0xe7, 0x53, 0xa8, 0x5d, 0xc7, 0xf1, 0x23, 0x33, 0x1e, 0xbe, 0x64, 0x2c,
|
||||
0x3b, 0x0f, 0x26, 0xd7, 0x00, 0xe1, 0x95, 0xc9, 0x65, 0x26, 0xb1, 0x85,
|
||||
0xbe, 0x1e, 0xe2, 0xf4, 0x9b, 0xfc, 0x6b, 0x14, 0x84, 0xda, 0x24, 0x61,
|
||||
0xa0, 0x1b, 0x9e, 0x79, 0x5c, 0xee, 0x69, 0x6e, 0xf9, 0x25, 0xb1, 0x1d,
|
||||
0xca, 0xa0, 0x31, 0xba, 0x02, 0x6f, 0x9e, 0x99, 0x0f, 0xdb, 0x25, 0x01,
|
||||
0x5b, 0xf1, 0xc7, 0x10, 0x19, 0x53, 0x3b, 0x29, 0x3f, 0x18, 0x00, 0xd6,
|
||||
0xfc, 0x85, 0x03, 0xdc, 0xf2, 0xe5, 0xe9, 0x5a, 0xb1, 0x1e, 0x61, 0xde,
|
||||
0xa7, 0xc8, 0xd0, 0x4c, 0x72, 0xca, 0xfb, 0x01, 0x37, 0x13, 0x89, 0x3f,
|
||||
0x90, 0x3c, 0x38, 0xe8, 0x4c, 0xfd, 0x72, 0x23, 0x61, 0x10, 0x81, 0x59,
|
||||
0x0c, 0xcc, 0x97, 0xd6, 0x8a, 0x66, 0xbb, 0xc4, 0xd7, 0xbc, 0x76, 0xfc,
|
||||
0xdc, 0xbf, 0x5c, 0xc4, 0x7c, 0xd1, 0x4f, 0xb5, 0xaa, 0x34, 0x32, 0x4c,
|
||||
0x1a, 0x98, 0x68, 0x7c, 0x18, 0xf4, 0x0a, 0xc4, 0x03, 0x9e, 0x86, 0x9b,
|
||||
0x87, 0x5e, 0x25, 0x1a, 0x38, 0x90, 0x49, 0x22, 0xdd, 0xfc, 0x83, 0x43,
|
||||
0x9e, 0x83, 0xb5, 0xf9, 0x2c, 0x2d, 0x88, 0x1b, 0x53, 0xb2, 0x0a, 0x2a,
|
||||
0xf7, 0x0b, 0x5b, 0xac, 0x6b, 0xc2, 0xa0, 0x53, 0x7f, 0x07, 0xa2, 0xea
|
||||
};
|
||||
Buffer longKey (192);
|
||||
if (pkcs5HmacBlake2s.DeriveKey (longKey, password, salt, 5) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (memcmp (longKey.Ptr(), longKeyBlake2s, sizeof (longKeyBlake2s)) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (pkcs5HmacSha512.DeriveKey (longKey, password, salt, 5) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (memcmp (longKey.Ptr(), longKeySha512, sizeof (longKeySha512)) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (pkcs5HmacWhirlpool.DeriveKey (longKey, password, salt, 5) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (memcmp (longKey.Ptr(), longKeyWhirlpool, sizeof (longKeyWhirlpool)) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (pkcs5HmacSha256.DeriveKey (longKey, password, salt, 5) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (memcmp (longKey.Ptr(), longKeySha256, sizeof (longKeySha256)) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (pkcs5HmacStreebog.DeriveKey (longKey, password, salt, 5) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
if (memcmp (longKey.Ptr(), longKeyStreebog, sizeof (longKeyStreebog)) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
|
||||
// Streebog: message blocks whose 512-bit sum hits the carry case of
|
||||
// add512() must hash the same on every CPU. VeraCrypt's add512()
|
||||
// drops this carry on purpose (existing volumes depend on it), so
|
||||
// the expected digest is not the GOST R 34.11-2012 one (which would
|
||||
// be c392d229...83639757).
|
||||
{
|
||||
// Read as 64-bit words by the portable Streebog code.
|
||||
CRYPTOPP_ALIGN_DATA(8) uint8 message[128];
|
||||
memset (message, 0, sizeof (message));
|
||||
memset (message, 0xff, 16);
|
||||
message[64] = 1;
|
||||
|
||||
Streebog streebog;
|
||||
Buffer digest (streebog.GetDigestSize ());
|
||||
streebog.ProcessData (ConstBufferPtr (message, sizeof (message)));
|
||||
streebog.GetDigest (digest);
|
||||
if (memcmp (digest.Ptr(), "\xf0\x7f\x6f\xae\x81\x90\xe4\x9d\x54\xe6\x98\x5a\x30\x44\xb3\x3d\xd8\xdb\x37\x08\x6b\x81\x83\x16\xcb\x19\xe2\x33\xf1\xa5\x81\x08"
|
||||
"\xb1\x2e\x7f\x02\x74\x48\x32\x31\x1c\x09\x44\x68\x70\xb4\xbb\x45\x4b\xb5\x4f\xa3\x41\x39\x2a\xfd\xdd\x62\x25\x2b\xaf\x8a\x08\x09", 64) != 0)
|
||||
throw TestFailed (SRC_POS);
|
||||
}
|
||||
|
||||
#ifndef VC_DCS_DISABLE_ARGON2
|
||||
Pkcs5Argon2 pkcs5Argon2;
|
||||
static const uint8 argon2SaltData[] = { 's', 'o', 'm', 'e', 's', 'a', 'l', 't' };
|
||||
|
||||
@@ -363,16 +363,20 @@ namespace VeraCrypt
|
||||
if (offset > header.Size())
|
||||
throw ParameterIncorrect (SRC_POS);
|
||||
|
||||
return Endian::Big (*reinterpret_cast<const T *> (header.Get() + offset - sizeof (T)));
|
||||
T value;
|
||||
memcpy (&value, header.Get() + offset - sizeof (T), sizeof (T));
|
||||
return Endian::Big (value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T VolumeHeader::DeserializeEntryAt (const ConstBufferPtr &header, const size_t &offset) const
|
||||
{
|
||||
if (offset > header.Size())
|
||||
if (offset > header.Size() || header.Size() - offset < sizeof (T))
|
||||
throw ParameterIncorrect (SRC_POS);
|
||||
|
||||
return Endian::Big (*reinterpret_cast<const T *> (header.Get() + offset));
|
||||
T value;
|
||||
memcpy (&value, header.Get() + offset, sizeof (T));
|
||||
return Endian::Big (value);
|
||||
}
|
||||
|
||||
void VolumeHeader::EncryptNew (const BufferPtr &newHeaderBuffer, const ConstBufferPtr &newSalt, const ConstBufferPtr &newHeaderKey, shared_ptr <Pkcs5Kdf> newPkcs5Kdf)
|
||||
@@ -486,7 +490,8 @@ namespace VeraCrypt
|
||||
if (offset > header.Size())
|
||||
throw ParameterIncorrect (SRC_POS);
|
||||
|
||||
*reinterpret_cast<T *> (header.Get() + offset - sizeof (T)) = Endian::Big (entry);
|
||||
T value = Endian::Big (entry);
|
||||
memcpy (header.Get() + offset - sizeof (T), &value, sizeof (T));
|
||||
}
|
||||
|
||||
void VolumeHeader::SetSize (uint32 headerSize)
|
||||
|
||||
Reference in new issue
Block a user