Skip to content

Add ECDSA and SHA-384 image-verify timings to the TI C2000 example - #650

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:c28x_ecdsa_bench
Open

dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:c28x_ecdsa_bench

Conversation

@dgarske

@dgarske dgarske commented Oct 24, 2026

Copy link
Copy Markdown
Member

Adds ECC384=1 (SECP384R1), ECCFAST=1 (drops WOLFSSL_SP_SMALL for the windowed SP path) and ECCBENCH=1, which swaps the test and benchmark harness for ECDSA sign/verify, ECDH and SHA-256/SHA-384 image-hash timings over a flash-resident 128 KB array. The stock benchmark reports nothing for ECC here, because the example builds with NO_ASN and bench_ecc() compiles its ECDSA section out behind that macro. The README gains the resulting table. ECCFAST=1 needs the companion SP recode fix in wolfSSL/wolfssl#11889. Validated on a LAUNCHXL-F28P55X.

@dgarske dgarske self-assigned this Oct 24, 2026
@dgarske
dgarske marked this pull request as ready for review October 26, 2026 18:29
@dgarske
dgarske requested a review from aidangarske October 26, 2026 18:35

@aidangarske aidangarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skoll Code Review

Scan type: review

Overall recommendation: COMMENT
Findings: 5 total — 5 posted, 0 skipped
5 finding(s) posted as inline comments (see file-level comments below)

Posted findings

  • [Medium] P-384 lacks an independent correctness test — embedded/ti-c2000-f28p55x/Source/wolf_main.c:879-881
  • [Medium] Failed iterations still produce successful-operation timing figures — embedded/ti-c2000-f28p55x/Source/wolf_main.c:693-701,746-770,802-810,849-859
  • [Medium] The flash-image benchmark repeatedly hashes only a 4 KiB allocation — embedded/ti-c2000-f28p55x/Source/wolf_main.c:672-677
  • [Medium] The documented ECCFAST option omits its required wolfSSL dependency — embedded/ti-c2000-f28p55x/README.md:94
  • [Low] ECC_USER_CURVES comment still says P-256 only — embedded/ti-c2000-f28p55x/Header/user_settings.h:238

Review generated by Skoll

wolf_sha384_image_bench();
wolf_ecdsa_bench(ECC_SECP256R1, 32, 10, "P-256");
wolf_ecdh_bench(ECC_SECP256R1, 32, 10, "P-256");
#ifdef WOLF_ECC384

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P-384 lacks an independent correctness test

ECC384=1 enables a new curve on a target whose 16-bit-byte behavior requires explicit validation, but P-384 is only exercised by self-generated sign/verify operations and a one-sided ECDH call when ECCBENCH=1 is also set. Building with ECC384=1 alone does not execute P-384 at all. Unlike the existing P-256 path, there is no deterministic verification KAT or comparison of secrets derived in both ECDH directions, so matching defects or serialization errors can escape detection.

Fix: Add a P-384 deterministic ECDSA verification KAT and bidirectional ECDH agreement check, mirroring wolf_ecc_test(), and run them whenever WOLF_ECC384 is enabled.

return;
}
(void)current_time(1);
for (i = 0; i < WOLF_IMG_REPS; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed iterations still produce successful-operation timing figures

The ECC loops break when an operation fails but still print the configured reps and divide by that value. A failed verification with ret == 0 and res == 0 likewise reports all repetitions as completed. The hash loops accumulate errors with ret |= ..., continue using the failed context, call Final, and publish a timing. Runtime failures, including an entropy-source failure in an ENTROPY=1 build, therefore produce misleading operation counts and latency figures.

Fix: Stop each benchmark on the first error, track the number of completed operations, and only calculate latency from successful iterations. Do not finalize a hash context after an update failure.

/* Timings for a secure-boot style image check: hash an image-sized block, then
* one ECDSA verify. CPU Timer 0 is sampled every iteration so no single
* interval can outrun the counter's ~28 s wrap. */
#define WOLF_IMG_BLK 4096U /* octets fed per Update */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flash-image benchmark repeatedly hashes only a 4 KiB allocation

The code processes 128 KiB in total, but it does so by hashing the same 4 KiB flash allocation 32 times. It therefore does not exercise the address range or working-set behavior of the claimed 128 KiB flash-resident image. This matters because the benchmark specifically attributes the measurement to flash wait-state behavior. On this target, a real secure-boot image may also use the packed flash representation documented elsewhere in the README, while this array stores one octet per 16-bit C byte.

Fix: Either stream across an actual image-sized flash allocation, preferably using the production packed/unpack path, or label the result as hashing 128 KiB from a repeated 4 KiB unpacked flash block and justify why that is representative.

|---|---|
| `ECC=1` | ECDSA/ECDH over SECP256R1 (SP math) |
| `ECC384=1` | Adds SECP384R1 (`HAVE_ECC384` + `WOLFSSL_SP_384`) |
| `ECCFAST=1` | Drops `WOLFSSL_SP_SMALL` for the windowed SP path (~10x faster ECDSA, +30 KB flash for P-256) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented ECCFAST option omits its required wolfSSL dependency

The PR context states that ECCFAST=1 requires the companion SP recode fix in wolfSSL PR 11889, but the README presents the option without a minimum wolfSSL revision or prerequisite. Since WOLFROOT may point to another checkout, users can select the known-dependent windowed path and receive incorrect or unreproducible behavior.

Fix: Land the companion fix before this change, or document and, if possible, compile-time gate the required wolfSSL revision.

@@ -239,6 +239,13 @@ extern "C" {
#define ECC_USER_CURVES

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ECC_USER_CURVES comment still says P-256 only

The comment now contradicts the immediately following conditional P-384 configuration and can mislead future configuration changes.

Fix: Update the comment to describe both the mandatory P-256 curve and optional P-384 curve.

Suggestion:

Suggested change
#define ECC_USER_CURVES
#undef ECC_USER_CURVES /* build only the curves named below */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants