Try   HackMD

Napkin Math: Elliptic Curve Addition in terms of Field Operations

Objective
This note aims to analyze the cost of elliptic curve addition in terms of operations in the underlying field.

Summary
We find that adding two points requires the following field operations:

  • one inverse operation
  • four multiply operations
  • 6 adds/subtract operations

Since one inverse operation requires

log(p) multiplications, that cost will dominate.

Problem Statement

Let

Fp be a field, and let
G
be the elliptic curve group defined by
(1)y2=x3+ax+b

for some
a,bFp
. Let
A1
and
A2
be points in
G
, where
x1x2
.[1]

The objective of this note is to count the number of field operations necessary to compute

A3=A1+A2.

Addition in Affine Coordinates

We write

A1=(x1,y1) and
A2=(x2,y2)
.

We proceed as follows:

  • construct the line
    L
    connecting
    A1
    and
    A2
  • use a clever observation to find
    x3
    , the
    x
    coordinate of the point of intersection of
    L
    and
    G
    (and the
    x
    -coordinate of
    A3
    )
  • find
    y3
    , the
    y
    coordinate of
    A3

We first write the line connecting

A1=(x1,y1) and
A2=(x2,y2)
. Denoting the slope of the line as
m=y2y1x2x1
, we find
b=mx1+y1
. Then, we can write the equation for
L
as

(2)y=mxmx1+y1

Computing

m requires 2 subtractions, finding one inverse, and one multiplication. Computing
b
requires one multiplication and one subtraction.

Cost for constructing

L is 1 inverse, 2 multiplications, and three subtractions.

AFAIK, Fermat's Little Theorem is the most efficient approach to computing multiplicative inverses. Using repeated squaring, computing

xp2 using takes ~
log(p)
multiplications.

Finding
(x3,y3)

Substituting equation (2) into equation (1) yields:

(3)(mxmx1+y1)2=x3ax+b

Bringing all terms to the right-hand side, we find

(4)0=x3+m2x2+(2m(y1mx1)a)x+b(y1mx1)2

Now, we make a clever[1] observation: since

x1,x2, and
x3
are solutions to equation (3), we can also write equation (3) in the form
(5)0=(xx1)(xx2)(xx3)

By comparing the coefficient of

x2 in equations (4) and (5), we can deduce that
x1+x2+x3=m2
. It follows that:
x3=m2x1x2

Cost for computing

x3 is one multiplication and two subtractions.

Now we can the

y coordinate of the point of intersection by substituting into equation (2). After reflecting across the
x
-axis, we find the
y
coordinate of
A3
:
y3=m(x1x3)y1

Cost for computing

y3 is one multiplication and one subtraction.

Addition in Projective Coordinates

The previous approach requires computing an inverse in order to add elliptic curve points. Writing our points in projective coordinates allows us to avoid that cost.

We write

P1=[x1z1:y1z1:1] and
P2=[x2z2:y2z2:1]
.
Assume
z1
is non-zero and
x1x2
.
We aim to compute
P3=P1+P2
.

We continue to follow the approach in Section 2.2 here:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

It folllows from the previous section that we can write the sum as

P3=[m2x1z1x2z2:m(x1z1x3):1]
Substituting in our expression for
x3
:
=[m2x1z1x2z2:m(x1z1(m2x1z1x2z2)):1]

Now we can clear denominators:
=[m2z1z2x1z2x2z1:m(x1z2(m2z1z2x1z2x2z1)):z1z2]

=[m2z1z2x1z2x2z1:mx1z2m3z1z2mx1z2mx2z1:z1z2]

Now, we simultaneously substitute
m=y2z1y1z2x2z1x1z2
, and multiply through by
(x2z1x1z2)3
to clear denominators:
=[(y2z1y1z2)2z1z2x1z2x2z1)(x2z1x1z2):(y2z1y1z2)3z1z2(y2z1y1z2)(x2z1x1z2)2x2z1:z1z2(x2z1x1z2)3]

Warning: Likely contains algebra errors, but it gets the idea across.

The reference notes suggest that with careful accounting it's possible to compute

P3 in 12 additions if
P1P2
and 14 additions for point doubling.

Addition in Montgomery Form

Details omitted. See Moon Math Manual for details.

Advantage here is constant time scalar multiplication. Note that even though it's "constant time," there's still a slight difference in the computational approach depending on whether

P1=P2, and whether one of the points is a point at infinity.

Addition in Twisted Edwards Form

Details omitted. See Moon Math Manual for details.

Advantage here is all additions use exactly the same computational approach: no branching necessary in your computational logic.

But, it seems this approach requires computing 2 inverses?!

Footnotes

[1]: For the case where

A1=A2 we proceed similarly using the tangent line for
L
. We can write find the tangent line using implicit differentiation. We find
m=dydx=3x12+a2y1
; the computation in this case requires one additional multiplication and one less addition. The remaining case is that
A1
is the reflection of
A2
across the
x
-axis. In this case, the sum is defined to be the point at infinity.
[2]: See Section 2.2 here