Index: modules/openid/openid.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.inc,v
retrieving revision 1.13
diff -u -9 -p -r1.13 openid.inc
--- modules/openid/openid.inc	1 Nov 2008 19:51:06 -0000	1.13
+++ modules/openid/openid.inc	1 Mar 2009 15:47:45 -0000
@@ -20,23 +20,18 @@ define('OPENID_DH_DEFAULT_MOD', '1551728
        '681476726513255747040765857479291291572334510643245094715007229621094194' .
        '349783925984760375594985848253359305585439638443');
 
 /**
  * Diffie-Hellman generator; used for Diffie-Hellman key exchange computations.
  */
 define('OPENID_DH_DEFAULT_GEN', '2');
 
 /**
- * SHA-1 hash block size; used for Diffie-Hellman key exchange computations.
- */
-define('OPENID_SHA1_BLOCKSIZE', 64);
-
-/**
  * Random number generator; used for Diffie-Hellman key exchange computations.
  */
 define('OPENID_RAND_SOURCE', '/dev/urandom');
 
 /**
  * OpenID Authentication 2.0 namespace URL.
  */
 define('OPENID_NS_2_0', 'http://specs.openid.net/auth/2.0');
 
@@ -254,48 +249,23 @@ function _openid_signature($association,
 
   foreach ($keys_to_sign as $key) {
     if (isset($message_array['openid.' . $key])) {
       $sign_data[$key] = $message_array['openid.' . $key];
     }
   }
 
   $message = _openid_create_message($sign_data);
   $secret = base64_decode($association->mac_key);
-  $signature = _openid_hmac($secret, $message);
+  $signature = hash_hmac('sha1', $message, $secret, TRUE);
 
   return base64_encode($signature);
 }
 
-function _openid_hmac($key, $text) {
-  if (strlen($key) > OPENID_SHA1_BLOCKSIZE) {
-    $key = _openid_sha1($key, TRUE);
-  }
-
-  $key = str_pad($key, OPENID_SHA1_BLOCKSIZE, chr(0x00));
-  $ipad = str_repeat(chr(0x36), OPENID_SHA1_BLOCKSIZE);
-  $opad = str_repeat(chr(0x5c), OPENID_SHA1_BLOCKSIZE);
-  $hash1 = _openid_sha1(($key ^ $ipad) . $text, TRUE);
-  $hmac = _openid_sha1(($key ^ $opad) . $hash1, TRUE);
-
-  return $hmac;
-}
-
-function _openid_sha1($text) {
-  $hex = sha1($text);
-  $raw = '';
-  for ($i = 0; $i < 40; $i += 2) {
-    $hexcode = substr($hex, $i, 2);
-    $charcode = (int)base_convert($hexcode, 16, 10);
-    $raw .= chr($charcode);
-  }
-  return $raw;
-}
-
 function _openid_dh_base64_to_long($str) {
   $b64 = base64_decode($str);
 
   return _openid_dh_binary_to_long($b64);
 }
 
 function _openid_dh_long_to_base64($str) {
   return base64_encode(_openid_dh_long_to_binary($str));
 }
@@ -337,19 +307,19 @@ function _openid_dh_long_to_binary($long
   foreach ($bytes as $byte) {
     $string .= pack('C', $byte);
   }
 
   return $string;
 }
 
 function _openid_dh_xorsecret($shared, $secret) {
   $dh_shared_str = _openid_dh_long_to_binary($shared);
-  $sha1_dh_shared = _openid_sha1($dh_shared_str);
+  $sha1_dh_shared = sha1($dh_shared_str, TRUE);
   $xsecret = "";
   for ($i = 0; $i < strlen($secret); $i++) {
     $xsecret .= chr(ord($secret[$i]) ^ ord($sha1_dh_shared[$i]));
   }
 
   return $xsecret;
 }
 
 function _openid_dh_rand($stop) {
