Bitcoin Learning 1-Understanding Elliptic Curve Algorithm

Introduction to Symmetric Encryption Algorithms and Asymmetric Encryption Algorithms

Original address: https://blog.csdn.net/yonggao023/article/details/80173950
Author: Dream Ace
Remarks : Welcome to reprint, please keep the original address.

Commonly used encryption algorithms can be divided into symmetric encryption and asymmetric encryption. Why are there two algorithms? Does one not meet the needs?

Symmetric encryption algorithm

Symmetric algorithms use the same key in the encryption and decryption process. For a simple example:
we use the simplest symmetric algorithm - the XOR algorithm to simulate the process of user A sending encrypted information to user B.
Suppose m1 is plaintext ,k is the key. m1 XOR k to get ciphertext m2
1. A passes m2 and k to B;
2. B receives m2 and k and performs XOR operation to obtain plaintext m1

Information eavesdropping problem: A and B are transmitted through the network, and the data transmitted in the middle may be intercepted by others. Since the XOR algorithm is public, the interceptor can easily get the plaintext m1.
In order to solve this key transmission problem, the cattle people invented the asymmetric algorithm

Asymmetric encryption algorithm

The encryption key and decryption key used in the symmetric algorithm are the same. But in an asymmetric encryption algorithm, the encryption key and the decryption key are not the same. Usually we refer to the encryption key as the public key (which can be disclosed to others) and the decryption key as the private key. Data encrypted by the public key can only be decrypted by the private key. Or use the above example to simulate the asymmetric encryption transmission process:
1. A generates a public key and a private key through a key generation algorithm.
2. A sends the public key to B
3. B encrypts m1 with the public key into the ciphertext m2
4. B sends m2 to A
5. A decrypts m2 with the private key to get m1

Information eavesdropping problem: In this process, A and B transmit only the ciphertext and the public key. Since the ciphertext can only be decrypted by the private key, even if someone intercepts the information, the ciphertext cannot be obtained.
So the question is, how does A transmit the encrypted information to B?

In the RSA algorithm, the private key and the public key are interchangeable, that is, the public key can be used to encrypt and the private key can be decrypted, and the private key can be used to encrypt and the public key can be used to decrypt. But it is not possible in other asymmetric algorithms, such as elliptic curve algorithm (I haven't found the formula for private key encryption of elliptic curve algorithm anyway, whoever found it is welcome to slap in the face). Although RSA is interchangeable, the scheme of encryption with public key and decryption with private key must be maintained. Please see this article for the specific reasons .
Now let's answer how A transmits encrypted information to B.
In fact, it is very simple. B generates a pair of public key and private key, and then sends the public key to A. A encrypts the data with B's public key and sends it to B. B decrypts it with its own private key.
Here we come to a conclusion:
the asymmetric encryption algorithm is to solve
the problem of being cracked during the transmission process of the
symmetric algorithm
.

Characteristics of asymmetric encryption algorithm (in my humble opinion, it has not been demonstrated by Daniel)

  1. All take values ​​in a finite field, so there will be a modulo operation in order to prevent the value from overflowing.
  2. The general asymmetric algorithm system will contain 3 algorithms

    1. Key generation algorithm (generate public and private keys)
    2. Encryption and decryption algorithms (public key encryption, private key decryption)
    3. Signature algorithm (private key signature, public key verification)
  3. The difficulty of cracking is based on the cracking of a mathematical problem, such as the large prime number decomposition problem of rsa, and the problem of solving discrete logarithms on the curve of elliptic curve algorithm.

Elliptic curve algorithm also has the above characteristics

Introduction to Elliptic Curve Algorithms

We briefly introduce the elliptic curve algorithm according to the characteristics of the above asymmetric encryption algorithm

The domain of the elliptic curve value

The formula of an elliptic curve that can usually be used for encryption operations is as long as this:

$y^2 = x^3 +ax + b$

image
The domain of the elliptic curve value is the point on the line.
In cryptography, to describe an elliptic curve on Fp, six parameters are commonly used:
T=(p,a,b,G,n,h).
(p, a, b are used to determine an elliptic curve,
G is the base point,
n is the order of point G - nG is equal to the point at infinity,
h is the integer part of the division of m and n, the number of all points on the elliptic curve)

The value of the Bitcoin elliptic curve can be seen here

key generation algorithm

The generation formula is K=kG, the uppercase K is the public key and a point on the curve, the lowercase k is the private key, and G is the base point of the curve defined above.
kG = (G+G+G….+G) is the addition of k Gs.
Here is a brief introduction to addition on elliptic curves.
We are used to the rational number method 1+1=2, but not everything is rational. Students who have studied C++ should have rewritten the addition operation of the class. You can understand that the addition on the elliptic curve has been rewritten, and its rules are different from the addition of rational numbers.

//椭圆曲线的加法像这样
Point operator+(const Point& a, const Point& b)
    {
        //a 和b各种操作后返回了一个poin c
        return c;
    }

The specific addition rule is to
arbitrarily take two points P and Q on the elliptic curve (if the two points of P and Q are coincident, the tangent to point P is used) to make a straight line to intersect with another point R' of the elliptic curve, and pass R' as the y-axis. Parallel lines meet R. We stipulate that P+Q=R
image
image
From the above addition rule, it can be concluded that the public key K is the point obtained by folding back and forth on the curve.
We can open a brain hole in the process of key generation and imagine a pool table. There is a fixed point G. Place the billiard ball on the G point, hitting the ball in the same direction each time with the cue. We hit the ball with different strengths. At the end the ball will come to rest at a certain point on the billiard ball. This point is our public key K, and the strength of our impact is the private key k. It's easy to bump the ball into the public key K point when you know the G point and the force. But you know the K point and G point of the public key, it is difficult to calculate how hard to hit. This is the difficulty of cracking the elliptic curve algorithm.

Encryption and decryption algorithm

Now we describe a process of encrypted communication using elliptic curves:
1. Both parties agree on an encrypted elliptic curve Ep(a,b), or A selects an elliptic curve and passes the parameters to B
2. User A selects a private encryption key k, and generate a public key K=kG.
3. User A's public key K is passed to B
4. After user B receives the information, it encodes the plaintext to be transmitted to a point M on Ep(a,b) (there are many encoding methods, which will not be discussed here), and generates a random integer r (r < n)
5. User B calculates the point C1=M+rK; C2=rG.
6. User B transmits C1 and C2 to User A.
7. After receiving the information, user A calculates C1-kC2, and the result is point M. Because
C1-kC2=M+rK-k(rG)=M+rK-r(kG)=M
and then decoding point M can get the plaintext.

Signature Verification Algorithm

Signature process
1. Both parties agree on an encrypted elliptic curve Ep(a,b), or A selects an elliptic curve and passes the parameters to B
2. User A selects a private key k and generates a public key K=kG .
3. Generate a random number r such that s1=rG(x,y)
4. Set the hash of the message M to be h, and get s2=(h+xk)/r
5. A combines M, s1, s2, and the public key K Pass it to B
6. B calculates the hash h of M
7. B judges whether hG/s2 + xK/s2 is equal to s1
8. Formula derivation: hG/s2 + xK/s2=hG+xK/s2=(hG+xK) *r/(h+xk)=(hG+xkG)*r/(h+xk)=(h+xk)*Gr/(h+xk)=rG

End of the full text
References: Introduction to
Proficient Bitcoin
ECC Encryption Algorithm Introduction to
the technical principles of elliptic curve encryption and decryption and signature algorithms and their implementation in Go language

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325940736&siteId=291194637