----- Original Message -----From: Tomas HollySent: martedì 23 aprile 2002 00:36Subject: Diffie-Hellman source codeCould somebody send me some simple source code on how to correctly implement a Diffie-Hellman key agreement class (DH) using Crypto++ with all the neccesary operations around ?Which random number generator should I use in my program instead of LC_RNG ?I'll be grateful for every response.Tomas, dyn...@globtelnet.sk
---
Outgoing message doesn't include viruses.
Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
Verze: 6.0.343 / Virová báze: 190 - datum vydání: 22. 3. 2002
Hi Wei Dai,
both Alice's and Bob's private keys contain many zeroes. Is that expected?
What is the typical key bit-length for Diffie-Hellman to be considered
secure?
If anyone knows the answers to the above questions, could you please reply
too?
Thank you
Gavin
////////////////////////////////////////////////////////////////////////
int iCounter = 0;
int iCounter2 = 0;
CString sText = "";
CString sText2 = "";
// Diffie Hellman (For posting)
// Alice
// Create auto seeded random number generator
CryptoPP::AutoSeededRandomPool autorng = CryptoPP::AutoSeededRandomPool();
// Create diffie hellman class
CryptoPP::DH dhDHA = CryptoPP::DH(autorng, 128);
// Get prime and generator
CryptoPP::Integer integerPrimeA = dhDHA.GetPrime();
CryptoPP::Integer integerGeneratorA = dhDHA.GetGenerator();
// Store prime and generator values
byte acPrimeA[16] = {0};
for (iCounter = 0; iCounter < 16; iCounter++)
{
acPrimeA[iCounter] = integerPrimeA.GetByte(iCounter);
}
byte cGeneratorA = integerGeneratorA.GetByte(0);
// Generate key pair
byte acPrivateKeyA[16] = {0};
byte acPublicKeyA[16] = {0};
dhDHA.GenerateKeyPair(autorng, acPrivateKeyA, acPublicKeyA);
// Display key pair
sText2 = "Alice:\nPrivate key is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acPrivateKeyA[iCounter]);
sText2 = sText2 + sText;
}
sText2 = sText2 + "\nPublic key is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acPublicKeyA[iCounter]);
sText2 = sText2 + sText;
}
MessageBox(sText2);
// Bob
// Get prime and generator from Alice
CryptoPP::Integer integerPrimeB;
for (iCounter = 0; iCounter < 16; iCounter++)
{
integerPrimeB.SetByte(iCounter, acPrimeA[iCounter]);
}
CryptoPP::Integer integerGeneratorB;
integerGeneratorB.SetByte(0, cGeneratorA);
// Create diffie hellman class based on Alice's p and g
CryptoPP::DH dhDHB = CryptoPP::DH(integerPrimeB, integerGeneratorB);
// Generate key pair
byte acPrivateKeyB[16] = {0};
byte acPublicKeyB[16] = {0};
dhDHB.GenerateKeyPair(autorng, acPrivateKeyB, acPublicKeyB);
// Display key pair
sText2 = "Bob:\nPrivate key 2 is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acPrivateKeyB[iCounter]);
sText2 = sText2 + sText;
}
sText2 = sText2 + "\nPublic key 2 is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acPublicKeyB[iCounter]);
sText2 = sText2 + sText;
}
MessageBox(sText2);
// To calculate agreed value between Alice and Bob
byte acAgreedValueA[16] = {0};
dhDHA.Agree(acAgreedValueA, acPrivateKeyA, acPublicKeyB, TRUE);
byte acAgreedValueB[16] = {0};
dhDHB.Agree(acAgreedValueB, acPrivateKeyB, acPublicKeyA, TRUE);
// Display both agreed values for comparison
sText2 = "Alice's agreed value is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acAgreedValueA[iCounter]);
sText2 = sText2 + sText;
}
sText2 = sText2 + "\nBob's agreed value is:\n";
for (iCounter = 0; iCounter < 16; iCounter++)
{
sText.Format("%02X", acAgreedValueB[iCounter]);
sText2 = sText2 + sText;
}
MessageBox(sText2);
////////////////////////////////////////////////////////////////////////
----Original Message Follows----
From: "Renzo Tomaselli" <renzo.t...@tecnotp.it>
Reply-To: crypto...@eskimo.com
To: <crypto...@eskimo.com>
Subject: Re: Diffie-Hellman source code
Date: Tue, 23 Apr 2002 09:45:17 +0200
Tomas, dyn...@globtelnet.sk
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Jörn