From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
<linux-crypto@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, Karina Yankevich <k.yankevich@omp.ru>
Subject: [PATCH v2] crypto: drbg - make drbg_{ctr_bcc,kcapi_sym}() return *void*
Date: Thu, 25 Sep 2025 00:00:10 +0300 [thread overview]
Message-ID: <1bb8aa58-7f40-4ba7-959a-e44655aa4a83@omp.ru> (raw)
From: Karina Yankevich <k.yankevich@omp.ru>
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.
[Sergey: fixed the subject, refreshed the patch]
Signed-off-by: Karina Yankevich <k.yankevich@omp.ru>
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
---
The patch is against the master branch of Linus Torvalds' linux.git repo
(I'm unable to use the other repos on git.kernel.org and I have to update
Linus' repo from GitHub).
crypto/drbg.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
Index: linux/crypto/drbg.c
===================================================================
--- linux.orig/crypto/drbg.c
+++ linux/crypto/drbg.c
@@ -296,8 +296,8 @@ MODULE_ALIAS_CRYPTO("drbg_nopr_ctr_aes12
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,
@@ -306,11 +306,10 @@ static int drbg_kcapi_sym_ctr(struct drb
#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;
@@ -327,9 +326,7 @@ static int drbg_ctr_bcc(struct drbg_stat
/* 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++;
@@ -339,9 +336,7 @@ static int drbg_ctr_bcc(struct drbg_stat
}
/* 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);
}
/*
@@ -388,7 +383,6 @@ static int drbg_ctr_df(struct drbg_state
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;
@@ -459,9 +453,7 @@ static int drbg_ctr_df(struct drbg_state
*/
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);
@@ -482,9 +474,7 @@ static int drbg_ctr_df(struct drbg_state
* 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) :
@@ -494,13 +484,10 @@ static int drbg_ctr_df(struct drbg_state
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;
}
/*
@@ -1806,15 +1793,14 @@ static void drbg_kcapi_symsetkey(struct
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,
next reply other threads:[~2025-09-24 21:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 21:00 Sergey Shtylyov [this message]
2025-10-17 8:18 ` [PATCH v2] crypto: drbg - make drbg_{ctr_bcc,kcapi_sym}() return *void* Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1bb8aa58-7f40-4ba7-959a-e44655aa4a83@omp.ru \
--to=s.shtylyov@omp.ru \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=k.yankevich@omp.ru \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox