设为首页 收藏本站
查看: 825|回复: 0

[经验分享] Diffie–Hellman key exchange

[复制链接]

尚未签到

发表于 2015-11-24 12:52:49 | 显示全部楼层 |阅读模式
  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 DSC0000.png   bap, g, Aga mod p = AA p, gbap, g, A DSC0001.png Bgb mod p = Bp, g, A, Bba, sp, g, A, BBa mod p = s Ab mod p = sp, g, A, Bb, s  

  • Alice and Bob agree to use a prime numberp=23 and baseg=5.
  • Alice chooses a secret integer a=6, then sends BobA =gamodp

    • A = 56 mod23
    • A = 15,625 mod23
    • A = 8

  • Bob chooses a secret integer b=15, then sends AliceB =gbmodp

    • B = 515 mod23
    • B = 30,517,578,125 mod23
    • B = 19

  • Alice computes s = Ba modp

    • s = 196 mod 23
    • s = 47,045,881 mod23
    • s = 2

  • Bob computes s = Ab modp

    • s = 815 mod 23
    • s = 35,184,372,088,832 mod23
    • s = 2

  • 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 = gbamodp 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 onlyto 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 300digits, 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 thediscretelogarithm 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:

  • 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.
  • Alice picks a random natural number a and sends ga to Bob.
  • Bob picks a random natural number b and sends gb to Alice.
  • Alice computes (gb)a.
  • 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 becausegroups 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 itselfneed 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:

  • The parties agree on the algorithm parameters p and g.
  • The parties generate their private keys, named a, b, and c.
  • Alice computes ga and sends it to Bob.
  • Bob computes (ga)b =gab and sends it to Carol.
  • Carol computes (gab)c =gabc and uses it as her secret.
  • Bob computes gb and sends it to Carol.
  • Carol computes (gb)c =gbc and sends it to Alice.
  • Alice computes (gbc)a =gbca =gabc and uses it as her secret.
  • Carol computes gc and sends it to Alice.
  • Alice computes (gc)a =gca and sends it to Bob.
  • 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 (otherwisethere 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 haveNkeys rotate around the circle, until eventually every key has been contributed to by allN participants (ending with its owner) and each participant has contributed toNkeys (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 usinga divide-and-conquer-style approach, given here for eight participants:

  • 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.
  • 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.
  • Participant A performs an exponentiation, yielding gefghcda, which it sends to B; similarly, B sendsgefghcdb to A. C and D do similarly.
  • 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.
  • 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.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143078-1-1.html 上篇帖子: 交换指令XCHG(exchange) 下篇帖子: Foreign exchange market
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表