Closed xuganyu96 closed 7 months ago
Attention: 12 lines
in your changes are missing coverage. Please review.
Comparison is base (
45152ad
) 99.21% compared to head (b59be9c
) 98.48%.
Files | Patch % | Lines |
---|---|---|
src/uint_traits.rs | 86.95% | 12 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Two other possible strategies for dealing with precision:
one()
and zero
methods on UintLike
objects that will take the object's precision. The problem is the naming. zero_with_the_same_precision()
?Personally I prefer explicit over implicit. Having "automatic" widening thus doesn't sound too appealing. Having a one/zero as an instance method also sound awkward.
Some of the places where "one" is used are for "minus by one". For that I think having a "wrapping/overflowing decrement/increment" method would make a lot of sense.
In other places, I think having an explicit "*_with_precision" and "widen" functions is the least awkward of all the awkward solutions.
https://github.com/RustCrypto/crypto-bigint/issues/312 is the tracking issue for where it might sense to implement automatic widening. Several operations do already support it.
It's actually fairly important for performance as it can cut down on the total number of operations that need to be performed versus explicitly widening the inputs to be the same size. So long as those widths are always fixed (for e.g. a given key size) the result is still constant-time.
https://github.com/RustCrypto/crypto-bigint/pull/403 includes some additional widening support.
Have one() and zero methods on UintLike objects that will take the object's precision. The problem is the naming. zero_with_the_same_precision()?
@fjarri I've kind of wanted something like that but have also been stuck on the name
If it's a "static" method, we could follow numpy
and call it Integer::zero_like()
and Integer::one_like()
.
For that particular application, I was thinking something which accepts &self
as an argument and returns zero/one with the same precision as the original value, versus the current BoxedUint::zero_with_precision(n.bits_precision())
I just think that in case of the static method the naming is easier. BoxedUint::zero_like(n)
Aah, yeah, makes sense
I finally dissolved the UintLike
trait in #36 (waiting for crypto-bigint
to have another pre
release to merge).
v0.6.0-pre.6 is out: https://github.com/RustCrypto/crypto-bigint/pull/527
I'm on vacation at this moment so apologies in advance for slow progress.
This PR builds upon #36 and adds the following items:
presets.rs
:prime_generation_boxed
andsafe_prime_generation_boxed
, both of which passoverflowing_shl_vartime
andoverflowing_shr_vartime
, as well asrandom_bits
forBoxedUint
one_with_precision
,zero_with_precision
, andwiden
toUintLike
so that allBoxedUint
sizes can be kept identicalmiller_rabin.rs
andlucas.rs
to maintain equalBoxedUint
sizes across the entire module.The most awkward part of these proposed changes is the need for
one_with_precision
,zero_with_precision
, andwiden
, which makes sense in the context ofBoxedUint
but feels redundant when working withUint
. Again, I think some clear documentation will suffice, but maybe there are some better ways.cc: @fjarri