crypto: drbg - make drbg_{ctr_bcc,kcapi_sym}() return *void*

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Karina Yankevich 2025-09-25 00:00:10 +03:00 committed by Herbert Xu
parent 96feb73def
commit 1617d93c12
1 changed files with 14 additions and 30 deletions

View File

@ -17,33 +17,29 @@
static void drbg_kcapi_symsetkey(struct crypto_aes_ctx *aesctx, static void drbg_kcapi_symsetkey(struct crypto_aes_ctx *aesctx,
const unsigned char *key, const unsigned char *key,
u8 keylen); u8 keylen);
static int drbg_kcapi_sym(struct crypto_aes_ctx *aesctx, unsigned char *outval,
const struct drbg_string *in, u8 blocklen_bytes);
static void drbg_kcapi_symsetkey(struct crypto_aes_ctx *aesctx, static void drbg_kcapi_symsetkey(struct crypto_aes_ctx *aesctx,
const unsigned char *key, u8 keylen) const unsigned char *key, u8 keylen)
{ {
aes_expandkey(aesctx, key, keylen); aes_expandkey(aesctx, key, keylen);
} }
static int drbg_kcapi_sym(struct crypto_aes_ctx *aesctx, unsigned char *outval, static void drbg_kcapi_sym(struct crypto_aes_ctx *aesctx,
const struct drbg_string *in, u8 blocklen_bytes) unsigned char *outval,
const struct drbg_string *in, u8 blocklen_bytes)
{ {
/* there is only component in *in */ /* there is only component in *in */
BUG_ON(in->len < blocklen_bytes); BUG_ON(in->len < blocklen_bytes);
aes_encrypt(aesctx, outval, in->buf); aes_encrypt(aesctx, outval, in->buf);
return 0;
} }
/* BCC function for CTR DRBG as defined in 10.4.3 */ /* BCC function for CTR DRBG as defined in 10.4.3 */
static int drbg_ctr_bcc(struct crypto_aes_ctx *aesctx, static void drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
unsigned char *out, const unsigned char *key, unsigned char *out, const unsigned char *key,
struct list_head *in, struct list_head *in,
u8 blocklen_bytes, u8 blocklen_bytes,
u8 keylen) u8 keylen)
{ {
int ret = 0;
struct drbg_string *curr = NULL; struct drbg_string *curr = NULL;
struct drbg_string data; struct drbg_string data;
short cnt = 0; short cnt = 0;
@ -60,9 +56,7 @@ static int drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
/* 10.4.3 step 4.2 */ /* 10.4.3 step 4.2 */
if (blocklen_bytes == cnt) { if (blocklen_bytes == cnt) {
cnt = 0; cnt = 0;
ret = drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes); drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
if (ret)
return ret;
} }
out[cnt] ^= *pos; out[cnt] ^= *pos;
pos++; pos++;
@ -72,9 +66,7 @@ static int drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
} }
/* 10.4.3 step 4.2 for last block */ /* 10.4.3 step 4.2 for last block */
if (cnt) if (cnt)
ret = drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes); drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
return ret;
} }
/* /*
@ -124,7 +116,6 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
u8 blocklen_bytes, u8 blocklen_bytes,
u8 statelen) u8 statelen)
{ {
int ret = -EFAULT;
unsigned char L_N[8]; unsigned char L_N[8];
/* S3 is input */ /* S3 is input */
struct drbg_string S1, S2, S4, cipherin; struct drbg_string S1, S2, S4, cipherin;
@ -196,10 +187,8 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
*/ */
drbg_cpu_to_be32(i, iv); drbg_cpu_to_be32(i, iv);
/* 10.4.2 step 9.2 -- BCC and concatenation with temp */ /* 10.4.2 step 9.2 -- BCC and concatenation with temp */
ret = drbg_ctr_bcc(aesctx, temp + templen, K, &bcc_list, drbg_ctr_bcc(aesctx, temp + templen, K, &bcc_list,
blocklen_bytes, keylen); blocklen_bytes, keylen);
if (ret)
goto out;
/* 10.4.2 step 9.3 */ /* 10.4.2 step 9.3 */
i++; i++;
templen += blocklen_bytes; templen += blocklen_bytes;
@ -220,9 +209,7 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
* implicit as the key is only drbg_blocklen in size based on * implicit as the key is only drbg_blocklen in size based on
* the implementation of the cipher function callback * the implementation of the cipher function callback
*/ */
ret = drbg_kcapi_sym(aesctx, X, &cipherin, blocklen_bytes); drbg_kcapi_sym(aesctx, X, &cipherin, blocklen_bytes);
if (ret)
goto out;
blocklen = (blocklen_bytes < blocklen = (blocklen_bytes <
(bytes_to_return - generated_len)) ? (bytes_to_return - generated_len)) ?
blocklen_bytes : blocklen_bytes :
@ -232,13 +219,10 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
generated_len += blocklen; generated_len += blocklen;
} }
ret = 0;
out:
memset(iv, 0, blocklen_bytes); memset(iv, 0, blocklen_bytes);
memset(temp, 0, statelen + blocklen_bytes); memset(temp, 0, statelen + blocklen_bytes);
memset(pad, 0, blocklen_bytes); memset(pad, 0, blocklen_bytes);
return ret; return 0;
} }
EXPORT_SYMBOL_GPL(crypto_drbg_ctr_df); EXPORT_SYMBOL_GPL(crypto_drbg_ctr_df);