Mamy Ratsimbazafy 4ccd8aaab8
EVM modexp: solve DOS vectors (#286)
* stash prep for Barret Reduction

* benches lost in rebase

* fix vartime reduction

* some improvement and fixes on reduce_vartime

* Fuse reductions when converting to Montgomery + use window=1 in powMont for small exponents. ~2.7x to 3.3x accel

* modexp: Introduce a no-reduction path for small base+exponent compared to modulus. Fix DOS

* optim for padded exponents

* remove commented out code [skip ci]

* Missing noInline for allocStackArray
2023-10-19 01:20:52 +02:00

22 lines
531 B
Nim

# From issue #241
import
../../constantine/math/[
arithmetic,
io/io_bigints],
../../constantine/math_arbitrary_precision/arithmetic/limbs_divmod_vartime
let a = BigInt[64].fromUint(0xa0e5cb56a1c08396'u64)
let M = BigInt[64].fromUint(0xae57180eceb0206f'u64)
var r, r2: BigInt[64]
r.reduce(a, M)
doAssert r2.limbs.reduce_vartime(a.limbs, M.limbs)
let rU64 = 0xa0e5cb56a1c08396'u64 mod 0xae57180eceb0206f'u64
# echo r.toHex()
doAssert rU64 == a.limbs[0].uint64
doAssert bool(a == r)
echo "SUCCESS: t_bigints_mod.nim"