Skip to contentSkip to conversation

crypto: ecc - Fix off-by-one missing to clear most significant digit

PATCH In review Stefan Berger 3 participants 3 messages Jun 13, 2024 – Jun 16, 2024

Subsystems (3)
lore
Share & tools
lore

Stefan Berger

author reviewer
#0 lore raw

PATCH 1/1 crypto: ecc - Fix off-by-one missing to clear most significant digit

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.

Fixes 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
---
 crypto/ecc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/ecc.c +1 -1
index fe761256e335..dd48d9928a21 100644
@@ -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) {
Signature · 1 line
2.44.0
Tested-by on v1 1/1
#1 lore raw

Tested with the proposed patch and issue is fixed.

Regards,

Venkat.

Quoted 28 lines · Stefan Berger

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.

Fixes 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
---
  crypto/ecc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
crypto/ecc.c +1 -1
index fe761256e335..dd48d9928a21 100644
@@ -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) {
maintainer
#2 lore raw
In reply to Stefan Berger
Quoted 7 lines · Stefan Berger

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.

Quoted 7 lines
Fixes 2fd2a82ccbfc ("crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array")
---
 crypto/ecc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt