secp256k1 - A tale of two elliptic curves

A tale of two elliptic curves

A few days ago I blogged about the elliptic curve secp256k1 and its use in Bitcoin. This curve has a sibling, secp256r1. Note the “r” in the penultimate position rather than a “k”. Both are defined in SEC 2: Recommended Elliptic Curve Domain Parameters. Both are elliptic curves over a field zp where p is a 256-bit prime (though different primes for each curve).

The “k” in sepc256k1 stands for Koblitz and the “r” in sepc256r1 stands for random. A Koblitz elliptic curve has some special properties that make it possible to implement the group operation more efficiently. It is believed that there is a small security trade-off, that more “randomly” selected parameters are more secure. However, some people suspect that the random coefficients may have been selected to provide a back door.

Both elliptic curves are of the form y² = x³ + ax + b. In the Koblitz curve, we have

a = 0
b = 7

and in the random case we have

a = FFFFFFFF 00000001 00000000 00000000 00000000 FFFFFFFF FFFFFFFF FFFFFFFC
b = 5AC635D8 AA3A93E7 B3EBBD55 769886BC 651D06B0 CC53B0F6 3BCE3C3E 27D2604B

You can find the rest of the elliptic curve parameters in the SEC 2 report. For some help understanding what the parameters mean and how to decode them, see my earlier post.

The NSA recommends the random curve for government use. It is also known as NIST P-256. Or rather it did recommend P-256 as part of its Suite B of cryptography recommendations. In August 21015 the NSA announced its concern that in the future, quantum computing could render the Suite B methods insecure. As far as we know, quantum computing at scale is years, maybe decades, away. But it takes a long time to develop quality encryption methods, and so the NSA and NIST are urging people to think ahead. (Update: The NSA recommends P-384 until post quantum methods mature.)

 

 

 

 

 

In the previous post, we’ve mention the math behind addition law for elliptic curves over Galois Field GF(p) – prime field. Now, math behind elliptic curves over Galois Field GF(2n) – binary field would be mentioned. In literature, elliptic curves over GF(2n) are more common than GF(p) because of their adaptability into the computer hardware implementations. These type of curves are also called as Koblitz curves.

 

 


Cryptography Basiscs From Scratch In Python

Elliptic Curves over GF(2n)

Algebraically, an elliptic curve over binary field is represented as the following form:

y2 + xy = x3 + ax2 + b, (b≠0)

Negative Point

Suppose that P(x, y) is a point on the curve. The negative of the point P(x, y) is -P(x, -(x+y)), and -P is still on the curve.

ecc_5

Put P(m, t) and Q(m,n) into the equation y2 + xy = x3 + ax2 + b

t2 + mt = m3 + am2 + b

n2 + mn = m3 + am2 + b

Extract 2nd equation from 1st equation

t2 – n2 + mt – mn = 0

t2 + mt – n2 -mn = 0

t2 + mt – n(n + m) = 0

According to the sum and product of the roots rule, the equation could be written as:





(t – n).(t + n + m) = 0

t1 = n

t2 = – n – m = – (n+m)

We’ve already know t1=n is on the curve at the point Q(m,n). So, t2= -(n+m) is still on the curve. That’s the proof of the negative point for elliptic curves over (2n).

Proven of Addition Law

ecc_6

The red line would satify the equation y = ß.x + µ . Slope formula could help to calculate ß.

ß = (y1-y2)/(x1-x2) [Eq. 1]

Let’s merge the curve function (y2 + xy = x3 + ax2 + b) and linear function (y = ß.x + µ).

(ß.x + µ)2 + x.(ß.x + µ) = x3 + ax2 + b

ß2.x2 +µ2 +2ßµx + ßx2 + µx = x3 + ax2 + b

x3 + (a – ß2 – ß).x2 + (2ßµ – µ).x + (b – µ2) = 0

As mentinoned on previous post, according to the polynomial relation rule between coefficients and roots, the sum of the roots (x1, x2, x3) have to be equal to the negative coefficient of x2 , which is (a – ß2 – ß)2.

-(a – ß2 – ß) = x1 + x2 + x3

x3 = ß2 + ß – x1 – x2 – a [Eq. 2]

We’ve already known that P(x1, y1) is on the linear line.





y1 =  ß.x1 + µ

µ = y1 – ß.x1

Also, the point -R(x3, -(x3+y3)) has to be located on the linear line y = ß.x + µ.

-(x3+y3) = ß.x3 + µ

Put the obtained µ the equation above

-(x3+y3) = ß.x3 + y1 – ß.x1

-x3 – y3 = ß.x3 + y1 – ß.x1

y3 = ß.x1 -x3 – ß.x3 – y1

y3 = ß(x1 – x3) – x3 – y1 [Eq. 3]

To sum up, addition of two point P(x1, y1) and Q(x2, y2) on the elliptic curve form y2 + xy = x3 + ax2 + b is another point on the curve which is labeled R(x3, y2) and could be computed by the following formulas.

P(x1, y1) + Q(x2, y2) = R(x3, y3)

ß = (y1-y2)/(x1-x2)

x3 = ß2 + ß – x1 – x2 – a

y3 = ß(x1 – x3) – x3 – y1

Doubling a point

Similarly, doubling a point on an elliptic curve is implemented by following principles.





ecc_7

The red line is tangential to the elliptic curve at the point labeled P(x1, y1). The slope of the tangent line is equal to the derivative of the elliptic curve function at the point labeled P(x1, y1).

(y2 + xy)’ = (x3 + ax2 + b)’

2y.dy + y.dx + x.dy = 3x2.dx + 2.a.x.dx

2y.dy + x.dy = 3x2.dx + 2.a.x.dx – y.dx

dy(2y + x) = dx(3x2 + 2.a.x – y)

ß = dy/dx = (3x2 + 2.a.x – y)/(2y + x)

We’ve known x1, y1 pairs are on the line. Let’s put the pairs into the slope formula.

ß = (3.(x1)2 + 2.a.x1 – y1)/(2y1 + x1)

Doubling a point on an elliptic curve over GF(2n) could be computed by the following formulas.

P(x1, y1) + P(x1, y1) = 2P(x2, y2)

ß = (3.(x1)2 + 2.a.x1 – y1)/(2y1 + x1)

x2 = ß2 + ß – 2.x1 – a

y2 = ß(x1 – x2) – x2 – y1

As metioned before, this type of elliptic curves are mostly used in cryptographic hardware implementations because of their speed and adaptability.

Bitcoin chose to use the less popular Koblitz curve for the reasons mentioned above, namely efficiency and concerns over a possible back door in the random curve. Before Bitcoin, secp256k1 was not widely used.

posted @   zJanly  阅读(374)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示