Cofactor canonicalisation of mpn_gcdext

Niels Möller nisse at
Thu Dec 3 14:23:30 CET 2009

nisse at (Niels Möller) writes:

> I'm attaching a patch addressing these first two points. For those with
> access to shell, it's also in the repository at ~nisse/hack/gmp-gcdext.

Below an updated patch (also in my repository at shell), which seems to
give the correct results and canonical cofactors. There's most likely a
performance regression, due to the naive Euclid algorithm used in

There was one subtle problem left by the previous patch. After reducing
numbers for a while, the gcdext code may find that the current two
values are equal, and hence it has found the gcd and should return. But
with which cofactor? Which of the two current cofactors is the canonical
one depends on the reduction leading up to equality, which we don't keep
track of. So in this case, we have to compare the two cofactors and
return the smallest one.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcdext.patch
Type: text/x-patch
Size: 15543 bytes
Desc: not available
URL: <>
-------------- next part --------------

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