{"id":339,"date":"2018-07-23T12:39:16","date_gmt":"2018-07-23T12:39:16","guid":{"rendered":"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=339"},"modified":"2018-12-27T12:17:31","modified_gmt":"2018-12-27T12:17:31","slug":"diffie-hellman-key-exchange","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/chapter\/diffie-hellman-key-exchange\/","title":{"rendered":"Diffie-Hellman Key Exchange"},"content":{"raw":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/XtojFDQdEMc\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>Security <\/strong><strong>Objectives<\/strong>\r\n<ul>\r\n \t<li>\u00a0To explain how to create a session key between Alice and bob using KDC<\/li>\r\n<\/ul>\r\n<ul>\r\n \t<li>To create session key method referred to as symmetric-key agreement<\/li>\r\n<\/ul>\r\n<ul>\r\n \t<li>\u00a0To discuss man-in-middle attack<\/li>\r\n<\/ul>\r\n<div>\r\n\r\n<strong>0.\u00a0 <\/strong><strong>Diffie-Hellman Key Exchange<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The first published public-key algorithm appeared in the seminal paper by Diffie and Hellman that defined public-key cryptography and is generally referred to as Diffie-Hellman key exchange. A number of commercial products employ this key exchange technique. The purpose of the algorithm is to enable two users to securely exchange a key that can then be used for subsequent encryption of messages. The algorithm itself is limited to the exchange of secret values.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The Diffie-Hellman algorithm depends for its effectiveness on the difficulty of computing discrete logarithms. Briefly, we can define the discrete logarithm in the following way. First, we define a primitive root of a prime number <em>p<\/em> as one whose powers modulo <em>p<\/em> generate all the integers from 1 to <em>p<\/em> 1. That is, if <em>a<\/em> is a primitive root of the prime number <em>p<\/em>, then the numbers <em>a<\/em> mod <em>p<\/em>, <em>a<\/em><sup>2<\/sup> mod <em>p<\/em>,..., <em>a<\/em><sup>p1<\/sup> mod <em>p<\/em><\/p>\r\nare distinct and consist of the integers from 1 through <em>p<\/em> 1 in some permutation.\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\">For any integer <em>b<\/em> and a primitive root <em>a<\/em> of prime number <em>p<\/em>, we can find a unique exponent <em>i<\/em> such that<em>b<\/em> <em>\u2261a<\/em><sup><em>i<\/em> <\/sup>(mod <em>p<\/em>) where 0\u2264 i \u2264(<em>p<\/em> 1). The exponent <em>i<\/em> is referred to as the discrete logarithm of <em>b<\/em> for the base <em>a<\/em>, mod <em>p<\/em>. We express this value as dlog<sub><em>a,p<\/em><\/sub> (<em>b<\/em>). See Chapter 8 for an extended discussion of discrete logarithms.<\/p>\r\n&nbsp;\r\n<ol start=\"2\">\r\n \t<li><strong> Principle behind Diffie-Hellman<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify\">Figure 1 summarizes the Diffie-Hellman key exchange algorithm. For this scheme, there are two publicly known numbers: a prime number <em>q<\/em> and an integer that is a primitive root of <em>q<\/em>. Suppose the users A and B wish to exchange a key. User A selects a random integer <em>X<\/em><em>A<\/em> &lt; <em>q<\/em> and computes <em>Y<\/em><em>A<\/em> = \u03b1<sup><em>XA<\/em><\/sup> mod <em>q<\/em>. Similarly, user B independently selects a random integer <em>X<\/em><em>A<\/em> &lt; <em>q<\/em> and computes <em>Y<\/em><em>B<\/em> = \u03b1<sup><em>XB<\/em><\/sup> mod <em>q<\/em>. Each side keeps the <em>X<\/em> value private and makes the <em>Y<\/em> value available publicly to the other side. User A computes the key as <em>K<\/em> = (<em>Y<\/em><em>B<\/em>)<sup><em>X<\/em><\/sup><em>A<\/em> mod <em>q<\/em> and user B computes the key as<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-340\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71.jpg\" alt=\"\" width=\"570\" height=\"284\" \/>\r\n\r\n<img class=\"alignnone size-full wp-image-341 aligncenter\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72.jpg\" alt=\"\" width=\"619\" height=\"559\" \/>\r\n\r\n&nbsp;\r\n<div>\r\n<p style=\"text-align: justify\">The result is that the two sides have exchanged a secret value. Furthermore, because <em>X<\/em><sub><em>A<\/em><\/sub> and <em>X<\/em><sub><em>B<\/em><\/sub> are private, an adversary only has the following ingredients to work with: <em>q<\/em>, \u03b1, <em>Y<\/em><sub><em>A<\/em><\/sub>, and <em>Y<\/em><sub><em>B<\/em><\/sub>. Thus, the adversary is forced to take a discrete logarithm to determine the key. For example, to determine the private key of user B, an adversary must compute\u00a0<em>X<\/em><sub><em>B<\/em><\/sub> = dlog\u03b1,<em>q<\/em> (<em>Y<\/em><sub><em>B<\/em><\/sub>) The adversary can then calculate the key<em> K <\/em>in the same manner as user B calculates it. The security of the Diffie-Hellman key exchange lies in the fact that, while it is relatively easy to calculate exponentials modulo a prime, it is very difficult to calculate discrete logarithms. For large primes, the latter task is considered infeasible.<\/p>\r\n\r\n<\/div>\r\n<strong>Example 1<\/strong>\r\n\r\n&nbsp;\r\n\r\nLet us give a trivial example to make the procedure clear. Our example uses small numbers, but note that in a real situation, the numbers are very large. Assume that g=7 and p=23.The steps are as follows:\r\n<ol>\r\n \t<li>Alice chooses x=3 and calculate R1 =7<sup>3<\/sup>mod 23=21<\/li>\r\n \t<li>Bob chooses y=6 and calculate R2=7<sup>6<\/sup>mod 23=4<\/li>\r\n \t<li>Alice sends the number 21 to Bob<\/li>\r\n \t<li>Bob sends the number 4 to Alice<\/li>\r\n \t<li>Alice calculates the symmetric key K=4<sup>3<\/sup> mod 23=18<\/li>\r\n \t<li>Bob calculates the symmetric key K=2<sup>16<\/sup> mod 23=18<\/li>\r\n<\/ol>\r\nThe value of K is the same for both Alice and Bob; gxy mod p=718 mod=18\r\n\r\n&nbsp;\r\n\r\n<strong>Example 2<\/strong>\r\n<p style=\"text-align: justify\">Let us give a more realistic example. We used a program to create a random integer of 512bits (the ideal is 1024 bits). The integer p is a 159-digit number.<\/p>\r\n<p style=\"text-align: justify\">We also choose g,x, and y as shown below:<\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-342\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73.jpg\" alt=\"\" width=\"518\" height=\"191\" \/>\r\n\r\n<img class=\"alignnone size-full wp-image-343\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74.jpg\" alt=\"\" width=\"613\" height=\"314\" \/>\r\n<ol start=\"3\">\r\n \t<li><strong> Key Exchange Protocols<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify\">Figure 2 shows a simple protocol that makes use of the Diffie-Hellman calculation. Suppose that user A, wishes to set up a connection with user B and use a secret key to encrypt messages on that connection. User A can generate a one-time private key <em>X<\/em><sub><em>A<\/em><\/sub>, calculate <em>Y<\/em><sub><em>A<\/em><\/sub>, and send that to user B. User B responds by generating a private value <em>X<\/em><sub><em>B<\/em> <\/sub>calculating <em>Y<\/em><sub><em>B<\/em><\/sub>, and sending <em>Y<\/em><sub><em>B<\/em><\/sub> to user A. Both users can now calculate the key. The necessary public values <em>q<\/em> and \u03b1 would need to be known ahead of time. Alternatively, user A could pick values for <em>q<\/em> and \u03b1 and include those in the first message.<\/p>\r\n<img class=\"alignnone size-full wp-image-344\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75.jpg\" alt=\"\" width=\"573\" height=\"349\" \/>\r\n<div>\r\n<p style=\"text-align: justify\">As an example of another use of the Diffie-Hellman algorithm, suppose that a group of users (e.g., all users on a LAN) each generate a long-lasting private value <em>Xi<\/em> (for user <em>i<\/em>) and calculate a public value <em>Yi<\/em>. These public values, together with global public values for <em>q<\/em> and \u03b1, are stored in some central directory. At any time, user <em>j<\/em> can access user <em>i<\/em>'s public value, calculate a secret key, and use that to send an encrypted message to user A. If the central directory is trusted, then this form of communication provides both confidentiality and a degree of authentication. Because only <em>i<\/em> and <em>j<\/em> can determine the key,no other user can read the message (confidentiality). Recipient <em>i<\/em> knows that only user <em>j<\/em> could have created a message using this key (authentication). However, the technique does not protect against replay attacks.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>4. Man-in-the-Middle Attack<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">It is insecure against a man-in-the-middle attack. Suppose Alice and Bob wish to exchange keys, and Darth is the adversary. The attack proceeds as follows:<\/p>\r\n&nbsp;\r\n\r\n<strong>1.\u00a0\u00a0 <\/strong>Darth prepares for the attack by generating two random private keys <em>X<\/em><em>D<\/em><sub>1<\/sub> and <em>X<\/em><em>D<\/em><sub>2<\/sub>\r\n\r\n&nbsp;\r\n\r\nand then computing the corresponding public keys <em>Y<\/em><em>D<\/em><sub>1<\/sub> and <em>Y<\/em><em>D<\/em><sub>2.<\/sub>\r\n\r\n&nbsp;\r\n\r\n<strong>2.\u00a0 <\/strong>Alice transmits <em>Y<\/em><sub><em>A<\/em><\/sub> to Bob.\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>3.\u00a0 <\/strong>Darth intercepts <em>Y<\/em><sub><em>A<\/em><\/sub> and transmits <em>Y<\/em><em>D<\/em><sup>1<\/sup> to Bob.Darth also calculates <em>K<\/em>2 = (<em>Y<\/em><sub><em>A<\/em><\/sub>)<sup><em>X<\/em><\/sup><em>D<\/em>2\r\n\r\n&nbsp;\r\n\r\nmod <em>q<\/em>.\r\n\r\n&nbsp;\r\n\r\n<strong>4.\u00a0 <\/strong>Bob receives <em>Y<\/em><em>D<\/em><sup>1<\/sup> and calculates <em>K<\/em>1 = (<em>Y<\/em><em>D<\/em><sup>1<\/sup>)<sup><em>X<\/em><\/sup><sub><em>E<\/em><\/sub> mod <em>q<\/em>.\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>5.\u00a0 <\/strong>Bob transmits <em>X<\/em><sub><em>A<\/em> <\/sub>to Alice.\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>6.\u00a0 <\/strong>Darth intercepts <em>X<\/em><em>A<\/em> and transmits <em>Y<\/em><em>D<\/em><sup><em>2<\/em><\/sup> to Alice. Darth calculates <em>K<\/em>1 = (<em>Y<\/em><sub><em>B<\/em><\/sub>)<sup><em>X<\/em><\/sup><em>D<\/em>1\r\n\r\n&nbsp;\r\n\r\nmod <em>q<\/em>.\r\n\r\n&nbsp;\r\n\r\n<strong>7.\u00a0 <\/strong>Alice receives <em>Y<\/em><em>D<\/em><sup><em>2<\/em><\/sup> and calculates <em>K<\/em>2 = (<em>Y<\/em><sub><em>D2<\/em><\/sub>)<sup><em>X<\/em><\/sup><sub><em>A<\/em><\/sub> mod <em>q<\/em>.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">At this point, Bob and Alice think that they share a secret key, but instead Bob and Darth share secret key <em>K<\/em>1 and Alice and Darth share secret key <em>K<\/em>2. All future communication between Bob and Alice is compromised in the following way:<\/p>\r\n&nbsp;\r\n\r\n<strong>1.\u00a0 <\/strong>Alice sends an encrypted message <em>M<\/em>: E(<em>K<\/em>2, <em>M<\/em>).\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>2.\u00a0 <\/strong>Darth intercepts the encrypted message and decrypts it, to recover <em>M<\/em>.\r\n\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong>3.\u00a0 <\/strong>Darth sends Bob E(<em>K<\/em>1, <em>M<\/em>) or E(<em>K<\/em>1, <em>M<\/em>'), where <em>M<\/em>' is any message.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In the first case, Darth simply wants to eavesdrop on the communication without altering it. In the second case, Darth wants to modify the message going to Bob. The key exchange protocol is vulnerable to such an attack because it does not authenticate the participants. This vulnerability can be overcome with the use of digital signatures and public-key certificates.<\/p>\r\n\r\n<\/div>\r\n<strong>Summary<\/strong>\r\n<ul>\r\n \t<li>A session key is created between Alice and bob using KDC<\/li>\r\n \t<li>Symmetric-key agreement method is discussed<\/li>\r\n \t<li>\u00a0Man-in-middle attack method is discussed<\/li>\r\n<\/ul>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Diffie-Hellman Key Exchange<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/XtojFDQdEMc\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<img class=\"size-full wp-image-345 aligncenter\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76.jpg\" alt=\"\" width=\"504\" height=\"427\" \/>","rendered":"<div><span style=\"float: right\"><a href=\"https:\/\/youtu.be\/XtojFDQdEMc\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Security <\/strong><strong>Objectives<\/strong><\/p>\n<ul>\n<li>\u00a0To explain how to create a session key between Alice and bob using KDC<\/li>\n<\/ul>\n<ul>\n<li>To create session key method referred to as symmetric-key agreement<\/li>\n<\/ul>\n<ul>\n<li>\u00a0To discuss man-in-middle attack<\/li>\n<\/ul>\n<div>\n<p><strong>0.\u00a0 <\/strong><strong>Diffie-Hellman Key Exchange<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The first published public-key algorithm appeared in the seminal paper by Diffie and Hellman that defined public-key cryptography and is generally referred to as Diffie-Hellman key exchange. A number of commercial products employ this key exchange technique. The purpose of the algorithm is to enable two users to securely exchange a key that can then be used for subsequent encryption of messages. The algorithm itself is limited to the exchange of secret values.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The Diffie-Hellman algorithm depends for its effectiveness on the difficulty of computing discrete logarithms. Briefly, we can define the discrete logarithm in the following way. First, we define a primitive root of a prime number <em>p<\/em> as one whose powers modulo <em>p<\/em> generate all the integers from 1 to <em>p<\/em> 1. That is, if <em>a<\/em> is a primitive root of the prime number <em>p<\/em>, then the numbers <em>a<\/em> mod <em>p<\/em>, <em>a<\/em><sup>2<\/sup> mod <em>p<\/em>,&#8230;, <em>a<\/em><sup>p1<\/sup> mod <em>p<\/em><\/p>\n<p>are distinct and consist of the integers from 1 through <em>p<\/em> 1 in some permutation.<\/p>\n<\/div>\n<p style=\"text-align: justify\">For any integer <em>b<\/em> and a primitive root <em>a<\/em> of prime number <em>p<\/em>, we can find a unique exponent <em>i<\/em> such that<em>b<\/em> <em>\u2261a<\/em><sup><em>i<\/em> <\/sup>(mod <em>p<\/em>) where 0\u2264 i \u2264(<em>p<\/em> 1). The exponent <em>i<\/em> is referred to as the discrete logarithm of <em>b<\/em> for the base <em>a<\/em>, mod <em>p<\/em>. We express this value as dlog<sub><em>a,p<\/em><\/sub> (<em>b<\/em>). See Chapter 8 for an extended discussion of discrete logarithms.<\/p>\n<p>&nbsp;<\/p>\n<ol start=\"2\">\n<li><strong> Principle behind Diffie-Hellman<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify\">Figure 1 summarizes the Diffie-Hellman key exchange algorithm. For this scheme, there are two publicly known numbers: a prime number <em>q<\/em> and an integer that is a primitive root of <em>q<\/em>. Suppose the users A and B wish to exchange a key. User A selects a random integer <em>X<\/em><em>A<\/em> &lt; <em>q<\/em> and computes <em>Y<\/em><em>A<\/em> = \u03b1<sup><em>XA<\/em><\/sup> mod <em>q<\/em>. Similarly, user B independently selects a random integer <em>X<\/em><em>A<\/em> &lt; <em>q<\/em> and computes <em>Y<\/em><em>B<\/em> = \u03b1<sup><em>XB<\/em><\/sup> mod <em>q<\/em>. Each side keeps the <em>X<\/em> value private and makes the <em>Y<\/em> value available publicly to the other side. User A computes the key as <em>K<\/em> = (<em>Y<\/em><em>B<\/em>)<sup><em>X<\/em><\/sup><em>A<\/em> mod <em>q<\/em> and user B computes the key as<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-340\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71.jpg\" alt=\"\" width=\"570\" height=\"284\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71.jpg 570w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71-300x149.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71-65x32.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71-225x112.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-71-350x174.jpg 350w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-341 aligncenter\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72.jpg\" alt=\"\" width=\"619\" height=\"559\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72.jpg 619w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72-300x271.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72-65x59.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72-225x203.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-72-350x316.jpg 350w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p style=\"text-align: justify\">The result is that the two sides have exchanged a secret value. Furthermore, because <em>X<\/em><sub><em>A<\/em><\/sub> and <em>X<\/em><sub><em>B<\/em><\/sub> are private, an adversary only has the following ingredients to work with: <em>q<\/em>, \u03b1, <em>Y<\/em><sub><em>A<\/em><\/sub>, and <em>Y<\/em><sub><em>B<\/em><\/sub>. Thus, the adversary is forced to take a discrete logarithm to determine the key. For example, to determine the private key of user B, an adversary must compute\u00a0<em>X<\/em><sub><em>B<\/em><\/sub> = dlog\u03b1,<em>q<\/em> (<em>Y<\/em><sub><em>B<\/em><\/sub>) The adversary can then calculate the key<em> K <\/em>in the same manner as user B calculates it. The security of the Diffie-Hellman key exchange lies in the fact that, while it is relatively easy to calculate exponentials modulo a prime, it is very difficult to calculate discrete logarithms. For large primes, the latter task is considered infeasible.<\/p>\n<\/div>\n<p><strong>Example 1<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Let us give a trivial example to make the procedure clear. Our example uses small numbers, but note that in a real situation, the numbers are very large. Assume that g=7 and p=23.The steps are as follows:<\/p>\n<ol>\n<li>Alice chooses x=3 and calculate R1 =7<sup>3<\/sup>mod 23=21<\/li>\n<li>Bob chooses y=6 and calculate R2=7<sup>6<\/sup>mod 23=4<\/li>\n<li>Alice sends the number 21 to Bob<\/li>\n<li>Bob sends the number 4 to Alice<\/li>\n<li>Alice calculates the symmetric key K=4<sup>3<\/sup> mod 23=18<\/li>\n<li>Bob calculates the symmetric key K=2<sup>16<\/sup> mod 23=18<\/li>\n<\/ol>\n<p>The value of K is the same for both Alice and Bob; gxy mod p=718 mod=18<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 2<\/strong><\/p>\n<p style=\"text-align: justify\">Let us give a more realistic example. We used a program to create a random integer of 512bits (the ideal is 1024 bits). The integer p is a 159-digit number.<\/p>\n<p style=\"text-align: justify\">We also choose g,x, and y as shown below:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-342\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73.jpg\" alt=\"\" width=\"518\" height=\"191\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73.jpg 518w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73-300x111.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73-65x24.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73-225x83.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-73-350x129.jpg 350w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-343\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74.jpg\" alt=\"\" width=\"613\" height=\"314\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74.jpg 613w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74-300x154.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74-65x33.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74-225x115.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-74-350x179.jpg 350w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/p>\n<ol start=\"3\">\n<li><strong> Key Exchange Protocols<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify\">Figure 2 shows a simple protocol that makes use of the Diffie-Hellman calculation. Suppose that user A, wishes to set up a connection with user B and use a secret key to encrypt messages on that connection. User A can generate a one-time private key <em>X<\/em><sub><em>A<\/em><\/sub>, calculate <em>Y<\/em><sub><em>A<\/em><\/sub>, and send that to user B. User B responds by generating a private value <em>X<\/em><sub><em>B<\/em> <\/sub>calculating <em>Y<\/em><sub><em>B<\/em><\/sub>, and sending <em>Y<\/em><sub><em>B<\/em><\/sub> to user A. Both users can now calculate the key. The necessary public values <em>q<\/em> and \u03b1 would need to be known ahead of time. Alternatively, user A could pick values for <em>q<\/em> and \u03b1 and include those in the first message.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-344\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75.jpg\" alt=\"\" width=\"573\" height=\"349\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75.jpg 573w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75-300x183.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75-65x40.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75-225x137.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-75-350x213.jpg 350w\" sizes=\"auto, (max-width: 573px) 100vw, 573px\" \/><\/p>\n<div>\n<p style=\"text-align: justify\">As an example of another use of the Diffie-Hellman algorithm, suppose that a group of users (e.g., all users on a LAN) each generate a long-lasting private value <em>Xi<\/em> (for user <em>i<\/em>) and calculate a public value <em>Yi<\/em>. These public values, together with global public values for <em>q<\/em> and \u03b1, are stored in some central directory. At any time, user <em>j<\/em> can access user <em>i<\/em>&#8216;s public value, calculate a secret key, and use that to send an encrypted message to user A. If the central directory is trusted, then this form of communication provides both confidentiality and a degree of authentication. Because only <em>i<\/em> and <em>j<\/em> can determine the key,no other user can read the message (confidentiality). Recipient <em>i<\/em> knows that only user <em>j<\/em> could have created a message using this key (authentication). However, the technique does not protect against replay attacks.<\/p>\n<\/div>\n<div>\n<p><strong>4. Man-in-the-Middle Attack<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">It is insecure against a man-in-the-middle attack. Suppose Alice and Bob wish to exchange keys, and Darth is the adversary. The attack proceeds as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.\u00a0\u00a0 <\/strong>Darth prepares for the attack by generating two random private keys <em>X<\/em><em>D<\/em><sub>1<\/sub> and <em>X<\/em><em>D<\/em><sub>2<\/sub><\/p>\n<p>&nbsp;<\/p>\n<p>and then computing the corresponding public keys <em>Y<\/em><em>D<\/em><sub>1<\/sub> and <em>Y<\/em><em>D<\/em><sub>2.<\/sub><\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u00a0 <\/strong>Alice transmits <em>Y<\/em><sub><em>A<\/em><\/sub> to Bob.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>3.\u00a0 <\/strong>Darth intercepts <em>Y<\/em><sub><em>A<\/em><\/sub> and transmits <em>Y<\/em><em>D<\/em><sup>1<\/sup> to Bob.Darth also calculates <em>K<\/em>2 = (<em>Y<\/em><sub><em>A<\/em><\/sub>)<sup><em>X<\/em><\/sup><em>D<\/em>2<\/p>\n<p>&nbsp;<\/p>\n<p>mod <em>q<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>4.\u00a0 <\/strong>Bob receives <em>Y<\/em><em>D<\/em><sup>1<\/sup> and calculates <em>K<\/em>1 = (<em>Y<\/em><em>D<\/em><sup>1<\/sup>)<sup><em>X<\/em><\/sup><sub><em>E<\/em><\/sub> mod <em>q<\/em>.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>5.\u00a0 <\/strong>Bob transmits <em>X<\/em><sub><em>A<\/em> <\/sub>to Alice.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>6.\u00a0 <\/strong>Darth intercepts <em>X<\/em><em>A<\/em> and transmits <em>Y<\/em><em>D<\/em><sup><em>2<\/em><\/sup> to Alice. Darth calculates <em>K<\/em>1 = (<em>Y<\/em><sub><em>B<\/em><\/sub>)<sup><em>X<\/em><\/sup><em>D<\/em>1<\/p>\n<p>&nbsp;<\/p>\n<p>mod <em>q<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>7.\u00a0 <\/strong>Alice receives <em>Y<\/em><em>D<\/em><sup><em>2<\/em><\/sup> and calculates <em>K<\/em>2 = (<em>Y<\/em><sub><em>D2<\/em><\/sub>)<sup><em>X<\/em><\/sup><sub><em>A<\/em><\/sub> mod <em>q<\/em>.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">At this point, Bob and Alice think that they share a secret key, but instead Bob and Darth share secret key <em>K<\/em>1 and Alice and Darth share secret key <em>K<\/em>2. All future communication between Bob and Alice is compromised in the following way:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.\u00a0 <\/strong>Alice sends an encrypted message <em>M<\/em>: E(<em>K<\/em>2, <em>M<\/em>).<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>2.\u00a0 <\/strong>Darth intercepts the encrypted message and decrypts it, to recover <em>M<\/em>.<\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong>3.\u00a0 <\/strong>Darth sends Bob E(<em>K<\/em>1, <em>M<\/em>) or E(<em>K<\/em>1, <em>M<\/em>&#8216;), where <em>M<\/em>&#8216; is any message.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In the first case, Darth simply wants to eavesdrop on the communication without altering it. In the second case, Darth wants to modify the message going to Bob. The key exchange protocol is vulnerable to such an attack because it does not authenticate the participants. This vulnerability can be overcome with the use of digital signatures and public-key certificates.<\/p>\n<\/div>\n<p><strong>Summary<\/strong><\/p>\n<ul>\n<li>A session key is created between Alice and bob using KDC<\/li>\n<li>Symmetric-key agreement method is discussed<\/li>\n<li>\u00a0Man-in-middle attack method is discussed<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Diffie-Hellman Key Exchange<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/XtojFDQdEMc\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-345 aligncenter\" src=\"http:\/\/csp11.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76.jpg\" alt=\"\" width=\"504\" height=\"427\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76.jpg 504w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76-300x254.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76-65x55.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76-225x191.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-content\/uploads\/sites\/55\/2018\/07\/Capture-76-350x297.jpg 350w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/p>\n","protected":false},"author":3,"menu_order":25,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-339","chapter","type-chapter","status-publish","hentry"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapters\/339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/wp\/v2\/users\/3"}],"version-history":[{"count":5,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapters\/339\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapters\/339\/revisions\/593"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapters\/339\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/pressbooks\/v2\/chapter-type?post=339"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/wp\/v2\/contributor?post=339"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp11\/wp-json\/wp\/v2\/license?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}