Skip to content
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

Expand integer trait #489

Merged
merged 22 commits into from
Dec 21, 2023
Merged

Conversation

xuganyu96
Copy link
Contributor

This is a another continuation of #436 after I lost track of where I overrode the master branch's changes.

Comment on lines 165 to 169
if err == 0 {
CtOption::new(Self { limbs: res.into() }, Choice::from(1))
} else {
CtOption::new(Self::zero_with_precision(bits_precision), Choice::from(0))
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err == 0 {
CtOption::new(Self { limbs: res.into() }, Choice::from(1))
} else {
CtOption::new(Self::zero_with_precision(bits_precision), Choice::from(0))
}
CtOption::new(Self { limbs: res.into() }, Choice::from((err == 0) as u8)

There may be a better way to construct the Choice, though I don't remember the possible values of err offhand

Comment on lines +99 to +102
// TODO: why not just !self.is_zero()?
self.limbs
.iter()
.fold(Choice::from(0), |acc, limb| acc | limb.is_nonzero().into())
Copy link
Member

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

Comment on lines +19 to +20
// TODO: investigate if directly comparing limbs is faster than performing a
// subtraction between limbs
Copy link
Member

Choose a reason for hiding this comment

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

It could short-circuit, so that's definitely a yes

Copy link
Member

@tarcieri tarcieri 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 fine aside from addressing some inline TODOs.

There are various allocations that could be optimized away in the boxed implementations but we can do that as a followup.

@tarcieri
Copy link
Member

I'm going to go ahead and land this since it's been so long in the tooth.

@xuganyu96 if you'd like to open some followups for those TODOs or optimizations, that'd be great.

@tarcieri tarcieri merged commit f9ef5aa into RustCrypto:master Dec 21, 2023
16 checks passed
@xuganyu96 xuganyu96 deleted the expand-integer-trait branch December 25, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants