root/OpenPNE_specification/patch/OpenPNE_2_10_x_Amazon_ticket_4166_2_fix.patch

Revision 12722, 13.7 kB (checked in by urabe, 3 years ago)

#4166 追加修正用のパッチファイルをコミット 2.10.x 2.8.x 用

  • lib/include/PHP/Compat/Function/hash_hmac.php

    old new  
     1<?php 
     2 
     3require_once dirname(__FILE__) . '/hash.php'; 
     4 
     5/** 
     6 * Replace hash_hmac() 
     7 * 
     8 * @category    PHP 
     9 * @package     PHP_Compat 
     10 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html 
     11 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net> 
     12 * @link        http://php.net/function.hash_hmac 
     13 * @author      revulo <revulon@gmail.com> 
     14 * @since       PHP 5.1.2 
     15 * @require     PHP 4.0.1 (str_pad) 
     16 */ 
     17function php_compat_hash_hmac($algo, $data, $key, $raw_output = false) 
     18{ 
     19    // Block size (byte) for MD5, SHA-1 and SHA-256. 
     20    $blocksize = 64; 
     21 
     22    $ipad = str_repeat("\x36", $blocksize); 
     23    $opad = str_repeat("\x5c", $blocksize); 
     24 
     25    if (strlen($key) > $blocksize) { 
     26        $key = hash($algo, $key, true); 
     27    } else { 
     28        $key = str_pad($key, $blocksize, "\x00"); 
     29    } 
     30 
     31    $ipad ^= $key; 
     32    $opad ^= $key; 
     33 
     34    return hash($algo, $opad . hash($algo, $ipad . $data, true), $raw_output); 
     35} 
     36 
     37 
     38// Define 
     39if (!function_exists('hash_hmac')) { 
     40    function hash_hmac($algo, $data, $key, $raw_output = false) 
     41    { 
     42        return php_compat_hash_hmac($algo, $data, $key, $raw_output); 
     43    } 
     44} 
  • lib/include/PHP/Compat/Function/sha1.php

    old new  
     1<?php 
     2 
     3/** 
     4 * Replace sha1() 
     5 * 
     6 * @category    PHP 
     7 * @package     PHP_Compat 
     8 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html 
     9 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net> 
     10 * @link        http://php.net/function.sha1 
     11 * @author      revulo <revulon@gmail.com> 
     12 * @since       PHP 4.3.0 
     13 * @require     PHP 4.0.0 
     14 */ 
     15function php_compat_sha1($str, $raw_output = false) 
     16{ 
     17    $h0 = (int)0x67452301; 
     18    $h1 = (int)0xefcdab89; 
     19    $h2 = (int)0x98badcfe; 
     20    $h3 = (int)0x10325476; 
     21    $h4 = (int)0xc3d2e1f0; 
     22 
     23    $len = strlen($str); 
     24 
     25    $str .= "\x80"; 
     26    $str .= str_repeat("\0", 63 - ($len + 8) % 64); 
     27    $str .= pack('N2', $len >> 29, $len << 3); 
     28 
     29    for ($i = 0; $i < strlen($str); $i += 64) { 
     30 
     31        $w = array(); 
     32        for ($j = 0; $j < 16; ++$j) { 
     33            $index = $i + $j * 4; 
     34            $w[$j] = ord($str[$index])     << 24 
     35                   | ord($str[$index + 1]) << 16 
     36                   | ord($str[$index + 2]) << 8 
     37                   | ord($str[$index + 3]); 
     38        } 
     39        for ($j = 16; $j < 80; ++$j) { 
     40            $w[$j] = php_compat_sha1_rotl_helper($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); 
     41        } 
     42 
     43        $a = $h0; 
     44        $b = $h1; 
     45        $c = $h2; 
     46        $d = $h3; 
     47        $e = $h4; 
     48 
     49        for ($j = 0; $j < 80; ++$j) { 
     50            if ($j < 20) { 
     51                $f = ($b & $c) | (~$b & $d); 
     52                $k = (int)0x5a827999; 
     53            } else if ($j < 40) { 
     54                $f = $b ^ $c ^ $d; 
     55                $k = (int)0x6ed9eba1; 
     56            } else if ($j < 60) { 
     57                $f = ($b & $c) | ($b & $d) | ($c & $d); 
     58                $k = (int)0x8f1bbcdc; 
     59            } else { 
     60                $f = $b ^ $c ^ $d; 
     61                $k = (int)0xca62c1d6; 
     62            } 
     63 
     64            $t = php_compat_sha1_add32_helper( 
     65                 php_compat_sha1_add32_helper( 
     66                 php_compat_sha1_add32_helper( 
     67                 php_compat_sha1_add32_helper( 
     68                 php_compat_sha1_rotl_helper($a, 5), $f), $e), $k), $w[$j]); 
     69 
     70            $e = $d; 
     71            $d = $c; 
     72            $c = php_compat_sha1_rotl_helper($b, 30); 
     73            $b = $a; 
     74            $a = $t; 
     75        } 
     76 
     77        $h0 = php_compat_sha1_add32_helper($h0, $a); 
     78        $h1 = php_compat_sha1_add32_helper($h1, $b); 
     79        $h2 = php_compat_sha1_add32_helper($h2, $c); 
     80        $h3 = php_compat_sha1_add32_helper($h3, $d); 
     81        $h4 = php_compat_sha1_add32_helper($h4, $e); 
     82    } 
     83 
     84    $h0 &= (int)0xffffffff; 
     85    $h1 &= (int)0xffffffff; 
     86    $h2 &= (int)0xffffffff; 
     87    $h3 &= (int)0xffffffff; 
     88    $h4 &= (int)0xffffffff; 
     89 
     90    $hash = sprintf('%08x%08x%08x%08x%08x', $h0, $h1, $h2, $h3, $h4); 
     91 
     92    if ($raw_output) { 
     93        return pack('H*', $hash); 
     94    } else { 
     95        return $hash; 
     96    } 
     97} 
     98 
     99function php_compat_sha1_add32_helper($x, $y) 
     100{ 
     101    $lsw = ($x & 0xffff) + ($y & 0xffff); 
     102    $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); 
     103    return ($msw << 16) | ($lsw & 0xffff); 
     104} 
     105 
     106function php_compat_sha1_rotl_helper($x, $n) 
     107{ 
     108    return ($x << $n) | ($x >> (32 - $n)) & (0x7fffffff >> (31 - $n)); 
     109} 
     110 
     111// Define 
     112if (!function_exists('sha1')) { 
     113    function sha1($str, $raw_output = false) 
     114    { 
     115        return php_compat_sha1($str, $raw_output); 
     116    } 
     117} 
  • lib/include/PHP/Compat/Function/hash_algos.php

    old new  
     1<?php 
     2 
     3/** 
     4 * Replace hash_algos() 
     5 * 
     6 * @category    PHP 
     7 * @package     PHP_Compat 
     8 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html 
     9 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net> 
     10 * @link        http://php.net/function.hash_algos 
     11 * @author      revulo <revulon@gmail.com> 
     12 * @since       PHP 5.1.2 
     13 * @require     PHP 4.0.0 
     14 */ 
     15function php_compat_hash_algos() 
     16{ 
     17    return array('md5', 'sha1', 'sha256'); 
     18} 
     19 
     20 
     21// Define 
     22if (!function_exists('hash_algos')) { 
     23    function hash_algos() 
     24    { 
     25        return php_compat_hash_algos(); 
     26    } 
     27} 
  • lib/include/PHP/Compat/Function/sha256.php

    old new  
     1<?php 
     2 
     3/** 
     4 * PHP implementation of SHA-256 hash function 
     5 * 
     6 * @category    PHP 
     7 * @package     PHP_Compat 
     8 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html 
     9 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net> 
     10 * @link        http://php.net/function.hash 
     11 * @author      revulo <revulon@gmail.com> 
     12 * @require     PHP 4.0.0 
     13 */ 
     14function php_compat_sha256($str, $raw_output = false) 
     15{ 
     16    $h0 = (int)0x6a09e667; 
     17    $h1 = (int)0xbb67ae85; 
     18    $h2 = (int)0x3c6ef372; 
     19    $h3 = (int)0xa54ff53a; 
     20    $h4 = (int)0x510e527f; 
     21    $h5 = (int)0x9b05688c; 
     22    $h6 = (int)0x1f83d9ab; 
     23    $h7 = (int)0x5be0cd19; 
     24 
     25    $k = array( 
     26        (int)0x428a2f98, (int)0x71374491, (int)0xb5c0fbcf, (int)0xe9b5dba5, 
     27        (int)0x3956c25b, (int)0x59f111f1, (int)0x923f82a4, (int)0xab1c5ed5, 
     28        (int)0xd807aa98, (int)0x12835b01, (int)0x243185be, (int)0x550c7dc3, 
     29        (int)0x72be5d74, (int)0x80deb1fe, (int)0x9bdc06a7, (int)0xc19bf174, 
     30        (int)0xe49b69c1, (int)0xefbe4786, (int)0x0fc19dc6, (int)0x240ca1cc, 
     31        (int)0x2de92c6f, (int)0x4a7484aa, (int)0x5cb0a9dc, (int)0x76f988da, 
     32        (int)0x983e5152, (int)0xa831c66d, (int)0xb00327c8, (int)0xbf597fc7, 
     33        (int)0xc6e00bf3, (int)0xd5a79147, (int)0x06ca6351, (int)0x14292967, 
     34        (int)0x27b70a85, (int)0x2e1b2138, (int)0x4d2c6dfc, (int)0x53380d13, 
     35        (int)0x650a7354, (int)0x766a0abb, (int)0x81c2c92e, (int)0x92722c85, 
     36        (int)0xa2bfe8a1, (int)0xa81a664b, (int)0xc24b8b70, (int)0xc76c51a3, 
     37        (int)0xd192e819, (int)0xd6990624, (int)0xf40e3585, (int)0x106aa070, 
     38        (int)0x19a4c116, (int)0x1e376c08, (int)0x2748774c, (int)0x34b0bcb5, 
     39        (int)0x391c0cb3, (int)0x4ed8aa4a, (int)0x5b9cca4f, (int)0x682e6ff3, 
     40        (int)0x748f82ee, (int)0x78a5636f, (int)0x84c87814, (int)0x8cc70208, 
     41        (int)0x90befffa, (int)0xa4506ceb, (int)0xbef9a3f7, (int)0xc67178f2 
     42    ); 
     43 
     44    $len = strlen($str); 
     45 
     46    $str .= "\x80"; 
     47    $str .= str_repeat("\0", 63 - ($len + 8) % 64); 
     48    $str .= pack('N2', $len >> 29, $len << 3); 
     49 
     50    for ($i = 0; $i < strlen($str); $i += 64) { 
     51 
     52        $w = array(); 
     53        for ($j = 0; $j < 16; ++$j) { 
     54            $index = $i + $j * 4; 
     55            $w[$j] = ord($str[$index])     << 24 
     56                   | ord($str[$index + 1]) << 16 
     57                   | ord($str[$index + 2]) << 8 
     58                   | ord($str[$index + 3]); 
     59        } 
     60        for ($j = 16; $j < 64; ++$j) { 
     61            $s0 = php_compat_sha256_rotr_helper($w[$j - 15],  7) 
     62                ^ php_compat_sha256_rotr_helper($w[$j - 15], 18) 
     63                ^ php_compat_sha256_shr_helper ($w[$j - 15],  3); 
     64 
     65            $s1 = php_compat_sha256_rotr_helper($w[$j - 2], 17) 
     66                ^ php_compat_sha256_rotr_helper($w[$j - 2], 19) 
     67                ^ php_compat_sha256_shr_helper ($w[$j - 2], 10); 
     68 
     69            $w[$j] = php_compat_sha256_add32_helper( 
     70                     php_compat_sha256_add32_helper( 
     71                     php_compat_sha256_add32_helper($w[$j - 16], $s0), $w[$j - 7]), $s1); 
     72        } 
     73 
     74        $a = $h0; 
     75        $b = $h1; 
     76        $c = $h2; 
     77        $d = $h3; 
     78        $e = $h4; 
     79        $f = $h5; 
     80        $g = $h6; 
     81        $h = $h7; 
     82 
     83        for ($j = 0; $j < 64; ++$j) { 
     84            $s1 = php_compat_sha256_rotr_helper($e,  6) 
     85                ^ php_compat_sha256_rotr_helper($e, 11) 
     86                ^ php_compat_sha256_rotr_helper($e, 25); 
     87 
     88            $ch = ($e & $f) ^ (~$e & $g); 
     89 
     90            $s0 = php_compat_sha256_rotr_helper($a,  2) 
     91                ^ php_compat_sha256_rotr_helper($a, 13) 
     92                ^ php_compat_sha256_rotr_helper($a, 22); 
     93 
     94            $maj = ($a & $b) ^ ($a & $c) ^ ($b & $c); 
     95 
     96            $t1 = php_compat_sha256_add32_helper( 
     97                  php_compat_sha256_add32_helper( 
     98                  php_compat_sha256_add32_helper( 
     99                  php_compat_sha256_add32_helper($h, $s1), $ch), $k[$j]), $w[$j]); 
     100 
     101            $t2 = php_compat_sha256_add32_helper($s0, $maj); 
     102 
     103            $h = $g; 
     104            $g = $f; 
     105            $f = $e; 
     106            $e = php_compat_sha256_add32_helper($d, $t1); 
     107            $d = $c; 
     108            $c = $b; 
     109            $b = $a; 
     110            $a = php_compat_sha256_add32_helper($t1, $t2); 
     111        } 
     112 
     113        $h0 = php_compat_sha256_add32_helper($h0, $a); 
     114        $h1 = php_compat_sha256_add32_helper($h1, $b); 
     115        $h2 = php_compat_sha256_add32_helper($h2, $c); 
     116        $h3 = php_compat_sha256_add32_helper($h3, $d); 
     117        $h4 = php_compat_sha256_add32_helper($h4, $e); 
     118        $h5 = php_compat_sha256_add32_helper($h5, $f); 
     119        $h6 = php_compat_sha256_add32_helper($h6, $g); 
     120        $h7 = php_compat_sha256_add32_helper($h7, $h); 
     121    } 
     122 
     123    $h0 &= (int)0xffffffff; 
     124    $h1 &= (int)0xffffffff; 
     125    $h2 &= (int)0xffffffff; 
     126    $h3 &= (int)0xffffffff; 
     127    $h4 &= (int)0xffffffff; 
     128    $h5 &= (int)0xffffffff; 
     129    $h6 &= (int)0xffffffff; 
     130    $h7 &= (int)0xffffffff; 
     131 
     132    $hash = sprintf('%08x%08x%08x%08x%08x%08x%08x%08x', $h0, $h1, $h2, $h3, $h4, $h5, $h6, $h7); 
     133 
     134    if ($raw_output) { 
     135        return pack('H*', $hash); 
     136    } else { 
     137        return $hash; 
     138    } 
     139} 
     140 
     141function php_compat_sha256_add32_helper($x, $y) 
     142{ 
     143    $lsw = ($x & 0xffff) + ($y & 0xffff); 
     144    $msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16); 
     145    return ($msw << 16) | ($lsw & 0xffff); 
     146} 
     147 
     148function php_compat_sha256_shr_helper($x, $n) 
     149{ 
     150    return ($x >> $n) & (0x7fffffff >> ($n - 1)); 
     151} 
     152 
     153function php_compat_sha256_rotr_helper($x, $n) 
     154{ 
     155    return ($x << (32 - $n)) | ($x >> $n) & (0x7fffffff >> ($n - 1)); 
     156} 
  • lib/include/PHP/Compat/Function/hash.php

    old new  
     1<?php 
     2 
     3/** 
     4 * Replace hash() 
     5 * 
     6 * @category    PHP 
     7 * @package     PHP_Compat 
     8 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html 
     9 * @copyright   2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net> 
     10 * @link        http://php.net/function.hash 
     11 * @author      revulo <revulon@gmail.com> 
     12 * @since       PHP 5.1.2 
     13 * @require     PHP 4.0.0 (user_error) 
     14 */ 
     15function php_compat_hash($algo, $data, $raw_output = false) 
     16{ 
     17    $algo = strtolower($algo); 
     18    switch ($algo) { 
     19        case 'md5': 
     20            $hash = md5($data); 
     21            break; 
     22 
     23        case 'sha1': 
     24            if (!function_exists('sha1')) { 
     25                require dirname(__FILE__) . '/sha1.php'; 
     26            } 
     27            $hash = sha1($data); 
     28            break; 
     29 
     30        case 'sha256': 
     31            if (!function_exists('php_compat_sha256')) { 
     32                require dirname(__FILE__) . '/sha256.php'; 
     33            } 
     34            $hash = php_compat_sha256($data); 
     35            break; 
     36 
     37        default: 
     38            user_error('hash(): Unknown hashing algorithm: ' . $algo, E_USER_WARNING); 
     39            return false; 
     40    } 
     41 
     42    if ($raw_output) { 
     43        return pack('H*', $hash); 
     44    } else { 
     45        return $hash; 
     46    } 
     47} 
     48 
     49 
     50// Define 
     51if (!function_exists('hash')) { 
     52    function hash($algo, $data, $raw_output = false) 
     53    { 
     54        return php_compat_hash($algo, $data, $raw_output); 
     55    } 
     56} 
  • webapp/lib/OpenPNE/Amazon.php

    old new  
    55 */ 
    66 
    77require_once 'Services/Amazon.php'; 
    8 require_once 'PHP/Compat/Function/mhash.php'; 
     8require_once 'PHP/Compat/Function/hash_hmac.php'; 
    99 
    1010/** 
    1111 * OpenPNEでAmazonECSを利用するためのクラス 
Note: See TracBrowser for help on using the browser.