Skip to content

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Sep 3, 2021

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.

@tarcieri tarcieri force-pushed the crypto-bigint/integer-trait branch 2 times, most recently from c822a1a to 7265346 Compare September 3, 2021 14:57
use rand_core::{CryptoRng, RngCore};

/// Integer type.
pub trait Integer:
Copy link
Member

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?

Copy link
Member Author

@tarcieri tarcieri Sep 3, 2021

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.

Copy link
Member Author

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.

Copy link
Member Author

@tarcieri tarcieri Sep 3, 2021

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

Copy link
Member

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

@tarcieri tarcieri force-pushed the crypto-bigint/integer-trait branch from 7265346 to 4546f0f Compare September 3, 2021 16:19
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.
@tarcieri tarcieri force-pushed the crypto-bigint/integer-trait branch from 4546f0f to 7b6aca1 Compare September 3, 2021 17:11
@tarcieri tarcieri changed the title [WIP] crypto-bigint: Integer trait crypto-bigint: Integer trait Sep 3, 2021
@tarcieri tarcieri marked this pull request as ready for review September 3, 2021 17:11
@tarcieri tarcieri merged commit 8fa1b4f into master Sep 3, 2021
@tarcieri tarcieri deleted the crypto-bigint/integer-trait branch September 3, 2021 17:15
@tarcieri tarcieri mentioned this pull request Sep 8, 2021
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.

2 participants