From 8f2ffd7b00c07f4da095dd8fa333ea1d114c5b63 Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 23 Oct 2026 16:48:31 -0700 Subject: [PATCH] Fix SP scalar recode to not depend on an 8-bit char --- wolfcrypt/src/sp_arm32.c | 6 +++--- wolfcrypt/src/sp_arm64.c | 14 +++++++------- wolfcrypt/src/sp_armthumb.c | 6 +++--- wolfcrypt/src/sp_c32.c | 8 ++++---- wolfcrypt/src/sp_c64.c | 8 ++++---- wolfcrypt/src/sp_cortexm.c | 6 +++--- wolfcrypt/src/sp_riscv64.c | 6 +++--- wolfcrypt/src/sp_x86_64.c | 14 +++++++------- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/wolfcrypt/src/sp_arm32.c b/wolfcrypt/src/sp_arm32.c index 528f33b52ae..7b19fdaec85 100644 --- a/wolfcrypt/src/sp_arm32.c +++ b/wolfcrypt/src/sp_arm32.c @@ -77335,7 +77335,7 @@ static void sp_256_ecc_recode_6_8(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -96225,7 +96225,7 @@ static void sp_384_ecc_recode_6_12(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -124265,7 +124265,7 @@ static void sp_521_ecc_recode_6_17(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; diff --git a/wolfcrypt/src/sp_arm64.c b/wolfcrypt/src/sp_arm64.c index d516f950b7a..d91647c5590 100644 --- a/wolfcrypt/src/sp_arm64.c +++ b/wolfcrypt/src/sp_arm64.c @@ -25891,7 +25891,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -29218,7 +29218,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<37; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -61623,7 +61623,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -64905,7 +64905,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<55; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -90286,7 +90286,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -94267,7 +94267,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<75; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -134315,7 +134315,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) n = k[j]; o = 0; for (i=0; i<147; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; diff --git a/wolfcrypt/src/sp_armthumb.c b/wolfcrypt/src/sp_armthumb.c index 69d91e17976..8f03409b472 100644 --- a/wolfcrypt/src/sp_armthumb.c +++ b/wolfcrypt/src/sp_armthumb.c @@ -102957,7 +102957,7 @@ static void sp_256_ecc_recode_6_8(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -114277,7 +114277,7 @@ static void sp_384_ecc_recode_6_12(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -128418,7 +128418,7 @@ static void sp_521_ecc_recode_6_17(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; diff --git a/wolfcrypt/src/sp_c32.c b/wolfcrypt/src/sp_c32.c index ed051a53e8a..3edd0cd1dd8 100644 --- a/wolfcrypt/src/sp_c32.c +++ b/wolfcrypt/src/sp_c32.c @@ -26175,7 +26175,7 @@ static void sp_256_ecc_recode_6_9(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 29) { y &= 0x3f; n >>= 6; @@ -33813,7 +33813,7 @@ static void sp_384_ecc_recode_6_15(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 26) { y &= 0x3f; n >>= 6; @@ -41516,7 +41516,7 @@ static void sp_521_ecc_recode_6_21(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 25) { y &= 0x3f; n >>= 6; @@ -50190,7 +50190,7 @@ static void sp_1024_ecc_recode_7_42(const sp_digit* k, ecc_recode_1024* v) n = k[j]; o = 0; for (i=0; i<147; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 25) { y &= 0x7f; n >>= 7; diff --git a/wolfcrypt/src/sp_c64.c b/wolfcrypt/src/sp_c64.c index e160e645834..93da67e2df6 100644 --- a/wolfcrypt/src/sp_c64.c +++ b/wolfcrypt/src/sp_c64.c @@ -27487,7 +27487,7 @@ static void sp_256_ecc_recode_6_5(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 52) { y &= 0x3f; n >>= 6; @@ -34590,7 +34590,7 @@ static void sp_384_ecc_recode_6_7(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 55) { y &= 0x3f; n >>= 6; @@ -42171,7 +42171,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 58) { y &= 0x3f; n >>= 6; @@ -49895,7 +49895,7 @@ static void sp_1024_ecc_recode_7_18(const sp_digit* k, ecc_recode_1024* v) n = k[j]; o = 0; for (i=0; i<147; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 57) { y &= 0x7f; n >>= 7; diff --git a/wolfcrypt/src/sp_cortexm.c b/wolfcrypt/src/sp_cortexm.c index 67db49f04dc..2c6b8a26b7c 100644 --- a/wolfcrypt/src/sp_cortexm.c +++ b/wolfcrypt/src/sp_cortexm.c @@ -42209,7 +42209,7 @@ static void sp_256_ecc_recode_6_8(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -53761,7 +53761,7 @@ static void sp_384_ecc_recode_6_12(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; @@ -67119,7 +67119,7 @@ static void sp_521_ecc_recode_6_17(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 32) { y &= 0x3f; n >>= 6; diff --git a/wolfcrypt/src/sp_riscv64.c b/wolfcrypt/src/sp_riscv64.c index fdcbeb5aaad..a4b1f4f85e1 100644 --- a/wolfcrypt/src/sp_riscv64.c +++ b/wolfcrypt/src/sp_riscv64.c @@ -41317,7 +41317,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -51998,7 +51998,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -62661,7 +62661,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; diff --git a/wolfcrypt/src/sp_x86_64.c b/wolfcrypt/src/sp_x86_64.c index 8c5487b0818..55aee80c519 100644 --- a/wolfcrypt/src/sp_x86_64.c +++ b/wolfcrypt/src/sp_x86_64.c @@ -9334,7 +9334,7 @@ static void sp_256_ecc_recode_6_4(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<43; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -11941,7 +11941,7 @@ static void sp_256_ecc_recode_7_4(const sp_digit* k, ecc_recode_256* v) n = k[j]; o = 0; for (i=0; i<37; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -28427,7 +28427,7 @@ static void sp_384_ecc_recode_6_6(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<65; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -31090,7 +31090,7 @@ static void sp_384_ecc_recode_7_6(const sp_digit* k, ecc_recode_384* v) n = k[j]; o = 0; for (i=0; i<55; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -53327,7 +53327,7 @@ static void sp_521_ecc_recode_6_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<87; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 6 < 64) { y &= 0x3f; n >>= 6; @@ -56091,7 +56091,7 @@ static void sp_521_ecc_recode_7_9(const sp_digit* k, ecc_recode_521* v) n = k[j]; o = 0; for (i=0; i<75; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7; @@ -94236,7 +94236,7 @@ static void sp_1024_ecc_recode_7_16(const sp_digit* k, ecc_recode_1024* v) n = k[j]; o = 0; for (i=0; i<147; i++) { - y = (word8)(int8_t)n; + y = (word8)(n & 0xff); if (o + 7 < 64) { y &= 0x7f; n >>= 7;