VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Random.c
diff options
context:
space:
mode:
authorlealem47 <60322859+lealem47@users.noreply.github.com>2023-11-12 16:51:31 -0700
committerGitHub <noreply@github.com>2023-11-13 00:51:31 +0100
commit9247ce1bb90c44d19a0069fadb12c0c480ac9b4f (patch)
tree66fb4728d502759271d03eba59d51c1a129b2ffb /src/Common/Random.c
parent458be85f84a097aa829658c50ce41d82791fb6a8 (diff)
downloadVeraCrypt-9247ce1bb90c44d19a0069fadb12c0c480ac9b4f.tar.gz
VeraCrypt-9247ce1bb90c44d19a0069fadb12c0c480ac9b4f.zip
wolfCrypt as crypto backend for VeraCrypt (#1227)
* wolfCrypt as crypto backend for VeraCrypt * Refactor to use EncryptionModeWolfCryptXTS class
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
@@ -262,19 +262,17 @@ 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;
@@ -283,6 +281,11 @@ BOOL Randmix ()
digestSize = SHA256_DIGESTSIZE;
break;
+ #ifndef WOLFCRYPT_BACKEND
+ case BLAKE2S:
+ digestSize = BLAKE2S_DIGESTSIZE;
+ break;
+
case WHIRLPOOL:
digestSize = WHIRLPOOL_DIGESTSIZE;
break;
@@ -290,7 +293,7 @@ BOOL Randmix ()
case STREEBOG:
digestSize = STREEBOG_DIGESTSIZE;
break;
-
+ #endif
default:
TC_THROW_FATAL_EXCEPTION;
}
@@ -303,12 +306,6 @@ BOOL Randmix ()
/* 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);
@@ -321,6 +318,13 @@ BOOL Randmix ()
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);
@@ -332,7 +336,7 @@ BOOL Randmix ()
STREEBOG_add (&stctx, pRandPool, RNG_POOL_SIZE);
STREEBOG_finalize (&stctx, hashOutputBuffer);
break;
-
+ #endif
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;
@@ -349,10 +353,6 @@ BOOL Randmix ()
burn (hashOutputBuffer, MAX_DIGESTSIZE);
switch (HashFunction)
{
- case BLAKE2S:
- burn (&bctx, sizeof(bctx));
- break;
-
case SHA512:
burn (&sctx, sizeof(sctx));
break;
@@ -361,6 +361,11 @@ BOOL Randmix ()
burn (&s256ctx, sizeof(s256ctx));
break;
+ #ifndef WOLFCRYPT_BACKEND
+ case BLAKE2S:
+ burn (&bctx, sizeof(bctx));
+ break;
+
case WHIRLPOOL:
burn (&wctx, sizeof(wctx));
break;
@@ -368,7 +373,7 @@ BOOL Randmix ()
case STREEBOG:
burn (&stctx, sizeof(sctx));
break;
-
+ #endif
default:
// Unknown/wrong ID
TC_THROW_FATAL_EXCEPTION;