You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the method "modinv" in the file zen_big.c, seems that this method find succesfully the inverse of a big number only if the modulo is a prime number.
When the modulo is a composite number two things can happen:
the computation doesn't stop (for example when the big number in input is not invertible).
It gives a wrong inverse.
For example in the ring Z/6Z the element 5 is invertible and its inverse is 5 since 25 mod 6 = 1. Instead the output of the function is 3.
local x = BIG.new(5)
local module = BIG.new(6)
local inv_x = x:modinv(module)
print(inv_x:decimal())
The text was updated successfully, but these errors were encountered:
Looking deeper into milagro library it seems to use the binary method in order to compute the modulo inverse. This algorithm, if I remember well, works only with odd modulos. Need to search better for this, if this is the case than we should add a check on the parity of the modulo.
I agree adding checks is the right approach, let's introduce a parity check?
Also the modinv function could check for 2^BIGBITS values and switch to use the BIG_XXX_invmod2m function in milagro which is much faster. See src/big.c.in at line 1432
/* a=1/a mod 2^BIGBITS. This is very fast! */voidBIG_XXX_invmod2m(BIG_XXXa)
and
/* Set r=1/a mod p. Binary method *//* SU= 240 */voidBIG_XXX_invmodp(BIG_XXXr,BIG_XXXa,BIG_XXXp)
the latter has internal checks on parity, but I don't know this technique well enough to judge on its constraints. I know that a must be <p on entry.
Looking at the method "modinv" in the file zen_big.c, seems that this method find succesfully the inverse of a big number only if the modulo is a prime number.
When the modulo is a composite number two things can happen:
For example in the ring Z/6Z the element 5 is invertible and its inverse is 5 since 25 mod 6 = 1. Instead the output of the function is 3.
The text was updated successfully, but these errors were encountered: