mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit
@ 2024-06-13 21:38 Stefan Berger
  2024-06-14  6:17 ` Venkat Rao Bagalkote
  2024-06-16  5:59 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Berger @ 2024-06-13 21:38 UTC (permalink / raw)
  To: keyrings, linux-crypto, herbert, davem
  Cc: linux-kernel, jarkko, Stefan Berger, Venkat Rao Bagalkote

Fix an off-by-one error where the most significant digit was not
initialized leading to signature verification failures by the testmgr.

Example: If a curve requires ndigits (=9) and diff (=2) indicates that
2 digits need to be set to zero then start with digit 'ndigits - diff' (=7)
and clear 'diff' digits starting from there, so 7 and 8.

Reported-by: Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>
Closes: https://lore.kernel.org/linux-crypto/619bc2de-b18a-4939-a652-9ca886bf6349@linux.ibm.com/T/#m045d8812409ce233c17fcdb8b88b6629c671f9f4
Fixes: 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 crypto/ecc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/ecc.c b/crypto/ecc.c
index fe761256e335..dd48d9928a21 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -78,7 +78,7 @@ void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
 	/* diff > 0: not enough input bytes: set most significant digits to 0 */
 	if (diff > 0) {
 		ndigits -= diff;
-		memset(&out[ndigits - 1], 0, diff * sizeof(u64));
+		memset(&out[ndigits], 0, diff * sizeof(u64));
 	}
 
 	if (o) {
-- 
2.44.0


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

* Re: [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit
  2024-06-13 21:38 [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit Stefan Berger
@ 2024-06-14  6:17 ` Venkat Rao Bagalkote
  2024-06-16  5:59 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Venkat Rao Bagalkote @ 2024-06-14  6:17 UTC (permalink / raw)
  To: Stefan Berger, keyrings, linux-crypto, herbert, davem
  Cc: linux-kernel, jarkko

Tested with the proposed patch and issue is fixed.


Tested-by: Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>

Regards,

Venkat.

On 14/06/24 3:08 am, Stefan Berger wrote:
> Fix an off-by-one error where the most significant digit was not
> initialized leading to signature verification failures by the testmgr.
>
> Example: If a curve requires ndigits (=9) and diff (=2) indicates that
> 2 digits need to be set to zero then start with digit 'ndigits - diff' (=7)
> and clear 'diff' digits starting from there, so 7 and 8.
>
> Reported-by: Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>
> Closes: https://lore.kernel.org/linux-crypto/619bc2de-b18a-4939-a652-9ca886bf6349@linux.ibm.com/T/#m045d8812409ce233c17fcdb8b88b6629c671f9f4
> Fixes: 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>   crypto/ecc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/crypto/ecc.c b/crypto/ecc.c
> index fe761256e335..dd48d9928a21 100644
> --- a/crypto/ecc.c
> +++ b/crypto/ecc.c
> @@ -78,7 +78,7 @@ void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
>   	/* diff > 0: not enough input bytes: set most significant digits to 0 */
>   	if (diff > 0) {
>   		ndigits -= diff;
> -		memset(&out[ndigits - 1], 0, diff * sizeof(u64));
> +		memset(&out[ndigits], 0, diff * sizeof(u64));
>   	}
>   
>   	if (o) {

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

* Re: [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit
  2024-06-13 21:38 [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit Stefan Berger
  2024-06-14  6:17 ` Venkat Rao Bagalkote
@ 2024-06-16  5:59 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2024-06-16  5:59 UTC (permalink / raw)
  To: Stefan Berger
  Cc: keyrings, linux-crypto, davem, linux-kernel, jarkko,
	Venkat Rao Bagalkote

On Thu, Jun 13, 2024 at 05:38:20PM -0400, Stefan Berger wrote:
> Fix an off-by-one error where the most significant digit was not
> initialized leading to signature verification failures by the testmgr.
> 
> Example: If a curve requires ndigits (=9) and diff (=2) indicates that
> 2 digits need to be set to zero then start with digit 'ndigits - diff' (=7)
> and clear 'diff' digits starting from there, so 7 and 8.
> 
> Reported-by: Venkat Rao Bagalkote <venkat88@linux.vnet.ibm.com>
> Closes: https://lore.kernel.org/linux-crypto/619bc2de-b18a-4939-a652-9ca886bf6349@linux.ibm.com/T/#m045d8812409ce233c17fcdb8b88b6629c671f9f4
> Fixes: 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>  crypto/ecc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

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] 3+ messages in thread

end of thread, other threads:[~2024-06-16  6:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 21:38 [PATCH] crypto: ecc - Fix off-by-one missing to clear most significant digit Stefan Berger
2024-06-14  6:17 ` Venkat Rao Bagalkote
2024-06-16  5:59 ` 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®