-
Notifications
You must be signed in to change notification settings - Fork 69
Expand integer trait #489
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
Merged
Merged
Expand integer trait #489
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
070dbd7
BoxedUint::bit_vartime and tests
xuganyu96 10974a6
trailing_ones and tests
xuganyu96 52f3344
decode_hex_byte should be shared in the crate
xuganyu96 5cfb093
Fallible from_be_hex implementation
xuganyu96 4e8b1ba
log2_bits
xuganyu96 f102b05
BoxedUint::is_nonzero
xuganyu96 2520df2
BoxedUint::cmp_vartime
xuganyu96 797274e
BoxedUint::wrapping_div_vartime
xuganyu96 4555f2a
BoxedUint's square roots
xuganyu96 65c09d4
BoxedUint::div_rem_limb_with_reciprocal and shl_limb
xuganyu96 ead807e
BoxedMontyForm::div_by_2
xuganyu96 41c4306
const expect for NonZero<Limb>
xuganyu96 cb1da6f
Cloning is inevitable at this moment
xuganyu96 a18c99e
div_by_2 for BoxedUint moved out of sub-module
xuganyu96 639ad58
Need to investigate performance
xuganyu96 f65f301
Reduntant test
xuganyu96 1e4a465
Mark todo for moving Repciprocal methods to ConstChoice
xuganyu96 8129546
Adopt 'Odd' struct
xuganyu96 5b2a02f
Gate relevant imports behind feature
xuganyu96 f3bfa39
Gate relevant imports behind feature
xuganyu96 002d55a
Gate relevant imports behind feature
xuganyu96 0fd00d6
Avoid branching
xuganyu96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,30 @@ use subtle::{ | |
Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess, | ||
}; | ||
|
||
impl BoxedUint { | ||
/// Returns the Ordering between `self` and `rhs` in variable time. | ||
pub fn cmp_vartime(&self, rhs: &Self) -> Ordering { | ||
debug_assert_eq!(self.limbs.len(), rhs.limbs.len()); | ||
let mut i = self.limbs.len() - 1; | ||
loop { | ||
// TODO: investigate if directly comparing limbs is faster than performing a | ||
// subtraction between limbs | ||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could short-circuit, so that's definitely a yes |
||
let (val, borrow) = self.limbs[i].sbb(rhs.limbs[i], Limb::ZERO); | ||
if val.0 != 0 { | ||
return if borrow.0 != 0 { | ||
Ordering::Less | ||
} else { | ||
Ordering::Greater | ||
}; | ||
} | ||
if i == 0 { | ||
return Ordering::Equal; | ||
} | ||
i -= 1; | ||
} | ||
} | ||
} | ||
|
||
impl ConstantTimeEq for BoxedUint { | ||
#[inline] | ||
fn ct_eq(&self, other: &Self) -> Choice { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
!self.is_zero()
is fine