其他分享
首页 > 其他分享> > Elliptic Curve Cryptography: a gentle introduction

Elliptic Curve Cryptography: a gentle introduction

作者:互联网

Those of you who know what public-key cryptography is may have already heard of ECC, ECDH or ECDSA. The first is an acronym for Elliptic Curve Cryptography, the others are names for algorithms based on it.

Today, we can find elliptic curves cryptosystems in TLS, PGP and SSH, which are just three of the main technologies on which the modern web and IT world are based. Not to mention Bitcoin and other cryptocurrencies.

Before ECC become popular, almost all public-key algorithms were based on RSA, DSA, and DH, alternative cryptosystems based on modular arithmetic. RSA and friends are still very important today, and often are used alongside ECC. However, while the magic behind RSA and friends can be easily explained, is widely understood, and rough implementations can be written quite easily, the foundations of ECC are still a mystery to most.

With a series of blog posts I’m going to give you a gentle introduction to the world of elliptic curve cryptography. My aim is not to provide a complete and detailed guide to ECC (the web is full of information on the subject), but to provide a simple overview of what ECC is and why it is considered secure, without losing time on long mathematical proofs or boring implementation details. I will also give helpful examples together with visual interactive tools and scripts to play with.

Specifically, here are the topics I’ll touch:

  1. Elliptic curves over real numbers and the group law (covered in this blog post)
  2. Elliptic curves over finite fields and the discrete logarithm problem
  3. Key pair generation and two ECC algorithms: ECDH and ECDSA
  4. Algorithms for breaking ECC security, and a comparison with RSA

In order to understand what’s written here, you’ll need to know some basic stuff of set theory, geometry and modular arithmetic, and have familiarity with symmetric and asymmetric cryptography. Lastly, you need to have a clear idea of what an “easy” problem is, what a “hard” problem is, and their roles in cryptography.

Ready? Let’s start!

Elliptic Curves

First of all: what is an elliptic curve? Wolfram MathWorld gives an excellent and complete definition. But for our aims, an elliptic curve will simply be the set of points described by the equation:

