1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
21
* Purpose: Provides 160 bit hashing using The Secure Hash Algorithm
22
* developed at the National Institute of Standards and Technology. The 40
23
* character SHA1 message hash is computationally infeasible to crack.
25
* This class is a fallback for servers that are not running PHP greater than
26
* 4.3, or do not have the MHASH library.
28
* This class is based on two scripts:
30
* Marcus Campbell's PHP implementation (GNU license)
31
* http://www.tecknik.net/sha-1/
33
* ...which is based on Paul Johnston's JavaScript version
34
* (BSD license). http://pajhome.org.uk/
36
* I encapsulated the functions and wrote one additional method to fix
37
* a hex conversion bug. - Rick Ellis
39
* @package CodeIgniter
40
* @subpackage Libraries
41
* @category Encryption
42
* @author ExpressionEngine Dev Team
43
* @link http://codeigniter.com/user_guide/general/encryption.html
47
public function __construct()
49
log_message('debug', "SHA1 Class Initialized");
59
function generate($str)
61
$n = ((strlen($str) + 8) >> 6) + 1;
63
for ($i = 0; $i < $n * 16; $i++)
68
for ($i = 0; $i < strlen($str); $i++)
70
$x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8);
73
$x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
75
$x[$n * 16 - 1] = strlen($str) * 8;
83
for ($i = 0; $i < count($x); $i += 16)
91
for ($j = 0; $j < 80; $j++)
99
$w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
102
$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)));
106
$c = $this->_rol($b, 30);
111
$a = $this->_safe_add($a, $olda);
112
$b = $this->_safe_add($b, $oldb);
113
$c = $this->_safe_add($c, $oldc);
114
$d = $this->_safe_add($d, $oldd);
115
$e = $this->_safe_add($e, $olde);
118
return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e);
121
// --------------------------------------------------------------------
124
* Convert a decimal to hex
134
if (strlen($str) == 7)
142
// --------------------------------------------------------------------
145
* Return result based on iteration
150
function _ft($t, $b, $c, $d)
153
return ($b & $c) | ((~$b) & $d);
157
return ($b & $c) | ($b & $d) | ($c & $d);
162
// --------------------------------------------------------------------
165
* Determine the additive constant
190
// --------------------------------------------------------------------
193
* Add integers, wrapping at 2^32
198
function _safe_add($x, $y)
200
$lsw = ($x & 0xFFFF) + ($y & 0xFFFF);
201
$msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);
203
return ($msw << 16) | ($lsw & 0xFFFF);
206
// --------------------------------------------------------------------
209
* Bitwise rotate a 32-bit number
214
function _rol($num, $cnt)
216
return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt);
219
// --------------------------------------------------------------------
222
* Pad string with zero
227
function _zero_fill($a, $b)
231
if (strlen($bin) < $b)
237
$bin = substr($bin, 0, strlen($bin) - $b);
240
for ($i=0; $i < $b; $i++)
250
/* End of file Sha1.php */
251
/* Location: ./system/libraries/Sha1.php */
b'\\ No newline at end of file'