* [PATCH] crypto: drbg - make drbg_kcapi_{ctr_bcc,kcapi_sym}() return void
@ 2024-03-05 18:43 Karina Yankevich
2024-03-28 10:46 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Karina Yankevich @ 2024-03-05 18:43 UTC (permalink / raw)
To: Herbert Xu
Cc: Karina Yankevich, David S. Miller, s.shtylyov, linux-kernel, lvc-project
drgb_kcapi_sym() always returns 0, so make it return void instead.
Consequently, make drbg_ctr_bcc() return void too.
Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.
Signed-off-by: Karina Yankevich <k.yankevich@omp.ru>
---
crypto/drbg.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
diff --git a/crypto/drbg.c b/crypto/drbg.c
index 3addce90930c..2402ca788899 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -295,8 +295,8 @@ MODULE_ALIAS_CRYPTO("drbg_nopr_ctr_aes128");
static void drbg_kcapi_symsetkey(struct drbg_state *drbg,
const unsigned char *key);
-static int drbg_kcapi_sym(struct drbg_state *drbg, unsigned char *outval,
- const struct drbg_string *in);
+static void drbg_kcapi_sym(struct drbg_state *drbg, unsigned char *outval,
+ const struct drbg_string *in);
static int drbg_init_sym_kernel(struct drbg_state *drbg);
static int drbg_fini_sym_kernel(struct drbg_state *drbg);
static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
@@ -305,11 +305,10 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
#define DRBG_OUTSCRATCHLEN 256
/* BCC function for CTR DRBG as defined in 10.4.3 */
-static int drbg_ctr_bcc(struct drbg_state *drbg,
- unsigned char *out, const unsigned char *key,
- struct list_head *in)
+static void drbg_ctr_bcc(struct drbg_state *drbg,
+ unsigned char *out, const unsigned char *key,
+ struct list_head *in)
{
- int ret = 0;
struct drbg_string *curr = NULL;
struct drbg_string data;
short cnt = 0;
@@ -326,9 +325,7 @@ static int drbg_ctr_bcc(struct drbg_state *drbg,
/* 10.4.3 step 4.2 */
if (drbg_blocklen(drbg) == cnt) {
cnt = 0;
- ret = drbg_kcapi_sym(drbg, out, &data);
- if (ret)
- return ret;
+ drbg_kcapi_sym(drbg, out, &data);
}
out[cnt] ^= *pos;
pos++;
@@ -338,9 +335,7 @@ static int drbg_ctr_bcc(struct drbg_state *drbg,
}
/* 10.4.3 step 4.2 for last block */
if (cnt)
- ret = drbg_kcapi_sym(drbg, out, &data);
-
- return ret;
+ drbg_kcapi_sym(drbg, out, &data);
}
/*
@@ -387,7 +382,6 @@ static int drbg_ctr_df(struct drbg_state *drbg,
unsigned char *df_data, size_t bytes_to_return,
struct list_head *seedlist)
{
- int ret = -EFAULT;
unsigned char L_N[8];
/* S3 is input */
struct drbg_string S1, S2, S4, cipherin;
@@ -458,9 +452,7 @@ static int drbg_ctr_df(struct drbg_state *drbg,
*/
drbg_cpu_to_be32(i, iv);
/* 10.4.2 step 9.2 -- BCC and concatenation with temp */
- ret = drbg_ctr_bcc(drbg, temp + templen, K, &bcc_list);
- if (ret)
- goto out;
+ drbg_ctr_bcc(drbg, temp + templen, K, &bcc_list);
/* 10.4.2 step 9.3 */
i++;
templen += drbg_blocklen(drbg);
@@ -481,9 +473,7 @@ static int drbg_ctr_df(struct drbg_state *drbg,
* implicit as the key is only drbg_blocklen in size based on
* the implementation of the cipher function callback
*/
- ret = drbg_kcapi_sym(drbg, X, &cipherin);
- if (ret)
- goto out;
+ drbg_kcapi_sym(drbg, X, &cipherin);
blocklen = (drbg_blocklen(drbg) <
(bytes_to_return - generated_len)) ?
drbg_blocklen(drbg) :
@@ -493,13 +483,10 @@ static int drbg_ctr_df(struct drbg_state *drbg,
generated_len += blocklen;
}
- ret = 0;
-
-out:
memset(iv, 0, drbg_blocklen(drbg));
memset(temp, 0, drbg_statelen(drbg) + drbg_blocklen(drbg));
memset(pad, 0, drbg_blocklen(drbg));
- return ret;
+ return 0;
}
/*
@@ -1807,15 +1794,14 @@ static void drbg_kcapi_symsetkey(struct drbg_state *drbg,
crypto_cipher_setkey(tfm, key, (drbg_keylen(drbg)));
}
-static int drbg_kcapi_sym(struct drbg_state *drbg, unsigned char *outval,
- const struct drbg_string *in)
+static void drbg_kcapi_sym(struct drbg_state *drbg, unsigned char *outval,
+ const struct drbg_string *in)
{
struct crypto_cipher *tfm = drbg->priv_data;
/* there is only component in *in */
BUG_ON(in->len < drbg_blocklen(drbg));
crypto_cipher_encrypt_one(tfm, outval, in->buf);
- return 0;
}
static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: drbg - make drbg_kcapi_{ctr_bcc,kcapi_sym}() return void
2024-03-05 18:43 [PATCH] crypto: drbg - make drbg_kcapi_{ctr_bcc,kcapi_sym}() return void Karina Yankevich
@ 2024-03-28 10:46 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2024-03-28 10:46 UTC (permalink / raw)
To: Karina Yankevich; +Cc: David S. Miller, s.shtylyov, linux-kernel, lvc-project
On Tue, Mar 05, 2024 at 09:43:16PM +0300, Karina Yankevich wrote:
> drgb_kcapi_sym() always returns 0, so make it return void instead.
> Consequently, make drbg_ctr_bcc() return void too.
>
> Found by Linux Verification Center (linuxtesting.org) with the Svace static
> analysis tool.
>
> Signed-off-by: Karina Yankevich <k.yankevich@omp.ru>
> ---
> crypto/drbg.c | 38 ++++++++++++--------------------------
> 1 file changed, 12 insertions(+), 26 deletions(-)
Please resend this to linux-crypto@vger.kernel.org.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-28 10:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 18:43 [PATCH] crypto: drbg - make drbg_kcapi_{ctr_bcc,kcapi_sym}() return void Karina Yankevich
2024-03-28 10:46 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.