|
| 1 | +# TI C2000 C28x (CHAR_BIT == 16) support |
| 2 | + |
| 3 | +wolfCrypt builds and runs on the TI C2000 C28x DSP family, a word-addressed |
| 4 | +architecture where `CHAR_BIT == 16` (a C `char`/`unsigned char` is 16 bits and |
| 5 | +is the smallest addressable unit). Support is gated behind `WOLFSSL_WIDE_BYTE`, |
| 6 | +which `wolfssl/wolfcrypt/types.h` auto-enables when `CHAR_BIT != 8` or a known |
| 7 | +16-bit-char TI toolchain macro is seen (`__TMS320C28XX__`, `__TMS320C2000__`, |
| 8 | +etc.). On normal 8-bit-byte targets none of this code changes behavior. |
| 9 | + |
| 10 | +## Validated on hardware (LAUNCHXL-F28P55X, TMS320F28P550SJ, cl2000) |
| 11 | + |
| 12 | +- SHA-224/256, SHA-384/512, SHA-512/224, SHA-512/256 |
| 13 | +- SHA3-224/256/384/512, SHAKE128/256 (split-64 Keccak permutation for |
| 14 | + `WC_16BIT_CPU`, ~53% faster than the generic C path) |
| 15 | +- ML-DSA-87 (Dilithium) verify and full keygen/sign/verify; ML-KEM-768 (FIPS 203) |
| 16 | +- AES-128/192/256 CBC/CTR/CFB/GCM; AES-CMAC, AES-CCM, AES-GMAC |
| 17 | +- HMAC + HKDF; ChaCha20-Poly1305; Poly1305 |
| 18 | +- X25519 + Ed25519; ECDSA + ECDH (SECP256R1, SP math) |
| 19 | +- RSA-2048 PKCS#1 v1.5 verify (SP math) |
| 20 | + |
| 21 | +## What `WOLFSSL_WIDE_BYTE` fixes |
| 22 | + |
| 23 | +The `CHAR_BIT != 8` work falls into a few recurring classes, each a no-op on |
| 24 | +8-bit targets: |
| 25 | + |
| 26 | +- Byte/word aliasing. Serializing a `word32`/`word64` via a `byte*` cast moves |
| 27 | + cells, not octets. Replaced with shift-based octet I/O. Shared helpers live in |
| 28 | + `wolfcrypt/src/misc.c`: `WordsFromBytesBE32`/`BytesFromWordsBE32`, |
| 29 | + `BytesFromWordsLE32`, the 64-bit variants, and octet-correct |
| 30 | + `readUnalignedWord32`/`readUnalignedWord64`. `sp_int.c sp_read_unsigned_bin` |
| 31 | + uses the endian-/`CHAR_BIT`-agnostic shift loop for its leftover bytes. |
| 32 | +- `(byte)x` not truncating to an octet (it keeps 16 bits). Masked with |
| 33 | + `WC_OCTET(x)` = `(byte)((x) & 0xFF)` (types.h). Used across the ML-KEM/ML-DSA |
| 34 | + encoders, the SP `*_to_bin` serializers, AES `GETBYTE`, base64, and DRBG. |
| 35 | +- Integer-promotion bugs. `1U << n` is 16-bit on C28x (use `1UL`); a bit width |
| 36 | + written `sizeof(t) * 8` is wrong when `CHAR_BIT != 8` (use `CHAR_BIT * |
| 37 | + sizeof(t)`); a `byte` operand promotes to a 16-bit `int`. |
| 38 | +- `sizeof` counting cells, not octets. e.g. `CHACHA_CHUNK_BYTES` is `16 * 4`, |
| 39 | + not `16 * sizeof(word32)` (= 32 on C28x, which halves the ChaCha block). |
| 40 | + |
| 41 | +The SP backend file `wolfcrypt/src/sp_c32.c` is generated; the `& 0xFF` octet |
| 42 | +masks added to its `sp_*_to_bin_*` serializers should be folded into the SP |
| 43 | +generator templates for a permanent upstream fix. |
| 44 | + |
| 45 | +## Enabling on your build |
| 46 | + |
| 47 | +Define a user-settings header (see `IDE/C2000/user_settings.h` for a |
| 48 | +minimal CHAR_BIT!=8 config) and build with `WOLFSSL_USER_SETTINGS`. For the SP |
| 49 | +math backend on a 16-bit-int target also set `WOLFSSL_SP_MATH`, |
| 50 | +`SP_WORD_SIZE 32`, and `WOLFSSL_SP_ALLOW_16BIT_CPU`. |
| 51 | + |
| 52 | +## Reference example |
| 53 | + |
| 54 | +A complete bare-metal example with KATs, benchmark, linker scripts, and per- |
| 55 | +algorithm build toggles is in wolfSSL Examples: |
| 56 | +`embedded/ti-c2000-f28p55x/` (see its `README.md` for the `make` options: |
| 57 | +`ECC`, `MLKEM`, `AES`, `AESEXTRA`, `X25519`, `HKDF`, `CHACHA`, `RSA`, `SIGN`, |
| 58 | +`BENCH`). |
| 59 | + |
| 60 | +Representative throughput on the F28P55X at 150 MHz: SHA-256 ~284 KiB/s; SHA3-256 |
| 61 | +~264 KiB/s; SHAKE128 ~319 KiB/s; RNG Hash-DRBG ~122 KiB/s. ML-DSA-87 verify |
| 62 | +~225 ms/op in ~10.7 KB RAM (zero heap, with `WOLFSSL_MLDSA_VERIFY_SMALLEST_MEM` |
| 63 | ++ `WOLFSSL_MLDSA_ASSIGN_KEY`). |
| 64 | + |
| 65 | +## Continuous integration |
| 66 | + |
| 67 | +`IDE/C2000/compile.sh` runs `cl2000 --compile_only` over the |
| 68 | +`CHAR_BIT != 8` wolfCrypt subset to guard these paths without hardware; |
| 69 | +`.github/workflows/ti-c2000-compile.yml` runs it in CI (it fetches/caches the |
| 70 | +TI C2000 code generation tools). |
0 commit comments