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.