Diffie–Hellman key exchange

来源:互联网 发布:java最有名的论坛 编辑:程序博客网 时间:2024/04/29 22:44

http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange

 

Diffie–Hellman key exchange

 

The simplest, and original, implementation of the protocol uses the multiplicative group of integers modulo p, where p is prime and g is primitive root mod p. Here is an example of the protocol, with non-secret values inblue, and secret values inboldface red:

AliceBobSecretPublicCalculatesSendsCalculatesPublicSecretap, g p,g\rightarrow  bap, g, Aga mod p = AA\rightarrow p, gbap, g, A \leftarrow Bgb mod p = Bp, g, A, Bba, sp, g, A, BBa mod p = s Ab mod p = sp, g, A, Bb, s  

  1. Alice and Bob agree to use a prime numberp=23 and baseg=5.
  2. Alice chooses a secret integer a=6, then sends BobA =ga modp
    • A = 56 mod23
    • A = 15,625 mod23
    • A = 8
  3. Bob chooses a secret integer b=15, then sends AliceB =gb modp
    • B = 515 mod23
    • B = 30,517,578,125 mod23
    • B = 19
  4. Alice computes s = Ba modp
    • s = 196 mod 23
    • s = 47,045,881 mod23
    • s = 2
  5. Bob computes s = Ab modp
    • s = 815 mod 23
    • s = 35,184,372,088,832 mod23
    • s = 2
  6. Alice and Bob now share a secret: s =2. This is because6*15 is the same as15*6. So somebody who had known both these private integers might also have calculateds as follows:
    • s = 56*15 mod 23
    • s = 515*6 mod 23
    • s = 590 mod 23
    • s = 807,793,566,946,316,088,741,610,050,849,573,099,185,363,389,551,639,556,884,765,625 mod23
    • s = 2

Both Alice and Bob have arrived at the same value, because (ga)b and (gb)a are equal modp. Note that onlya,b andgab = gba modp are kept secret. All the other values –p,g,ga mod p, andgb mod p – are sent in the clear. Once Alice and Bob compute the shared secret they can use it as an encryption key, known only to them, for sending messages across the same open communications channel. Of course, much larger values ofa,b, and p would be needed to make this example secure, since it is easy to try all the possible values ofgab mod 23. There are only 23 possible integers as the result of mod 23. Ifp were a prime of at least 300 digits, and a and b were at least 100 digits long, then even the best algorithms known today could not finda given onlyg,p,gb modp andga modp, even using all of mankind's computing power. The problem is known as thediscrete logarithm problem. Note thatg need not be large at all, and in practice is usually either 2 or 5.

 

 

Here's a more general description of the protocol:

  1. Alice and Bob agree on a finite cyclic group G and a generating element g in G. (This is usually done long before the rest of the protocol;g is assumed to be known by all attackers.) We will write the groupG multiplicatively.
  2. Alice picks a random natural number a and sends ga to Bob.
  3. Bob picks a random natural number b and sends gb to Alice.
  4. Alice computes (gb)a.
  5. Bob computes (ga)b.

Both Alice and Bob are now in possession of the group element gab, which can serve as the shared secret key. The values of (gb)a and (ga)b are the same because groups are power associative. (See also exponentiation.)

In order to decrypt a message m, sent as mgab, Bob (or Alice) must first compute(gab)-1, as follows:

Bob knows |G|, b, and ga. A result from group theory establishes that from the construction of G,x|G| = 1 for allx inG.

Bob then calculates (ga)|G|-b = ga(|G|-b) = ga|G|-ab = ga|G|g-ab = (g|G|)ag-ab=1ag-ab=g-ab=(gab)-1.

When Alice sends Bob the encrypted message, mgab, Bob applies(gab)-1 and recoversmgab(gab)-1 = m(1) = m.

 

Operation with more than two parties

Diffie-Hellman key agreement is not limited to negotiating a key shared by only two participants. Any number of users can take part in an agreement by performing iterations of the agreement protocol and exchanging intermediate data (which does not itself need to be kept secret). For example, Alice, Bob, and Carol could participate in a Diffie-Hellman agreement as follows, with all operations taken to be modulop:

  1. The parties agree on the algorithm parameters p and g.
  2. The parties generate their private keys, named a, b, and c.
  3. Alice computes ga and sends it to Bob.
  4. Bob computes (ga)b =gab and sends it to Carol.
  5. Carol computes (gab)c =gabc and uses it as her secret.
  6. Bob computes gb and sends it to Carol.
  7. Carol computes (gb)c =gbc and sends it to Alice.
  8. Alice computes (gbc)a =gbca =gabc and uses it as her secret.
  9. Carol computes gc and sends it to Alice.
  10. Alice computes (gc)a =gca and sends it to Bob.
  11. Bob computes (gca)b =gcab =gabc and uses it as his secret.

An eavesdropper has been able to see ga,gb,gc,gab,gac, andgbc, but cannot use any combination of these to reproducegabc.

To extend this mechanism to larger groups, two basic principles must be followed:

  • Starting with an “empty” key consisting only of g, the secret is made by raising the current value to every participant’s private exponent once, in any order (the first such exponentiation yields the participant’s own public key).
  • Any intermediate value (having up to N − 1 exponents applied, whereN is the number of participants in the group) may be revealed publicly, but the final value (having had allN exponents applied) constitutes the shared secret and hence must never be revealed publicly. Thus, each user must obtain their copy of the secret by applying their own private key last (otherwise there would be no way for the last contributor to communicate the final key to its recipient, as that last contributor would have turned the key into the very secret the group wished to protect).

These principles leave open various options for choosing in which order participants contribute to keys. The simplest and most obvious solution is to arrange theN participants in a circle and haveN keys rotate around the circle, until eventually every key has been contributed to by allN participants (ending with its owner) and each participant has contributed toN keys (ending with their own). However, this requires that every participant performN modular exponentiations.

By choosing a more optimal order, and relying on the fact that keys can be duplicated, it is possible to reduce the number of modular exponentiations performed by each participant tolog 2N + 1 using a divide-and-conquer-style approach, given here for eight participants:

  1. Participants A, B, C, and D each perform one exponentiation, yielding gabcd; this value is sent to E, F, G, and H. In return, participants A, B, C, and D receivegefgh.
  2. Participants A and B each perform one exponentiation, yielding gefghab, which they send to C and D, while C and D do the same, yieldinggefghcd, which they send to A and B.
  3. Participant A performs an exponentiation, yielding gefghcda, which it sends to B; similarly, B sendsgefghcdb to A. C and D do similarly.
  4. Participant A performs one final exponentiation, yielding the secret gefghcdba = gabcdefgh, while B does the same to getgefghcdab =gabcdefgh; again, C and D do similarly.
  5. Participants E through H simultaneously perform the same operations using gabcd as their starting point.

Upon completing this algorithm, all participants will possess the secret gabcdefgh, but each participant will have performed only four modular exponentiations, rather than the eight implied by a simple circular arrangement.

原创粉丝点击