libressl/0031-gost-drop-key_len-from-Gost28147_set_key.patch

186 lines
7 KiB
Diff
Raw Permalink Normal View History

From 9ccc19763e8020f1a760521c269fc561741b2aaf Mon Sep 17 00:00:00 2001
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
Date: Mon, 23 Mar 2020 22:53:46 +0300
Subject: [PATCH 31/87] gost: drop key_len from Gost28147_set_key
There is no point in specifying key length to Gost28147_set_key,
everybody just passes 256 (or 32 * 8) no matter what.
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
src/lib/libcrypto/evp/e_gost2814789.c | 4 +++-
src/lib/libcrypto/evp/m_gost2814789.c | 3 ++-
src/lib/libcrypto/gost/gost.h | 3 +--
src/lib/libcrypto/gost/gost2814789.c | 2 +-
src/lib/libcrypto/gost/gost89_keywrap.c | 6 +++---
src/lib/libcrypto/gost/gost89_params.c | 12 +++---------
src/lib/libcrypto/gost/gostr341194.c | 8 ++++----
7 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c
index 730de4fed..e3c608f0e 100644
--- a/src/lib/libcrypto/evp/e_gost2814789.c
+++ b/src/lib/libcrypto/evp/e_gost2814789.c
@@ -93,7 +93,9 @@ gost2814789_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
{
EVP_GOST2814789_CTX *c = ctx->cipher_data;
- return Gost2814789_set_key(&c->ks, key, ctx->key_len * 8);
+ Gost2814789_set_key(&c->ks, key);
+
+ return 1;
}
int
diff --git a/src/lib/libcrypto/evp/m_gost2814789.c b/src/lib/libcrypto/evp/m_gost2814789.c
index 279af872e..779ccf07d 100644
--- a/src/lib/libcrypto/evp/m_gost2814789.c
+++ b/src/lib/libcrypto/evp/m_gost2814789.c
@@ -82,7 +82,8 @@ gost2814789_md_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
switch (cmd) {
case EVP_MD_CTRL_SET_KEY:
- return Gost2814789_set_key(&gctx->cipher, p2, p1);
+ Gost2814789_set_key(&gctx->cipher, p2);
+ return 1;
case EVP_MD_CTRL_GOST_SET_SBOX:
return Gost2814789_set_sbox(&gctx->cipher, p1);
}
diff --git a/src/lib/libcrypto/gost/gost.h b/src/lib/libcrypto/gost/gost.h
index 092f96fb6..b6e5b51c4 100644
--- a/src/lib/libcrypto/gost/gost.h
+++ b/src/lib/libcrypto/gost/gost.h
@@ -73,8 +73,7 @@ typedef struct gost2814789_key_st {
} GOST2814789_KEY;
int Gost2814789_set_sbox(GOST2814789_KEY *key, int nid);
-int Gost2814789_set_key(GOST2814789_KEY *key,
- const unsigned char *userKey, const int bits);
+void Gost2814789_set_key(GOST2814789_KEY *key, const unsigned char *userKey);
void Gost2814789_ecb_encrypt(const unsigned char *in, unsigned char *out,
GOST2814789_KEY *key, const int enc);
void Gost2814789_cfb64_encrypt(const unsigned char *in, unsigned char *out,
diff --git a/src/lib/libcrypto/gost/gost2814789.c b/src/lib/libcrypto/gost/gost2814789.c
index e285413ed..5016ed004 100644
--- a/src/lib/libcrypto/gost/gost2814789.c
+++ b/src/lib/libcrypto/gost/gost2814789.c
@@ -461,7 +461,7 @@ GOST2814789IMIT(const unsigned char *d, size_t n, unsigned char *md, int nid,
md = m;
GOST2814789IMIT_Init(&c, nid);
memcpy(c.mac, iv, 8);
- Gost2814789_set_key(&c.cipher, key, 256);
+ Gost2814789_set_key(&c.cipher, key);
GOST2814789IMIT_Update(&c, d, n);
GOST2814789IMIT_Final(md, &c);
explicit_bzero(&c, sizeof(c));
diff --git a/src/lib/libcrypto/gost/gost89_keywrap.c b/src/lib/libcrypto/gost/gost89_keywrap.c
index a754c4d56..47a11ad0c 100644
--- a/src/lib/libcrypto/gost/gost89_keywrap.c
+++ b/src/lib/libcrypto/gost/gost89_keywrap.c
@@ -85,7 +85,7 @@ key_diversify_crypto_pro(GOST2814789_KEY *ctx, const unsigned char *inputKey,
p = S;
l2c (s1, p);
l2c (s2, p);
- Gost2814789_set_key(ctx, outputKey, 256);
+ Gost2814789_set_key(ctx, outputKey);
mask = 0;
Gost2814789_cfb64_encrypt(outputKey, outputKey, 32, ctx, S,
&mask, 1);
@@ -102,7 +102,7 @@ gost_key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey,
Gost2814789_set_sbox(&ctx, nid);
key_diversify_crypto_pro(&ctx, keyExchangeKey, ukm, kek_ukm);
- Gost2814789_set_key(&ctx, kek_ukm, 256);
+ Gost2814789_set_key(&ctx, kek_ukm);
memcpy(wrappedKey, ukm, 8);
Gost2814789_encrypt(sessionKey + 0, wrappedKey + 8 + 0, &ctx);
Gost2814789_encrypt(sessionKey + 8, wrappedKey + 8 + 8, &ctx);
@@ -122,7 +122,7 @@ gost_key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey,
Gost2814789_set_sbox(&ctx, nid);
/* First 8 bytes of wrapped Key is ukm */
key_diversify_crypto_pro(&ctx, keyExchangeKey, wrappedKey, kek_ukm);
- Gost2814789_set_key(&ctx, kek_ukm, 256);
+ Gost2814789_set_key(&ctx, kek_ukm);
Gost2814789_decrypt(wrappedKey + 8 + 0, sessionKey + 0, &ctx);
Gost2814789_decrypt(wrappedKey + 8 + 8, sessionKey + 8, &ctx);
Gost2814789_decrypt(wrappedKey + 8 + 16, sessionKey + 16, &ctx);
diff --git a/src/lib/libcrypto/gost/gost89_params.c b/src/lib/libcrypto/gost/gost89_params.c
index 35d8f62fe..526710cb0 100644
--- a/src/lib/libcrypto/gost/gost89_params.c
+++ b/src/lib/libcrypto/gost/gost89_params.c
@@ -212,21 +212,15 @@ Gost2814789_set_sbox(GOST2814789_KEY *key, int nid)
return 1;
}
-int
-Gost2814789_set_key(GOST2814789_KEY *key, const unsigned char *userKey,
- const int bits)
+void
+Gost2814789_set_key(GOST2814789_KEY *key, const unsigned char *userKey)
{
int i;
- if (bits != 256)
- return 0;
-
for (i = 0; i < 8; i++)
c2l(userKey, key->key[i]);
key->count = 0;
-
- return 1;
}
void
@@ -239,6 +233,6 @@ Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key)
Gost2814789_decrypt(CryptoProKeyMeshingKey + 16, newkey + 16, key);
Gost2814789_decrypt(CryptoProKeyMeshingKey + 24, newkey + 24, key);
- Gost2814789_set_key(key, newkey, 256);
+ Gost2814789_set_key(key, newkey);
}
#endif
diff --git a/src/lib/libcrypto/gost/gostr341194.c b/src/lib/libcrypto/gost/gostr341194.c
index 2a462185a..9b750efd6 100644
--- a/src/lib/libcrypto/gost/gostr341194.c
+++ b/src/lib/libcrypto/gost/gostr341194.c
@@ -139,7 +139,7 @@ hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
xor_blocks(W, H, M, 32);
swap_bytes(W, Key);
/* Encrypt first 8 bytes of H with first key */
- Gost2814789_set_key(&c->cipher, Key, 256);
+ Gost2814789_set_key(&c->cipher, Key);
Gost2814789_encrypt(H, S, &c->cipher);
/* Compute second key */
@@ -149,7 +149,7 @@ hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
xor_blocks(W, U, V, 32);
swap_bytes(W, Key);
/* encrypt second 8 bytes of H with second key */
- Gost2814789_set_key(&c->cipher, Key, 256);
+ Gost2814789_set_key(&c->cipher, Key);
Gost2814789_encrypt(H+8, S+8, &c->cipher);
/* compute third key */
@@ -175,7 +175,7 @@ hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
xor_blocks(W, U, V, 32);
swap_bytes(W, Key);
/* encrypt third 8 bytes of H with third key */
- Gost2814789_set_key(&c->cipher, Key, 256);
+ Gost2814789_set_key(&c->cipher, Key);
Gost2814789_encrypt(H+16, S+16, &c->cipher);
/* Compute fourth key */
@@ -185,7 +185,7 @@ hash_step(GOSTR341194_CTX *c, unsigned char *H, const unsigned char *M)
xor_blocks(W, U, V, 32);
swap_bytes(W, Key);
/* Encrypt last 8 bytes with fourth key */
- Gost2814789_set_key(&c->cipher, Key, 256);
+ Gost2814789_set_key(&c->cipher, Key);
Gost2814789_encrypt(H+24, S+24, &c->cipher);
for (i = 0; i < 12; i++)
--
2.17.1