IP : 3.149.228.132Hostname : host45.registrar-servers.comKernel : Linux host45.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
../
var/
softaculous/
popoji/
../
easyp/
../
qtoa/
../
fiyo/
../
spip/
sha256.inc.php/
/
<?php /* * Transparent SHA-256 Implementation for PHP 4 and PHP 5 * * Author: Perry McGee (pmcgee@nanolink.ca) * Website: http://www.nanolink.ca/pub/sha256 * * Copyright (C) 2006,2007,2008,2009 Nanolink Solutions * * Created: Feb 11, 2006 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * or see <http://www.gnu.org/licenses/>. * * Include: * * require_once("[path/]sha256.inc.php"); * * Usage Options: * * 1) $shaStr = hash('sha256', $string_to_hash); * * 2) $shaStr = sha256($string_to_hash[, bool ignore_php5_hash = false]); * * 3) $obj = new nanoSha2([bool $upper_case_output = false]); * $shaStr = $obj->hash($string_to_hash[, bool $ignore_php5_hash = false]); * * Reference: http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html * * 2007-12-13: Cleaned up for initial public release * 2008-05-10: Moved all helper functions into a class. API access unchanged. * 2009-06-23: Created abstraction of hash() routine * 2009-07-23: Added detection of 32 vs 64bit platform, and patches. * Ability to define "_NANO_SHA2_UPPER" to yeild upper case hashes. * 2009-08-01: Added ability to attempt to use mhash() prior to running pure * php code. * * 2010-06-10: Added support for 16bytes char and utf8 in string * * NOTE: Some sporadic versions of PHP do not handle integer overflows the * same as the majority of builds. If you get hash results of: * 7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff7fffffff * * If you do not have permissions to change PHP versions (if you did * you'd probably upgrade to PHP 5 anyway) it is advised you install a * module that will allow you to use their hashing routines, examples are: * - mhash module : http://ca3.php.net/mhash * - Suhosin : http://www.hardened-php.net/suhosin/ * * If you install the Suhosin module, this script will transparently * use their routine and define the PHP routine as _nano_sha256(). * * If the mhash module is present, and $ignore_php5_hash = false the * script will attempt to use the output from mhash prior to running * the PHP code. */ if (!class_exists('nanoSha2')) { class nanoSha2 { // php 4 - 5 compatable class properties var $toUpper; var $platform; var $bytesString = 16;
// Php 4 - 6 compatable constructor function nanoSha2($toUpper = false) { // Determine if the caller wants upper case or not. $this->toUpper = is_bool($toUpper) ? $toUpper : ((defined('_NANO_SHA2_UPPER')) ? true : false);
// Deteremine if the system is 32 or 64 bit. $tmpInt = (int)4294967295; $this->platform = ($tmpInt > 0) ? 64 : 32; }
// Here are the bitwise and functions as defined in FIPS180-2 Standard function addmod2n($x, $y, $n = 4294967296) // Z = (X + Y) mod 2^32 { $mask = 0x80000000;
// Logical bitwise right shift (PHP default is arithmetic shift) function SHR($x, $n) // x >> n { if ($n >= 32) { // impose some limits to keep it 32-bit return (int)0; }
function string2ordUTF8($s,&$byteSize){ $chars = array(); // par defaut sur 8bits $byteSize = 8; $i = 0; while ($i<strlen($s)){ $chars[] = $this->ordUTF8($s, $i, $bytes); $i+=$bytes; // mais si un char necessite 16bits, on passe tout sur 16 // sinon on ne concorde pas avec le lecture de la chaine en js // et le sha256 js if ($bytes>1) $byteSize = 16; } return $chars; }
/** * Process and return the hash. * * @param $str Input string to hash * @param $ig_func Option param to ignore checking for php > 5.1.2 * @return string Hexadecimal representation of the message digest */ function hash($str, $ig_func = true) { unset($binStr); // binary representation of input string unset($hexStr); // 256-bit message digest in readable hex format
// check for php's internal sha256 function, ignore if ig_func==true if ($ig_func == false) { if (version_compare(PHP_VERSION,'5.1.2','>=') AND !defined('_NO_HASH_DEFINED')) { return hash("sha256", $str, false); } else if (function_exists('mhash') && defined('MHASH_SHA256')) { return base64_encode(bin2hex(mhash(MHASH_SHA256, $str))); } }
/* * SHA-256 Constants * Sequence of sixty-four constant 32-bit words representing the * first thirty-two bits of the fractional parts of the cube roots * of the first sixtyfour prime numbers. */ $K = array((int)0x428a2f98, (int)0x71374491, (int)0xb5c0fbcf, (int)0xe9b5dba5, (int)0x3956c25b, (int)0x59f111f1, (int)0x923f82a4, (int)0xab1c5ed5, (int)0xd807aa98, (int)0x12835b01, (int)0x243185be, (int)0x550c7dc3, (int)0x72be5d74, (int)0x80deb1fe, (int)0x9bdc06a7, (int)0xc19bf174, (int)0xe49b69c1, (int)0xefbe4786, (int)0x0fc19dc6, (int)0x240ca1cc, (int)0x2de92c6f, (int)0x4a7484aa, (int)0x5cb0a9dc, (int)0x76f988da, (int)0x983e5152, (int)0xa831c66d, (int)0xb00327c8, (int)0xbf597fc7, (int)0xc6e00bf3, (int)0xd5a79147, (int)0x06ca6351, (int)0x14292967, (int)0x27b70a85, (int)0x2e1b2138, (int)0x4d2c6dfc, (int)0x53380d13, (int)0x650a7354, (int)0x766a0abb, (int)0x81c2c92e, (int)0x92722c85, (int)0xa2bfe8a1, (int)0xa81a664b, (int)0xc24b8b70, (int)0xc76c51a3, (int)0xd192e819, (int)0xd6990624, (int)0xf40e3585, (int)0x106aa070, (int)0x19a4c116, (int)0x1e376c08, (int)0x2748774c, (int)0x34b0bcb5, (int)0x391c0cb3, (int)0x4ed8aa4a, (int)0x5b9cca4f, (int)0x682e6ff3, (int)0x748f82ee, (int)0x78a5636f, (int)0x84c87814, (int)0x8cc70208, (int)0x90befffa, (int)0xa4506ceb, (int)0xbef9a3f7, (int)0xc67178f2);
// Pre-processing: Padding the string $binStr = $this->string2binint($str,512);
// Parsing the Padded Message (Break into N 512-bit blocks) $M = $this->array_split($binStr, 16);
/** * Main routine called from an application using this include. * * General usage: * require_once('sha256.inc.php'); * $hashstr = sha256('abc'); * * Note: * PHP Strings are limitd to (2^31)-1, so it is not worth it to * check for input strings > 2^64 as the FIPS180-2 defines. */ function _nano_sha256($str, $ig_func = true) { $obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false); return $obj->hash($str, $ig_func); } // 2009-07-23: Added check for function as the Suhosin plugin adds this routine. if (!function_exists('sha256')) { function sha256($str, $ig_func = true) { return _nano_sha256($str, $ig_func); } }
// support to give php4 the hash() routine which abstracts this code. if (!function_exists('hash')) { define('_NO_HASH_DEFINED',true); function hash($algo, $data) { if (empty($algo) || !is_string($algo) || !is_string($data)) { return false; }
if (function_exists($algo)) { return $algo($data); } } }