RustCrypto / RustCrypto/crypto-bigint

`Uint::wrapping_div_wide(_exact)`

Open
#1,315 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
309
Forks
95
Avg merge
1d 14h
Merged PRs (30d)
3

Description

As we have rem_wide, I'd like to request wrapping_div_wide with a type signature:

fn wrapping_div_wide<const HI_LIMBS: usize, const RHS_LIMBS: usize>((lo, hi): (Self, Uint<HI_LIMBS>), rhs: &NonZero<Uint<RHS_LIMBS>>) -> Self;

(or approximate)

For my specific use case, I know the division to be exact, hence why I'd be fine with a wrapping_div_wide_exact method instead of a wrapping_div_wide method. I did poke at adding this myself but it appeared non-trivial. Modifying div_exact to also intake a x_hi: &mut UintRef, indexing x_lo when xi < x_lo.nlimbs() and x_hi otherwise was fine, but it still poked a bit too much for me to be comfortable without first making an issue to discuss this.

My practical use-case is I have such a need within my code and currently do lo.concat(hi).div_exact(rhs), but this requires the types implement Concat. As my segments are ~5k bits, the only types which reliably implement Concat are U6144, U8192, at which point I'm way over the size I'd like to be operating with. Removing the Concat bound would dramatically increase which types are eligible for use within my constraints.

This is horribly niche and I would not be offended at all if this was immediately closed as out-of-current-scope-availability/unreasonable.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing rem_wide and div_exact implementations, including how UintRef and limb indexing are handled. Compare the requested wrapping_div_wide(_exact) signature with the current lo.concat(hi).div_exact(rhs) approach and determine how to support differing high and right-hand-side limb counts without requiring Concat. Done means the requested wide division operation is available for the stated use case and its exactness behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.