當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Crypt_Blowfish::_getLambdaFunctions方法代碼示例

本文整理匯總了PHP中Crypt_Blowfish::_getLambdaFunctions方法的典型用法代碼示例。如果您正苦於以下問題:PHP Crypt_Blowfish::_getLambdaFunctions方法的具體用法?PHP Crypt_Blowfish::_getLambdaFunctions怎麽用?PHP Crypt_Blowfish::_getLambdaFunctions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Crypt_Blowfish的用法示例。


在下文中一共展示了Crypt_Blowfish::_getLambdaFunctions方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _setupInlineCrypt

    /**
     * Setup the performance-optimized function for de/encrypt()
     *
     * @see Crypt_Base::_setupInlineCrypt()
     * @access private
     */
    function _setupInlineCrypt()
    {
        $lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
        // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
        // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
        $gen_hi_opt_code = (bool) (count($lambda_functions) < 10);
        switch (true) {
            case $gen_hi_opt_code:
                $code_hash = md5(str_pad("Crypt_Blowfish, {$this->mode}, ", 32, "") . $this->key);
                break;
            default:
                $code_hash = "Crypt_Blowfish, {$this->mode}";
        }
        if (!isset($lambda_functions[$code_hash])) {
            switch (true) {
                case $gen_hi_opt_code:
                    $p = $this->bctx['p'];
                    $init_crypt = '
                        static $sb_0, $sb_1, $sb_2, $sb_3;
                        if (!$sb_0) {
                            $sb_0 = $self->bctx["sb"][0];
                            $sb_1 = $self->bctx["sb"][1];
                            $sb_2 = $self->bctx["sb"][2];
                            $sb_3 = $self->bctx["sb"][3];
                        }
                    ';
                    break;
                default:
                    $p = array();
                    for ($i = 0; $i < 18; ++$i) {
                        $p[] = '$p_' . $i;
                    }
                    $init_crypt = '
                        list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"];
                        list(' . implode(',', $p) . ') = $self->bctx["p"];

                    ';
            }
            // Generating encrypt code:
            $encrypt_block = '
                $in = unpack("N*", $in);
                $l = $in[1];
                $r = $in[2];
            ';
            for ($i = 0; $i < 16; $i += 2) {
                $encrypt_block .= '
                    $l^= ' . $p[$i] . ';
                    $r^= ($sb_0[$l >> 24 & 0xff]  +
                          $sb_1[$l >> 16 & 0xff]  ^
                          $sb_2[$l >>  8 & 0xff]) +
                          $sb_3[$l       & 0xff];

                    $r^= ' . $p[$i + 1] . ';
                    $l^= ($sb_0[$r >> 24 & 0xff]  +
                          $sb_1[$r >> 16 & 0xff]  ^
                          $sb_2[$r >>  8 & 0xff]) +
                          $sb_3[$r       & 0xff];
                ';
            }
            $encrypt_block .= '
                $in = pack("N*",
                    $r ^ ' . $p[17] . ',
                    $l ^ ' . $p[16] . '
                );
            ';
            // Generating decrypt code:
            $decrypt_block = '
                $in = unpack("N*", $in);
                $l = $in[1];
                $r = $in[2];
            ';
            for ($i = 17; $i > 2; $i -= 2) {
                $decrypt_block .= '
                    $l^= ' . $p[$i] . ';
                    $r^= ($sb_0[$l >> 24 & 0xff]  +
                          $sb_1[$l >> 16 & 0xff]  ^
                          $sb_2[$l >>  8 & 0xff]) +
                          $sb_3[$l       & 0xff];

                    $r^= ' . $p[$i - 1] . ';
                    $l^= ($sb_0[$r >> 24 & 0xff]  +
                          $sb_1[$r >> 16 & 0xff]  ^
                          $sb_2[$r >>  8 & 0xff]) +
                          $sb_3[$r       & 0xff];
                ';
            }
            $decrypt_block .= '
                $in = pack("N*",
                    $r ^ ' . $p[0] . ',
                    $l ^ ' . $p[1] . '
                );
            ';
            $lambda_functions[$code_hash] = $this->_createInlineCryptFunction(array('init_crypt' => $init_crypt, 'init_encrypt' => '', 'init_decrypt' => '', 'encrypt_block' => $encrypt_block, 'decrypt_block' => $decrypt_block));
        }
//.........這裏部分代碼省略.........
開發者ID:nobitagamer,項目名稱:DAws,代碼行數:101,代碼來源:Blowfish.php

示例2: _setupInlineCrypt

    /**
     * Setup the performance-optimized function for de/encrypt()
     *
     * @see Crypt_Base::_setupInlineCrypt()
     * @access private
     */
    function _setupInlineCrypt()
    {
        $lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
        // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
        // (Currently, for Crypt_Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit)
        // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
        $gen_hi_opt_code = (bool) (count($lambda_functions) < 10);
        // Generation of a unique hash for our generated code
        $code_hash = "Crypt_Blowfish, {$this->mode}";
        if ($gen_hi_opt_code) {
            $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
        }
        // on 32-bit linux systems with PHP < 5.3 float to integer conversion is bad
        switch (true) {
            case defined('PHP_INT_SIZE') && PHP_INT_SIZE == 8:
            case version_compare(PHP_VERSION, '5.3.0') >= 0:
            case (PHP_OS & "ßßß") === 'WIN':
                $safeint = '%s';
                break;
            default:
                $safeint = '(is_int($temp = %s) ? $temp : (fmod($temp, 0x80000000) & 0x7FFFFFFF) | ';
                $safeint .= '((fmod(floor($temp / 0x80000000), 2) & 1) << 31))';
        }
        if (!isset($lambda_functions[$code_hash])) {
            switch (true) {
                case $gen_hi_opt_code:
                    $p = $this->bctx['p'];
                    $init_crypt = '
                        static $sb_0, $sb_1, $sb_2, $sb_3;
                        if (!$sb_0) {
                            $sb_0 = $self->bctx["sb"][0];
                            $sb_1 = $self->bctx["sb"][1];
                            $sb_2 = $self->bctx["sb"][2];
                            $sb_3 = $self->bctx["sb"][3];
                        }
                    ';
                    break;
                default:
                    $p = array();
                    for ($i = 0; $i < 18; ++$i) {
                        $p[] = '$p_' . $i;
                    }
                    $init_crypt = '
                        list($sb_0, $sb_1, $sb_2, $sb_3) = $self->bctx["sb"];
                        list(' . implode(',', $p) . ') = $self->bctx["p"];

                    ';
            }
            // Generating encrypt code:
            $encrypt_block = '
                $in = unpack("N*", $in);
                $l = $in[1];
                $r = $in[2];
            ';
            for ($i = 0; $i < 16; $i += 2) {
                $encrypt_block .= '
                    $l^= ' . $p[$i] . ';
                    $r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
                          $sb_2[$l >>  8 & 0xff]) +
                          $sb_3[$l       & 0xff]') . ';

                    $r^= ' . $p[$i + 1] . ';
                    $l^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]') . '  ^
                          $sb_2[$r >>  8 & 0xff]) +
                          $sb_3[$r       & 0xff]') . ';
                ';
            }
            $encrypt_block .= '
                $in = pack("N*",
                    $r ^ ' . $p[17] . ',
                    $l ^ ' . $p[16] . '
                );
            ';
            // Generating decrypt code:
            $decrypt_block = '
                $in = unpack("N*", $in);
                $l = $in[1];
                $r = $in[2];
            ';
            for ($i = 17; $i > 2; $i -= 2) {
                $decrypt_block .= '
                    $l^= ' . $p[$i] . ';
                    $r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
                          $sb_2[$l >>  8 & 0xff]) +
                          $sb_3[$l       & 0xff]') . ';

                    $r^= ' . $p[$i - 1] . ';
                    $l^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]') . ' ^
                          $sb_2[$r >>  8 & 0xff]) +
                          $sb_3[$r       & 0xff]') . ';
                ';
            }
            $decrypt_block .= '
                $in = pack("N*",
//.........這裏部分代碼省略.........
開發者ID:aaronfrey,項目名稱:PepperLillie-Cambridge,代碼行數:101,代碼來源:Blowfish.php


注:本文中的Crypt_Blowfish::_getLambdaFunctions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。