DH key exchange (Diffie–hellman key exchange) algorithm notes

Source: Internet
Author: User

Note: Just notes, there may be incorrect places

? The following ^ represents a exponentiation operation, such as 2^3=2*2*2=6, reference:Http://zh.wikipedia.org/wiki/%E5%86%AA

% represents modulo operations, such as 5%3=2, reference:http://zh.wikipedia.org/wiki/%E6%A8%A1%E9%99%A4 ?

The function of the DH key exchange algorithm is to enable both sides of the communication to establish an identical key in an unsecured channel for encrypting communication.

Examples of Fundamentals:

1, communication Party A and communication party B Convention an initial number g,g is public, such as G=5

2, a generates a random number a,a is confidential, such as A=6

3, a calculation g^a sent to B,g^a=5^6

4, b generate a random number b,b is confidential, such as b=15

5, B calculation G^b sent to a,g^b=5^15

6, a received g^b, and then use the confidential A, calculation (g^b) ^a=g^ (a*b) =5^ (6*15)

7, B after receiving g^a, then use the confidential B, calculation (g^a) ^b=g^ (a*b) =5^ (6*15)

8, so that the communication party A and b get a Same "key" g^ (a*b) =5^ (6*15)

The whole communication process G, g^a, g^b is public, but because G, a, b are integers, by G and g^a get a or is relatively easy, B is so, so the final "key" g^ (a*b) can be calculated. So the actual process also involves adding a new computational- modulo operation to the fundamentals:

1, communication Party A and communication party B Convention an initial number g, such as g=5, a prime p, such as P=23,G and P is public

2, a generates a random number a,a is confidential, such as A=6

3, a calculation g^a%p sent to B,g^a%p=5^6%23=8

4, b generate a random number b,b is confidential, such as b=15

5, B calculation g^b%p sent to a,g^b%p=5^15%23=19

6, a after receiving g^b%p, then use the confidential A, calculation (g^b%p) ^a%p=19^6%23=2

7, B after receiving g^a%p, then use the confidential B, calculation (g^a%p) ^b%p=8^15%23=2

8, so that the communication party A and B get a same key: 2

(g^b%p) Proof of ^a%p= (g^a%p) ^b%p:

If a=2:

(g^b%p) ^a%p= (g^b%p) ^2%p= (g^b-n*p) ^2%p= (g^ (2*b) -2*g^b*n*p+ (n*p) ^2)%p=g^ (2*b)%p

It can be seen that (g^b-n*p) ^2 expansion, except g^ (2*B), the other is a multiple of p, so the result of the entire calculation is g^ (2*b)%p

Similarly to (g^b-n*p) ^a expansion, except g^ (A*b), the others are multiples of p, so the result of the entire calculation is g^ (a*b)%p

The same can be obtained (g^a%p) ^b%p=g^ (a*b)%p

So (g^b%p) ^a%p= (g^a%p) ^b%p

The whole communication process G, p, g^a%p, g^b%p is public, at this time through G, p, g^a%p get a more difficult, also through G, p, g^b%p get B more difficult, so the final key is relatively safe.

Take g=5, p=23, g^a%p=8 to calculate a for example, A=log (5, (8+23*n)), this can only bring the possible values of n into the formula experiment to get the value of a. It is more difficult to calculate if a and p are relatively large numbers.

If it is noted that, in order to prevent the application of optimization algorithms to calculate the above problem, prime number p is not random choice , need to meet certain conditions. the generation algorithm of the random number A and B must also be noted that the results should be as random as possible and not predictable, otherwise it will make the crack easier.

The above calculation process can also be seen that the DH algorithm can not only be applied in the case of 2-party communication, if the multiparty communication , can also use the algorithm.

The DH key exchange algorithm cannot verify the identity of the other, so the DH key exchange algorithm cannot resist the man-in-the- Middle attack (Mitm,man-in-the-middle attack).

Reference:

Wiki:http://en.wikipedia.org/wiki/diffie%e2%80%93hellman_key_exchange


DH key exchange (Diffie–hellman key exchange) algorithm notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.