# How can we generate a shared key from two key pairs for an ECC implementation? This is the diagram of an ecc implementation here that needs to generate the shared key, how can it be done?

• i'm a newbie that's why posted many question mark instead of one. if you find that offensive then i'm sorry. – Dark Prince Apr 1 '17 at 13:55
• I have removed the superfluous question marks because from what I could tell they added no value to the question as opposed to a simple question mark (and the question looks better with a single one I think). No offense was taken at all by anyone I strongly believe. – SEJPM Apr 1 '17 at 14:29
• Shared secret is just one private key multiplied by the other's public point (public key is usually the x coordinate of that point). Since they are both starting from the same base point the result is the same for both (base point * one private key * the other private key). – user10653 Apr 19 '17 at 5:52

## 1 Answer

The diagram leaves out something (rather assumes it implicitly), which is that you and the recipient have agreed upon curve parameters / a standardized curve with which to perform key exchange. We can derive the shared key as follows once we agree upon parameters (this method is basically elliptic curve Diffie Hellman):

1. Use the RNG to generate an integer $d \in \mathbb{Z}_q$ where $q$ is the order of the generator point $G$ of the curve (technically $d$ can be arbitrarily large but there's no advantage to this).
2. Your ECC key pair is then $(d, Q)$ where $Q = d*G$. $d$ is the private key, $Q$ is the public key. Note that $Q$ is a point on the curve.
3. Given the recipients public key $R$ (also a point on the curve) compute $S = d * R$. $S$ is the shared secret. (Note that if $e$ is the recipients private key that means $R = e * G$, and thus $S = d * e * G$, meaning if we send the recipient our public key $Q$ they can also derive the secret $S = e * Q = e * d * G$).

Now we have shared key material we can pass into a KDF to derive symmetric keys.

• Isn't Q the public key? How come R became the public key? What is R? – twodee Sep 30 '20 at 20:53
• $Q$ is your public key, $R$ is the recipients (the person you want to create a shared key with) public key. – puzzlepalace Oct 1 '20 at 22:14