diff options
author | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2020-02-05 16:06:30 +0300 |
---|---|---|
committer | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2020-02-05 16:06:30 +0300 |
commit | ef04f619bc4b560a66d48c233948fd3877fbe29e (patch) | |
tree | 13dc4cfce316d1edd95ff71fd396161afca98131 | |
parent | e825a5ddbf604a2f9e7dfe69813c1819615edbfa (diff) | |
download | gnutls-ef04f619bc4b560a66d48c233948fd3877fbe29e.tar.gz |
nettle/gost: gost28147: require calling set_param before set_key
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>
-rw-r--r-- | lib/nettle/cipher.c | 10 | ||||
-rw-r--r-- | lib/nettle/gost/gost28147.c | 19 | ||||
-rw-r--r-- | lib/nettle/mac.c | 2 |
3 files changed, 11 insertions, 20 deletions
diff --git a/lib/nettle/cipher.c b/lib/nettle/cipher.c index 28f676a480..5e9f25b2ec 100644 --- a/lib/nettle/cipher.c +++ b/lib/nettle/cipher.c @@ -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 diff --git a/lib/nettle/gost/gost28147.c b/lib/nettle/gost/gost28147.c index d6a278ab09..8d648c1045 100644 --- a/lib/nettle/gost/gost28147.c +++ b/lib/nettle/gost/gost28147.c @@ -2292,25 +2292,18 @@ 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) { assert(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 diff --git a/lib/nettle/mac.c b/lib/nettle/mac.c index 25054dc267..c3ea6fb655 100644 --- a/lib/nettle/mac.c +++ b/lib/nettle/mac.c @@ -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 |