Partial backport of secp256k1#831:
https://github.com/bitcoin-core/secp256k1/pull/831/commits/aa404d53bef21d252a23171381d4bfda6e7e25c6
https://github.com/bitcoin-core/secp256k1/pull/831/commits/436281afdcb68991395f97338197d208212965e2
These are move only commits in preparation for replacing the functions
with their new safegcd variants. There is no change in behavior.
Depends on D9403.