RustCrypto / RustCrypto/crypto-bigint

`MaybeResize` for `Uint`

Open
#1,275 0 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

I open this as an issue as I'm sure it'll need discussion.

Problem:

I need 1 << x where x is ~256-2000, but variable and specified by the caller. I want either:

  • The caller to pass me T = U2048
  • The caller to pass me T = BoxedUint

My issue is if I get T = BoxedUint, I cannot get a 2048-bit BoxedUint without using BoxedUint::one_with_precision, Resize, or BoxedUint::one_like. The first two are specific to BoxedUint. The third is portable with Uint, but would require the caller pass in one_shl_x so that I had the value to 'be like'.

Ideally, I'd have a MaybeResize::resize(One::one(), x) which for fixed types, does nothing, but for BoxedUint, does call BoxedUint::resize.

Are we fine with MaybeResize as a complement to Resize for this purpose? Is there some function I'm missing? Should we instead have One::one_with_precision?

As an absolute hack, I can simply have an RNG which always outputs 0 and abuse RandomBits for this today. As an oddity, RandomBits::try_random_bits_with_precision appears to be the only trait method today which is implemented for both Uint and BoxedUint, while supporting a precision argument (which is discarded if inapplicable). That at least suggests precedent for this...

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

Read the existing One, Resize, and RandomBits trait APIs, especially BoxedUint::resize and RandomBits::try_random_bits_with_precision, to understand current fixed- versus variable-precision behavior. Done means the project has agreed on a portable way to construct a one value at caller-selected precision, with its scope and trait API settled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.