Skip to content

ESP32: RSA, SHA fixes#5592

Merged
MabezDev merged 5 commits into
esp-rs:mainfrom
bugadani:esp32-sha
May 26, 2026
Merged

ESP32: RSA, SHA fixes#5592
MabezDev merged 5 commits into
esp-rs:mainfrom
bugadani:esp32-sha

Conversation

@bugadani
Copy link
Copy Markdown
Contributor

@bugadani bugadani commented May 22, 2026

Fixes #5584 and applies #5443 for ESP32 as well

Changelog

esp-hal/SHA

  • Fixed: ESP32 implementation no longer powers down the SHA accelerator while in use
  • Fixed: ESP32 no longer tries to use the hardware accelerator when it's held by another SHA operation.

esp-hal/RSA

  • Fixed: ESP32 now correctly disables its interrups before disabling the RSA accelerator

Copilot AI review requested due to automatic review settings May 22, 2026 08:27
@bugadani bugadani added the esp-hal-backport Backport this PR to the latest esp-hal-x.y.x branch.” label May 22, 2026
@bugadani
Copy link
Copy Markdown
Contributor Author

/hil full --test crypto

@bugadani
Copy link
Copy Markdown
Contributor Author

I will reorganize the tests in a later PR to prevent similar issues, this PR is minimal for backporting reasons.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

Triggered full HIL run for #5592.

Run: https://github.com/esp-rs/esp-hal/actions/runs/26277245978

Status update: ❌ HIL (full) run failed (conclusion: failure).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses incorrect multi-block SHA digests on ESP32 by ensuring the SHA peripheral is not powered down between work-queue operations when a digest context relies on the hardware’s internal state (since ESP32 can’t restore saved hash state). It also adjusts the SHA HIL test to avoid holding the SHA peripheral resources in a way that could mask the bug.

Changes:

  • ESP32: introduce an Esp32Hasher wrapper so a hardware-backed context holds a GenericPeripheralGuard to keep SHA powered while the context is alive.
  • ESP32: update ShaContext to use Esp32Hasher (hardware vs software fallback) and gate update/finalize accordingly.
  • HIL test: drop the Sha driver from the test Context before starting a ShaBackend, allowing the backend to manage peripheral resources.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
esp-hal/src/sha.rs Adds an ESP32-specific hasher wrapper that keeps the SHA peripheral clock enabled for hardware-backed contexts to preserve internal hash state across operations.
hil-test/src/bin/crypto/sha.rs Drops the Sha driver in the interleaving test to ensure the backend can release/acquire SHA resources as intended during the test.

Comment thread esp-hal/src/sha.rs Outdated
Comment thread esp-hal/src/sha.rs Outdated
Copilot AI review requested due to automatic review settings May 22, 2026 08:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread esp-hal/src/sha.rs
@bugadani bugadani changed the title Prevent ESP32 SHA powering down mid-operation ESP32: RSA, SHA fixes May 22, 2026
Copilot AI review requested due to automatic review settings May 22, 2026 11:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread esp-hal/src/rsa/mod.rs
Comment thread hil-test/src/bin/crypto/sha.rs
Comment thread esp-hal/src/sha.rs
@bugadani
Copy link
Copy Markdown
Contributor Author

/hil esp32 --test crypto

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

Triggered HIL run for #5592 (chips: esp32).

Run: https://github.com/esp-rs/esp-hal/actions/runs/26443574290

Status update: ✅ HIL (per-chip) run succeeded.

Copy link
Copy Markdown
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Thanks!

@MabezDev MabezDev added this pull request to the merge queue May 26, 2026
Merged via the queue into esp-rs:main with commit 72d44d0 May 26, 2026
25 checks passed
@github-actions
Copy link
Copy Markdown

Created backport PR for esp-hal-1.1.x:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin backport-5592-to-esp-hal-1.1.x
git worktree add --checkout .worktree/backport-5592-to-esp-hal-1.1.x backport-5592-to-esp-hal-1.1.x
cd .worktree/backport-5592-to-esp-hal-1.1.x
git reset --hard HEAD^
git cherry-pick -x 72d44d0721677f07b35bcdcb716943f56e7b66f6
git push --force-with-lease

@bugadani bugadani deleted the esp32-sha branch May 26, 2026 17:58
MabezDev pushed a commit that referenced this pull request May 29, 2026
* Prevent ESP32 SHA powering down mid-operation

* Only clear HW accelerator flag if the hardware-using context is dropped

* Rename field

* Fix RSA on ESP32

* Allow large enum variant lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

esp-hal-backport Backport this PR to the latest esp-hal-x.y.x branch.”

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ShaBackend: incorrect digest for multi-block messages on ESP32

3 participants