Add mpz_inp_str to mini-gmp

Niels Möller nisse at
Fri Jul 8 11:51:33 UTC 2016

tg at (Torbjörn Granlund) writes:

> I haven't looked at mini-gmp's mpz_set_str, but I assume it is O(n^2),
> so not much is lost by using a trivial implementation like the one
> above.

It tries to be O(n) when base is a power of two. Which I think is a
reasonable tradeoff. I was a bit surprised and disappointed when I found
out (a few years ago, no idea if it's still the case) that the base-256
conversion in libtomcrypt, used by the dropbear ssh implementation which
is popular on embedded systems, was O(n^2). And one use-case for
mini-gmp is constrained embedded systems.

> (I don't think we should accomodate spaces in the numbers, since that's
> considered a mis-feature of the main GMP.)

Then the documentation should perhaps be more explicit and discourage
use of that feature.

Speaking of documentation, the docs for mpz_inp_str isn't clear at all
on what input characters are considered to terminate the input.


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list