-
Notifications
You must be signed in to change notification settings - Fork 892
[crypto] Harden hardened_xor
function
#28085
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
Conversation
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 @nasahlpa this looks nice!
534e75f
to
e5c31ca
Compare
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 Pascal! I checked the last two commits. One share should not overwrite the other anymore. I also compared the loop to the existing hardened_memcpy
implementation.
I also left two questions. But this looks good.
e5c31ca
to
5e5592d
Compare
5e5592d
to
960d3fd
Compare
Rename this function to hardend_xor_in_place as the next commit introduces a hardened_xor that does not store the result in-place. Signed-off-by: Pascal Nasahl <[email protected]>
960d3fd
to
51127d4
Compare
Takes `x` and `y` and writes `x ^ y` to the `dest` output buffer. To avoid combining `x` and `y` in the XOR operation, the function actually performs: `dest = ((rand ^ x) ^ y) ^ rand` Closes lowRISC#28008 Signed-off-by: Pascal Nasahl <[email protected]>
With the previous hardend_xor implementation, we were overriding share0 with share1, which leaks. By using the improved hardened_xor, we avoiding this issue. Signed-off-by: Pascal Nasahl <[email protected]>
51127d4
to
b126c26
Compare
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin earlgrey_1.0.0
git worktree add -d .worktree/backport-28085-to-earlgrey_1.0.0 origin/earlgrey_1.0.0
cd .worktree/backport-28085-to-earlgrey_1.0.0
git switch --create backport-28085-to-earlgrey_1.0.0
git cherry-pick -x 542beff0988afcfc65f8fb501beed186600a8544 54116843ab4dc031f04e6cfc3e2452fff6980a74 b126c26037688f186230539c47165d4f7fb6b9b3 |
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin earlgrey_1.0.0
git worktree add -d .worktree/backport-28085-to-earlgrey_1.0.0 origin/earlgrey_1.0.0
cd .worktree/backport-28085-to-earlgrey_1.0.0
git switch --create backport-28085-to-earlgrey_1.0.0
git cherry-pick -x 542beff0988afcfc65f8fb501beed186600a8544 54116843ab4dc031f04e6cfc3e2452fff6980a74 b126c26037688f186230539c47165d4f7fb6b9b3 |
This PR improves the
hardened_xor
function.In the previous version of this function, when passing two shares of a secret variable to it, one share was overwritten with the other share, which leaks.
The new function now performs:
dest = ((x ^ rand) ^ y) ^ rand
This looks like the following in assembly:
The first commit in this PR belongs to #27984