xieyuschen / quic-example

Explore the http3 by quic with examples
Apache License 2.0
14 stars 2 forks source link

Diffe-Hellman algorithm #10

Open xieyuschen opened 2 years ago

xieyuschen commented 2 years ago

Diffe-Hellman is used to exchange a private key during an unsafe communication channel. It is Not an encrypting algorithm.

The server and client exchanges: A, B, g and p: So both side could calculate the session key:

client_key = B^a mod p = ((g^a)^b) mod p = g^ab mod p.
server_key = A^b mod p = ((g^b)^a) mod p = g^ab mod p.

But the listener could only get A, B, g and p. To get an a from an equalisation A = g^a mod p is a dlb(Discrete Logarithm Problem) question. It's imposible to get the anwser now.

xieyuschen commented 1 year ago

In RSA:

The public key is (N,e), and the private key is d. In a real case, message M could be encrypted:

The RSA PUBLIC/PRIVATE KEY is not the key pair files we use in normal life, that file is a kind of RSA key expression, see RFC3447

xieyuschen commented 1 year ago

In ECC, y^2 = x^3 + ax +b. P = mQ, both P and Q belong to F*p. The key pair generator choose a random m and Q in curve, and then calculate P.

The public key encrypts and the private key decrypts:

So we could decrypt by private key:

xieyuschen commented 1 year ago

it's an INVILIAD operation to encrypt a message with a private key. Signature instead.