mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point()
@ 2024-06-14  3:09 Jiapeng Chong
  2024-06-14  3:09 ` [PATCH] crypto: lib - Use swap() in mpi_powm() Jiapeng Chong
  2024-06-21 12:34 ` [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Jiapeng Chong @ 2024-06-14  3:09 UTC (permalink / raw)
  To: herbert; +Cc: davem, linux-crypto, linux-kernel, Jiapeng Chong, Abaci Robot

Use existing swap() function rather than duplicating its implementation.

./lib/crypto/mpi/ec.c:1291:20-21: WARNING opportunity for swap().
./lib/crypto/mpi/ec.c:1292:20-21: WARNING opportunity for swap().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9328
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 lib/crypto/mpi/ec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/crypto/mpi/ec.c b/lib/crypto/mpi/ec.c
index e16dca1e23d5..4781f00982ef 100644
--- a/lib/crypto/mpi/ec.c
+++ b/lib/crypto/mpi/ec.c
@@ -1285,14 +1285,12 @@ void mpi_ec_mul_point(MPI_POINT result,
 		sum = &p2_;
 
 		for (j = nbits-1; j >= 0; j--) {
-			MPI_POINT t;
-
 			sw = mpi_test_bit(scalar, j);
 			point_swap_cond(q1, q2, sw, ctx);
 			montgomery_ladder(prd, sum, q1, q2, point->x, ctx);
 			point_swap_cond(prd, sum, sw, ctx);
-			t = q1;  q1 = prd;  prd = t;
-			t = q2;  q2 = sum;  sum = t;
+			swap(q1, prd);
+			swap(q2, sum);
 		}
 
 		mpi_clear(result->y);
-- 
2.20.1.7.g153144c


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] crypto: lib - Use swap() in mpi_powm()
  2024-06-14  3:09 [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Jiapeng Chong
@ 2024-06-14  3:09 ` Jiapeng Chong
  2024-06-21 12:34   ` Herbert Xu
  2024-06-21 12:34 ` [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Jiapeng Chong @ 2024-06-14  3:09 UTC (permalink / raw)
  To: herbert; +Cc: davem, linux-crypto, linux-kernel, Jiapeng Chong, Abaci Robot

Use existing swap() function rather than duplicating its implementation.

./lib/crypto/mpi/mpi-pow.c:211:11-12: WARNING opportunity for swap().
./lib/crypto/mpi/mpi-pow.c:239:12-13: WARNING opportunity for swap().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9327
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 lib/crypto/mpi/mpi-pow.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/crypto/mpi/mpi-pow.c b/lib/crypto/mpi/mpi-pow.c
index 2fd7a46d55ec..67fbd4c2503d 100644
--- a/lib/crypto/mpi/mpi-pow.c
+++ b/lib/crypto/mpi/mpi-pow.c
@@ -176,7 +176,6 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 
 		for (;;) {
 			while (c) {
-				mpi_ptr_t tp;
 				mpi_size_t xsize;
 
 				/*if (mpihelp_mul_n(xp, rp, rp, rsize) < 0) goto enomem */
@@ -207,9 +206,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 					xsize = msize;
 				}
 
-				tp = rp;
-				rp = xp;
-				xp = tp;
+				swap(rp, xp);
 				rsize = xsize;
 
 				if ((mpi_limb_signed_t) e < 0) {
@@ -235,9 +232,7 @@ int mpi_powm(MPI res, MPI base, MPI exp, MPI mod)
 						xsize = msize;
 					}
 
-					tp = rp;
-					rp = xp;
-					xp = tp;
+					swap(rp, xp);
 					rsize = xsize;
 				}
 				e <<= 1;
-- 
2.20.1.7.g153144c


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point()
  2024-06-14  3:09 [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Jiapeng Chong
  2024-06-14  3:09 ` [PATCH] crypto: lib - Use swap() in mpi_powm() Jiapeng Chong
@ 2024-06-21 12:34 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2024-06-21 12:34 UTC (permalink / raw)
  To: Jiapeng Chong; +Cc: davem, linux-crypto, linux-kernel, Abaci Robot

On Fri, Jun 14, 2024 at 11:09:11AM +0800, Jiapeng Chong wrote:
> Use existing swap() function rather than duplicating its implementation.
> 
> ./lib/crypto/mpi/ec.c:1291:20-21: WARNING opportunity for swap().
> ./lib/crypto/mpi/ec.c:1292:20-21: WARNING opportunity for swap().
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9328
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  lib/crypto/mpi/ec.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)

Patch applied.  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] 4+ messages in thread

* Re: [PATCH] crypto: lib - Use swap() in mpi_powm()
  2024-06-14  3:09 ` [PATCH] crypto: lib - Use swap() in mpi_powm() Jiapeng Chong
@ 2024-06-21 12:34   ` Herbert Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2024-06-21 12:34 UTC (permalink / raw)
  To: Jiapeng Chong; +Cc: davem, linux-crypto, linux-kernel, Abaci Robot

On Fri, Jun 14, 2024 at 11:09:12AM +0800, Jiapeng Chong wrote:
> Use existing swap() function rather than duplicating its implementation.
> 
> ./lib/crypto/mpi/mpi-pow.c:211:11-12: WARNING opportunity for swap().
> ./lib/crypto/mpi/mpi-pow.c:239:12-13: WARNING opportunity for swap().
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9327
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  lib/crypto/mpi/mpi-pow.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)

Patch applied.  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] 4+ messages in thread

end of thread, other threads:[~2024-06-21 12:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-14  3:09 [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Jiapeng Chong
2024-06-14  3:09 ` [PATCH] crypto: lib - Use swap() in mpi_powm() Jiapeng Chong
2024-06-21 12:34   ` Herbert Xu
2024-06-21 12:34 ` [PATCH] crypto: lib/mpi - Use swap() in mpi_ec_mul_point() Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®