diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-12-24 01:20:24 +0300 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2019-12-27 11:59:42 +0300 |
commit | 650b60cc590f2c918dd84e42e4ce154a1d20acf3 (patch) | |
tree | 091b3794198085efbc5c2cdc4ed7f00067b4ad9e | |
parent | 0af5ee946d2e49549ff19968e13d0703b3dcf75e (diff) | |
download | gnutls-650b60cc590f2c918dd84e42e4ce154a1d20acf3.tar.gz |
nettle/gost: remove gost28147_imit_init
Rewrite gost28147 imit code to clean up state and index on key setup to
be sure that imit context is properly cleaned.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
-rw-r--r-- | lib/nettle/gost/gost-wrap.c | 2 | ||||
-rw-r--r-- | lib/nettle/gost/gost28147.c | 14 | ||||
-rw-r--r-- | lib/nettle/gost/gost28147.h | 4 |
3 files changed, 8 insertions, 12 deletions
diff --git a/lib/nettle/gost/gost-wrap.c b/lib/nettle/gost/gost-wrap.c index 63e1c321e2..e4a616ed2c 100644 --- a/lib/nettle/gost/gost-wrap.c +++ b/lib/nettle/gost/gost-wrap.c @@ -93,7 +93,6 @@ gost28147_key_wrap_cryptopro(const struct gost28147_param *param, gost28147_set_param(&ctx, param); gost28147_encrypt(&ctx, GOST28147_KEY_SIZE, enc, cek); - gost28147_imit_init(&ictx); gost28147_imit_set_key(&ictx, GOST28147_KEY_SIZE, kd); gost28147_imit_set_param(&ictx, param); gost28147_imit_set_nonce(&ictx, ukm); @@ -121,7 +120,6 @@ gost28147_key_unwrap_cryptopro(const struct gost28147_param *param, gost28147_set_param(&ctx, param); gost28147_decrypt(&ctx, GOST28147_KEY_SIZE, cek, enc); - gost28147_imit_init(&ictx); gost28147_imit_set_key(&ictx, GOST28147_KEY_SIZE, kd); gost28147_imit_set_param(&ictx, param); gost28147_imit_set_nonce(&ictx, ukm); diff --git a/lib/nettle/gost/gost28147.c b/lib/nettle/gost/gost28147.c index da8ec9ef14..d6a278ab09 100644 --- a/lib/nettle/gost/gost28147.c +++ b/lib/nettle/gost/gost28147.c @@ -2470,13 +2470,13 @@ gost28147_cnt_crypt(struct gost28147_cnt_ctx *ctx, } } -void -gost28147_imit_init(struct gost28147_imit_ctx *ctx) +static void +_gost28147_imit_reinit(struct gost28147_imit_ctx *ctx) { - memset(ctx->state, 0, GOST28147_BLOCK_SIZE); + ctx->state[0] = 0; + ctx->state[1] = 0; ctx->index = 0; ctx->count = 0; - gost28147_set_param(&ctx->cctx, &gost28147_param_TC26_Z); /* Default */ } void @@ -2488,7 +2488,9 @@ gost28147_imit_set_key(struct gost28147_imit_ctx *ctx, assert(key); _gost28147_set_key(&ctx->cctx, key); - /* Do not reset param here */ + _gost28147_imit_reinit(ctx); + if (!ctx->cctx.sbox) + gost28147_set_param(&ctx->cctx, &gost28147_param_TC26_Z); } void @@ -2549,6 +2551,6 @@ gost28147_imit_digest(struct gost28147_imit_ctx *ctx, } _nettle_write_le32(length, digest, ctx->state); - gost28147_imit_init(ctx); + _gost28147_imit_reinit(ctx); } #endif diff --git a/lib/nettle/gost/gost28147.h b/lib/nettle/gost/gost28147.h index ae4a385589..14c865e6e6 100644 --- a/lib/nettle/gost/gost28147.h +++ b/lib/nettle/gost/gost28147.h @@ -73,7 +73,6 @@ extern "C" { #define gost28147_key_wrap_cryptopro _gnutls_gost28147_key_wrap_cryptopro #define gost28147_key_unwrap_cryptopro _gnutls_gost28147_key_unwrap_cryptopro -#define gost28147_imit_init _gnutls_gost28147_imit_init #define gost28147_imit_set_key _gnutls_gost28147_imit_set_key #define gost28147_imit_set_nonce _gnutls_gost28147_imit_set_nonce #define gost28147_imit_set_param _gnutls_gost28147_imit_set_param @@ -186,9 +185,6 @@ struct gost28147_imit_ctx }; void -gost28147_imit_init(struct gost28147_imit_ctx *ctx); - -void gost28147_imit_set_key(struct gost28147_imit_ctx *ctx, size_t length, const uint8_t *key); |