Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Reported tests cover only 8-bit-char hosts, leaving digit copying, shifting, and zeroization unverified on TI C28x after the cryptographic buffer-length changes.
No open issues 🎉
What changed in this PR
This PR corrects SP integer memory-operation sizes on targets with characters wider than 8 bits, such as TI C28x, while preserving behavior on 8-bit-character targets.
Changes:
- Separates digit sizes in character units (
SP_WORD_SIZEOF) from octet counts (SP_WORD_OCTETS). - Updates octet-based calculations and alignment declarations to use
SP_WORD_OCTETS. - Adds a compile-time check that
SP_WORD_SIZEOFmatchessizeof(sp_int_digit).
| File | Description |
|---|---|
wolfssl/wolfcrypt/sp_int.h |
Defines separate size macros, updates alignment, and adds a static assertion. |
wolfcrypt/test/test.c |
Keeps the oversized-input test expressed in octets. |
wolfcrypt/src/sp_int.c |
Uses octet counts for binary conversion and digit-capacity calculations. |
Review effort: Balanced
|
f8b0ff4 to
5acc102
Compare
5acc102 to
6f0da66
Compare
6f0da66 to
9acbfce
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The secure-erasure and memory-boundary changes on 16-bit-char targets need maintainer validation of the new canary tests with the C28x toolchain/runtime, since supplied results cover only 8-bit-char hosts.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
9acbfce to
0cd364c
Compare
…wider than 8 bits
0cd364c to
6ed5c35
Compare
|
Retest this please |
1 similar comment
|
Retest this please |

Description
SP_WORD_SIZEOFholds the number of octets in an SP digit. This is confusing, because its name suggests a size incharunits, likesizeof.SP_WORD_SIZEOFwas also used with two meanings: as a count of octets and as a size incharunits. Functions such assp_read_unsigned_bin()andsp_to_unsigned_bin_len_ct()work with octets, while memory functions such asForceZero(),XMEMCPY(),XMEMMOVE()andXMEMSET()take a size incharunits.This is not a problem on targets with an 8-bit
char, where the two values are the same. On targets with a 16-bitchar, such as the TI C28x, they differ. For example, withSP_WORD_SIZE32:char:SP_WORD_SIZEOFis 4 (octets) andsizeof(sp_int_digit)is 4 (chars).char:SP_WORD_SIZEOFis 4 (octets) andsizeof(sp_int_digit)is 2 (chars).As a result, the memory function calls cover twice the intended region on such targets. For example,
sp_forcezero()zeroes memory past the end ofdp[].Fixes ZD#22792
Changes
Replace
SP_WORD_SIZEOFin wolfSSL according to how it is used:XALIGNED()and preprocessor conditionals: use the newSP_WORD_OCTETS. It is an integer literal, so it can be used inXALIGNED()and#if.ForceZero(),XMEMCPY(),XMEMMOVE(),XMEMSET()): usesizeof(sp_int_digit).SP_WORD_SIZEOFremains only as a deprecated alias ofSP_WORD_OCTETS. It is kept mainly for FIPS test code maintained outside of the wolfSSL repository, and also for user code. It is only defined where acharis 8 bits, where the two meanings agree, and it is not available when building wolfSSL itself.Testing
--enable-cryptonly --enable-sp-math-all --enable-ecc --disable-sp-asm:CFLAGS="-DSP_WORD_SIZE=32 -DWOLFSSL_SP_INT_NEGATIVE":testwolfcryptpasses.SP_WORD_SIZE(64):testwolfcryptpasses.Checklist