]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
nettle/gost: remove gost28147_imit_init
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Mon, 23 Dec 2019 22:20:24 +0000 (01:20 +0300)
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Fri, 27 Dec 2019 08:59:42 +0000 (11:59 +0300)
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>
lib/nettle/gost/gost-wrap.c
lib/nettle/gost/gost28147.c
lib/nettle/gost/gost28147.h

index 63e1c321e2622764e267a1299b6362163bbf4750..e4a616ed2cedfec1a93ea398c1c27cfb77e61592 100644 (file)
@@ -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);
index da8ec9ef14322ad92db6ebc29829e6b79c0531d1..d6a278ab09eac8fb68c236fdb0701f1869bcf867 100644 (file)
@@ -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
index ae4a385589d05171631fb241792dea1ef9f8a141..14c865e6e6f93e4d76be39bdddec0d0f188cede6 100644 (file)
@@ -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
@@ -185,9 +184,6 @@ struct gost28147_imit_ctx
   uint32_t state[GOST28147_IMIT_BLOCK_SIZE/4];
 };
 
-void
-gost28147_imit_init(struct gost28147_imit_ctx *ctx);
-
 void
 gost28147_imit_set_key(struct gost28147_imit_ctx *ctx,
                       size_t length,