]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
nettle/gost: gost28147: require calling set_param before set_key
authorDmitry Baryshkov <dbaryshkov@gmail.com>
Wed, 5 Feb 2020 13:06:30 +0000 (16:06 +0300)
committerDmitry Baryshkov <dbaryshkov@gmail.com>
Wed, 5 Feb 2020 13:06:30 +0000 (16:06 +0300)
Require selecting parameter set before setting the key. There is no need
to provide default setting, if a param is always selected anyway.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
lib/nettle/cipher.c
lib/nettle/gost/gost28147.c
lib/nettle/mac.c

index 28f676a480504f64f4ab82796a9d5e1892657522..5e9f25b2ec9b80846404a4cbe0ea4433c3f07df1 100644 (file)
@@ -166,36 +166,36 @@ _cfb_decrypt(struct nettle_cipher_ctx *ctx, size_t length, uint8_t * dst,
 static void
 _gost28147_set_key_tc26z(void *ctx, const uint8_t *key)
 {
-       gost28147_set_key(ctx, key);
        gost28147_set_param(ctx, &gost28147_param_TC26_Z);
+       gost28147_set_key(ctx, key);
 }
 
 static void
 _gost28147_set_key_cpa(void *ctx, const uint8_t *key)
 {
-       gost28147_set_key(ctx, key);
        gost28147_set_param(ctx, &gost28147_param_CryptoPro_A);
+       gost28147_set_key(ctx, key);
 }
 
 static void
 _gost28147_set_key_cpb(void *ctx, const uint8_t *key)
 {
-       gost28147_set_key(ctx, key);
        gost28147_set_param(ctx, &gost28147_param_CryptoPro_B);
+       gost28147_set_key(ctx, key);
 }
 
 static void
 _gost28147_set_key_cpc(void *ctx, const uint8_t *key)
 {
-       gost28147_set_key(ctx, key);
        gost28147_set_param(ctx, &gost28147_param_CryptoPro_C);
+       gost28147_set_key(ctx, key);
 }
 
 static void
 _gost28147_set_key_cpd(void *ctx, const uint8_t *key)
 {
-       gost28147_set_key(ctx, key);
        gost28147_set_param(ctx, &gost28147_param_CryptoPro_D);
+       gost28147_set_key(ctx, key);
 }
 
 static void
index d6a278ab09eac8fb68c236fdb0701f1869bcf867..8d648c1045087412d669d495d71e15696595e556 100644 (file)
@@ -2292,24 +2292,17 @@ static void gost28147_key_mesh_cryptopro(struct gost28147_ctx *ctx)
   ctx->key_count = 0;
 }
 
-static void
-_gost28147_set_key(struct gost28147_ctx *ctx, const uint8_t *key)
+void
+gost28147_set_key(struct gost28147_ctx *ctx, const uint8_t *key)
 {
   unsigned i;
 
+  assert(key);
   for (i = 0; i < 8; i++, key += 4)
     ctx->key[i] = LE_READ_UINT32(key);
   ctx->key_count = 0;
 }
 
-void
-gost28147_set_key(struct gost28147_ctx *ctx, const uint8_t *key)
-{
-  assert(key);
-  _gost28147_set_key(ctx, key);
-  gost28147_set_param(ctx, &gost28147_param_TC26_Z);
-}
-
 void
 gost28147_set_param(struct gost28147_ctx *ctx, const struct gost28147_param *param)
 {
@@ -2419,8 +2412,8 @@ gost28147_cnt_init(struct gost28147_cnt_ctx *ctx,
                   const uint8_t *key,
                   const struct gost28147_param *param)
 {
-  gost28147_set_key(&ctx->ctx, key);
   gost28147_set_param(&ctx->ctx, param);
+  gost28147_set_key(&ctx->ctx, key);
   ctx->bytes = 0;
 }
 
@@ -2487,10 +2480,8 @@ gost28147_imit_set_key(struct gost28147_imit_ctx *ctx,
   assert(length == GOST28147_IMIT_KEY_SIZE);
   assert(key);
 
-  _gost28147_set_key(&ctx->cctx, key);
   _gost28147_imit_reinit(ctx);
-  if (!ctx->cctx.sbox)
-    gost28147_set_param(&ctx->cctx, &gost28147_param_TC26_Z);
+  gost28147_set_key(&ctx->cctx, key);
 }
 
 void
index 25054dc2675ec38460d0891273b653660745775d..c3ea6fb655ae1efe11e393b604aaf91dbbef9f46 100644 (file)
@@ -138,8 +138,8 @@ struct nettle_mac_ctx {
 static void
 _wrap_gost28147_imit_set_key_tc26z(void *ctx, size_t len, const uint8_t * key)
 {
-       gost28147_imit_set_key(ctx, len, key);
        gost28147_imit_set_param(ctx, &gost28147_param_TC26_Z);
+       gost28147_imit_set_key(ctx, len, key);
 }
 #endif