includes/hmac.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
--- a/includes/hmac.php	Sun Mar 28 21:49:26 2010 -0400
+++ b/includes/hmac.php	Sun Mar 28 23:10:46 2010 -0400
@@ -14,68 +14,68 @@
 
 function hmac_core($message, $key, $hashfunc)
 {
-  if ( strlen($key) % 2 == 1 )
-    $key .= '0';
-  
-  if ( strlen($key) > 128 )
-    $key = $hashfunc($key);
-  
-  while ( strlen($key) < 128 )
-  {
-    $key .= '00';
-  }
-  $opad = hmac_hexbytearray($key);
-  $ipad = $opad;
-  for ( $i = 0; $i < count($ipad); $i++ )
-  {
-    $opad[$i] = $opad[$i] ^ 0x5c;
-    $ipad[$i] = $ipad[$i] ^ 0x36;
-  }
-  $opad = hmac_bytearraytostring($opad);
-  $ipad = hmac_bytearraytostring($ipad);
-  return $hashfunc($opad . hexdecode($hashfunc($ipad . $message)));
+	if ( strlen($key) % 2 == 1 )
+		$key .= '0';
+	
+	if ( strlen($key) > 128 )
+		$key = $hashfunc($key);
+	
+	while ( strlen($key) < 128 )
+	{
+		$key .= '00';
+	}
+	$opad = hmac_hexbytearray($key);
+	$ipad = $opad;
+	for ( $i = 0; $i < count($ipad); $i++ )
+	{
+		$opad[$i] = $opad[$i] ^ 0x5c;
+		$ipad[$i] = $ipad[$i] ^ 0x36;
+	}
+	$opad = hmac_bytearraytostring($opad);
+	$ipad = hmac_bytearraytostring($ipad);
+	return $hashfunc($opad . hexdecode($hashfunc($ipad . $message)));
 }
 
 function hmac_hexbytearray($val)
 {
-  $val = hexdecode($val);
-  return hmac_bytearray($val);
+	$val = hexdecode($val);
+	return hmac_bytearray($val);
 }
 
 function hmac_bytearray($val)
 {
-  $val = str_split($val, 1);
-  foreach ( $val as &$char )
-  {
-    $char = ord($char);
-  }
-  return $val;
+	$val = str_split($val, 1);
+	foreach ( $val as &$char )
+	{
+		$char = ord($char);
+	}
+	return $val;
 }
 
 function hmac_bytearraytostring($val)
 {
-  foreach ( $val as &$char )
-  {
-    $char = chr($char);
-  }
-  return implode('', $val);
+	foreach ( $val as &$char )
+	{
+		$char = chr($char);
+	}
+	return implode('', $val);
 }
 
 function hmac_md5($message, $key)
 {
-  return hmac_core($message, $key, 'md5');
+	return hmac_core($message, $key, 'md5');
 }
 
 function hmac_sha1($message, $key)
 {
-  return hmac_core($message, $key, 'sha1');
+	return hmac_core($message, $key, 'sha1');
 }
 
 function hmac_sha256($message, $key)
 {
-  require_once(ENANO_ROOT . '/includes/math.php');
-  require_once(ENANO_ROOT . '/includes/diffiehellman.php');
-  return hmac_core($message, $key, 'sha256');
+	require_once(ENANO_ROOT . '/includes/math.php');
+	require_once(ENANO_ROOT . '/includes/diffiehellman.php');
+	return hmac_core($message, $key, 'sha256');
 }
 
 ?>