Sergei Trofimovich <[email protected]> writes:

> Overlap happens at a call of
> ```
>     ecc_modp_mul (ecc, y3, B, z1);
> ```
> which is basically
> ```
>      mpn_mul_n (y3, B, z1, m->size),
> ```
>

I'm adding asserts to these functions, and then I can easily reproduce.

I think linking with a gmp configured with --enable-assert should be
enough to catch the problem in a platform-independent way?

Nikos, is it easy to add that gmp config to one of the gitlab ci jobs?
Alternatively, we could add the no-overlap asserts to mini-gmp, to catch
it in mini-gmp builds.

>  /* NOTE: mul and sqr needs 2*m->size limbs at rp */
>  void
>  ecc_mod_mul (const struct ecc_modulo *m, mp_limb_t *rp,
>            const mp_limb_t *ap, const mp_limb_t *bp)
>  {
> +  /* NOTE: mpn_mul_n does not work correctly when source and destination 
> overlap */
> +  assert (no_overlap (rp, 2 * m->size, ap, m->size));
> +  assert (no_overlap (rp, 2 * m->size, bp, m->size));
>    mpn_mul_n (rp, ap, bp, m->size);
>    m->reduce (m, rp);
>  }

As you observed, this function doesn't allow in-place operation. It's
less clear what the interface of the ecc_add_* and ecc_dup_* functions
is. It needs to be determined if they should or shouldn't allow in-place
operation, and if not, back that up with asserts.

Thanks for the bug report,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to