Open zhiqiangxu opened 1 year ago
This is probably left over from when pow_vartime
was on FieldExt
and took a fixed-length array (IIRC). Generally +1 on the PR, but I'm on PTO and am not reviewing Zcash PRs currently.
This is probably left over from when
pow_vartime
was onFieldExt
and took a fixed-length array (IIRC). Generally +1 on the PR, but I'm on PTO and am not reviewing Zcash PRs currently.
No hurry:)
BTW, it seems pow_vartime
and pow
are almost the same, is the difference really that big or another left over to be unified?
UPDATE
I see what constant time
means here now: it doesn't mean it's faster, just that the time is constant no matter which branch is chosen, to anti timing attack.
E.g:
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
// if choice = 0, mask = (-0) = 0000...0000
// if choice = 1, mask = (-1) = 1111...1111
let mask = -(choice.unwrap_u8() as to_signed_int!($t)) as $t;
a ^ (mask & (a ^ b))
}
pow_vartime([n, 0, 0, 0] == pow_vartime([n]
always holds, so it seems there's no point in wasting resource computingpow_vartime([n, 0, 0, 0]
instead ofpow_vartime([n]
.