]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: drbg - make drbg_{ctr_bcc,kcapi_sym}() return *void*
authorKarina Yankevich <k.yankevich@omp.ru>
Wed, 24 Sep 2025 21:00:10 +0000 (00:00 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 17 Oct 2025 08:10:27 +0000 (16:10 +0800)
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>
crypto/df_sp80090a.c

index bad38c267180ac806c317e16658604071affd187..dc63b31a93fc2daff63fc8fe4bc9aa56e78eacf8 100644 (file)
 static void drbg_kcapi_symsetkey(struct crypto_aes_ctx *aesctx,
                                 const unsigned char *key,
                                 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,
                                 const unsigned char *key, u8 keylen)
 {
        aes_expandkey(aesctx, key, 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_sym(struct crypto_aes_ctx *aesctx,
+                          unsigned char *outval,
+                          const struct drbg_string *in, u8 blocklen_bytes)
 {
        /* there is only component in *in */
        BUG_ON(in->len < blocklen_bytes);
        aes_encrypt(aesctx, outval, in->buf);
-       return 0;
 }
 
 /* BCC function for CTR DRBG as defined in 10.4.3 */
 
-static int drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
-                       unsigned char *out, const unsigned char *key,
-                       struct list_head *in,
-                       u8 blocklen_bytes,
-                       u8 keylen)
+static void drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
+                        unsigned char *out, const unsigned char *key,
+                        struct list_head *in,
+                        u8 blocklen_bytes,
+                        u8 keylen)
 {
-       int ret = 0;
        struct drbg_string *curr = NULL;
        struct drbg_string data;
        short cnt = 0;
@@ -60,9 +56,7 @@ static int drbg_ctr_bcc(struct crypto_aes_ctx *aesctx,
                        /* 10.4.3 step 4.2 */
                        if (blocklen_bytes == cnt) {
                                cnt = 0;
-                               ret = drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
-                               if (ret)
-                                       return ret;
+                               drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
                        }
                        out[cnt] ^= *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 */
        if (cnt)
-               ret = drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
-
-       return ret;
+               drbg_kcapi_sym(aesctx, out, &data, blocklen_bytes);
 }
 
 /*
@@ -124,7 +116,6 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
                       u8 blocklen_bytes,
                       u8 statelen)
 {
-       int ret = -EFAULT;
        unsigned char L_N[8];
        /* S3 is input */
        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);
                /* 10.4.2 step 9.2 -- BCC and concatenation with temp */
-               ret = drbg_ctr_bcc(aesctx, temp + templen, K, &bcc_list,
-                                  blocklen_bytes, keylen);
-               if (ret)
-                       goto out;
+               drbg_ctr_bcc(aesctx, temp + templen, K, &bcc_list,
+                            blocklen_bytes, keylen);
                /* 10.4.2 step 9.3 */
                i++;
                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
                 * the implementation of the cipher function callback
                 */
-               ret = drbg_kcapi_sym(aesctx, X, &cipherin, blocklen_bytes);
-               if (ret)
-                       goto out;
+               drbg_kcapi_sym(aesctx, X, &cipherin, blocklen_bytes);
                blocklen = (blocklen_bytes <
                                (bytes_to_return - generated_len)) ?
                            blocklen_bytes :
@@ -232,13 +219,10 @@ int crypto_drbg_ctr_df(struct crypto_aes_ctx *aesctx,
                generated_len += blocklen;
        }
 
-       ret = 0;
-
-out:
        memset(iv, 0, blocklen_bytes);
        memset(temp, 0, statelen + blocklen_bytes);
        memset(pad, 0, blocklen_bytes);
-       return ret;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(crypto_drbg_ctr_df);