Cryptopals 35 - Implement DH with negotiated groups...

TL;DR

Challenge 35 in Cryptopals.

I know, I know. It says “implement” and I should implement it. But it seems that we’re able to negotiate an alternative value for g, and the alternatives call for very insecure results that boil down to settling to a specific and trivial value for the shared secret s.

So… well, it’s basically the same code as the last time, only with a different value of the not-so-secret s. Let’s start with a little recap about it:

s=Am(modp)s=(ga)m(modp)s=gam(modp)s=ge(modp)

where m is our private key as man-in-the-middle and e=am>0.

In case we manage to force g=1, we end up with s=1 because elevating it to whatever non-zero power always yields itself:

g=1s=1e(modp)=1

When we trick the peer to accept g=p, instead, we’re setting to a zero value for s, because whatever the value of the two (non-zero) private parts, the result will surely be divisible by p:

g=ps=pe(modp)=0

Last, when we trick the peer to accept g=p1, which is the same as g=1(modp):

g=p1s=1e(modp)

that is:

s={1,if e is evenp1,if e is odd

If we can also trick the peer into giving the public key first, we can adjust our value of m so that we end up with an even value for e and always use s=1. Otherwise, we can just try both possible values to see which of them allows us decripting the peer’s message.

Stay safe and secure!


Comments? Octodon, , GitHub, Reddit, or drop me a line!