This explains .
Motivation
Compute 2P+Q without the intermediate results 2P and P+Q given E:y2=x3+a⋅x+b, where 4a3+27b2=0,
2P: 1 multiplication, 2 squarings and 1 division. If P=(x1,y1), R=2P=(x2,y2) is computed as follows:
λ=2y13x12+ax2=λ2−2x1y2=(x1−x2)λ−y1 P+Q: 1 multiplication, 1 squaring and 1 division. If P=(x1,y1) and Q=(x2,y2), R=P+Q=(x3,y3) is computed as follows:
λ1=(y2−y1)/(x2−x1),x3=λ12−x1−x2,y3=(x1−x3)λ1−y1 Naive 2P+Q: 2 multiplications, 3 squarings and 2 divisions
How can we improve this?
Algorithm
Suppose P=(x1,y1) and Q=(x2,y2) are distinct points on E, with x1=x2. The sum P+Q has coordinates (x3,y3), where:
λ1=(y2−y1)/(x2−x1),x3=λ12−x1−x2,y3=(x1−x3)λ1−y1 Now suppose we want to add (P+Q) to P. To do this, we add (x1,y1) to (x3,y3) using the same addition rule. Assuming x3=x1, the resulting coordinates are (x4,y4), where
λ2=(y3−y1)/(x3−x1),x4=λ22−x1−x3,y4=(x1−x4)λ2−y1 We can omit the explicit computation of y3 since it is used only to calculate λ2. Instead, λ2 can be computed directly as:
λ2=(y3−y1)/(x3−x1)=((x1−x3)λ1−2y1)/(x3−x1)=−λ1−2y1/(x3−x1) Which means you can compute λ2 using x1,y1 and λ1.
λ2=−λ1−2y1/(λ12−x2−2x1) Additionally, you can compute x4 using x2,λ1 and λ2.
x3x3−x4−x4x4=λ12−x1−x2=λ12−x1−x2−(λ22−x1−x3)=λ12−x2−λ22=x2+λ22−λ12 This trick can also be applied when computing 3P. Thus, 3P+Q=((P+Q)+P)+P saves 2 multiplicaitons.
Conclusion
The cost of this algorithm is as follows:
Optimized 2P+Q: 1 multiplication, 2 squarings and 2 divisions (+ 1 squaring when P=Q)
Idea: (P+Q)+P instead of 2P+Q and y-coordinate is not computed when computing (P+Q) ⇒ This saves a field multiplication
if P=Q
2 * (1 multiplication, 2 squarings and 1 division) - 1 multiplication
otherwise
2 * (1 multiplication, 1 squaring and 1 division) - 1 multiplication