解释:
在,Curve25519是一个提供128位的安全性,并设计用于(ECDH)密钥协商方案。它是最快的ECC曲线之一,并没有被任何已知的专利所涵盖。所述的是。
原来的Curve25519论文将其定义为(DH)功能。曾经提出使用Curve25519的名称作为基础曲线,而名称为X25519为DH功能。
数学性质
所使用的曲线是由2 255 - 19定义的场的上的y 2 = x 3 + 486662 x 2 + x,,并且使用基点x = 9。协议使用压缩椭圆点(只有X坐标),因此它允许仅使用XZ坐标有效地使用进行。
Curve25519的构建使得它避免了许多潜在的实施陷阱。通过设计,它免受定时攻击,它接受任何32字节的字符串作为有效的公钥,不需要验证。
曲线与Ed25519签名方案中使用的曲线是。
首先安装
pip install donna25519
代码:
In [116]:
import random# help(random.randrange)import binasciiimport donna25519 as curve25519
In [121]:
bobs_private=curve25519.PrivateKey()bobs_public=bobs_private.get_public()print("BOb's Private Key:",binascii.hexlify(bobs_private.private))print("BOb's Public Key:",binascii.hexlify(bobs_public.public))
BOb's Private Key: b'180b6a7274b2797688d7d7d6e982ad13c49923ba6d52f8ecd93a9a1b2ba60a76'BOb's Public Key: b'f43ae3b47138a406ac72ce599cb5f25e1714922a966861d97775843956dfcd26'
In [122]:
Alis_private=curve25519.PrivateKey()Alis_public=Alis_private.get_public()print("Alis's Private Key:",binascii.hexlify(Alis_private.private))print("Alis's Public Key:",binascii.hexlify(Alis_public.public))
Alis's Private Key: b'f8f699f118a912df27cefad42b247fceb4b11e0b5f77471ebfd67308cf1b5e64'Alis's Public Key: b'cff4d3898bcd945b45391ff79d139064777f3117f732eb26b22a2cc73261ab0f'
In [123]:
# Alis pub --> bobbobs_sharekey=bobs_private.do_exchange(Alis_public)# Bobs pub -->Alisalis_sharekey=Alis_private.do_exchange(bobs_public)print("Bob's Share Key:",binascii.hexlify(bobs_sharekey))print("Alis's Share Key:",binascii.hexlify(alis_sharekey))
Bob's Share Key: b'0457f7dcdbaeb6bc2aa843a431a2117ad0b38568d1c1e3c1adac88da7008ca48'Alis's Share Key: b'0457f7dcdbaeb6bc2aa843a431a2117ad0b38568d1c1e3c1adac88da7008ca48'
In [124]:
if bobs_sharekey == alis_sharekey: print("ShareKey SAME 100%")else: print("ShareKey Diff")
ShareKey SAME 100%