00001 <?php
00002
00017 require_once 'Auth/OpenID.php';
00018 require_once 'Auth/OpenID/BigMath.php';
00019
00020 function Auth_OpenID_getDefaultMod()
00021 {
00022 return '155172898181473697471232257763715539915724801'.
00023 '966915404479707795314057629378541917580651227423'.
00024 '698188993727816152646631438561595825688188889951'.
00025 '272158842675419950341258706556549803580104870537'.
00026 '681476726513255747040765857479291291572334510643'.
00027 '245094715007229621094194349783925984760375594985'.
00028 '848253359305585439638443';
00029 }
00030
00031 function Auth_OpenID_getDefaultGen()
00032 {
00033 return '2';
00034 }
00035
00043 class Auth_OpenID_DiffieHellman {
00044
00045 var $mod;
00046 var $gen;
00047 var $private;
00048 var $lib = null;
00049
00050 function Auth_OpenID_DiffieHellman($mod = null, $gen = null,
00051 $private = null, $lib = null)
00052 {
00053 if ($lib === null) {
00054 $this->lib =& Auth_OpenID_getMathLib();
00055 } else {
00056 $this->lib =& $lib;
00057 }
00058
00059 if ($mod === null) {
00060 $this->mod = $this->lib->init(Auth_OpenID_getDefaultMod());
00061 } else {
00062 $this->mod = $mod;
00063 }
00064
00065 if ($gen === null) {
00066 $this->gen = $this->lib->init(Auth_OpenID_getDefaultGen());
00067 } else {
00068 $this->gen = $gen;
00069 }
00070
00071 if ($private === null) {
00072 $r = $this->lib->rand($this->mod);
00073 $this->private = $this->lib->add($r, 1);
00074 } else {
00075 $this->private = $private;
00076 }
00077
00078 $this->public = $this->lib->powmod($this->gen, $this->private,
00079 $this->mod);
00080 }
00081
00082 function getSharedSecret($composite)
00083 {
00084 return $this->lib->powmod($composite, $this->private, $this->mod);
00085 }
00086
00087 function getPublicKey()
00088 {
00089 return $this->public;
00090 }
00091
00092 function usingDefaultValues()
00093 {
00094 return ($this->mod == Auth_OpenID_getDefaultMod() &&
00095 $this->gen == Auth_OpenID_getDefaultGen());
00096 }
00097
00098 function xorSecret($composite, $secret, $hash_func)
00099 {
00100 $dh_shared = $this->getSharedSecret($composite);
00101 $dh_shared_str = $this->lib->longToBinary($dh_shared);
00102 $hash_dh_shared = $hash_func($dh_shared_str);
00103
00104 $xsecret = "";
00105 for ($i = 0; $i < Auth_OpenID::bytes($secret); $i++) {
00106 $xsecret .= chr(ord($secret[$i]) ^ ord($hash_dh_shared[$i]));
00107 }
00108
00109 return $xsecret;
00110 }
00111 }
00112
00113 ?>