views:

244

answers:

2

In the code below, from the Crypto++ wiki, is 128 the number I really should be using?

CryptoPP::AutoSeededRandomPool arngA;
CryptoPP::RandomNumberGenerator& rngA = *dynamic_cast<CryptoPP::RandomNumberGenerator *>(&arngA); 
CryptoPP::DH dhA(rngA, 128);
CryptoPP::Integer iPrime = dhA.GetGroupParameters().GetModulus();
CryptoPP::Integer iGenerator = dhA.GetGroupParameters().GetSubgroupGenerator();
A: 

2128 is a ridiculously huge number*; so yes, that's more than enough.

* (It's about 340,000,000,000,000,000,000,000,000,000,000,000,000 [37 zeros]. A usual supercomputer can do about 2,000,000,000,000,000 [15 zeros] operations a second)

BlueRaja - Danny Pflughoeft
What does "ridiculously" huge mean in terms of security? Have you looked at the NIST or IETF recommedations for DH key sizes?
GregS
You are right, I deserve that -1, what was I smoking. If 128 is referring to the size of the DH prime, then 128 is ridiculously low - the security of the DH prime is the same as the security of the RSA *n* (http://en.wikipedia.org/wiki/Key_size#Asymmetric_algorithm_key_lengths). Since sieving primes is much faster than brute-forcing a truly random key, anything less than 1024 bits is generally considered insecure.
BlueRaja - Danny Pflughoeft
+3  A: 

Integer factorization and discrete logarithm over Z/(pZ) are roughly equally difficult. Therefore the size of the modulus for Diffie-Hellman should be about the same size as you would choose for an RSA modulus. If you are comfortable with a 1024-bit RSA key then you can also be comfortable with a 1024-bit Diffie-Hellman key.

It is not easy to tell if key sizes in crypto++ are measured in bits or bytes. As Sebastian points out dhA(rngA, 128) may indeed generate a 128 bit Diffie-Hellman key, which would be too small. Going through the code it looks like this is indeed the case.

The size of the generator iGenerator does not affect the security of Diffie-Hellman. (I.e. iGenerator = 2 could be perfectly fine)

abc
Trying out this code gives a number with roughly 40 digits which corresponds to a 128bit code. Changing the parameter to 1024, iPrime has about 300 digits.
Sebastian
@Sebastian, Thanks, it looks like you are right.
abc