# What are the rules regarding to numbers in RSA?

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:

1. Does $$n$$ must be prime? or it's just better for security?
2. 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:

1. you can't impose restrictions on the message itself
2. $$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?

• DH relies on the Discrete Logarithm Problem (DLP), RSA on the RSA problem. Both use modular exponentiation. What's your question exactly? You need to study DH and RSA at least in some depth before trying to ask questions about it. Note that there are two "are"'s in your question title. Jan 27, 2021 at 15:22
• I removed the incorrect use of$\pmod n$ where $\bmod n$ was thought. $x\bmod n$ is the uniquely defined integer $y$ with $0\le y<n$ and $x-y$ a multiple of $n$. Whereas $x\pmod n$ is not an integer, and $y\equiv x\pmod n$ only states that $y-x$ is a multiple of $n$, without specifying a range of $y$. The difference is important in both Diffie-Hellman and RSA.
– fgrieu
Jan 27, 2021 at 15:40
• Related question: Is Diffie-Hellman mathematically the same as RSA?. Dupe, perhaps!
– fgrieu
Jan 27, 2021 at 15:43
• It's also generally misleading to think of the $m$ in RSA as a "message". It can be in some cases (OAEP-padding of a symmetric key for key exchange, though even then it's not the true "message" that eventually gets encrypted with that key) but often isn't (signatures, some random integer for RSA-KEM). Signatures are a lot more common as a use of RSA than RSA-OAEP for key exchange. Jan 27, 2021 at 15:48
• Also, we generally don't use a primitive root as a generator for DH, but a number which generates a large prime order subgroup. Jan 28, 2021 at 3:44