Skip to content

[base/hardened_memory] Add a hardened_add, hardened_sub, and hardened_range_check#29667

Merged
nasahlpa merged 2 commits intolowRISC:earlgrey_1.0.0from
siemen11:hardened_add
Apr 9, 2026
Merged

[base/hardened_memory] Add a hardened_add, hardened_sub, and hardened_range_check#29667
nasahlpa merged 2 commits intolowRISC:earlgrey_1.0.0from
siemen11:hardened_add

Conversation

@siemen11
Copy link
Copy Markdown
Contributor

@siemen11 siemen11 commented Apr 2, 2026

The OTBN calculates with shared keys using arithmetic masking. When we require the same operation on Ibex, we implement the hardened_add and the hardened_sub.
Note that due to the addition/subtraction nature, this loop is not randomized against SCA.
We also provide a range check function to check whether a buffer is between a value N and 0. Again, this is not hardened against SCA but it provides fault countermeasures.

Implement a test that the hardened_sub of the hardened_add comes back to the same result.
hardened_xor's test was missing, implement the same reversibility test for that as well.
Tests are also added for the range check.

@siemen11 siemen11 requested a review from a team as a code owner April 2, 2026 22:08
@siemen11 siemen11 requested review from andrea-caforio, johannheyszl and pamaury and removed request for a team and pamaury April 2, 2026 22:08
@siemen11 siemen11 added the CherryPick:master This PR should be cherry-picked to master label Apr 2, 2026
The OTBN calculates with shared keys using arithmetic masking. When we
require the same operation on Ibex, we implement the hardened_add and the
hardened_sub.
Note that due to the addition/subtraction nature, this loop is not
randomized against SCA.

Implement a test that the hardened_sub of the hardened_add comes back to
the same result.
hardened_xor's test was missing, implement the same reversibility test
for that as well.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 changed the title [base/hardened_memory] Add a hardened_add and hardened_sub [base/hardened_memory] Add a hardened_add, hardened_sub, and hardened_range_check Apr 4, 2026
@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Apr 6, 2026
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@andrea-caforio andrea-caforio left a comment

Choose a reason for hiding this comment

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

This is nice @siemen11. I will try to make use of these functions in the testcases for the ECC raw key import.

@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Apr 7, 2026
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Apr 7, 2026
Comment thread sw/device/lib/base/hardened_memory.h Outdated
Copy link
Copy Markdown
Contributor

@johannheyszl johannheyszl left a comment

Choose a reason for hiding this comment

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

Thanks @siemen11 this is helpful for some integrations.

Add a function that can check whether a value is between 0 and a given
value N. The function works on word buffers and is protected against
fault injections and is made to be constant time. However, the function
is not protected against side-channel attacks as it operates on
non-masked values.
The function expects buffers in little-endian format.

Signed-off-by: Siemen Dhooghe <sdhooghe@google.com>
@siemen11 siemen11 added the CI:Rerun Rerun failed CI jobs label Apr 9, 2026
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Apr 9, 2026
@nasahlpa nasahlpa merged commit 90c2380 into lowRISC:earlgrey_1.0.0 Apr 9, 2026
96 of 109 checks passed
@lowrisc-ci
Copy link
Copy Markdown

lowrisc-ci bot commented Apr 9, 2026

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

Labels

CherryPick:master This PR should be cherry-picked to master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants