How to Compute the Modular Inverse in Elliptic-Curve Addition
At a glance
- 1. Find the denominator
Use the difference in x-coordinates, or twice the y-coordinate when doubling a point.
- 2. Run extended Euclid
Find integers that express the denominator and the prime modulus as a linear combination.
- 3. Reduce the coefficient
The coefficient of the denominator, reduced modulo p, is its multiplicative inverse.
- 4. Finish the point formula
Multiply the slope numerator by that inverse modulo p, then compute the resulting coordinates.
When you add elliptic-curve points over a finite field, the slope formula contains a division. Since field elements are calculated modulo a prime , that division means multiplication by a modular inverse. The extended Euclidean algorithm computes the inverse.
This is not the same as finding the inverse point of a curve point. The modular inverse is used to calculate the slope; the inverse point is the point that adds to the identity.
The short-Weierstrass formulas below assume an odd prime and a nonsingular curve, so .
What needs to be inverted?
For distinct points and on a short Weierstrass curve over the prime field , when , the slope is
The notation means the multiplicative inverse of modulo . It is the residue satisfying
When doubling a point with , use the tangent slope instead:
After finding the slope, the coordinates of the sum are
All arithmetic, including subtraction and multiplication, is reduced modulo .
Find the inverse with extended Euclid
For an integer not divisible by prime , the Euclidean algorithm finds the greatest common divisor of and . The extended version also finds integers and such that
Because is prime and is nonzero modulo , the gcd is . Reducing the equation modulo gives , so reduced modulo is the inverse of .
For example, to invert modulo :
Back-substitute to express using and :
Thus , and . You can verify it directly: .
Worked point-addition example
Consider the curve over and the points and . Both lie on the curve. For instance, at , the right side is .
The slope denominator is . From the Euclidean calculation above, its inverse modulo is . Therefore
Now calculate the sum coordinates, reducing each result modulo :
So . The inverse was needed only to evaluate the slope; after that, the ordinary point-addition formulas give the result using modular arithmetic.
Common mistakes and special cases
- Using an ordinary fraction: Dividing by modulo does not mean using the real number . It means multiplying by .
- Forgetting to reduce modulo : Reduce intermediate results as needed. For example, is modulo .
- Confusing two kinds of inverse: The additive inverse of is . On the example curve, over .
- Trying to invert zero: If distinct-point addition has , the denominator is zero. For distinct points on the curve, this means they are negatives of each other, and their sum is the point at infinity, the identity. In doubling, if , the tangent is vertical and is the point at infinity.
- Applying the prime-field rule to a composite modulus: A nonzero number modulo a composite may not have an inverse. In general, an inverse exists exactly when . Elliptic-curve cryptographic groups commonly use a prime field, where every nonzero denominator has an inverse.
In code, an extended-Euclidean routine can return the inverse as a signed integer; reduce that result into the range before using it. A denominator that is zero modulo is a point-addition special case, not an input for modular inversion.
References
- Guide to Elliptic Curve Cryptography, Darrel Hankerson, Alfred Menezes, and Scott Vanstone
- A Course in Computational Algebraic Number Theory, Henri Cohen
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.