where (this is required to exclude singular curves). The equation above is what is called Weierstrass normal form for elliptic curves.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-t2sCbknF-1634280911143)(https://andrea.corbellini.name/images/curves.png)]

Different shapes for different elliptic curves (, varying from 2 to -3).

Types of singularities

Types of singularities: on the left, a curve with a cusp (). On the right, a curve with a self-intersection (). None of them is a valid elliptic curve.

Depending on the value of and , elliptic curves may assume different shapes on the plane. As it can be easily seen and verified, elliptic curves are symmetric about the -axis.

For our aims, we will also need a point at infinity (also known as ideal point) to be part of our curve. From now on, we will denote our point at infinity with the symbol 0 (zero).

If we want to explicitly take into account the point at infinity, we can refine our definition of elliptic curve as follows:

Groups

A group in mathematics is a set for which we have defined a binary operation that we call “addition” and indicate with the symbol +. In order for the set to be a group, addition must defined so that it respects the following four properties:

  1. closure: if and are members of , then is a member of ;
  2. associativity: ;
  3. there exists an identity element 0 such that ;
  4. every element has an inverse, that is: for every there exists such that .

If we add a fifth requirement:

  1. commutativity: ,

then the group is called abelian group.

With the usual notion of addition, the set of integer numbers is a group (moreover, it’s an abelian group). The set of natural numbers however is not a group, as the fourth property can’t be satisfied.

Groups are nice because, if we can demonstrate that those four properties hold, we get some other properties for free. For example: the identity element is unique; also the inverses are unique, that is: for every there exists only one such that (and we can write as ). Either directly or indirectly, these and other facts about groups will be very important for us later.

The group law for elliptic curves

We can define a group over elliptic curves. Specifically:

Three aligned points

The sum of three aligned point is 0.

Note that with the last rule, we only require three aligned points, and three points are aligned without respect to order. This means that, if , and are aligned, then . This way, we have intuitively proved that our + operator is both associative and commutative: we are in an abelian group.

So far, so great. But how do we actually compute the sum of two arbitrary points?

Geometric addition

Thanks to the fact that we are in an abelian group, we can write as . This equation, in this form, lets us derive a geometric method to compute the sum between two points and : if we draw a line passing through and , this line will intersect a third point on the curve, (this is implied by the fact that , and are aligned). If we take the inverse of this point, , we have found the result of .

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vGibeMi6-1634280911149)(https://andrea.corbellini.name/images/point-addition.png)]

Draw the line through and . The line intersects a third point . The point symmetric to it, , is the result of .

This geometric method works but needs some refinement. Particularly, we need to answer a few questions:

As tends towards , the line passing through and becomes tangent to the curve. In the light of this we can say that , where is the point of intersection between the curve and the line tangent to the curve in . * What if , but there is no third point ? We are in a case very similar to the previous one. In fact, we are in the case where the line passing through and is tangent to the curve.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-loiSJXQz-1634280911153)(https://andrea.corbellini.name/images/animation-tangent-line.gif)]

If our line intersects just two points, then it means that it’s tangent to the curve. It’s easy to see how the result of the sum becomes symmetric to one of the two points.

Let’s assume that is the tangency point. In the previous case, we would have written . That equation now becomes . If, on the other hand, were the tangency point, the correct equation would have been .

The geometric method is now complete and covers all cases. With a pencil and a ruler we are able to perform addition involving every point of any elliptic curve. If you want to try, take a look at the HTML5/JavaScript visual tool I’ve built for computing sums on elliptic curves!

Algebraic addition

If we want a computer to perform point addition, we need to turn the geometric method into an algebraic method. Transforming the rules described above into a set of equations may seem straightforward, but actually it can be really tedious because it requires solving cubic equations. For this reason, here I will report only the results.

First, let’s get get rid of the most annoying corner cases. We already know that , and we also know that . So, in our equations, we will avoid these two cases and we will only consider two non-zero, non-symmetric points and .

If and are distinct (), the line through them has slope:

The intersection of this line with the elliptic curve is a third point :

or, equivalently:

Hence (pay attention at the signs and remember that ).

If we wanted to check whether this result is right, we would have had to check whether belongs to the curve and whether , and are aligned. Checking whether the points are aligned is trivial, checking that belongs to the curve is not, as we would need to solve a cubic equation, which is not fun at all.

Instead, let’s play with an example: according to our visual tool, given and over the curve , their sum is . Let’s see if our equations agree:

Yes, this is correct!

Note that these equations work even if one of or is a tangency point. Let’s try with and .

We get the result , which is the same result given by the visual tool.

The case needs to be treated a bit differently: the equations for and are the same, but given that , we must use a different equation for the slope:

Note that, as we would expect, this expression for is the first derivative of:

To prove the validity of this result it is enough to check that belongs to the curve and that the line passing through and has only two intersections with the curve. But again, we don’t prove this fact, and instead try with an example: .

Which gives us . Correct!

Although the procedure to derive them can be really tedious, our equations are pretty compact. This is thanks to Weierstrass normal form: without it, these equations could have been really long and complicated!

Scalar multiplication

Other than addition, we can define another operation: scalar multiplication, that is:

where is a natural number. I’ve written a visual tool for scalar multiplication too, if you want to play with that.

Written in that form, it may seem that computing requires additions. If has binary digits, then our algorithm would be , which is not really good. But there exist faster algorithms.

One of them is the double and add algorithm. Its principle of operation can be better explained with an example. Take . Its binary representation is . This binary representation can be turned into a sum of powers of two:

(We have taken each binary digit of and multiplied it by a power of two.)

In view of this, we can write:

What the double and add algorithm tells us to do is:

In the end, we can compute performing just seven doublings and four additions.

If this is not clear enough, here’s a Python script that implements the algorithm:

def bits(n):
    """
    Generates the binary digits of n, starting
    from the least significant bit.

    bits(151) -> 1, 1, 1, 0, 1, 0, 0, 1
    """
    while n:
        yield n & 1
        n >>= 1

def double_and_add(n, x):
    """
    Returns the result of n * x, computed using
    the double and add algorithm.
    """
    result = 0
    addend = x

    for bit in bits(n):
        if bit == 1:
            result += addend
        addend *= 2

    return result

If doubling and adding are both operations, then this algorithm is (or if we consider the bit length), which is pretty good. Surely much better than the initial algorithm!

Logarithm

Given and , we now have at least one polynomial time algorithm for computing . But what about the other way round? What if we know and and need to find out ? This problem is known as the logarithm problem. We call it “logarithm” instead of “division” for conformity with other cryptosystems (where instead of multiplication we have exponentiation).

I don’t know of any “easy” algorithm for the logarithm problem, however playing with multiplication it’s easy to see some patterns. For example, take the curve and the point . We can immediately verify that, if is odd, is on the curve on the left semiplane; if is even, is on the curve on the right semiplane. If we experimented more, we could probably find more patterns that eventually could lead us to write an algorithm for computing the logarithm on that curve efficiently.

But there’s a variant of the logarithm problem: the discrete logarithm problem. As we will see in the next post, if we reduce the domain of our elliptic curves, scalar multiplication remains “easy”, while the discrete logarithm becomes a “hard” problem. This duality is the key brick of elliptic curve cryptography.

See you next week

That’s all for today, I hope you enjoyed this post! Next week we will discover finite fields and the discrete logarithm problem, along with examples and tools to play with. If this stuff sounds interesting to you, then stay tuned!

Read the next post of the series »

标签:point,introduction,curve,Curve,gentle,result,elliptic,our,line
来源: https://blog.csdn.net/wuhaotongxue/article/details/120783434