-
Notifications
You must be signed in to change notification settings - Fork 56
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
Int
- Bit ops
#697
Int
- Bit ops
#697
Conversation
e83d77c
to
8e3b710
Compare
pub const fn expect(self, msg: &str) -> Int<LIMBS> { | ||
assert!(self.is_some.is_true_vartime(), "{}", msg); | ||
self.value | ||
} |
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.
I copy-pasted this from ConstCtOption<Uint>
.
In doing so, I did notice that, although it uses is_true_vartime
, ConstCtOption<Uint>::expect
was not annotated as being vartime. Moreover, it is used for Uint::shr
and Uint::shl
, among others, which are not vartime either. Is this OK because unwraps are vartime anyway, or do we need to do something about this @tarcieri ?
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.
They're not really "vartime" in that if the condition is violated, it will crash the entire program, as opposed to completing successfully in a variable number of CPU cycles
@tarcieri this is the next PR ready for review. I am looking forward to your input! |
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.
LGTM,
Although I am wondering if we also need unsigned right shifts for Ints.
Sorry for taking this so long, I was out of reach :).
@tarcieri ping 😄 |
@lleoha IMHO, I see no added value in supporting logical (=unsigned) right shift on a signed integer: it could be confusing for users, and the difference is quite subtle. Moreover, when logically shifting-right a negative value, you get some bizarre behaviour. To illustrate with an Moreover, if for some reason you really need the logical shift right, the solution |
I'm sold :). |
Bit operations on
Int
, in preparation for implementingInteger
trait.