-
Notifications
You must be signed in to change notification settings - Fork 147
crypto-bigint: Integer
trait
#612
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
Conversation
c822a1a
to
7265346
Compare
use rand_core::{CryptoRng, RngCore}; | ||
|
||
/// Integer type. | ||
pub trait Integer: |
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.
why no requirements for Add, Mul etc?
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.
Those traits are presently only impl'd for Wrapping<UInt<_>>
in order to be explicit about the wrapping vs checked behavior.
However, it would be possible to bound on Wrapping<Self>
impl'ing them.
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.
FWIW, in elliptic-curve
I end up bounding on the modular arithmetic traits: https://github.com/RustCrypto/traits/pull/732/files#diff-58bf09549ae77b47fcc1f18c3335fd0f6a4eb49a1e3cee51332fe40dcfd66daaR113-R120
type UInt: bigint::AddMod<Output = Self::UInt>
+ bigint::Integer
+ bigint::NegMod<Output = Self::UInt>
+ bigint::Random
+ bigint::RandomMod
+ bigint::SubMod<Output = Self::UInt>
+ zeroize::Zeroize;
They could potentially be included in the Integer
bounds.
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 guess I didn't add bounds on *Mod
initially because they are only impl'd for a subset of the supported integer values
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.
Yeah makes sens to wait for adding those bound, until we have a more complete set
7265346
to
4546f0f
Compare
Adds a trait encompassing the interesting bounds of `UInt`. Since traits like `elliptic_curve::Curve` can't yet be generic over `const LIMBS`, this trait provides a convenient way of wrapping up `UInt` behavior such that it's still usable without spelling out all of these bounds explicitly.
4546f0f
to
7b6aca1
Compare
Integer
traitInteger
trait
Adds a trait encompassing the interesting bounds of
UInt
.Since traits like
elliptic_curve::Curve
can't yet be generic overconst LIMBS
, this trait provides a convenient way of wrapping upUInt
behavior such that it's still usable without spelling out all of these bounds explicitly.