[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/openid/Auth/OpenID/ -> DiffieHellman.php (source)

   1  <?php
   2  
   3  /**
   4   * The OpenID library's Diffie-Hellman implementation.
   5   *
   6   * PHP versions 4 and 5
   7   *
   8   * LICENSE: See the COPYING file included in this distribution.
   9   *
  10   * @access private
  11   * @package OpenID
  12   * @author JanRain, Inc. <openid@janrain.com>
  13   * @copyright 2005-2008 Janrain, Inc.
  14   * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  15   */
  16  
  17  // Do not allow direct access
  18  defined( '_JEXEC' ) or die( 'Restricted access' );
  19  
  20  require_once 'Auth/OpenID.php';
  21  require_once 'Auth/OpenID/BigMath.php';
  22  
  23  function Auth_OpenID_getDefaultMod()
  24  {
  25      return '155172898181473697471232257763715539915724801'.
  26          '966915404479707795314057629378541917580651227423'.
  27          '698188993727816152646631438561595825688188889951'.
  28          '272158842675419950341258706556549803580104870537'.
  29          '681476726513255747040765857479291291572334510643'.
  30          '245094715007229621094194349783925984760375594985'.
  31          '848253359305585439638443';
  32  }
  33  
  34  function Auth_OpenID_getDefaultGen()
  35  {
  36      return '2';
  37  }
  38  
  39  /**
  40   * The Diffie-Hellman key exchange class.  This class relies on
  41   * {@link Auth_OpenID_MathLibrary} to perform large number operations.
  42   *
  43   * @access private
  44   * @package OpenID
  45   */
  46  class Auth_OpenID_DiffieHellman {
  47  
  48      var $mod;
  49      var $gen;
  50      var $private;
  51      var $lib = null;
  52  
  53      function Auth_OpenID_DiffieHellman($mod = null, $gen = null,
  54                                         $private = null, $lib = null)
  55      {
  56          if ($lib === null) {
  57              $this->lib =& Auth_OpenID_getMathLib();
  58          } else {
  59              $this->lib =& $lib;
  60          }
  61  
  62          if ($mod === null) {
  63              $this->mod = $this->lib->init(Auth_OpenID_getDefaultMod());
  64          } else {
  65              $this->mod = $mod;
  66          }
  67  
  68          if ($gen === null) {
  69              $this->gen = $this->lib->init(Auth_OpenID_getDefaultGen());
  70          } else {
  71              $this->gen = $gen;
  72          }
  73  
  74          if ($private === null) {
  75              $r = $this->lib->rand($this->mod);
  76              $this->private = $this->lib->add($r, 1);
  77          } else {
  78              $this->private = $private;
  79          }
  80  
  81          $this->public = $this->lib->powmod($this->gen, $this->private,
  82                                             $this->mod);
  83      }
  84  
  85      function getSharedSecret($composite)
  86      {
  87          return $this->lib->powmod($composite, $this->private, $this->mod);
  88      }
  89  
  90      function getPublicKey()
  91      {
  92          return $this->public;
  93      }
  94  
  95      function usingDefaultValues()
  96      {
  97          return ($this->mod == Auth_OpenID_getDefaultMod() &&
  98                  $this->gen == Auth_OpenID_getDefaultGen());
  99      }
 100  
 101      function xorSecret($composite, $secret, $hash_func)
 102      {
 103          $dh_shared = $this->getSharedSecret($composite);
 104          $dh_shared_str = $this->lib->longToBinary($dh_shared);
 105          $hash_dh_shared = $hash_func($dh_shared_str);
 106  
 107          $xsecret = "";
 108          for ($i = 0; $i < Auth_OpenID::bytes($secret); $i++) {
 109              $xsecret .= chr(ord($secret[$i]) ^ ord($hash_dh_shared[$i]));
 110          }
 111  
 112          return $xsecret;
 113      }
 114  }
 115  
 116  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1