From 9fef016106ea8574bf8b84b1c3383ac169ac284c Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 22 Apr 2026 15:47:39 -0700 Subject: [PATCH 1/2] Fix W560 "possible truncation at implicit conversion to type unsigned char" warnings raised by Tasking compiler. --- src/tls13.c | 2 +- src/wolfio.c | 6 +++++- wolfcrypt/src/fe_low_mem.c | 18 +++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/tls13.c b/src/tls13.c index 824ad08b696..a3a6607e5b1 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -8577,7 +8577,7 @@ static WC_INLINE int DecodeTls13SigAlg(byte* input, byte* hashAlgo, break; #endif case NEW_SA_MAJOR: - *hashAlgo = GetNewSAHashAlgo(input[1]); + *hashAlgo = (byte)GetNewSAHashAlgo(input[1]); /* PSS encryption: 0x080[4-6] */ if (input[1] >= RSA_PSS_RSAE_SHA256_MINOR && diff --git a/src/wolfio.c b/src/wolfio.c index c6ffe7da11b..22a4e6ee6b2 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -3286,7 +3286,11 @@ int LwIPNativeSend(WOLFSSL* ssl, char* buf, int sz, void* ctx) err_t ret; WOLFSSL_LWIP_NATIVE_STATE* nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx; - ret = tcp_write(nlwip->pcb, buf, sz, TCP_WRITE_FLAG_COPY); + if (sz > UINT16_MAX || sz < 0) { + return BAD_FUNC_ARG; + } + + ret = tcp_write(nlwip->pcb, buf, (u16_t)sz, TCP_WRITE_FLAG_COPY); if (ret != ERR_OK) { sz = WOLFSSL_FATAL_ERROR; } diff --git a/wolfcrypt/src/fe_low_mem.c b/wolfcrypt/src/fe_low_mem.c index f1c5eddd340..61b88769043 100644 --- a/wolfcrypt/src/fe_low_mem.c +++ b/wolfcrypt/src/fe_low_mem.c @@ -546,7 +546,7 @@ void fe_load(byte *x, word32 c) word32 i; for (i = 0; i < sizeof(c); i++) { - x[i] = c; + x[i] = (byte)c; c >>= 8; } @@ -636,7 +636,7 @@ void lm_sub(byte* r, const byte* a, const byte* b) c = 218; for (i = 0; i + 1 < F25519_SIZE; i++) { c += 65280 + ((word32)a[i]) - ((word32)b[i]); - r[i] = c; + r[i] = (byte)c; c >>= 8; } @@ -646,7 +646,7 @@ void lm_sub(byte* r, const byte* a, const byte* b) for (i = 0; i < F25519_SIZE; i++) { c += r[i]; - r[i] = c; + r[i] = (byte)c; c >>= 8; } } @@ -661,7 +661,7 @@ void lm_neg(byte* r, const byte* a) c = 218; for (i = 0; i + 1 < F25519_SIZE; i++) { c += 65280 - ((word32)a[i]); - r[i] = c; + r[i] = (byte)c; c >>= 8; } @@ -671,7 +671,7 @@ void lm_neg(byte* r, const byte* a) for (i = 0; i < F25519_SIZE; i++) { c += r[i]; - r[i] = c; + r[i] = (byte)c; c >>= 8; } } @@ -693,7 +693,7 @@ void fe_mul__distinct(byte *r, const byte *a, const byte *b) c += ((word32)a[j]) * ((word32)b[i + F25519_SIZE - j]) * 38; - r[i] = c; + r[i] = (byte)c; } r[31] &= 127; @@ -701,7 +701,7 @@ void fe_mul__distinct(byte *r, const byte *a, const byte *b) for (i = 0; i < F25519_SIZE; i++) { c += r[i]; - r[i] = c; + r[i] = (byte)c; c >>= 8; } } @@ -724,7 +724,7 @@ void fe_mul_c(byte *r, const byte *a, word32 b) for (i = 0; i < F25519_SIZE; i++) { c >>= 8; c += b * ((word32)a[i]); - r[i] = c; + r[i] = (byte)c; } r[31] &= 127; @@ -733,7 +733,7 @@ void fe_mul_c(byte *r, const byte *a, word32 b) for (i = 0; i < F25519_SIZE; i++) { c += r[i]; - r[i] = c; + r[i] = (byte)c; c >>= 8; } } From c69d9693f017e6468fb5a47ef760e1e75632752c Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 22 Apr 2026 16:33:07 -0700 Subject: [PATCH 2/2] Fix code review feedback and test failure. --- src/tls13.c | 5 ++++- src/wolfio.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tls13.c b/src/tls13.c index a3a6607e5b1..8b49cc33bcf 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -8577,7 +8577,10 @@ static WC_INLINE int DecodeTls13SigAlg(byte* input, byte* hashAlgo, break; #endif case NEW_SA_MAJOR: - *hashAlgo = (byte)GetNewSAHashAlgo(input[1]); + { + enum wc_MACAlgorithm mac = GetNewSAHashAlgo(input[1]); + *hashAlgo = (byte)mac; + } /* PSS encryption: 0x080[4-6] */ if (input[1] >= RSA_PSS_RSAE_SHA256_MINOR && diff --git a/src/wolfio.c b/src/wolfio.c index 22a4e6ee6b2..e438e8fe7f5 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -3286,7 +3286,7 @@ int LwIPNativeSend(WOLFSSL* ssl, char* buf, int sz, void* ctx) err_t ret; WOLFSSL_LWIP_NATIVE_STATE* nlwip = (WOLFSSL_LWIP_NATIVE_STATE*)ctx; - if (sz > UINT16_MAX || sz < 0) { + if (sz < 0 || sz > (int)WOLFSSL_MAX_16BIT) { return BAD_FUNC_ARG; }