hi guys and Wei Dai,

i sincerely hope that someone can pointed out what's wrong with the coding below, which i got from the mailing list archive. i tested the code, and found two problems, which are (1) the private keys for Alice and Bob are empty, and (2) the agreed values are not identical.
thank you very much.


------------------------------------------------------------------------

// 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
int iCounter = 0;

byte acPrimeA[16] = {0};
for (iCounter = 0; iCounter < 16; iCounter++)
     {
      acPrimeA[iCounter] = integerPrimeA.GetByte(iCounter);
     }

byte cGeneratorA[16]={0};
for (iCounter = 0; iCounter < 16; iCounter++)
     {
      cGeneratorA[iCounter] = integerGeneratorA.GetByte(iCounter);
     }

// Generate key pair
byte acPrivateKeyA[16] = {0};
byte acPublicKeyA[16] = {0};
dhDHA.GenerateKeyPair(autorng, acPrivateKeyA, acPublicKeyA);

// Bob
// Get prime and generator from Alice
CryptoPP::Integer integerPrimeB;
for (iCounter = 0; iCounter < 16; iCounter++)
     {
      integerPrimeB.SetByte(iCounter, acPrimeA[iCounter]);
     }

CryptoPP::Integer integerGeneratorB;
for (iCounter = 0; iCounter < 16; iCounter++)
     {
      integerGeneratorB.SetByte(iCounter, cGeneratorA[iCounter]);
     }

// Create diffie hellman class based on Alice's p and g
DH dhDHB (integerPrimeB, integerGeneratorB);

// Generate key pair
byte acPrivateKeyB[16] = {0};
byte acPublicKeyB[16] = {0};
dhDHB.GenerateKeyPair(autorng, acPrivateKeyB, acPublicKeyB);

// 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);

------------------------------------------------------------------------


_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail




Reply via email to