TÀI L IU THAM KHO

Một phần của tài liệu Nghiên cứu giao thức trao đổi khóa an toàn (Trang 77)

- Quy trình kiểm tra ch ký:

TÀI L IU THAM KHO

Ti ng Việt

1. TS. Dương Anh Đức, Ths. Trần Minh Triết (2005), Mã hóa và ứng dụng, Trường Đại học khoa học tự nhiên - Đại học quốc gia TP.HCM

Ti ng Anh

2. B. Arazi (1993), “Integrating a key distribution procedure into the digital signature standard”, Electronics Letters, 29, (11), 966-967.

3. Diffie & M. Hellman (1976), “New Directions in Cryptography”, IEEE Trans. On Info. Theory, IT-22(6), 644-654.

4. D. R. Stinson (1995), Cryptocraphy: theory and practice, CRC press, Nebraska & Lincoln University.

5. Enge (1999), A. Elliptic Curves and their Applications to Cryptography: an Introduction, Springer.

6. J. Liu and J. Li (2010), “A Better Improvement on the Integrated Diffie-Hellman - DSA Key Agreement Protocol”, IEEE Communication Letters, 11, (2), 114- 117.

7. K. Nyberg and R. Rueppel (1994), “Weaknesses in some recent key agreement protocols”, Electronics Letters, 30, (1), 26-27.

8. L. Harn, Ma. Mehta, and W. J. Hsin (2004), “Integrating Diffie-Hellman key exchange into the digital signature algorithm (DSA)”, IEEE Communication Letters, 8, (3), 198-200.

9. Menezes, P. van Oorschot and S. Vanstone (1997), Handbook of Applied Cryptography, Boca Raton, Florida: CRC Press.

10.R. C. W. Phan (2005), “Fixing the integrated Diffie-Hellman DSA key exchange protocol”, IEEE CommunicationLetters, 9, (6), 570-572.

11.R. Kenneth (2000), Elementary number theory and its applications, AT & T Bell Laboratories, 4th edition, ISBN:0-201-87073-8.

12.Wenbo Mao, Prentice Hall PTR (2003), Modern Cryptography: Theory and Practice. River, New Jersey 07458

13.William Stallings (2005), Cryptography and Network Security Principles and Practices, Fourth Edition, Prentice Hall PTR, p. 592.

14.National Institute of Standards and Techonogy , FIPS 186-1, FIPS 186-2, FIPS 186-3, FIPS 186-4.

PH L C

1. Hàm tính giá trị hàm băm

private BigInteger H(string hash) {

UTF8Encoding gbyte = new UTF8Encoding(); byte[] bytes1 = gbyte.GetBytes(hash);

SHA1CryptoServiceProvider SHS = new SHA1CryptoServiceProvider(); byte[] hashBytes = SHS.ComputeHash(bytes1);

BigInteger res = new BigInteger(hashBytes); return res;

}

2. Hàm tạo các số nguyên tố lớn ngẫu nhiên p, q, g private void TaoPQG()

