-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package CodeIgniter\r
- * @author ExpressionEngine Dev Team\r
- * @copyright Copyright (c) 2008, EllisLab, Inc.\r
- * @license http://codeigniter.com/user_guide/license.html\r
- * @link http://codeigniter.com\r
- * @since Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * SHA1 Encoding Class\r
- *\r
- * Purpose: Provides 160 bit hashing using The Secure Hash Algorithm\r
- * developed at the National Institute of Standards and Technology. The 40\r
- * character SHA1 message hash is computationally infeasible to crack.\r
- *\r
- * This class is a fallback for servers that are not running PHP greater than\r
- * 4.3, or do not have the MHASH library.\r
- *\r
- * This class is based on two scripts:\r
- *\r
- * Marcus Campbell's PHP implementation (GNU license)\r
- * http://www.tecknik.net/sha-1/\r
- *\r
- * ...which is based on Paul Johnston's JavaScript version\r
- * (BSD license). http://pajhome.org.uk/\r
- *\r
- * I encapsulated the functions and wrote one additional method to fix\r
- * a hex conversion bug. - Rick Ellis\r
- *\r
- * @package CodeIgniter\r
- * @subpackage Libraries\r
- * @category Encryption\r
- * @author ExpressionEngine Dev Team\r
- * @link http://codeigniter.com/user_guide/general/encryption.html\r
- */\r
-class CI_SHA {\r
-\r
- function CI_SHA()\r
- {\r
- log_message('debug', "SHA1 Class Initialized");\r
- }\r
-\r
- /**\r
- * Generate the Hash\r
- *\r
- * @access public\r
- * @param string\r
- * @return string\r
- */ \r
- function generate($str)\r
- {\r
- $n = ((strlen($str) + 8) >> 6) + 1;\r
-\r
- for ($i = 0; $i < $n * 16; $i++)\r
- {\r
- $x[$i] = 0;\r
- }\r
-\r
- for ($i = 0; $i < strlen($str); $i++)\r
- {\r
- $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8);\r
- }\r
-\r
- $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);\r
-\r
- $x[$n * 16 - 1] = strlen($str) * 8;\r
-\r
- $a = 1732584193;\r
- $b = -271733879;\r
- $c = -1732584194;\r
- $d = 271733878;\r
- $e = -1009589776;\r
-\r
- for ($i = 0; $i < sizeof($x); $i += 16)\r
- {\r
- $olda = $a;\r
- $oldb = $b;\r
- $oldc = $c;\r
- $oldd = $d;\r
- $olde = $e;\r
-\r
- for($j = 0; $j < 80; $j++)\r
- {\r
- if ($j < 16)\r
- {\r
- $w[$j] = $x[$i + $j];\r
- }\r
- else\r
- {\r
- $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);\r
- }\r
-\r
- $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j)));\r
-\r
- $e = $d;\r
- $d = $c;\r
- $c = $this->_rol($b, 30);\r
- $b = $a;\r
- $a = $t;\r
- }\r
-\r
- $a = $this->_safe_add($a, $olda);\r
- $b = $this->_safe_add($b, $oldb);\r
- $c = $this->_safe_add($c, $oldc);\r
- $d = $this->_safe_add($d, $oldd);\r
- $e = $this->_safe_add($e, $olde);\r
- }\r
-\r
- return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e);\r
- }\r
- \r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Convert a decimal to hex\r
- *\r
- * @access private\r
- * @param string\r
- * @return string\r
- */ \r
- function _hex($str)\r
- {\r
- $str = dechex($str);\r
-\r
- if (strlen($str) == 7)\r
- {\r
- $str = '0'.$str;\r
- }\r
-\r
- return $str;\r
- }\r
- \r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Return result based on iteration\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _ft($t, $b, $c, $d)\r
- {\r
- if ($t < 20)\r
- return ($b & $c) | ((~$b) & $d);\r
- if ($t < 40)\r
- return $b ^ $c ^ $d;\r
- if ($t < 60)\r
- return ($b & $c) | ($b & $d) | ($c & $d);\r
-\r
- return $b ^ $c ^ $d;\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Determine the additive constant\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _kt($t)\r
- {\r
- if ($t < 20)\r
- {\r
- return 1518500249;\r
- }\r
- else if ($t < 40)\r
- {\r
- return 1859775393;\r
- }\r
- else if ($t < 60)\r
- {\r
- return -1894007588;\r
- }\r
- else\r
- {\r
- return -899497514;\r
- }\r
- }\r
- \r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Add integers, wrapping at 2^32\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _safe_add($x, $y)\r
- {\r
- $lsw = ($x & 0xFFFF) + ($y & 0xFFFF);\r
- $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);\r
-\r
- return ($msw << 16) | ($lsw & 0xFFFF);\r
- }\r
- \r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Bitwise rotate a 32-bit number\r
- *\r
- * @access private\r
- * @return integer\r
- */ \r
- function _rol($num, $cnt)\r
- {\r
- return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Pad string with zero\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _zero_fill($a, $b)\r
- {\r
- $bin = decbin($a);\r
-\r
- if (strlen($bin) < $b)\r
- {\r
- $bin = 0;\r
- }\r
- else\r
- {\r
- $bin = substr($bin, 0, strlen($bin) - $b);\r
- }\r
-\r
- for ($i=0; $i < $b; $i++)\r
- {\r
- $bin = "0".$bin;\r
- }\r
-\r
- return bindec($bin);\r
- }\r
-}\r
-// END CI_SHA\r
-\r
-/* End of file Sha1.php */\r
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2008, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * SHA1 Encoding Class
+ *
+ * Purpose: Provides 160 bit hashing using The Secure Hash Algorithm
+ * developed at the National Institute of Standards and Technology. The 40
+ * character SHA1 message hash is computationally infeasible to crack.
+ *
+ * This class is a fallback for servers that are not running PHP greater than
+ * 4.3, or do not have the MHASH library.
+ *
+ * This class is based on two scripts:
+ *
+ * Marcus Campbell's PHP implementation (GNU license)
+ * http://www.tecknik.net/sha-1/
+ *
+ * ...which is based on Paul Johnston's JavaScript version
+ * (BSD license). http://pajhome.org.uk/
+ *
+ * I encapsulated the functions and wrote one additional method to fix
+ * a hex conversion bug. - Rick Ellis
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Encryption
+ * @author ExpressionEngine Dev Team
+ * @link http://codeigniter.com/user_guide/general/encryption.html
+ */
+class CI_SHA {
+
+ function CI_SHA()
+ {
+ log_message('debug', "SHA1 Class Initialized");
+ }
+
+ /**
+ * Generate the Hash
+ *
+ * @access public
+ * @param string
+ * @return string
+ */
+ function generate($str)
+ {
+ $n = ((strlen($str) + 8) >> 6) + 1;
+
+ for ($i = 0; $i < $n * 16; $i++)
+ {
+ $x[$i] = 0;
+ }
+
+ for ($i = 0; $i < strlen($str); $i++)
+ {
+ $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8);
+ }
+
+ $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
+
+ $x[$n * 16 - 1] = strlen($str) * 8;
+
+ $a = 1732584193;
+ $b = -271733879;
+ $c = -1732584194;
+ $d = 271733878;
+ $e = -1009589776;
+
+ for ($i = 0; $i < sizeof($x); $i += 16)
+ {
+ $olda = $a;
+ $oldb = $b;
+ $oldc = $c;
+ $oldd = $d;
+ $olde = $e;
+
+ for($j = 0; $j < 80; $j++)
+ {
+ if ($j < 16)
+ {
+ $w[$j] = $x[$i + $j];
+ }
+ else
+ {
+ $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
+ }
+
+ $t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j)));
+
+ $e = $d;
+ $d = $c;
+ $c = $this->_rol($b, 30);
+ $b = $a;
+ $a = $t;
+ }
+
+ $a = $this->_safe_add($a, $olda);
+ $b = $this->_safe_add($b, $oldb);
+ $c = $this->_safe_add($c, $oldc);
+ $d = $this->_safe_add($d, $oldd);
+ $e = $this->_safe_add($e, $olde);
+ }
+
+ return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Convert a decimal to hex
+ *
+ * @access private
+ * @param string
+ * @return string
+ */
+ function _hex($str)
+ {
+ $str = dechex($str);
+
+ if (strlen($str) == 7)
+ {
+ $str = '0'.$str;
+ }
+
+ return $str;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Return result based on iteration
+ *
+ * @access private
+ * @return string
+ */
+ function _ft($t, $b, $c, $d)
+ {
+ if ($t < 20)
+ return ($b & $c) | ((~$b) & $d);
+ if ($t < 40)
+ return $b ^ $c ^ $d;
+ if ($t < 60)
+ return ($b & $c) | ($b & $d) | ($c & $d);
+
+ return $b ^ $c ^ $d;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Determine the additive constant
+ *
+ * @access private
+ * @return string
+ */
+ function _kt($t)
+ {
+ if ($t < 20)
+ {
+ return 1518500249;
+ }
+ else if ($t < 40)
+ {
+ return 1859775393;
+ }
+ else if ($t < 60)
+ {
+ return -1894007588;
+ }
+ else
+ {
+ return -899497514;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Add integers, wrapping at 2^32
+ *
+ * @access private
+ * @return string
+ */
+ function _safe_add($x, $y)
+ {
+ $lsw = ($x & 0xFFFF) + ($y & 0xFFFF);
+ $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);
+
+ return ($msw << 16) | ($lsw & 0xFFFF);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Bitwise rotate a 32-bit number
+ *
+ * @access private
+ * @return integer
+ */
+ function _rol($num, $cnt)
+ {
+ return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Pad string with zero
+ *
+ * @access private
+ * @return string
+ */
+ function _zero_fill($a, $b)
+ {
+ $bin = decbin($a);
+
+ if (strlen($bin) < $b)
+ {
+ $bin = 0;
+ }
+ else
+ {
+ $bin = substr($bin, 0, strlen($bin) - $b);
+ }
+
+ for ($i=0; $i < $b; $i++)
+ {
+ $bin = "0".$bin;
+ }
+
+ return bindec($bin);
+ }
+}
+// END CI_SHA
+
+/* End of file Sha1.php */
/* Location: ./system/libraries/Sha1.php */
\ No newline at end of file