Imagine there is 256-bit uniform input
from CSPRNG. Suppose there is a curve like secp256r1 whose curve order is slightly less than 256 bits.
We cannot just mod(input, curve_order)
because it will introduce modulo bias. What if we trim 256 bits to 255 bits which is less than curve order? Then all values within 255 bits will have an equal chance of appearance.
ed25519 seems to do exactly that, with their ~252-bit curve order - they adjust 3 bits.
Rejection sampling from NIST SP 800-56A rev 3, section 5.6.1.2.2 is not constant-time, so looking for something simpler.
Additional question: What if we also adjust last 1 bit so that keys 0
and 1
will never appear by using |= 2
that will force them to always be 1 (the same way we always force beginning to be 0?