密码学课程设计报告要求及模板.doc_第1页
密码学课程设计报告要求及模板.doc_第2页
密码学课程设计报告要求及模板.doc_第3页
密码学课程设计报告要求及模板.doc_第4页
密码学课程设计报告要求及模板.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

计算机与信息工程学院 密码学课程设计报告 (2013/2014学年 第 二学期) 题 目: Diffie-Hellman密钥交换协议 系 别: 计算机与信息工程学院 专 业: 信息安全 班 级: 学 号: 姓 名: 成绩类别成 绩个人考勤(20)实践成绩(40)总结报告(40)总成绩(100)等级制成绩2014年05月30日密码学课程设计报告(一)题目Diffie-Hellman密钥交换协议(二)开发工具与环境:window7环境下的Visual Studio2010(三)设计原理: Diffie-Hellman算法的安全性基于求离散对数的困难性。算法的惟一目的是使得两个用户能够安全地交换密钥,得到一个共享的会话密钥,算法本身不能用于加、解密,因此,这里用产生的最终的密钥作为仿射变换加密的密钥来实现对消息的加解密。Diffie-Hellman的设计原理如下:A和B两方要生成共享密钥Y,则首先选定一个大素数p,以及p的原根g,p,g为双方共享,用户A选择一保密的随机证书Xa,并将Ya=gXa modp发送给用户B,类似,B选择一保密的随机整数Xb,并将Yb=gXb modp发送给用户A.之后A和B分别由Y=YbXa modp和Y=YaXb计算出的就是共享密钥。因为Xa,Xb是保密的,敌手只能得到p,a,Ya,Yb,要想得到Y,必须得到Xa,Xb中的一个,这意味着要求离散对数,因此敌手求Y是不可行的,保证了安全。(四)系统功能描述及软件模块划分系统需手动输入随机数Xa,Xb,点击确定后可以隐藏输入的随机数。在原文框中输入需要处理的原文,选择加密或者解密按钮,在结果框中会生成对应的解密或者加密的结果。系统共分为两个模块,一块是Diffie-Hellman模块,用来处理输入的随机数,系统随机生成大素数并找到该大素数的原根,再按照算法思想最终生成共享密钥Y.Mainwindow 模块通过函数接收Diffie-Hellman模块的密钥(五)设计的核心代码MainWindow:MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui:MainWindow) ui-setupUi(this); label1=findChild(label1); label2=findChild(label2); label3=findChild(label3); label4=findChild(label4); text1=findChild(textEdit1); text2=findChild(textEdit2); yuanwen=findChild(textEdit3); jieguo=findChild(textBrowser1); queren=findChild(pushButton1); jiami=findChild(pushButton2); jiemi=findChild(pushButton3); fanhui=findChild(pushButton4); init();MainWindow:MainWindow()delete ui;void MainWindow:on_pushButton1_clicked() unsigned _int64 p,g,Alice_Y,Bob_Y,Alice_key,Bob_key; DiffieHellman Alice,Bob; Alice.init(); Bob.init(); Alice.CreatePrimeAndGenerator(); p=Alice.GetPrime(); g=Alice.GetGenerator(); Bob.SetPrimeAndGenerator(p,g); Alice.CreatePrivateKey(text1-toPlainText().toInt(); Bob.CreatePrivateKey(text2-toPlainText().toInt(); Alice_Y=Alice.GetPublicKey(); Bob_Y=Bob.GetPublicKey(); Alice_key=Alice.GetKey(Bob_Y); Bob_key=Bob.GetKey(Alice_Y); this-Setkey(Alice_key);void MainWindow:on_pushButton2_clicked() eguo-clear(); QString jg,yw; yw = yuanwen-toPlainText(); for(int i = 0;i JiaMi(ywi); jieguo-append(jg);void MainWindow:on_pushButton4_clicked()init();void MainWindow:on_pushButton3_clicked() jieguo-clear(); QString jg,yw; yw = yuanwen-toPlainText(); for(int i = 0;i JieMi(ywi); jieguo-append(jg);class DiffieHellmanpublic: DiffieHellman() p=0; g=0; X=0; Y=0;Key=0; void init(); int CreatePrimeAndGenerator(); unsigned _int64 GetPrime(); unsigned _int64 GetGenerator(); unsigned _int64 GetPublicKey(); unsigned _int64 GetKey(unsigned _int64 HisPublieKey); int SetPrimeAndGenerator(unsigned _int64 Prime,unsigned _int64 Generator); int CreatePrivateKey(int key);private: _int64 GetRandNum( void ); unsigned _int64 GenerateRandomNumber(void); _int64 XpowYmodN(_int64 x, _int64 y, _int64 N); bool IsItPrime (_int64 n, _int64 a) ; bool MillerRabin (_int64 n, _int64 trials); unsigned _int64 GeneratePrime(); int CreatePublicKey(); int GenerateKey(unsigned _int64 HisPublicKey); unsigned _int64 p; /素数 unsigned _int64 g; /对应的本原根 unsigned _int64 X; /私钥 unsigned _int64 Y; /公钥 unsigned _int64 Key;/通讯密钥;void DiffieHellman:init() p=0; g=0; X=0; Y=0; Key=0;_int64 DiffieHellman:GetRandNum( void ) srand(unsigned)time(0); _int64 tmp = (_int64)rand()*(_int64)rand(); return tmp;unsigned _int64 DiffieHellman:GenerateRandomNumber(void) static unsigned long rnd = 0x41594c49; static unsigned long x = 0x94c49514; LFSR(x); rnd=GetRandNum()x; ROT(rnd,7); return (unsigned _int64)GetRandNum() + rnd;_int64 DiffieHellman:XpowYmodN(_int64 x, _int64 y, _int64 N) _int64 tmp = 0; if (y=1) return (x % N); if (y&1)=0) tmp = XpowYmodN(x,y/2,N); return (tmp * tmp) % N); else tmp = XpowYmodN(x,(y-1)/2,N); tmp = (tmp * tmp) % N); tmp = (tmp * x) % N); return (tmp) bool DiffieHellman:IsItPrime (_int64 n, _int64 a) _int64 d = XpowYmodN(a, n-1, n); if (d=1) return true; else return false;bool DiffieHellman:MillerRabin (_int64 n, _int64 trials) _int64 a = 0; for (_int64 i=0; itrials; i+) a = (rand() % (n-3)+2;/ gets random value in 2.n-1 if (IsItPrime (n,a)=false) return false; return true; / n probably primeunsigned _int64 DiffieHellman:GeneratePrime() unsigned _int64 tmp = 0; tmp = GenerateRandomNumber() % MAX_PRIME_NUMBER; /ensure it is an odd number if (tmp % 2)=0) tmp += 1; if (MillerRabin(tmp,5)=true) return tmp; do tmp+=2; while (MillerRabin(tmp,5)=false); return tmp;int DiffieHellman:CreatePrimeAndGenerator()/ 产生素数p,和它的本原根g unsigned _int64 q; bool f=true; while(f) p=GeneratePrime(); q=p*2+1; if(MillerRabin(q,5)=true) f=false; f=true; while(f) g=GenerateRandomNumber() % (p-2); if(XpowYmodN(g, 2, p)!=1 & XpowYmodN(g, q, p)!=1) f=false; return 0;unsigned _int64 DiffieHellman:GetPrime() return p;unsigned _int64 DiffieHellman:GetGenerator() return g;int DiffieHellman:CreatePrivateKey(int key) X=key; return 0;int DiffieHellman:CreatePublicKey() Y=XpowYmodN(g, X, p); return 0;unsigned _int64 DiffieHellman:GetPublicKey() if(Y=0) CreatePublicKey(); return Y;int DiffieHellman:GenerateKey(unsigned _int64 HisPublicKey) Key=XpowYmodN(HisPublicKey, X, p); return 0;unsigned _int64 DiffieHellman:GetKey(unsigned _int64 HisPublicKey) if(Key = 0) Key=XpowYmodN(HisPublicKey, X, p); return Key;int DiffieHellman:SetPrimeAndGenerator(unsigned _int64 Prime,unsigned _int64 Generator) p=Prime; g=Generator; return 0; (六)关键问题及解决方法(1)用Diffie-Hellm

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论