Dear all,
I am trying to use CryptoPP to program an ECDH key exchange algorithm.
I have started coding basing myself in the following Diffie-Helman
code:
int main(int argc, char* argv[]) {
//////////////////////////////////////////////////////////////////
// Alice
// Initialize the Diffie-Hellman class with a random prime and base
AutoSeededRandomPool arngA;
RandomNumberGenerator& rngA = *dynamic_cast<RandomNumberGenerator
*>(&arngA);
DH dhA(rngA, 128);
// Extract the prime and base. These values could also have been
hardcoded
// in the application
Integer iPrime = dhA.GetGroupParameters().GetModulus();
Integer iGenerator = dhA.GetGroupParameters().GetSubgroupGenerator();
SecByteBlock privA(dhA.PrivateKeyLength());
SecByteBlock pubA(dhA.PublicKeyLength());
SecByteBlock secretKeyA(dhA.AgreedValueLength());
// Generate a pair of integers for Alice. The public integer is
forwarded to Bob.
dhA.GenerateKeyPair(rngA, privA, pubA);
cout << "---------------------------------------------------" << endl;
cout << "ALICE" << endl;
cout << "Integer iPrime: " << iPrime.AbsoluteValue() << endl;
cout << "Integer iGenerator: " << iGenerator.AbsoluteValue() << endl;
cout << "Private key privA: " << privA.end() << endl;
cout << " Public key pubA: " << pubA.begin() << endl;
//////////////////////////////////////////////////////////////////////////
// Bob
AutoSeededRandomPool arngB;
RandomNumberGenerator& rngB = *dynamic_cast<RandomNumberGenerator
*>(&arngB);
// Initialize the Diffie-Hellman class with the prime and base that
Alice generated.
DH dhB(iPrime, iGenerator);
SecByteBlock privB(dhB.PrivateKeyLength());
SecByteBlock pubB(dhB.PublicKeyLength());
SecByteBlock secretKeyB(dhB.AgreedValueLength());
// Generate a pair of integers for Bob. The public integer is
forwarded to Alice.
dhB.GenerateKeyPair(rngB, privB, pubB);
cout << "---------------------------------------------------" << endl;
cout << "BOB" << endl;
cout << "Integer iPrime: " << iPrime.AbsoluteValue() << endl;
cout << "Integer iGenerator: " << iGenerator.AbsoluteValue() << endl;
cout << "Private key privB: " << privB.end() << endl;
cout << " Public key pubB: " << pubB.begin() << endl;
//////////////////////////////////////////////////////////////////////////
// Agreement
// Alice calculates the secret key based on her private integer as
well as the
// public integer she received from Bob.
if (!dhA.Agree(secretKeyA, privA, pubB))
return false;
// Bob calculates the secret key based on his private integer as well
as the
// public integer he received from Alice.
if (!dhB.Agree(secretKeyB, privB, pubA))
return false;
// Just a validation check. Did Alice and Bob agree on the same secret
key?
if (memcmp(secretKeyA.begin(), secretKeyB.begin(),
dhA.AgreedValueLength()))
return false;
cout << "---------------------------------------------------" << endl;
cout <<"\nAlice secret key: " << secretKeyA.begin() << endl;
cout <<" Bob secret key: " << secretKeyB.begin() << endl;
system("PAUSE");
return 0;
}
What I would like to do now is to extend this sample code to cope with
the ECDH scheme. I know there is the class ECDH into Crypto++ but I don
´t really see how to initialize it, getting confused with the template
stuff.
I have seen in another thread in the group that in order to initialize
an ECDH object one does something like:
DL_GroupParameters_EC<ECP> gp;
ECDH<ECP>::Domain m_ecdh(gp);
but I don´t really see how I would relate this initialization to the
elliptic curve I would like to use (sect571k1()) nor how it relates to
a piece of code doing something like the sample above.
Could anyone throw any light on this? any advice, hints, sample code
or similar will be highly appreciated.
Thank you very much indeed.
--~--~---------~--~----~------------~-------~--~----~
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.
-~----------~----~----~----~------~----~------~--~---