diff --git a/src/fields/fp.rs b/src/fields/fp.rs index c475d98..45605cb 100644 --- a/src/fields/fp.rs +++ b/src/fields/fp.rs @@ -588,15 +588,26 @@ impl ff::Field for Fp { } fn pow_vartime>(&self, exp: S) -> Self { + // PATCH (Aeneas compatibility): index-based loops instead of + // `iter().rev()` / `(0..64).rev()` (double-ended range iterators have + // no Aeneas model). Iteration order and arithmetic are IDENTICAL to + // upstream: limbs from most- to least-significant, bits from high to + // low, square-then-conditionally-multiply. let mut res = Self::one(); let mut found_one = false; - for e in exp.as_ref().iter().rev() { - for i in (0..64).rev() { + let exp = exp.as_ref(); + let mut j = exp.len(); + while j > 0 { + j -= 1; + let e = exp[j]; + let mut i = 64u32; + while i > 0 { + i -= 1; if found_one { res = res.square(); } - if ((*e >> i) & 1) == 1 { + if ((e >> i) & 1) == 1 { found_one = true; res *= self; }