Public Member Functions | |
| CI_SHA () | |
| generate ($str) | |
| Generate the Hash. | |
| _hex ($str) | |
| Convert a decimal to hex. | |
| _ft ($t, $b, $c, $d) | |
| Return result based on iteration. | |
| _kt ($t) | |
| Determine the additive constant. | |
| _safe_add ($x, $y) | |
| Add integers, wrapping at 2^32. | |
| _rol ($num, $cnt) | |
| Bitwise rotate a 32-bit number. | |
| _zero_fill ($a, $b) | |
| Pad string with zero. | |
Definition at line 45 of file Sha1.php.
| CI_SHA::_ft | ( | $ | t, | |
| $ | b, | |||
| $ | c, | |||
| $ | d | |||
| ) |
Return result based on iteration.
private
Definition at line 150 of file Sha1.php.
Referenced by generate().
00151 { 00152 if ($t < 20) 00153 return ($b & $c) | ((~$b) & $d); 00154 if ($t < 40) 00155 return $b ^ $c ^ $d; 00156 if ($t < 60) 00157 return ($b & $c) | ($b & $d) | ($c & $d); 00158 00159 return $b ^ $c ^ $d; 00160 }

| CI_SHA::_hex | ( | $ | str | ) |
Convert a decimal to hex.
private
| string |
Definition at line 130 of file Sha1.php.
Referenced by generate().
00131 { 00132 $str = dechex($str); 00133 00134 if (strlen($str) == 7) 00135 { 00136 $str = '0'.$str; 00137 } 00138 00139 return $str; 00140 }

| CI_SHA::_kt | ( | $ | t | ) |
Determine the additive constant.
private
Definition at line 170 of file Sha1.php.
Referenced by generate().
00171 { 00172 if ($t < 20) 00173 { 00174 return 1518500249; 00175 } 00176 else if ($t < 40) 00177 { 00178 return 1859775393; 00179 } 00180 else if ($t < 60) 00181 { 00182 return -1894007588; 00183 } 00184 else 00185 { 00186 return -899497514; 00187 } 00188 }

| CI_SHA::_rol | ( | $ | num, | |
| $ | cnt | |||
| ) |
Bitwise rotate a 32-bit number.
private
Definition at line 214 of file Sha1.php.
References _zero_fill().
Referenced by generate().
00215 { 00216 return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt); 00217 }


| CI_SHA::_safe_add | ( | $ | x, | |
| $ | y | |||
| ) |
Add integers, wrapping at 2^32.
private
Definition at line 198 of file Sha1.php.
Referenced by generate().
00199 { 00200 $lsw = ($x & 0xFFFF) + ($y & 0xFFFF); 00201 $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); 00202 00203 return ($msw << 16) | ($lsw & 0xFFFF); 00204 }

| CI_SHA::_zero_fill | ( | $ | a, | |
| $ | b | |||
| ) |
Pad string with zero.
private
Definition at line 227 of file Sha1.php.
Referenced by _rol().
00228 { 00229 $bin = decbin($a); 00230 00231 if (strlen($bin) < $b) 00232 { 00233 $bin = 0; 00234 } 00235 else 00236 { 00237 $bin = substr($bin, 0, strlen($bin) - $b); 00238 } 00239 00240 for ($i=0; $i < $b; $i++) 00241 { 00242 $bin = "0".$bin; 00243 } 00244 00245 return bindec($bin); 00246 }

| CI_SHA::CI_SHA | ( | ) |
Definition at line 47 of file Sha1.php.
References log_message().
00048 { 00049 log_message('debug', "SHA1 Class Initialized"); 00050 }

| CI_SHA::generate | ( | $ | str | ) |
Generate the Hash.
public
| string |
Definition at line 59 of file Sha1.php.
References _ft(), _hex(), _kt(), _rol(), and _safe_add().
00060 { 00061 $n = ((strlen($str) + 8) >> 6) + 1; 00062 00063 for ($i = 0; $i < $n * 16; $i++) 00064 { 00065 $x[$i] = 0; 00066 } 00067 00068 for ($i = 0; $i < strlen($str); $i++) 00069 { 00070 $x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8); 00071 } 00072 00073 $x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); 00074 00075 $x[$n * 16 - 1] = strlen($str) * 8; 00076 00077 $a = 1732584193; 00078 $b = -271733879; 00079 $c = -1732584194; 00080 $d = 271733878; 00081 $e = -1009589776; 00082 00083 for ($i = 0; $i < sizeof($x); $i += 16) 00084 { 00085 $olda = $a; 00086 $oldb = $b; 00087 $oldc = $c; 00088 $oldd = $d; 00089 $olde = $e; 00090 00091 for($j = 0; $j < 80; $j++) 00092 { 00093 if ($j < 16) 00094 { 00095 $w[$j] = $x[$i + $j]; 00096 } 00097 else 00098 { 00099 $w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); 00100 } 00101 00102 $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))); 00103 00104 $e = $d; 00105 $d = $c; 00106 $c = $this->_rol($b, 30); 00107 $b = $a; 00108 $a = $t; 00109 } 00110 00111 $a = $this->_safe_add($a, $olda); 00112 $b = $this->_safe_add($b, $oldb); 00113 $c = $this->_safe_add($c, $oldc); 00114 $d = $this->_safe_add($d, $oldd); 00115 $e = $this->_safe_add($e, $olde); 00116 } 00117 00118 return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e); 00119 }
