/    Sign up×
Community /Pin to ProfileBookmark

Google Cart and the HMAC_SHA1 function

Googles instructions state that i have to use this HMAC_SHA1 function for some kind of encryption alogorithm.

Is anyone familiar with this?

(my obeisance absolute)

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsDec 02.2006 — SHA-1 is built into php >= 4.0, this is what i made to force raw_output in older version of php:<?php
function shr($x, $n)
{
return (0x80000000 & $x) ? (($x >> 1) & ~0x80000000 | 0x40000000) >> ($n - 1) : ($x >> $n);
}
function rotl($x, $n)
{
return ($x << $n) | shr($x, (32 - $n));
}
if(phpversion() >= '5.0')
{
function sha160($str, $raw_output = false)
{
return sha1($str, $raw_output);
}
}
else if(phpversion() >= '4.3')
{
function sha160($str, $raw_output = false)
{
$hash = sha1($str);
return ($raw_output) ? bin2hex($hash) : $hash;
}
}
else
{
function sha160($str, $raw_output = false)
{
$h0 = 0x67452301;
$h1 = 0xefcdaB89;
$h2 = 0x98badcfe;
$h3 = 0x10325476;
$h4 = 0xc3d2e1f0;
$l = strlen($str);
$str .= "x80" . str_repeat("x0", ($l & ~63) + (($l & 63 < 56) ? 60 : 124)) . pack('N', $l << 3);

<i> </i> for($i = 0; $i &lt; strlen($str); $i += 64)
<i> </i> {
<i> </i> $w = array_values(unpack('N16', substr($str, $i, 64)));
<i> </i> $a = $h0;
<i> </i> $b = $h1;
<i> </i> $c = $h2;
<i> </i> $d = $h3;
<i> </i> $e = $h4;

<i> </i> for($t = 0; $t &lt;= 79; $t++)
<i> </i> {
<i> </i> if(16 &lt;= $t)
<i> </i> {
<i> </i> $w[] = rotl($w[$t - 3] ^ $w[$t - 8] ^ $w[$t - 14] ^ $w[$t - 16], 1);
<i> </i> }
<i> </i> if(0 &lt;= $t &amp;&amp; $t &lt;= 19)
<i> </i> {
<i> </i> $f = ($b &amp; $c) ^ (~$b &amp; $d);
<i> </i> $k = 0x5a827999;
<i> </i> }
<i> </i> else if(20 &lt;= $t &amp;&amp; $t &lt;= 39)
<i> </i> {
<i> </i> $f = $b ^ $c ^ $d;
<i> </i> $k = 0x6ed9eba1;
<i> </i> }
<i> </i> else if(40 &lt;= $t &amp;&amp; $t &lt;= 59)
<i> </i> {
<i> </i> $f = ($b &amp; $c) ^ ($b &amp; $d) ^ ($c &amp; $d);
<i> </i> $k = 0x8f1bbcdc;
<i> </i> }
<i> </i> else if(60 &lt;= $t &amp;&amp; $t &lt;= 79)
<i> </i> {
<i> </i> $f = $b ^ $c ^ $d;
<i> </i> $k = 0xca62c1d6;
<i> </i> }
<i> </i> $tmp = intval(rotl($a, 5) + $f + $e + $k + $w[$t]);
<i> </i> $e = $d;
<i> </i> $d = $c;
<i> </i> $c = rotl($b, 30);
<i> </i> $b = $a;
<i> </i> $a = $tmp;
<i> </i> }
<i> </i> $h0 = $a + $h0;
<i> </i> $h1 = $b + $h1;
<i> </i> $h2 = $c + $h2;
<i> </i> $h3 = $d + $h3;
<i> </i> $h4 = $e + $h4;
<i> </i> }
<i> </i> $hash = pack('N*', $h0, $h1, $h2, $h3, $h4);
<i> </i> return ($raw_output) ? bin2hex($hash) : $hash;
<i> </i>}
}
?&gt;
×

Success!

Help @mparker1113 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...