-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[otbn/rsa] Add SCA hardening for sel_sqr_or_sqrmul #25300
Conversation
This commit hardens two sources of leakage - DMEM writeback: The selected temporary result, either sqr or sqrmul depending on the current exponent bit, is written to the DMEM. At this DMEM address the sqr result is stored. In the case of selecting the sqr result the HD of the selected result and the DMEM value is zero and in the other case a high value. This allows to distinguish exponent bits. The hardening overwrites the value at the DMEM address with a random value. - SEL instruction: BN.SEL selects one of the two source WDRs based on the carry flag. The selection depends on the current exponent bit. This allows to distinguish exponent bits. The hardening randomizes the WDRs which contain the sqr or sqrmul results. The randomization is performed for each limb. Signed-off-by: Johann Heyszl <[email protected]> Signed-off-by: Alexander Wagner <[email protected]>
f86681c
to
525b1de
Compare
@aewag and I worked on this fix. It effectively prevents a leak that was uncovered in pentesting. Alex also tested that it maintains correct function. More thoughts welcome @jadephilipoom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
co-developed and approve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for hardening this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this and the clear commit messages and comments in the code! Nice work!
Before merging this we should also get @jadephilipoom 's feedback I think.
Thanks for the contribution. I have a few questions/concerns:
|
Just to be more precise about what I mean asking about
If this is just a matter of stylistic preference and it seemed nicer to use the indirect registers, that's fine -- just trying to understand the rationale from the PR description about the the select instruction. |
@jadephilipoom is there a reason you switch x9 vs. x11 when loading the two select candidates? Otherwise let's try this:
|
Nope, looks like a bug on my part. Thanks for the catch! |
Johann let me know over slack that this snippet still produced incorrect answers, so I debugged it properly and can verify that this version passes the full
|
nice, yes this makes a lot of sense hehe. I stared at the code quite long but understand how I missed it :) |
This has been addressed through #25694 and can be closed. |
Thanks @jadephilipoom for the collaboration and offline chats along the way - I see #25694 is now merged, which basically applies our public coding guidelines to bring this code up to speed and it passes testing. Great example for OT project collab. |
As I cannot add reviewers I link you @jadephilipoom @johannheyszl @vogelpi
This commit hardens two sources of leakage
EDIT:
Grep into OTBN ISA SIM log to show functionality