Skip to content

[crypto] Cleanup on failures#30181

Merged
nasahlpa merged 2 commits into
lowRISC:earlgrey_1.0.0from
siemen11:crypto_cleanup_logic
May 26, 2026
Merged

[crypto] Cleanup on failures#30181
nasahlpa merged 2 commits into
lowRISC:earlgrey_1.0.0from
siemen11:crypto_cleanup_logic

Conversation

@siemen11

@siemen11 siemen11 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Use the cleanup attribute in order to attach cleanup functions to a guard to cleanup the hardware. These functions are called when the variables go out of scope. Hence, we clear the hardware on both the succesful execution (as it was before) and on bad status output (which is new).

@andrea-caforio

Copy link
Copy Markdown
Contributor

This attribute generates some code in the background, if we have many of these, will it have an measurable impact on the code size?

@siemen11

siemen11 commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

This attribute generates some code in the background, if we have many of these, will it have an measurable impact on the code size?

Super good question, for the AES it's size went from 3928 bytes to 4028 bytes which means we are looking at a 2.5% increase

@siemen11 siemen11 force-pushed the crypto_cleanup_logic branch 4 times, most recently from 827f843 to e8f93ca Compare May 22, 2026 19:59
@siemen11

Copy link
Copy Markdown
Contributor Author

Argh, you are definitely correct. I see that GCM costs a lot more giving 600 bytes which is around an 8% increase in size to wipe everything

@siemen11 siemen11 force-pushed the crypto_cleanup_logic branch 4 times, most recently from 3cb4593 to a4f7dbe Compare May 23, 2026 15:16
Use the cleanup attribute in order to attach a guard to cleanup the hardware.
These functions are called when the variables go out of scope.
Hence, we clear the hardware on both the succesful execution (as it was before) and on bad status
output (which is new).

Apply this new setting to the AES, CMAC, and GCM where we split the driver to no longer
clean the HW when calling aes_end. Instead, we always call it from impl
(and users using the drivers still can manually call the clean in
drivers).

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 force-pushed the crypto_cleanup_logic branch from a4f7dbe to 69c4d28 Compare May 23, 2026 15:18
Clean the HMAC and KMAC also on errors by using a cleanup attribute.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 marked this pull request as ready for review May 23, 2026 15:58
@siemen11 siemen11 requested a review from a team as a code owner May 23, 2026 15:58
@siemen11 siemen11 requested review from alees24 and removed request for a team May 23, 2026 15:58
@siemen11

Copy link
Copy Markdown
Contributor Author

I instead refactored it to clean up the HW also on bad status returns. This was already the case for our PKE, but not yet for HMAC/KMAC/AES. This PR adds a total of 266 bytes of code, but gives meaningful protection

@siemen11 siemen11 removed the request for review from alees24 May 23, 2026 15:59
@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label May 24, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label May 24, 2026

@nasahlpa nasahlpa 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.

Nice - this is a great approach of making sure that we are properly cleaning the CL and its HW before releasing it.

@nasahlpa nasahlpa merged commit d8d4fb3 into lowRISC:earlgrey_1.0.0 May 26, 2026
67 of 70 checks passed
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