nisse at lysator.liu.se
Wed Jun 23 11:07:30 CEST 2010
Torbjorn Granlund <tg at gmplib.org> writes:
> Changning all of mpn to use error code for typically fatal allocation
> problems rather than the current efficient method is the main daunting
> task. It will not be done, since I think it is the wrong approach.
You haven't yet mentioned the itch/scratch interface. Maybe it's not yet
decided if this really is the way to go, but if we had this one could do
an error-returning multiplication function fairly easily, something like
(ignoring signs and source-destination overlap):
foo_mul (mpz_t r, const mpz_t a, const mpz_t b)
mp_size_t itch = mpn_mul_itch (SIZ(a), SIZ(b));
mp_size_t rsize = SIZ(a) + SIZ(b);
mp_ptr scratch = foo_alloc_limbs (itch);
return 0; /* fail */
if (!mpz_resize(r, rsize)) /* Let's assume this one returns success/fail */
mpn_mul (PTR(r), SIZ(a), PTR(a), SIZ(b), PTR(b), scratch);
SIZ(r) = rsize - PTR(r)[rsize-1] == 0
But multiplication is easy, since one could choose to use mul_basecase
always. powm and division are more difficult since they need temporary
storage also for inputs in the size range that is relevant for crypto.
I'd like to see mpn itch/scratch functions for those computations.
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
More information about the gmp-devel