newhope后量子密钥交换算法的实验实现
PyNewHope的Python项目详细描述
新希望
pynewhope是alkim、ducas、poppelmann和schwabe提出的newhope量子安全密钥交换加密方案的实验性(不稳定)python实现:https://eprint.iacr.org/2015/1092
newhope使用基于晶格的加密技术,更精确地说是环lwe(有错误的环学习),它被设计成抗量子的。
这个python实现基于并复制了liboqs
存储库中可用的参考c实现的大部分功能:https://github.com/open-quantum-safe/liboqs/tree/master/src/kex_rlwe_newhope
这个实现被设计为在python应用程序中本地使用,而不需要包装器或将c实现合并到生产软件中的其他方法。测试工具在test_newhope.py
中提供,文档作为代码注释提供。代码应该是可读的和可用的。
仅用于教育目的!避免在实际项目中使用此代码。
这项工作是作为硕士学位论文提交给纽约大学库兰特数学科学研究所计算机科学系的高级实验室。它应该被认为是开源的,可以自由使用和修改。
必须安装Python3.6才能使此实现正常工作,因为它依赖于hashlib.shake_128()
,而该版本仅在3.6及更高版本中可用。
从pypi安装说明:
这个库在pypi存储库中可用(由Svetlin Nakov打包)。要安装它,请使用以下命令:
pip install pynewhope
示例用法:
frompynewhopeimportnewhope# Step 1: Alice generates random keys and her public msg to BobalicePrivKey,aliceMsg=newhope.keygen()print("Alice sends to Bob her public message:",aliceMsg)# Step 2: Bob receives the msg from Alice and responds to Alice with a msgbobSharedKey,bobMsg=newhope.sharedB(aliceMsg)print("\nBob sends to Alice his public message:",bobMsg)print("\nBob's shared key:",bobSharedKey)# Step 3: Alice receives the msg from Bob and generates her shared secretaliceSharedKey=newhope.sharedA(bobMsg,alicePrivKey)print("\nAlice's shared key:",aliceSharedKey)ifaliceSharedKey==bobSharedKey:print("\nSuccessful key exchange! Keys match.")else:print("\nError! Keys do not match.")
样本输出:
Alice sends to Bob her public message: ([1328, 8117, 8737, 6265, 8128, 12924, 3390, 12041, 4568, 7602, 2673, 7517, 2410, 1291, 2125, 2789, 11486, 1568, 12043, 9209, 6681, 9858, 5936, ..., 1021, 2113, 8424, 8501, 3442, 4238, 9503, 4625, 11250, 11609], b"\r\x8c\x89\xd0\xa0\x06gc8\xd2%:\xb0Z'\x9c\x8cs\xf9\xf8\xe7\x9f\x84T\xb73\x85w\xcc\xe5\xb5\xe1")
Bob sends to Alice his public message: ([2, 0, 3, 1, 0, 3, 0, 3, 0, 1, 0, 1, 0, 0, 1, 1, 1, 3, 0, 2, 0, 2, 2, 1, 1, 3, 2, 3, 3, 3, 3, 1, 3, 1, 0, 1, 2, 0, 1, 1, 3, 3, 2, 1, 1, 2, 0, 3, 3, 2, 1, 1, 1, 0, 2, 3, 1, ..., 3, 3, 2, 2, 0, 1], [9328, 8906, 2517, 6830, 4517, 2142, 8296, 938, 3333, 10585, 12196, 11496, 3726, 12462, 10271, 4871, 4499, 2899, 11284, 8994, 4732, 7381, 2950, 8675, 4349, 2534, 2161, ..., 6591, 6369, 8664, 5182, 10856, 4314, 7919, 3651, 2352, 4103, 6035, 3990])
Bob's shared key: [92, 122, 75, 33, 239, 164, 84, 241, 245, 204, 106, 197, 142, 230, 28, 189, 54, 112, 190, 124, 176, 66, 129, 69, 108, 66, 110, 42, 115, 70, 17, 107]
Alice's shared key: [92, 122, 75, 33, 239, 164, 84, 241, 245, 204, 106, 197, 142, 230, 28, 189, 54, 112, 190, 124, 176, 66, 129, 69, 108, 66, 110, 42, 115, 70, 17, 107]
Successful key exchange! Keys match.
从输出中可以看到,alice的公共消息由一系列多项式系数+一个随机种子(字节序列)组成。bob的公共消息由两个多项式系数序列组成。由alice和bob共享密钥得到的密钥也由一系列多项式系数组成。
有关在Mac/Linux上克隆和测试Pynewhope的说明:
安装了Python3.6和Git后,打开一个终端并输入以下命令:
git clone https://github.com/nakov/PyNewHope
cd PyNewHope
python3.6 test_newhope.py
在windows上克隆和测试pynewhope的说明:
首先确保安装了Python3.6。
使用“克隆或下载”按钮从https://github.com/nakov/PyNewHope将pynewhope作为zip文件下载。
将pynewhope解压到python路径中的目录中。
打开一个python shell并输入以下命令:
import test_newhope
test_newhope
贡献者:
- 最初由Scott Wyman Neagle创建(2017)-https://github.com/scottwn/
- 基于开放量子安全项目(2016)-https://github.com/open-quantum-safe/liboqs/
- 由Svetlin Nakov修改并上传至PYPI(2018)-https://github.com/nakov