Skip to content
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

Add BoxedUint: heap-allocated fixed-precision unsigned integers #221

Merged
merged 1 commit into from
May 29, 2023

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Apr 30, 2023

Use cases like DSA and RSA benefit from having heap-allocated integers whose precision can be chosen at runtime rather than compile time.

These algorithms are used in conjunction with varying key sizes, and when dealing with a large number of potential key sizes it's helpful not to have to monomorphize the algorithm implementation for each one.

Ideally we can define traits so that code can be written generically but used with either Uint or BoxedUint, allowing heapless no_std users to use e.g. U2048, while users with a heap can use BoxedUint.

It should also be possible to make some of the existing algorithm implementations generic over Uint vs BoxedUint.

This initial implementation only provides addition and comparison support, but also the initial scaffolding for adding more operations.

Closes #58

@tarcieri
Copy link
Member Author

tarcieri commented Apr 30, 2023

While UintVec may at least communicate it's heap-allocated, I'm not sure it's a good name.

Maybe DynUint would be better?

Edit: renamed to BoxedUint.

src/uint_vec/cmp.rs Outdated Show resolved Hide resolved
@dignifiedquire
Copy link
Member

would be really useful to have benchmarks against gmp and num-bigint-dig for various ops and sizes, even if slower, just so we can orientate things

@tarcieri
Copy link
Member Author

Definitely want to add benchmarks, especially to play around with optimizing the carry chain function.

@dignifiedquire I didn't think about competitive benchmarks with other crates yet though... that's a good idea!

@fjarri
Copy link
Contributor

fjarri commented Apr 30, 2023

Maybe DynUint would be better?

Or HeapUint?

@andrewwhitehead
Copy link
Contributor

AllocUint? HeapUint wouldn't make sense if custom allocator support was added

@tarcieri
Copy link
Member Author

I guess a problem with DynUint is what would we call the corresponding Residue/DynResidue types?

So something other than Dyn seems good. Heap is explicit but eventual custom allocator support is a good point.

In interest of keeping it short and familiar, perhaps BigUint, although I'm used to Big meaning arbitrary precision instead of dynamic fixed precision.

Naming is hard!

@tarcieri
Copy link
Member Author

Some other options: BoxUint or BoxedUint

Use cases like DSA and RSA benefit from having heap-allocated integers
whose precision can be chosen at runtime rather than compile time.

These algorithms are used in conjunction with varying key sizes, and
when dealing with a large number of potential key sizes it's helpful not
to have to monomorphize the algorithm implementation for each one.

Ideally we can define traits so that code can be written generically but
used with either `Uint` or `BoxedUint`, allowing heapless `no_std` users
to use e.g. `U2048`, while users with a heap can use `BoxedUint`.

It should also be possible to make some of the existing algorithm
implementations generic over `Uint` vs `BoxedUint`.

This initial implementation only provides addition and comparison
support, but also the initial scaffolding for adding more operations.
@tarcieri tarcieri changed the title Add UintVec: heap-allocated fixed-precision integers Add BoxedUint: heap-allocated fixed-precision unsigned integers May 29, 2023
@tarcieri
Copy link
Member Author

tarcieri commented May 29, 2023

I went with BoxedUint, which I think is sufficiently clear. A hypothetical future BoxedResidue is nicely distinct from DynResidue.

Going to merge this despite the limited functionality to have a basic scaffold in place. Additional functionality can be added in independent followup PRs.

@tarcieri tarcieri merged commit cd4286f into master May 29, 2023
@tarcieri tarcieri deleted the uint_vec branch May 29, 2023 18:56
@tarcieri tarcieri mentioned this pull request Sep 4, 2023
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.

Heap-backed fixed-width integers
4 participants