General overview[edit]

 

Illustration of the idea behind Diffie–Hellman key exchange

Diffie–Hellman key exchange establishes a shared secret between two parties that can be used for secret communication for exchanging data over a public network. The following conceptual diagram illustrates the general idea of the key exchange by using colors instead of very large numbers.

The process begins by having the two parties, Alice and Bob, agree on an arbitrary starting color that does not need to be kept secret (but should be different every time[3]); in this example the color is yellow. Each of them selects a secret color that they keep to themselves. In this case, orange and blue-green. The crucial part of the process is that Alice and Bob now mix their secret color together with their mutually shared color, resulting in orange-tan and light-blue mixtures respectively, then publicly exchange the two mixed colors. Finally, each of the two mix together the color they received from the partner with their own private color. The result is a final color mixture yellow-brown that is identical to the partner's color mixture.

If a third party listened to the exchange, it would be computationally difficult for them to determine the secret colors. In fact, when using large numbers rather than colors, this action is computationally expensive for modern supercomputers to do in a reasonable amount of time.

Cryptographic explanation[edit]

The simplest and the original implementation of the protocol uses the multiplicative group of integers modulo p, where p is prime, and g is a primitive root modulo p. These two values are chosen in this way to ensure that the resulting shared secret can take on any value from 1 to p–1. Here is an example of the protocol, with non-secret values in blue, and secret values in red.

  1. Alice and Bob agree to use a modulus p = 23 and base g = 5 (which is a primitive root modulo 23).
  2. Alice chooses a secret integer a = 4, then sends Bob A = ga mod p
    • A = 54 mod 23 = 4
  3. Bob chooses a secret integer b = 3, then sends Alice B = gb mod p
    • B = 53 mod 23 = 10
  4. Alice computes s = Ba mod p
    • s = 104 mod 23 = 18
  5. Bob computes s = Ab mod p
    • s = 43 mod 23 = 18
  6. Alice and Bob now share a secret (the number 18).

Both Alice and Bob have arrived at the same value s, because, under mod p,

{\displaystyle {\color {Blue}A}^{\color {Red}b}{\bmod {\color {Blue}p}}={\color {Blue}g}^{\color {Red}ab}{\bmod {\color {Blue}p}}={\color {Blue}g}^{\color {Red}ba}{\bmod {\color {Blue}p}}={\color {Blue}B}^{\color {Red}a}{\bmod {\color {Blue}p}}}[8]

More specifically,

{\displaystyle ({\color {Blue}g}^{\color {Red}a}{\bmod {\color {Blue}p}})^{\color {Red}b}{\bmod {\color {Blue}p}}=({\color {Blue}g}^{\color {Red}b}{\bmod {\color {Blue}p}})^{\color {Red}a}{\bmod {\color {Blue}p}}}

Note that only ab, and (gab mod p = gba mod p) are kept secret. All the other values – pgga mod p, and gb 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 of ab, and p would be needed to make this example secure, since there are only 23 possible results of n mod 23. However, if p is a prime of at least 600 digits, then even the fastest modern computers cannot find a given only gp and ga mod p. Such a problem is called the discrete logarithm problem.[3] The computation of ga mod p is known as modular exponentiation and can be done efficiently even for large numbers. Note that g need not be large at all, and in practice is usually a small integer (like 2, 3, ...).

最新文章

  1. onethink连接操作 sqlite 数据库
  2. 如何快速有效的修改java的环境变量
  3. 使用 Python 创建你自己的 Shell(下)
  4. SQL分页查询总结{转}
  5. 错误: 找不到或无法加载主类 / Class not found
  6. Http的Post和Get
  7. vim 多文件编辑【超实用】
  8. MP3 信息读取
  9. Java常用类--数字常用类
  10. 如何将maven的jar项目简单快速的转变成war项目
  11. Qt532.线程(_beginthread)
  12. windows 下 wamp php单元测试工具PHPUnit的安装
  13. ios中修改数字键盘
  14. "CMAKE_CXX_COMPILER-NOTFOUND"
  15. 3、Docker能干什么?
  16. yum 下载RPM包而不进行安装
  17. Linux的vi&vim
  18. ajax请求php,在返回信息前面出现了奇怪的红点点
  19. 会议中心[APIO2009]
  20. Spring入门第五课

热门文章

  1. Struts2-从值栈中获取数据-EL表达式从值栈获取
  2. STL源码分析-rbtree
  3. vim 到文件开头 结尾
  4. proc文件系统介绍
  5. LeakCanary原理分析
  6. C#获取用户基本信息一(关注了公众号的用户)
  7. proxy vue3.0
  8. JAVA多线程提高二:传统线程的互斥与同步&传统线程通信机制
  9. 超越icon font
  10. 你知道吗?31种 CSS 选择器的应用