Skip to content

Offload SHA-2, AES, the TRNG, ECC and RSA to the PolarFire SoC Athena engine - #12055

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

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

Conversation

@dgarske

@dgarske dgarske commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Description

The Athena F5200 port offloaded SHA-384 and AES-256-CTR. This extends it to what the engine and Microchip's CAL support, and fixes four problems outside the new handlers that the bare-metal builds depend on.

  • Hash: SHA-224, SHA-256, SHA-512 and SHA-512/t on the same engine context, copy and free handling as SHA-384. A SHA-512 family object is identified by its IV, since wolfCrypt reports every SHA-512/t update as SHA-512.
  • AES at all three key sizes: ECB, which carries XTS through _AesXtsHelper()'s bulk call; CBC; CTR; native GCM and GMAC; one-shot CMAC; RFC 3394 and RFC 5649 key wrap. WC_MPFS_ATHENA_AES_MIN_SZ keeps XTS's one-block tweak and tail calls in software. CAL moves GCM data and AAD in whole blocks, so other lengths go through a padded copy.
  • RNG: random.c's wc_GenerateSeed() reads the NRBG directly when the port is enabled, so every RNG is seeded from the engine whatever its devId (WC_MPFS_ATHENA_NO_RNG opts out, and a CUSTOM_RAND_GENERATE_SEED still takes precedence); WC_MPFS_ATHENA_RNG_DRBG also generates from the engine's DRBG.
  • ECDSA sign and verify, ECDH and EC key generation on P-192 to P-521, with the curve parameters taken from ecc.c's curve table, and the RSA CRT private operation. Private operations use the engine's countermeasure paths and purge the PKX afterwards; nonces are drawn before the hardware mutex is taken. RSA public operations are opt-in with WC_MPFS_ATHENA_RSA_PUBLIC, since with a small public exponent the engine is slower than software.
  • Anything wolfCrypt would reject after the callback, such as an all-zero ECDSA digest or an RSA input outside 1 < x < n - 1, or that the engine cannot do, is declined to software. Each family has a WC_MPFS_ATHENA_NO_* opt-out.
  • CTR counter carry: the engine increments only the low 32 bits of the counter block, so any stream crossing that boundary diverged from wc_AesCtrEncrypt(). Each transfer now stops at the wrap and aes->reg is advanced in software.
  • aes.c: the 64-bit GMULT() table path reads at odd offsets and had no WOLFSSL_USE_ALIGN guard, unlike the 32-bit path; a strict-alignment 64-bit target now takes the byte loop.
  • riscv-64-sha256-asm.S: the SHA-256 round constant tables were aligned to 4 bytes for the 8-byte ld loads that read them. Regenerated with the wolfSSL/scripts generator fix (wolfSSL/scripts#718).
  • benchmark.c: benchmark_free() clears the static-memory hint. With it kept, the next benchmark_init() partitioned the same pool again from its start, over the heap structures already there, so running the benchmark more than once, as wolfBoot's test-app does per call size, corrupted the free lists.
  • The known-answer self-test, wc_MpfsAthena_SelfTest(), is opt-in with WC_MPFS_ATHENA_SELFTEST.
  • configure.ac no longer requires SHA-384 and AES-CTR. CI compiles every configuration, with and without the self-test, in one job, and checks every CAL symbol against the archive; README.

Testing

MPFS250TS Video Kit, E51 bare metal under wolfBoot's test-app (wolfBoot PR 980): the port self-test and the full wolfcrypt_test() with every family on the engine, including RSA-2048 and all five NIST curves, and the benchmark against software C and the RISC-V assembly. Host: wolfcrypt_test() through the port under ASan and UBSan against a CAL stub that models the engine's transfers, block granularity and operand layout, single and multi-threaded; make check with --enable-all; every CI leg.

@dgarske dgarske self-assigned this Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +28 B, text +11,728 B (+4.2%, 294,228 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12055

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/mpfs-athena-compile.yml, configure.ac, wolfcrypt/src/port/microchip/README.md
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@dgarske
dgarske force-pushed the mpfs_athena_aesxts branch 3 times, most recently from 82a90b6 to 1e6ea49 Compare November 13, 2026 16:17
Copilot AI balanced review requested due to automatic review settings November 13, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The documented custom-seed configuration lacks a visible function prototype in random.c, causing strict builds to fail, while the custom-seed CI leg omits random.c and misses the failure.

1 open issue
What changed in this PR

This PR expands PolarFire SoC Athena integration for accelerated cryptography, including AES-ECB-backed XTS, and addresses strict-alignment issues affecting bare-metal RISC-V targets.

Changes:

  • Expands port declarations, configuration, and documentation for supported offloads.
  • Adds alignment-safe GCM multiplication and 8-byte alignment for SHA-256 constant tables.
  • Broadens compile-only CI coverage across algorithms and port configurations.
File Description
wolfssl/​wolfcrypt/​settings.h Clarifies hash-context ownership and software-fallback comments.
wolfssl/​wolfcrypt/​port/​microchip/​mpfs_athena.h Documents expanded capabilities and adds configuration macros and the entropy API declaration.
wolfcrypt/​src/​port/​riscv64/​riscv-64-sha256-asm.S Aligns three constant tables for 64-bit loads.
wolfcrypt/​src/​port/​microchip/​README.md Expands setup, offload coverage, XTS benchmarks, and hardware guidance.
wolfcrypt/​src/​aes.c Adds a byte-oriented GCM multiplication path for strict-alignment builds.
configure.ac Enables ECB automatically for Athena XTS builds and removes mandatory SHA-384/CTR checks.
.github/​workflows/​mpfs-athena-compile.yml Adds algorithm, RNG, memory, and opt-out compile configurations.

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12055

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/mpfs-athena-compile.yml, configure.ac, wolfcrypt/src/port/microchip/README.md, wolfcrypt/src/port/riscv64/riscv-64-sha256-asm.S
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfssl/wolfcrypt/settings.h Resolved
@dgarske dgarske changed the title Add AES-256-ECB to the PolarFire SoC Athena port for AES-XTS and carry its CTR counter past the engine's 32-bit wrap Extend the PolarFire SoC Athena port to the rest of SHA-2 and AES, the NRBG, ECC and RSA Nov 13, 2026
@dgarske
dgarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 13, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Repeated benchmark runs can leak or reinitialize a live static-memory heap mutex because the heap is not unloaded before its hint is cleared.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/benchmark/benchmark.c Resolved
Comment thread wolfcrypt/src/port/microchip/README.md Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12055

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs
Unchanged since last review (not re-run): wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/mpfs-athena-compile.yml, configure.ac, wolfcrypt/benchmark/benchmark.c, wolfcrypt/src/port/microchip/README.md, wolfcrypt/src/port/riscv64/riscv-64-sha256-asm.S
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

@dgarske
dgarske force-pushed the mpfs_athena_aesxts branch 2 times, most recently from 1707cd4 to f6fb35a Compare November 13, 2026 21:52
@dgarske
dgarske requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 13, 2026 22:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Clearing the static heap hint without unloading the pool leaks mutex resources across benchmark runs, and the NRBG completion guidance can lead callers to wait forever.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12055

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/mpfs-athena-compile.yml, configure.ac, wolfcrypt/benchmark/benchmark.c, wolfcrypt/src/port/microchip/README.md, wolfcrypt/src/port/riscv64/riscv-64-sha256-asm.S
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Lite

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself November 13, 2026 22:22

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@dgarske dgarske changed the title Extend the PolarFire SoC Athena port to the rest of SHA-2 and AES, the NRBG, ECC and RSA Offload SHA-2, AES, the TRNG, ECC and RSA to the PolarFire SoC Athena engine Nov 13, 2026
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.

3 participants