Windows: solve benchmark issue for Whirlpool which caused wrong numbers when a 1GB buffer is chosen.
This commit is contained in:
parent
73703095b2
commit
3aaf5c7045
|
@ -5153,7 +5153,7 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
|
|||
|
||||
case WHIRLPOOL:
|
||||
WHIRLPOOL_init (&wctx);
|
||||
WHIRLPOOL_add (lpTestBuffer, benchmarkBufferSize * 8, &wctx);
|
||||
WHIRLPOOL_add (lpTestBuffer, benchmarkBufferSize, &wctx);
|
||||
WHIRLPOOL_finalize (&wctx, (unsigned char *) digest);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -719,7 +719,7 @@ void hmac_whirlpool_internal
|
|||
|
||||
memcpy (ctx, &(hmac->inner_digest_ctx), sizeof (WHIRLPOOL_CTX));
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) d, ld * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) d, ld, ctx);
|
||||
|
||||
WHIRLPOOL_finalize (ctx, (unsigned char *) d);
|
||||
|
||||
|
@ -727,7 +727,7 @@ void hmac_whirlpool_internal
|
|||
|
||||
memcpy (ctx, &(hmac->outer_digest_ctx), sizeof (WHIRLPOOL_CTX));
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) d, WHIRLPOOL_DIGESTSIZE * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) d, WHIRLPOOL_DIGESTSIZE, ctx);
|
||||
|
||||
WHIRLPOOL_finalize (ctx, (unsigned char *) d);
|
||||
}
|
||||
|
@ -758,7 +758,7 @@ void hmac_whirlpool
|
|||
WHIRLPOOL_CTX tctx;
|
||||
|
||||
WHIRLPOOL_init (&tctx);
|
||||
WHIRLPOOL_add ((unsigned char *) k, lk * 8, &tctx);
|
||||
WHIRLPOOL_add ((unsigned char *) k, lk, &tctx);
|
||||
WHIRLPOOL_finalize (&tctx, (unsigned char *) key);
|
||||
|
||||
k = key;
|
||||
|
@ -777,7 +777,7 @@ void hmac_whirlpool
|
|||
buf[b] = (char) (k[b] ^ 0x36);
|
||||
memset (&buf[lk], 0x36, WHIRLPOOL_BLOCKSIZE - lk);
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE, ctx);
|
||||
|
||||
/**** Precompute HMAC Outer Digest ****/
|
||||
|
||||
|
@ -788,7 +788,7 @@ void hmac_whirlpool
|
|||
buf[b] = (char) (k[b] ^ 0x5C);
|
||||
memset (&buf[lk], 0x5C, WHIRLPOOL_BLOCKSIZE - lk);
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE, ctx);
|
||||
|
||||
hmac_whirlpool_internal(k, lk, d, ld, &hmac);
|
||||
|
||||
|
@ -846,7 +846,7 @@ void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uin
|
|||
WHIRLPOOL_CTX tctx;
|
||||
|
||||
WHIRLPOOL_init (&tctx);
|
||||
WHIRLPOOL_add ((unsigned char *) pwd, pwd_len * 8, &tctx);
|
||||
WHIRLPOOL_add ((unsigned char *) pwd, pwd_len, &tctx);
|
||||
WHIRLPOOL_finalize (&tctx, (unsigned char *) key);
|
||||
|
||||
pwd = key;
|
||||
|
@ -876,7 +876,7 @@ void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uin
|
|||
buf[b] = (char) (pwd[b] ^ 0x36);
|
||||
memset (&buf[pwd_len], 0x36, WHIRLPOOL_BLOCKSIZE - pwd_len);
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE, ctx);
|
||||
|
||||
/**** Precompute HMAC Outer Digest ****/
|
||||
|
||||
|
@ -887,7 +887,7 @@ void derive_key_whirlpool (char *pwd, int pwd_len, char *salt, int salt_len, uin
|
|||
buf[b] = (char) (pwd[b] ^ 0x5C);
|
||||
memset (&buf[pwd_len], 0x5C, WHIRLPOOL_BLOCKSIZE - pwd_len);
|
||||
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE * 8, ctx);
|
||||
WHIRLPOOL_add ((unsigned char *) buf, WHIRLPOOL_BLOCKSIZE, ctx);
|
||||
|
||||
/* first l - 1 blocks */
|
||||
for (b = 1; b < l; b++)
|
||||
|
|
|
@ -299,7 +299,7 @@ BOOL Randmix ()
|
|||
|
||||
case WHIRLPOOL:
|
||||
WHIRLPOOL_init (&wctx);
|
||||
WHIRLPOOL_add (pRandPool, RNG_POOL_SIZE * 8, &wctx);
|
||||
WHIRLPOOL_add (pRandPool, RNG_POOL_SIZE, &wctx);
|
||||
WHIRLPOOL_finalize (&wctx, hashOutputBuffer);
|
||||
break;
|
||||
|
||||
|
|
|
@ -605,16 +605,16 @@ void ComputeBootloaderFingerprint (byte *bootLoaderBuf, unsigned int bootLoaderS
|
|||
WHIRLPOOL_init (&whirlpool);
|
||||
sha512_begin (&sha2);
|
||||
|
||||
WHIRLPOOL_add (bootLoaderBuf, TC_BOOT_SECTOR_PIM_VALUE_OFFSET * 8, &whirlpool);
|
||||
WHIRLPOOL_add (bootLoaderBuf, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &whirlpool);
|
||||
sha512_hash (bootLoaderBuf, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &sha2);
|
||||
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)) * 8, &whirlpool);
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &whirlpool);
|
||||
sha512_hash (bootLoaderBuf + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &sha2);
|
||||
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1, (TC_MAX_MBR_BOOT_CODE_SIZE - (TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1)) * 8, &whirlpool);
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1, (TC_MAX_MBR_BOOT_CODE_SIZE - (TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1)), &whirlpool);
|
||||
sha512_hash (bootLoaderBuf + TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1, (TC_MAX_MBR_BOOT_CODE_SIZE - (TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1)), &sha2);
|
||||
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_SECTOR_SIZE_BIOS, (bootLoaderSize - TC_SECTOR_SIZE_BIOS) * 8, &whirlpool);
|
||||
WHIRLPOOL_add (bootLoaderBuf + TC_SECTOR_SIZE_BIOS, (bootLoaderSize - TC_SECTOR_SIZE_BIOS), &whirlpool);
|
||||
sha512_hash (bootLoaderBuf + TC_SECTOR_SIZE_BIOS, (bootLoaderSize - TC_SECTOR_SIZE_BIOS), &sha2);
|
||||
|
||||
WHIRLPOOL_finalize (&whirlpool, fingerprint);
|
||||
|
|
|
@ -898,11 +898,11 @@ void WHIRLPOOL_init(WHIRLPOOL_CTX * const ctx) {
|
|||
* This method maintains the invariant: bufferBits < DIGESTBITS
|
||||
*/
|
||||
void WHIRLPOOL_add(const unsigned char * input,
|
||||
unsigned __int32 sourceBits,
|
||||
unsigned __int32 sourceBytes,
|
||||
WHIRLPOOL_CTX * const ctx)
|
||||
{
|
||||
uint64 num, oldCountLo = ctx->countLo, oldCountHi = ctx->countHi;
|
||||
uint64 len = sourceBits >> 3;
|
||||
uint64 len = sourceBytes;
|
||||
if ((ctx->countLo = oldCountLo + (uint64)len) < oldCountLo)
|
||||
ctx->countHi++; // carry from low to high
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ typedef struct WHIRLPOOL_CTX {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void WHIRLPOOL_add(const unsigned char * source, unsigned __int32 sourceBits, WHIRLPOOL_CTX * const ctx);
|
||||
void WHIRLPOOL_add(const unsigned char * source, unsigned __int32 sourceBytes, WHIRLPOOL_CTX * const ctx);
|
||||
void WHIRLPOOL_finalize(WHIRLPOOL_CTX* const ctx, unsigned char * result);
|
||||
void WHIRLPOOL_init(WHIRLPOOL_CTX* const ctx);
|
||||
|
||||
|
|
|
@ -265,9 +265,9 @@ static void ComputeBootLoaderFingerprint(PDEVICE_OBJECT LowerDeviceObject, byte*
|
|||
if (HasISSE())
|
||||
saveStatus = KeSaveFloatingPointState (&floatingPointState);
|
||||
#endif
|
||||
WHIRLPOOL_add (ioBuffer, TC_BOOT_SECTOR_PIM_VALUE_OFFSET * 8, &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)) * 8, &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1, (TC_MAX_MBR_BOOT_CODE_SIZE - (TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1)) * 8, &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer + TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1, (TC_MAX_MBR_BOOT_CODE_SIZE - (TC_BOOT_SECTOR_USER_CONFIG_OFFSET + 1)), &whirlpool);
|
||||
|
||||
sha512_hash (ioBuffer, TC_BOOT_SECTOR_PIM_VALUE_OFFSET, &sha2);
|
||||
sha512_hash (ioBuffer + TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, (TC_BOOT_SECTOR_USER_CONFIG_OFFSET - (TC_BOOT_SECTOR_USER_MESSAGE_OFFSET + TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH)), &sha2);
|
||||
|
@ -285,7 +285,7 @@ static void ComputeBootLoaderFingerprint(PDEVICE_OBJECT LowerDeviceObject, byte*
|
|||
{
|
||||
remainingBytes -= bytesToRead;
|
||||
offset.QuadPart += bytesToRead;
|
||||
WHIRLPOOL_add (ioBuffer, bytesToRead * 8, &whirlpool);
|
||||
WHIRLPOOL_add (ioBuffer, bytesToRead, &whirlpool);
|
||||
sha512_hash (ioBuffer, bytesToRead, &sha2);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -136,6 +136,6 @@ namespace VeraCrypt
|
|||
void Whirlpool::ProcessData (const ConstBufferPtr &data)
|
||||
{
|
||||
if_debug (ValidateDataParameters (data));
|
||||
WHIRLPOOL_add (data.Get(), (int) data.Size() * 8, (WHIRLPOOL_CTX *) Context.Ptr());
|
||||
WHIRLPOOL_add (data.Get(), (int) data.Size(), (WHIRLPOOL_CTX *) Context.Ptr());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue