# Why does the Node crypto library do Diffie Hellman this way?

I was sifting through the Node Crytpo library and I came across their Diffie Hellman utility class. Their class implements a generateKeys function that, in their words,

Generates private and public Diffie-Hellman key values, and returns the public key in the specified encoding

My understanding of Diffie Hellman is that both parties only ever need to generate a single random number, not a public/private key. I suppose that you could call this random number a public key and that's what this function returns, but where does a private key come into this process?

I know that in Station to Station protocol a public/private key pair is used for signing. Is that what is happening here? Could this class be used for Station to Station protocol as is?

• DH uses two keypairs, one for each party, each consisting of a private key and a public key, to derive a share secret. Generating a keypair consists of choosing the private key randomly (and secretly) and computing the public key, so yes each party only chooses one random (per instance) but they do more than just choose that one random. For STS each party needs a DH keypair and a signing keypair; that class could provide the former (only) and do part but not all of the protocol. – dave_thompson_085 Nov 23 '18 at 5:56

(g ^ (a * b)) % p

where a is Alice’s private key and b is Bob’s. Of course, each side can do this calculation without the other party revealing their private key.