subtle
subtle copied to clipboard
Conditionally select usize
trafficstars
Background is an RSA implementation I'm writing, where I'm using type Digit = usize.
I presume lack of implementation for usize/isize was an oversight, not intentional?
The lack of implementation for usize was because usize is most commonly used to index arrays, and providing ConditionallySelectable for usize could lead someone to think that doing
let index = usize::conditional_select(&a, &b, choice);
let val = array[index];
was doing a constant-time selection out of the array, when in fact using secret array indices can leak information into caches.
For a constant-time RSA implementation (I'm assuming Digit is used for a big-integer representation), it seems better to use Digit = u64, so that you know the size of your digits.