# How to multiply two Public Keys in Elliptic Curve in Go

I am working on a messaging client similar to Signal. I am stuck on implementing Tripartite Diffie-Hellman handshake in which three DH exchanges are combined to authenticate both parties and produce a session. Alice starts with identity key $$g^A$$ and ephemeral key $$g^a$$ (her secrets are $$A$$ and $$a$$). Similarly Bob has identity key $$g^B$$ and ephemeral key $$g^b$$ (his secrets are $$B$$ and $$b$$). Alice send Bob $$g^A$$ and $$g^a$$ and he sends back $$g^B$$ and $$g^b$$. Their initial shared secret is: Now my question is to how to implement $$g^{a*B}$$ which are both public keys? Also the code to calculate DH share for private with public key is working which is as follow: Thanks.

## 1 Answer

Now my question is to how to implement $$g^{a*B}$$ which are both public keys?

Just given $$g^a$$ and $$g^B$$, this is a hard problem (or so we hope); if that is feasible, the strength of the entire system falls apart.

However, both Alice and Bob can compute: for Alice, she computes $$(g^B)^a$$ (given the value $$g^B$$ from Bob and her secret $$a$$). Similarly, Bob computes $$(g^a)^B$$ (given the value $$g^a$$ from Alice and his secret $$B$$)

Both computations yield the common value $$g^{a\cdot B}$$

• g^a and g^B are known. I need to multiply them in elliptic curve for p256. – Tahir Abbas Mar 25 at 13:13
• @TahirAbbas: you can't, you need to know either $a$ or $B$ – poncho Mar 25 at 13:47
• @TahirAbbas Multiplying $g^a$ and $g^B$ would not result in $g^{aB}$ but in $g^{a+B}$. – Maeher Mar 25 at 21:09
• Yes thats correct. I solved the question this way. I had to multiply g^a with private key B instead of g^b to get g^(aB). Thankyou. – Tahir Abbas Mar 26 at 1:20