RustCrypto / crypto-bigint

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

Fix `bernstein_yang_nlimbs!` calculation #610

Closed tarcieri closed 3 months ago

tarcieri commented 3 months ago

The previous calculation of the number of unsaturated 62-bit limbs needed to represent an integer of a given size was incorrect, leading to miscomputed results as seen in #606.

This commit switches to a much simpler calculation based on div_ceiling(62), and also adds a const assertion that the computed number of limbs is sufficient to hold a $bits-sized integer.