RustCrypto / crypto-bigint

Cryptography-oriented big integer library with constant-time, stack-allocated (no_std-friendly) implementations of modern formulas
Apache License 2.0
167 stars 45 forks source link

Single-limb `u64` conversion #575

Closed AaronFeickert closed 4 months ago

AaronFeickert commented 4 months ago

It may be useful to perform constant-time arithmetic on primitive unsigned integers. While it might be ideal to keep all such operations within this library's Uint type, this seems unlikely in practice. I came across this exact situation while solving a problem requiring simple constant-time arithmetic on unsigned integers that eventually needed to be used in contexts that couldn't use Uint directly.

This PR adds to_u64 to Uint in the style of the existing from_u64 functionality. It requires a single limb, and simply extracts the underlying word as a u64 (depending on the target).

AaronFeickert commented 4 months ago

Wow, I completely missed that this functionality already exists.

Appreciate the review anyway!

Closing.