1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-12 11:28:26 -06:00

Add test vectors for Kuznyechik and GOST89 (the later is deprecated)

This commit is contained in:
Mounir IDRASSI
2016-09-25 22:37:45 +02:00
parent d18ecc1a37
commit b65eabe23d
8 changed files with 338 additions and 30 deletions

View File

@@ -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,37 +84,34 @@ 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)
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);
#if defined (DEVICE_DRIVER) && !defined (_WIN64)
if (NT_SUCCESS (saveStatus) && (HasSSE2() || HasSSE41()))
KeRestoreFloatingPointState (&floatingPointState);
if (NT_SUCCESS (saveStatus) && (HasSSE2() || HasSSE41()))
KeRestoreFloatingPointState (&floatingPointState);
#endif
xor_s_box(ks->sbox, sbox_seed);
#endif
xor_s_box(ks->sbox, sbox_seed);
}
gost_prepare_kds(ks);
}

View File

@@ -56,7 +56,7 @@ typedef struct gost_kds
void gost_encrypt(const byte *in, byte *out, gost_kds *ks, int count);
void gost_decrypt(const byte *in, byte *out, gost_kds *ks, int count);
void gost_set_key(const byte *key, gost_kds *ks);
void gost_set_key(const byte *key, gost_kds *ks, int useDynamicSbox);
#else
#define GOST_KS (0)