I have coded 2 fragments, but I am having a difference on the results.

-------------------------------------------------------
Code that does not work as expected:
-------------------------------------------------------
// Load the given Domain Parameters and given Public Key into a byte
array
BYTE *GivenDHPublicKey;
unsigned long GivenDHPublicKeyLength;
BYTE *GivenDHDomainParameters;
unsigned long GivenDHDomainParametersLength;
LoadBytesFromFile("GivenPublicKey.bin", GivenDHPublicKey,
&GivenDHPublicKeyLength);
LoadBytesFromFile("GivenDomainParams.bin", GivenDHDomainParameters,
&GivenDHDomainParametersLength);

// Initiate DH with the given Domain Parameters
DH dh(StringSource(GivenDHDomainParameters,
GivenDHDomainParametersLength, true, NULL));

// Generate my Key Pairs
BYTE *myPriv = new BYTE[dh.PrivateKeyLength()];
BYTE *myPub = new BYTE[dh.PublicKeyLength()];
AutoSeededRandomPool arng;
RandomNumberGenerator& rng = *dynamic_cast<RandomNumberGenerator
*>(&arng);
dh.GenerateKeyPair(rng, myPriv, myPub);

// Generate Shared Secret Key
unsigned int secretKeyLength = dh.AgreedValueLength();
BYTE *secretKey = new BYTE[secretKeyLength];
bool result = dh.Agree(secretKey, myPriv, GivenDHPublicKey);  // --->
result is equal to 0 here!!! which I think is a bad result



-------------------------------------------------------
Code that does work:
-------------------------------------------------------
// Load the given Domain Parameters and given Public Key into a byte
array
BYTE *GivenDHPublicKey;
unsigned long GivenDHPublicKeyLength;
BYTE *GivenDHDomainParameters;
unsigned long GivenDHDomainParametersLength;
LoadBytesFromFile("GivenPublicKey.bin", GivenDHPublicKey,
&GivenDHPublicKeyLength);
LoadBytesFromFile("GivenDomainParams.bin", GivenDHDomainParameters,
&GivenDHDomainParametersLength);

// Initiate DH with the given Domain Parameters
DH dh(StringSource(GivenDHDomainParameters,
GivenDHDomainParametersLength, true, NULL));
// This here is the difference on the code: basically I had to create
a dhTemp and pass the prime and generator... why???
Integer iPrime = dh.GetGroupParameters().GetModulus();
Integer iGenerator = dh.GetGroupParameters().GetSubgroupGenerator();
DH dhTemp(iPrime, iGenerator);

// Generate my Key Pairs
BYTE *myPriv = new BYTE[dhTemp.PrivateKeyLength()];
BYTE *myPub = new BYTE[dhTemp.PublicKeyLength()];
AutoSeededRandomPool arng;
RandomNumberGenerator& rng = *dynamic_cast<RandomNumberGenerator
*>(&arng);
dhTemp.GenerateKeyPair(rng, myPriv, myPub);

// Generate Shared Secret Key
unsigned int secretKeyLength = dhTemp.AgreedValueLength();
BYTE *secretKey = new BYTE[secretKeyLength];
bool result = dhTemp.Agree(secretKey, myPriv, GivenDHPublicKey);    //
---> result is equal to 1 here, which I think is OK




Why does the second fragment work and not the first one... probably I
am getting too tired and don't see something obvious... :)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [EMAIL PROTECTED]
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to