I ran the code unmodified, and it worked just fine. The agreed values came
out identical. Since the code you gave does not contain any output
statements, I'm thinking maybe you failed to use the debugger correctly to
examine the variables. If you need any more help, please provide the
following:
-a minimal program with a main() function, that reproduces the problem
-versions of Crypto++, operating system (output of "uname -a" command if
using Unix), and compiler (output of "gcc -v" if using GCC)
And for the test program, print out the variables you're interested in.
On Tue, Feb 18, 2003 at 01:04:35PM +0000, James Lee wrote:
> 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