[PATCH v2] crypto: tcrypt: avoid 32-bit overflow in throughput calculation

From: Artem Novak

Date: Thu Nov 26 2026 - 01:05:56 EST


Cast bcount to u64 before multiplying by blen to prevent 32-bit
overflow when calculating throughput on 32-bit architectures.

Fixes: beb63da739f7 ("crypto: tcrypt - Add speed tests for async hashing")

Signed-off-by: Artem Novak <artem122novak@xxxxxxxxx>
---
crypto/tcrypt.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e6834bdde9b9..1e6132045c24 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -28,6 +28,7 @@
#include <linux/interrupt.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/scatterlist.h>
@@ -734,6 +735,7 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
{
struct ahash_request *req = treq->req;
unsigned long start, end;
+ u64 bytes;
int bcount;
int ret;

@@ -744,8 +746,9 @@ static int test_ahash_jiffies_digest(struct tcrypt_ahash_request *treq,
return ret;
}

- pr_cont("%6u opers/sec, %9lu bytes/sec\n",
- bcount / secs, ((long)bcount * blen) / secs);
+ bytes = div_u64((u64)bcount * blen, secs);
+ pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+ bcount / secs, (unsigned long long)bytes);

return 0;
}
@@ -755,6 +758,7 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
{
struct ahash_request *req = treq->req;
unsigned long start, end;
+ u64 bytes;
int bcount, pcount;
int ret;

@@ -777,8 +781,9 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
return ret;
}

- pr_cont("%6u opers/sec, %9lu bytes/sec\n",
- bcount / secs, ((long)bcount * blen) / secs);
+ bytes = div_u64((u64)bcount * blen, secs);
+ pr_cont("%6u opers/sec, %9llu bytes/sec\n",
+ bcount / secs, (unsigned long long)bytes);

return 0;
}
--
2.56.1