源工程: https://sourceforge.net/projects/rsaref/files/
1. Alice:
选择1个素数 p (即Prime: 模数N, RFC3526协议中定义,协商中Diffie-Hellman Group Num决定) , 比如509;
底数 g (即:素数 A ) 比如 5;
随机数 a (即:私钥dhpriv/指数E),取值范围 [1:p-1], 比如123。
然后 ==>
计算:公钥Pa( 即(公钥dhpub): B ):Pa=g^a mod p=bcmod(bcpow(5,123),509)=215
发送:Alice现在有[p=509,g=5,a=123,Pa=215], 把模数p,底数g, 公钥Pa发送给Bob
2. Bob:
收到 p=509, g=5, Pa = 215(dhpub_p)后, 选择一个随机数 b = 456(私钥dhpriv)
然后 ==>
计算: 公钥Pb=g^b mod p=bcmod(bcpow(5,456),509)=181
同时计算: 对称密钥 s =Pa^b mod p=bcmod(bcpow(215,456),509)=121
发送:Bob现在有[p=509,g=5,b=456,B=181,s=121,A=125];Bob把公钥 Pb=181发送给Alice
3. Alice:
现在有[p,g,a,A,B] ,Alice再
计算:对称密钥 s =Pb^a mod p=bcmod(bcpow(181,123),509)=121
参考:
https://www.cnblogs.com/HKUI/p/12865277.html
https://www.codetd.com/article/1828792
https://datatracker.ietf.org/doc/rfc7296/ //Internet Key Exchange Protocol Version 2 (IKEv2)
http://mirrors.zju.edu.cn/rfc/rfc3526.txt //More Modular Exponential (MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)
http://mirrors.ustc.edu.cn/rfc/rfc5114.txt //Additional Diffie-Hellman Groups for Use with IETF Standards
http://mirrors.ustc.edu.cn/rfc/rfc4753.txt //椭圆曲线 ECP Groups for IKE and IKEv2