@@ -109,6 +109,9 @@ void sc_reduce(byte* s)
109109{
110110 sword64 t[24];
111111 sword64 carry;
112+ #ifdef WOLFSSL_WIDE_BYTE
113+ int i;
114+ #endif
112115
113116 t[ 0] = MASK_21 & (load_3(s + 0) >> 0);
114117 t[ 1] = MASK_21 & (load_4(s + 2) >> 5);
@@ -296,6 +299,12 @@ void sc_reduce(byte* s)
296299 s[29] = (byte)(t[11] >> 1);
297300 s[30] = (byte)(t[11] >> 9);
298301 s[31] = (byte)(t[11] >> 17);
302+ #ifdef WOLFSSL_WIDE_BYTE
303+ /* CHAR_BIT != 8: a (byte) cast does not truncate to an octet, so mask each
304+ * output cell to its low 8 bits (the intended octet computed above). */
305+ for (i = 0; i < 32; i++)
306+ s[i] = WC_OCTET(s[i]);
307+ #endif
299308}
300309
301310/*
@@ -313,6 +322,9 @@ void sc_muladd(byte* s, const byte* a, const byte* b, const byte* c)
313322 word32 ad[12], bd[12], cd[12];
314323 sword64 t[24];
315324 sword64 carry;
325+ #ifdef WOLFSSL_WIDE_BYTE
326+ int i;
327+ #endif
316328
317329 ad[ 0] = MASK_21 & (load_3(a + 0) >> 0);
318330 ad[ 1] = MASK_21 & (load_4(a + 2) >> 5);
@@ -616,6 +628,12 @@ void sc_muladd(byte* s, const byte* a, const byte* b, const byte* c)
616628 s[29] = (byte)(t[11] >> 1);
617629 s[30] = (byte)(t[11] >> 9);
618630 s[31] = (byte)(t[11] >> 17);
631+ #ifdef WOLFSSL_WIDE_BYTE
632+ /* CHAR_BIT != 8: a (byte) cast does not truncate to an octet, so mask each
633+ * output cell to its low 8 bits (the intended octet computed above). */
634+ for (i = 0; i < 32; i++)
635+ s[i] = WC_OCTET(s[i]);
636+ #endif
619637}
620638#endif
621639#else
@@ -974,7 +992,10 @@ static unsigned char equal(unsigned char b,unsigned char c)
974992
975993static unsigned char negative(signed char b)
976994{
977- return ((unsigned char)b) >> 7;
995+ /* Want bit 7 (the 8-bit sign bit) as 0/1. An (unsigned char) cast does not
996+ * truncate to 8 bits where a byte is wider than an octet (C28x), so mask to
997+ * an octet first; WC_OCTET is a no-op on 8-bit targets. */
998+ return (unsigned char)(WC_OCTET(b) >> 7);
978999}
9791000
9801001static WC_INLINE void cmov(ge_precomp *t,const ge_precomp *u,unsigned char b,
0 commit comments