{

Random Rand = new Random();

//***********Khoi tao tham so P, Q, G**************** q = new BigInteger();

p = new BigInteger(); g = new BigInteger(); g = new BigInteger();

//***********TAO THAM SO Q**************** while (q.isProbablePrime(20) == false) while (q.isProbablePrime(20) == false) {

Rand = new Random();

q.genRandomBits(160, Rand);//q ngau nhien 160 bit } (adsbygoogle = window.adsbygoogle || []).push({});

//

//***********TAO THAM SO P****************

BigInteger temp = new BigInteger(Rand.Next(10, 10000)); Random rn = new Random();

temp.genRandomBits(320, rn); p = temp * q + 1; while (!p.isProbablePrime(20)) { rn = new Random(); temp.genRandomBits(320, rn); p = temp * q + 1; } // //***********TAO THAM SO G**************** Rand = new Random();

temp = new BigInteger(Rand.Next(10, 10000)); g = temp.modPow((p - 1) / q, p);

while (g == 1) {

temp = new BigInteger(Rand.Next(10, 100));

g = temp.modPow((p - 1) / q, p);//g=temp^((p-1)/q)mod p }

}

private void txtYA_Click(object sender, EventArgs e) {

Random rn = new Random(); if (txtXA.Text == "") { xA = new BigInteger(rn.Next(10, 100)); xA.genRandomBits(160, rn); txtXA.Text = xA.ToString(); } xA = H(txtXA.Text); yA = g.modPow(xA, p); txtYA.Text = yA.ToHexString(); }

private void txtYB_Click(object sender, EventArgs e) {

Random rn = new Random(); if (txtXB.Text == "") { xB = new BigInteger(rn.Next(10, 100)); xB.genRandomBits(160, rn); txtXB.Text = xB.ToString(); } xB = H(txtXB.Text); yB = g.modPow(xB, p); txtYB.Text = yB.ToHexString(); }

4. Hàm tạo các tham số mA, nA, oAvà gửi cho B

private void btnTao_ma_na_oa_Click(object sender, EventArgs e) {

pic_buoc1.Visible = true; grbBuoc2.Visible = true; //

//Lấy ngẫu nhiên hai số v , v có 8 bit đảm bảo thuộc [ , q-1] Random rd1 = new Random(14);

v1 = new BigInteger(); v1.genRandomBits(128, rd1); mA = g.modPow(v1, p); //

Random rd2 = new Random(74); v2 = new BigInteger(); v2.genRandomBits(128, rd2); nA = g.modPow(v2, p); //

BigInteger temp = mA * nA; oA = temp.modPow(xA, p); txtMA.Text = mA.ToHexString(); txtNA.Text = nA.ToHexString(); txtOA.Text = oA.ToHexString(); }

private void btnTao_mB_nB_oB_sB_Click(object sender, EventArgs e) {

pic_buoc2.Visible = true; grbBuoc3.Visible = true;

BigInteger temp = new BigInteger(); // //Tính rB khác 0 do { do {

//Lấy ngẫu nhiên hai số w , w có 8 bit đảm bảo thuộc [ ,

q-1]

Random rd1 = new Random(2); w1 = new BigInteger(); w1.genRandomBits(128, rd1); Random rd2 = new Random(7); w2 = new BigInteger(); w2.genRandomBits(128, rd2); // //Tính mB, nB, oB, rB mB = g.modPow(w1, p); nB = g.modPow(w2, p); temp = mB * nB; oB = temp.modPow(xB, p); // temp = ((mB * nB) % p) % q; }

while (temp == 0); // (rB=temp)

DH1B = oA.modPow(((w1 + w2) * xB), p); DH2B = mA.modPow(w1, p); DH3B = yA.modPow(xB, p); DH4B = nA.modPow(w2, p); rB = temp; // //Tính sB khác 0 gửi cho A sB = (((w1 + w2).modInverse(q)) * (H(mB.ToHexString() + nB.ToHexString() +

DH1B.ToHexString() + DH2B.ToHexString() + DH3B.ToHexString() + DH4B.ToHexString()) + xB * rB) % q) % q; } while (sB == 0); // txtMB.Text = mB.ToHexString(); txtNB.Text = nB.ToHexString(); txtOB.Text = oB.ToHexString(); txtSB.Text = sB.ToString(); }

6. Hàm kiểm tra chữ ký số DSA (adsbygoogle = window.adsbygoogle || []).push({});

private bool KiemTraDSA(BigInteger e_nho, BigInteger r, BigInteger s, BigInteger y)

{

BigInteger i = s.modInverse(q); BigInteger u1 = (e_nho * i) % q; BigInteger u2 = (r * i) % q;

BigInteger D_lon = (g.modPow(u1, p) * y.modPow(u2, p)) % p; BigInteger D_nho = D_lon % q;

bool res = false; if (D_nho == r) res = true; return res; }

7. Hàm kiểm tra chữ ký DSA (rB, sB) và các thông tin từ B

private void btnKiemTra_rB_sB_Click(object sender, EventArgs e) {

BigInteger rB_A_gui = new BigInteger(); rB_A_gui = ((mB * nB) % p) % q;

if ((rB_A_gui >= q) || (sB >= q)) {

MessageBox.Show("Thông tin nhận không phải của B.\nKết thúc giao thức");

return; }

//

//Kiểm tra chữ ký số DSA rB,sB

//

DH1A = oB.modPow(((v1 + v2) * xA), p); DH2A = mB.modPow(v1, p);

DH3A = yB.modPow(xA, p); DH4A = nB.modPow(v2, p);

BigInteger e_nho = H(mB.ToHexString() + nB.ToHexString() + DH1A.ToHexString() + DH2A.ToHexString()

+ DH3A.ToHexString() + DH4A.ToHexString()); rB_A_gui = ((mB * nB) % p) % q;

if (KiemTraDSA(e_nho, rB_A_gui, sB, yB) == true)//rB_A_gui { MessageBox.Show("Chữ ký hợp lệ!"); } else { MessageBox.Show("Chữ ký không hợp lệ"); } } 8. Hàm tính sAvà gửi cho B

private void btnTinh_sA_Click(object sender, EventArgs e) {

pic_buoc3.Visible = true; grbBuoc4.Visible = true; //Tính KAB1, KAB2, KAB3

kAB1_A = H(DH1A.ToHexString());

kAB2_A = H(DH2A.ToHexString() + DH3A.ToHexString()); kAB3_A = H(DH3A.ToHexString() + DH4A.ToHexString()); //

//Tính rA khác 0 và Tính sA khác 0 gửi cho B

Một phần của tài liệu Nghiên cứu giao thức trao đổi khóa an toàn (Trang 77)