Skip to content

Conversation

@fjarri
Copy link
Contributor

@fjarri fjarri commented Dec 25, 2023

Adds a trait for generating a random number of a given bit size.

Can be improved by using masking instead of shift.

  • Is there a better way to express this API?
  • Should it be constant-time in bit_length?
  • Should the inherent BoxedUint::random() take bits_precision as well?

@fjarri
Copy link
Contributor Author

fjarri commented Dec 27, 2023

Expanded the API - added fallible methods, and convenience methods allowing one to omit bits_precision (with behavior depending on whether it's Uint or BoxedUint). The main question that still remains - should it be constant-time in bit_length, or even whether it is expected to be. That is, should I add _vartime suffixes? Or redo it to be constant-time?

@fjarri
Copy link
Contributor Author

fjarri commented Dec 27, 2023

Also the inherent BoxedUint::random() is identical in behavior to BoxedUint::random_bits() now. Should it be removed?

@tarcieri
Copy link
Member

The main question that still remains - should it be constant-time in bit_length, or even whether it is expected to be.

@fjarri perhaps we should document it, but I consider everything to be implicitly variable-time around the integer size.

I guess "bit length" is a slightly different question, particularly in regard to that versus the precision / capacity of the underlying type.

@tarcieri
Copy link
Member

Also the inherent BoxedUint::random() is identical in behavior to BoxedUint::random_bits() now. Should it be removed?

That's fine I guess

@fjarri fjarri force-pushed the random-trait branch 2 times, most recently from f3e11d3 to 2fa3263 Compare December 27, 2023 20:26
@fjarri
Copy link
Contributor Author

fjarri commented Dec 27, 2023

Actually, I am kind of questioning now if the Random trait is needed at all if RandomBits exists.

@tarcieri
Copy link
Member

Perhaps Random could be kept but with a blanket impl for FixedInteger + RandomBits? (and possibly a different name)

@tarcieri tarcieri merged commit 90d7b0a into RustCrypto:master Dec 27, 2023
@fjarri fjarri deleted the random-trait branch December 27, 2023 21:00
@tarcieri tarcieri mentioned this pull request Jan 22, 2025
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