@ 2014-09-09T17:43:44Z <?php
//require_once (dirname(__FILE__) . "/sha256.php");
$AWS_ACCESS_KEY = 'AKIAIDMODWRW3CRDO2BA';
$AWS_PRIVATE_KEY = 'kMuJRvcejqzMvmoZWsURIDKkteVTXa3ReDXQ6RqE';
$AWS_REGION = 'us-west-2';
$TOPIC_ARN_UPDATECUS = 'arn:aws:sns:us-west-2:791920038536:updateCusNumberRequest';
$endpoints = array(
'US-EAST-1' => 'sns.us-east-1.amazonaws.com',
'US-WEST-1' => 'sns.us-west-1.amazonaws.com',
'US-WEST-2' => 'sns.us-west-2.amazonaws.com',
'EU-WEST-1' => 'sns.eu-west-1.amazonaws.com',
'AP-SE-1' => 'sns.ap-southeast-1.amazonaws.com',
'AP-NE-1' => 'sns.ap-northeast-1.amazonaws.com',
'SA-EAST-1' => 'sns.sa-east-1.amazonaws.com'
);
$endpoint = $endpoints[strtoupper($AWS_REGION)];
$protocol = 'https://';
$email = '';
$cus_id = '';
$message = array(
'topic' => 'updateCusNumberRequest',
'email' => $email,
'cus_id' => $cus_id
);
$params = array(
'TopicArn' => $TOPIC_ARN_UPDATECUS,
'Message' => php_compat_json_encode($message)
);
$params['Action'] = 'Publish';
$params['AWSAccessKeyId'] = $AWS_ACCESS_KEY;
$params['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
$params['SignatureVersion'] = 2;
$params['SignatureMethod'] = 'HmacSHA256';
uksort($params, 'strnatcmp');
$queryString = '';
foreach ($params as $key => $val) {
$queryString .= "&{$key}=".rawurlencode($val);
}
$queryString = substr($queryString, 1);
$requestString = "GET\n"
. $endpoint."\n"
. "/\n"
. $queryString;
$params['Signature'] = base64_encode(
php_compat_hash_hmac('sha256', $requestString, $AWS_PRIVATE_KEY, true)
);
$request = $protocol . $endpoint . '/?' . php_compat_http_build_query($params);
var_dump($request);
/* php4 compatible functions */
//http://bit.ly/1qd0Usl
function php_compat_hash_hmac($algo, $data, $key, $raw_output = false)
{
// Block size (byte) for MD5, SHA-1 and SHA-256.
$blocksize = 64;
$ipad = str_repeat("\x36", $blocksize);
$opad = str_repeat("\x5c", $blocksize);
if (strlen($key) > $blocksize) {
$key = php_compat_hash($algo, $key, true);
} else {
$key = str_pad($key, $blocksize, "\x00");
}
$ipad ^= $key;
$opad ^= $key;
return php_compat_hash($algo, $opad . php_compat_hash($algo, $ipad . $data, true), $raw_output);
}
//http://bit.ly/1nIYD2h
function php_compat_hash($algo, $data, $raw_output = false)
{
$hash = sha256($data);
if ($raw_output) {
return pack('H*', $hash);
} else {
echo "returnhash";
return $hash;
}
}
//http://bit.ly/1uH6OR0
function php_compat_json_encode($a=false)
{
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a))
{
if (is_float($a))
{
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a))
{
$jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
}
else
return $a;
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
{
if (key($a) !== $i)
{
$isList = false;
break;
}
}
$result = array();
if ($isList)
{
foreach ($a as $v) $result[] = php_compat_json_encode($v);
return '[' . join(',', $result) . ']';
}
else
{
foreach ($a as $k => $v) $result[] = php_compat_json_encode($k).':'.php_compat_json_encode($v);
return '{' . join(',', $result) . '}';
}
}
//http://bit.ly/1q8GwII
function php_compat_http_build_query($data, $prefix = null, $sep = '', $key = '')
{
$ret = array();
foreach ((array )$data as $k => $v) {
$k = urlencode($k);
if (is_int($k) && $prefix != null) {
$k = $prefix . $k;
}
if (!empty($key)) {
$k = $key . "[" . $k . "]";
}
if (is_array($v) || is_object($v)) {
array_push($ret, http_build_query($v, "", $sep, $k));
} else {
array_push($ret, $k . "=" . urlencode($v));
}
}
if (empty($sep)) {
$sep = ini_get("arg_separator.output");
}
return implode($sep, $ret);
}
class nanoSha2
{
// php 4 - 5 compatable class properties
var $toUpper;
var $platform;
// 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;
}
// Do the SHA-256 Padding routine (make input a multiple of 512 bits)
function char_pad($str)
{
$tmpStr = $str;
$l = strlen($tmpStr)*8; // # of bits from input string
$tmpStr .= "\x80"; // append the "1" bit followed by 7 0's
$k = (512 - (($l + 8 + 64) % 512)) / 8; // # of 0 bytes to append
$k += 4; // PHP Strings will never exceed (2^31)-1, 1st 32bits of
// the 64-bit value representing $l can be all 0's
for ($x = 0; $x < $k; $x++) {
$tmpStr .= "\0";
}
// append the 32-bits representing # of bits from input string ($l)
$tmpStr .= chr((($l>>24) & 0xFF));
$tmpStr .= chr((($l>>16) & 0xFF));
$tmpStr .= chr((($l>>8) & 0xFF));
$tmpStr .= chr(($l & 0xFF));
return $tmpStr;
}
// 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;
if ($x < 0) {
$x &= 0x7FFFFFFF;
$x = (float)$x + $mask;
}
if ($y < 0) {
$y &= 0x7FFFFFFF;
$y = (float)$y + $mask;
}
$r = $x + $y;
if ($r >= $n) {
while ($r >= $n) {
$r -= $n;
}
}
return (int)$r;
}
// 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;
}
if ($n <= 0) {
return (int)$x;
}
$mask = 0x40000000;
if ($x < 0) {
$x &= 0x7FFFFFFF;
$mask = $mask >> ($n-1);
return ($x >> $n) | $mask;
}
return (int)$x >> (int)$n;
}
function ROTR($x, $n) { return (int)(($this->SHR($x, $n) | ($x << (32-$n)) & 0xFFFFFFFF)); }
function Ch($x, $y, $z) { return ($x & $y) ^ ((~$x) & $z); }
function Maj($x, $y, $z) { return ($x & $y) ^ ($x & $z) ^ ($y & $z); }
function Sigma0($x) { return (int) ($this->ROTR($x, 2)^$this->ROTR($x, 13)^$this->ROTR($x, 22)); }
function Sigma1($x) { return (int) ($this->ROTR($x, 6)^$this->ROTR($x, 11)^$this->ROTR($x, 25)); }
function sigma_0($x) { return (int) ($this->ROTR($x, 7)^$this->ROTR($x, 18)^$this->SHR($x, 3)); }
function sigma_1($x) { return (int) ($this->ROTR($x, 17)^$this->ROTR($x, 19)^$this->SHR($x, 10)); }
/*
* Custom functions to provide PHP support
*/
// split a byte-string into integer array values
function int_split($input)
{
$l = strlen($input);
if ($l <= 0) {
return (int)0;
}
if (($l % 4) != 0) { // invalid input
return false;
}
for ($i = 0; $i < $l; $i += 4)
{
$int_build = (ord($input[$i]) << 24);
$int_build += (ord($input[$i+1]) << 16);
$int_build += (ord($input[$i+2]) << 8);
$int_build += (ord($input[$i+3]));
$result[] = $int_build;
}
return $result;
}
/**
* 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 = false)
{
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','>=')) {
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->char_pad($str);
// Parsing the Padded Message (Break into N 512-bit blocks)
$M = str_split($binStr, 64);
// Set the initial hash values
$h[0] = (int)0x6a09e667;
$h[1] = (int)0xbb67ae85;
$h[2] = (int)0x3c6ef372;
$h[3] = (int)0xa54ff53a;
$h[4] = (int)0x510e527f;
$h[5] = (int)0x9b05688c;
$h[6] = (int)0x1f83d9ab;
$h[7] = (int)0x5be0cd19;
// loop through message blocks and compute hash. ( For i=1 to N : )
$N = count($M);
for ($i = 0; $i < $N; $i++)
{
// Break input block into 16 32bit words (message schedule prep)
$MI = $this->int_split($M[$i]);
// Initialize working variables
$_a = (int)$h[0];
$_b = (int)$h[1];
$_c = (int)$h[2];
$_d = (int)$h[3];
$_e = (int)$h[4];
$_f = (int)$h[5];
$_g = (int)$h[6];
$_h = (int)$h[7];
unset($_s0);
unset($_s1);
unset($_T1);
unset($_T2);
$W = array();
// Compute the hash and update
for ($t = 0; $t < 16; $t++)
{
// Prepare the first 16 message schedule values as we loop
$W[$t] = $MI[$t];
// Compute hash
$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t]);
$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
// Update working variables
$_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1);
$_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2);
}
for (; $t < 64; $t++)
{
// Continue building the message schedule as we loop
$_s0 = $W[($t+1)&0x0F];
$_s0 = $this->sigma_0($_s0);
$_s1 = $W[($t+14)&0x0F];
$_s1 = $this->sigma_1($_s1);
$W[$t&0xF] = $this->addmod2n($this->addmod2n($this->addmod2n($W[$t&0xF], $_s0), $_s1), $W[($t+9)&0x0F]);
// Compute hash
$_T1 = $this->addmod2n($this->addmod2n($this->addmod2n($this->addmod2n($_h, $this->Sigma1($_e)), $this->Ch($_e, $_f, $_g)), $K[$t]), $W[$t&0xF]);
$_T2 = $this->addmod2n($this->Sigma0($_a), $this->Maj($_a, $_b, $_c));
// Update working variables
$_h = $_g; $_g = $_f; $_f = $_e; $_e = $this->addmod2n($_d, $_T1);
$_d = $_c; $_c = $_b; $_b = $_a; $_a = $this->addmod2n($_T1, $_T2);
}
$h[0] = $this->addmod2n($h[0], $_a);
$h[1] = $this->addmod2n($h[1], $_b);
$h[2] = $this->addmod2n($h[2], $_c);
$h[3] = $this->addmod2n($h[3], $_d);
$h[4] = $this->addmod2n($h[4], $_e);
$h[5] = $this->addmod2n($h[5], $_f);
$h[6] = $this->addmod2n($h[6], $_g);
$h[7] = $this->addmod2n($h[7], $_h);
}
// Convert the 32-bit words into human readable hexadecimal format.
$hexStr = sprintf("%08x%08x%08x%08x%08x%08x%08x%08x", $h[0], $h[1], $h[2], $h[3], $h[4], $h[5], $h[6], $h[7]);
return ($this->toUpper) ? strtoupper($hexStr) : $hexStr;
}
}
/**
* Splits a string into an array of strings with specified length.
* Compatability with older verions of PHP
*/
if (!function_exists('str_split'))
{
function str_split($string, $split_length = 1)
{
$sign = ($split_length < 0) ? -1 : 1;
$strlen = strlen($string);
$split_length = abs($split_length);
if (($split_length == 0) || ($strlen == 0)) {
$result = false;
} elseif ($split_length >= $strlen) {
$result[] = $string;
} else {
$length = $split_length;
for ($i = 0; $i < $strlen; $i++)
{
$i = (($sign < 0) ? $i + $length : $i);
$result[] = substr($string, $sign*$i, $length);
$i--;
$i = (($sign < 0) ? $i : $i + $length);
$length = (($i + $split_length) > $strlen)
? ($strlen - ($i + 1))
: $split_length;
}
}
return $result;
}
}
/**
* 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.
*/
// 2009-07-23: Added check for function as the Suhosin plugin adds this routine.
function sha256($str, $ig_func = false) {
$obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
return $obj->hash($str, $ig_func);
}
function _nano_sha256($str, $ig_func = false) {
$obj = new nanoSha2((defined('_NANO_SHA2_UPPER')) ? true : false);
return $obj->hash($str, $ig_func);
}
// support to give php4 the hash() routine which abstracts this code.
function hash($algo, $data)
{
if (empty($algo) || !is_string($algo) || !is_string($data)) {
return false;
}
if (function_exists($algo)) {
return $algo($data);
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.1 0.043 0.063 20.65 5.6.0 0.040 0.077 20.64 5.5.16 0.043 0.050 20.44 5.5.15 0.047 0.047 20.41 5.5.14 0.033 0.060 20.30 5.5.13 0.037 0.057 20.37 5.5.12 0.027 0.070 20.32 5.5.11 0.037 0.060 20.44 5.5.10 0.040 0.060 20.25 5.5.9 0.037 0.053 20.26 5.5.8 0.037 0.060 20.20 5.5.7 0.063 0.070 20.27 5.5.6 0.040 0.050 20.27 5.5.5 0.037 0.057 20.24 5.5.4 0.023 0.063 20.29 5.5.3 0.040 0.050 20.24 5.5.2 0.027 0.067 20.18 5.5.1 0.037 0.067 20.22 5.5.0 0.030 0.063 20.22 5.4.32 0.050 0.060 19.01 5.4.31 0.027 0.070 19.20 5.4.30 0.047 0.053 19.23 5.4.29 0.030 0.067 19.29 5.4.28 0.057 0.077 18.93 5.4.27 0.050 0.043 19.30 5.4.26 0.037 0.047 19.33 5.4.25 0.053 0.053 19.23 5.4.24 0.027 0.060 19.13 5.4.23 0.037 0.057 19.23 5.4.22 0.030 0.060 19.17 5.4.21 0.047 0.047 19.21 5.4.20 0.030 0.057 19.13 5.4.19 0.047 0.043 18.93 5.4.18 0.040 0.057 19.18 5.4.17 0.053 0.067 19.09 5.4.16 0.047 0.050 19.22 5.4.15 0.017 0.063 19.17 5.4.14 0.013 0.050 16.53 5.4.13 0.030 0.047 16.51 5.4.12 0.057 0.053 16.67 5.4.11 0.057 0.040 16.41 5.4.10 0.050 0.043 16.62 5.4.9 0.050 0.063 16.52 5.4.8 0.050 0.063 16.51 5.4.7 0.043 0.070 16.46 5.4.6 0.040 0.070 16.36 5.4.5 0.057 0.077 16.59 5.4.4 0.050 0.060 16.61 5.4.3 0.047 0.060 16.57 5.4.2 0.057 0.057 16.61 5.4.1 0.043 0.087 16.59 5.4.0 0.033 0.060 16.01
preferences:dark mode live preview
139.14 ms | 1394 KiB | 7 Q