curve: use subtle::BlackBox
optimization barrier
#662
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaces the security mitigation added in #659 and #661 for masking-related timing variability which used an inline
black_box
using the recently addedsubtle::BlackBox
newtype (see dalek-cryptography/subtle#123)Internally
BlackBox
uses a volatile read by default (i.e. same strategy which was used before) or when thecore_hint_black_box
feature ofsubtle
is enabled, it usescore::hint::black_box
(whose documentation was recently updated to reflect the nuances of potential cryptographic use, see rust-lang/rust#126703)This PR goes ahead and uses
BlackBox
for bothmask
andunderflow_mask
where previously it was only used onunderflow_mask
. The general pattern of bitwise masking inside a loop seems worrisome for the optimizer potentially inserting branches in the future.Below are godbolt inspections of the generated assembly, which are free of the
jns
instructions originally spotted in #659/#661: