/** * Calculates the shared secret for Diffie-Hellman key exchange. * * This is the second step in the Diffle-Hellman key exchange process. The other * party (in OpenID 1.0 terms, the consumer) has already generated the public * key ($dh_consumer_public) and sent it to this party (the server). * * @param string $their_public the other party's public key, in Base64 representation * @return BigNum the shared secret * * @see generateKeyPair() * @link http://www.ietf.org/rfc/rfc2631.txt RFC 2631 */ protected function getSharedSecret($their_public) { // Decode the keys $their_y = new BigNum(base64_decode($their_public), 256); // Generate the shared secret = their public ^ my private mod p = my public ^ their private mod p $ZZ = $their_y->powmod($this->x, $this->p); return $ZZ; }