VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Random.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Random.c')
-rw-r--r--src/Common/Random.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/Common/Random.c b/src/Common/Random.c
index fd836c7f..ee3fcf53 100644
--- a/src/Common/Random.c
+++ b/src/Common/Random.c
@@ -235,167 +235,172 @@ BOOL IsRandomNumberGeneratorStarted ()
void RandSetHashFunction (int hash_algo_id)
{
if (HashIsDeprecated (hash_algo_id))
hash_algo_id = DEFAULT_HASH_ALGORITHM;
HashFunction = hash_algo_id;
}
int RandGetHashFunction (void)
{
return HashFunction;
}
void SetRandomPoolEnrichedByUserStatus (BOOL enriched)
{
RandomPoolEnrichedByUser = enriched;
}
BOOL IsRandomPoolEnrichedByUser ()
{
return RandomPoolEnrichedByUser;
}
/* The random pool mixing function */
BOOL Randmix ()
{
if (bRandmixEnabled)
{
unsigned char hashOutputBuffer [MAX_DIGESTSIZE];
- WHIRLPOOL_CTX wctx;
- blake2s_state bctx;
+ #ifndef WOLFCRYPT_BACKEND
+ WHIRLPOOL_CTX wctx;
+ blake2s_state bctx;
+ STREEBOG_CTX stctx;
+ #endif
sha512_ctx sctx;
sha256_ctx s256ctx;
- STREEBOG_CTX stctx;
int poolIndex, digestIndex, digestSize;
switch (HashFunction)
{
- case BLAKE2S:
- digestSize = BLAKE2S_DIGESTSIZE;
- break;
-
case SHA512:
digestSize = SHA512_DIGESTSIZE;
break;
case SHA256:
digestSize = SHA256_DIGESTSIZE;
break;
+ #ifndef WOLFCRYPT_BACKEND
+ case BLAKE2S:
+ digestSize = BLAKE2S_DIGESTSIZE;
+ break;
+
case WHIRLPOOL:
digestSize = WHIRLPOOL_DIGESTSIZE;
break;
case STREEBOG:
digestSize = STREEBOG_DIGESTSIZE;
break;
-
+ #endif
default:
TC_THROW_FATAL_EXCEPTION;
}
if (RNG_POOL_SIZE % digestSize)
TC_THROW_FATAL_EXCEPTION;
for (poolIndex = 0; poolIndex < RNG_POOL_SIZE; poolIndex += digestSize)
{
/* Compute the message digest of the entire pool using the selected hash function. */
switch (HashFunction)
{
- case BLAKE2S:
- blake2s_init(&bctx);
- blake2s_update(&bctx, pRandPool, RNG_POOL_SIZE);
- blake2s_final(&bctx, hashOutputBuffer);
- break;
-
case SHA512:
sha512_begin (&sctx);
sha512_hash (pRandPool, RNG_POOL_SIZE, &sctx);
sha512_end (hashOutputBuffer, &sctx);
break;
case SHA256:
sha256_begin (&s256ctx);
sha256_hash (pRandPool, RNG_POOL_SIZE, &s256ctx);
sha256_end (hashOutputBuffer, &s256ctx);
break;
+ #ifndef WOLFCRYPT_BACKEND
+ case BLAKE2S:
+ blake2s_init(&bctx);
+ blake2s_update(&bctx, pRandPool, RNG_POOL_SIZE);
+ blake2s_final(&bctx, hashOutputBuffer);
+ break;
+
case WHIRLPOOL:
WHIRLPOOL_init (&wctx);
WHIRLPOOL_add (pRandPool, RNG_POOL_SIZE, &wctx);
WHIRLPOOL_finalize (&wctx, hashOutputBuffer);
break;
case STREEBOG:
STREEBOG_init (&stctx);
STREEBOG_add (&stctx, pRandPool, RNG_POOL_SIZE);
STREEBOG_finalize (&stctx, hashOutputBuffer);
break;
-
+ #endif
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
}
/* XOR the resultant message digest to the pool at the poolIndex position. */
for (digestIndex = 0; digestIndex < digestSize; digestIndex++)
{
pRandPool [poolIndex + digestIndex] ^= hashOutputBuffer [digestIndex];
}
}
/* Prevent leaks */
burn (hashOutputBuffer, MAX_DIGESTSIZE);
switch (HashFunction)
{
- case BLAKE2S:
- burn (&bctx, sizeof(bctx));
- break;
-
case SHA512:
burn (&sctx, sizeof(sctx));
break;
case SHA256:
burn (&s256ctx, sizeof(s256ctx));
break;
+ #ifndef WOLFCRYPT_BACKEND
+ case BLAKE2S:
+ burn (&bctx, sizeof(bctx));
+ break;
+
case WHIRLPOOL:
burn (&wctx, sizeof(wctx));
break;
case STREEBOG:
burn (&stctx, sizeof(sctx));
break;
-
+ #endif
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
}
}
return TRUE;
}
/* Add a buffer to the pool */
void RandaddBuf (void *buf, int len)
{
int i;
for (i = 0; i < len; i++)
{
RandaddByte (((unsigned char *) buf)[i]);
}
}
BOOL RandpeekBytes (void* hwndDlg, unsigned char *buf, int len, DWORD* mouseCounter)
{
if (!bRandDidInit)
return FALSE;
if (len > RNG_POOL_SIZE)
{
Error ("ERR_NOT_ENOUGH_RANDOM_DATA", (HWND) hwndDlg);
len = RNG_POOL_SIZE;
}
EnterCriticalSection (&critRandProt);