From b65eabe23d5910a26d741439b1f5ea45ba4a0777 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sun, 25 Sep 2016 22:37:45 +0200 Subject: Add test vectors for Kuznyechik and GOST89 (the later is deprecated) --- src/Crypto/GostCipher.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/Crypto/GostCipher.c') 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); } -- cgit v1.2.3