VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Crypto/GostCipher.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/GostCipher.c')
-rw-r--r--src/Crypto/GostCipher.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/Crypto/GostCipher.c b/src/Crypto/GostCipher.c
index b84fd4ed..4d7e5070 100644
--- a/src/Crypto/GostCipher.c
+++ b/src/Crypto/GostCipher.c
@@ -69,7 +69,6 @@ void gost_prepare_kds(gost_kds* kds) {
}
-#ifdef GOST_DYNAMIC_SBOXES
static void xor_s_box(byte s_box[8][16], byte *seed)
{
int i;
@@ -85,38 +84,35 @@ static void xor_s_box(byte s_box[8][16], byte *seed)
s_box[7][i] ^= (seed[ (i * 4) + 3 ]>>4) & 0xF;
}
}
-#endif
-void gost_set_key(const byte *key, gost_kds *ks)
+void gost_set_key(const byte *key, gost_kds *ks, int useDynamicSbox)
{
-#ifdef GOST_DYNAMIC_SBOXES
- STREEBOG_CTX sctx;
- byte sbox_seed[64];
-#if defined (DEVICE_DRIVER) && !defined (_WIN64)
- KFLOATING_SAVE floatingPointState;
- NTSTATUS saveStatus = STATUS_SUCCESS;
- if (HasSSE2() || HasSSE41())
- saveStatus = KeSaveFloatingPointState (&floatingPointState);
-#endif
-#endif
-
memcpy(ks->key, key, GOST_KEYSIZE);
memcpy(ks->sbox, S_TC26, sizeof(ks->sbox));
-#ifdef GOST_DYNAMIC_SBOXES
- //Generate pseudorandom data based on the key
- STREEBOG_init(&sctx);
- STREEBOG_add(&sctx, key, 32);
- STREEBOG_finalize(&sctx, sbox_seed);
-
+ if (useDynamicSbox)
+ {
+ STREEBOG_CTX sctx;
+ byte sbox_seed[64];
#if defined (DEVICE_DRIVER) && !defined (_WIN64)
- if (NT_SUCCESS (saveStatus) && (HasSSE2() || HasSSE41()))
- KeRestoreFloatingPointState (&floatingPointState);
+ KFLOATING_SAVE floatingPointState;
+ NTSTATUS saveStatus = STATUS_SUCCESS;
+ if (HasSSE2() || HasSSE41())
+ saveStatus = KeSaveFloatingPointState (&floatingPointState);
#endif
+ //Generate pseudorandom data based on the key
+ STREEBOG_init(&sctx);
+ STREEBOG_add(&sctx, key, 32);
+ STREEBOG_finalize(&sctx, sbox_seed);
- xor_s_box(ks->sbox, sbox_seed);
+#if defined (DEVICE_DRIVER) && !defined (_WIN64)
+ if (NT_SUCCESS (saveStatus) && (HasSSE2() || HasSSE41()))
+ KeRestoreFloatingPointState (&floatingPointState);
#endif
+ xor_s_box(ks->sbox, sbox_seed);
+ }
+
gost_prepare_kds(ks);
}