I'd like to have a small sanity check first: As far as I understand, diffie-hellman is all about that fact that, given the generator ($g$), the modulo ($n$) and the remainder ($c$), it's hard to find the exponent a in:
$g^a \bmod n = c$
But the conditions for this are that n is a big prime number, and g is a root primitive. So my questions are:
- Does $n$ must be prime? or it's just better for security?
- Does $g$ must be root primitive mod $n$?
Ok now to RSA. As far as I understand, RSA stands on another notion, and that is that it's hard to find the message (m) given the cipher (c), modulo (n) and exponent (e) in:
$m^e \bmod n = c$
So my question is: Does the same restrictions regarding diffie-hellman apply to RSA? Seemingly that's not possible since:
- you can't impose restrictions on the message itself
- $n$ is a composite of two (or more) prime numbers.
Am I right here? Please correct me if not.
I suppose that my questions comes down to this: Do Diffie-Hellman and RSA rely on the same mechanism of modular arithmetic, or is it completely different?