ModInverse from the package math/big is used to implement InvModP. However the implementation of InvModP does not check the return value, which could be nil in case the arguments are not relatively prime, in which case the multiplicative inverse does not exist.