当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt_Rijndael::get_lambda_functions方法代码示例

本文整理汇总了PHP中Crypt_Rijndael::get_lambda_functions方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_Rijndael::get_lambda_functions方法的具体用法?PHP Crypt_Rijndael::get_lambda_functions怎么用?PHP Crypt_Rijndael::get_lambda_functions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt_Rijndael的用法示例。


在下文中一共展示了Crypt_Rijndael::get_lambda_functions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: inline_crypt_setup

    /**
     * Creates performance-optimized function for de/encrypt(), storing it in $this->inline_crypt
     *
     * @see Crypt_Rijndael::encrypt()
     * @see Crypt_Rijndael::decrypt()
     * @access private
     */
    function inline_crypt_setup()
    {
        // Note: inline_crypt_setup() will be called only if $this->changed === true
        // So here we are'nt under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
        // However...the here generated function- $code, stored as php callback in $this->inline_crypt, must work as fast as even possible.
        $lambda_functions =& Crypt_Rijndael::get_lambda_functions();
        $block_size = $this->block_size;
        $mode = $this->mode;
        // The first 5 generated $lambda_functions will use the key-words hardcoded for better performance.
        // For memory reason we limit those ultra-optimized function code to 5.
        // After that, we use pure (extracted) integer vars for the key-words which is faster than accessing them via array.
        if (count($lambda_functions) < 5) {
            $w = $this->w;
            $dw = $this->dw;
            $init_encryptBlock = '';
            $init_decryptBlock = '';
        } else {
            for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
                $w[] = '$w_' . $i;
                $dw[] = '$dw_' . $i;
            }
            $init_encryptBlock = 'extract($self->w,  EXTR_PREFIX_ALL, "w");';
            $init_decryptBlock = 'extract($self->dw, EXTR_PREFIX_ALL, "dw");';
        }
        $code_hash = md5("{$mode}, {$block_size}, " . implode(',', $w));
        if (!isset($lambda_functions[$code_hash])) {
            $Nr = $this->Nr;
            $Nb = $this->Nb;
            $c = $this->c;
            // Generating encrypt code:
            $init_encryptBlock .= '

                $t0 = $self->t0;

                $t1 = $self->t1;

                $t2 = $self->t2;

                $t3 = $self->t3;

                $sbox = $self->sbox;';
            $s = 'e';
            $e = 's';
            $wc = $Nb - 1;
            // Preround: addRoundKey
            $_encryptBlock = '$in = unpack("N*", $in);' . "\n";
            for ($i = 0; $i < $Nb; ++$i) {
                $_encryptBlock .= '$s' . $i . ' = $in[' . ($i + 1) . '] ^ ' . $w[++$wc] . ";\n";
            }
            // Mainrounds: shiftRows + subWord + mixColumns + addRoundKey
            for ($round = 1; $round < $Nr; ++$round) {
                list($s, $e) = array($e, $s);
                for ($i = 0; $i < $Nb; ++$i) {
                    $_encryptBlock .= '$' . $e . $i . ' =

                        $t0[($' . $s . $i . ' >> 24) & 0xff] ^

                        $t1[($' . $s . ($i + $c[1]) % $Nb . ' >> 16) & 0xff] ^

                        $t2[($' . $s . ($i + $c[2]) % $Nb . ' >>  8) & 0xff] ^

                        $t3[ $' . $s . ($i + $c[3]) % $Nb . '        & 0xff] ^

                        ' . $w[++$wc] . ";\n";
                }
            }
            // Finalround: subWord + shiftRows + addRoundKey
            for ($i = 0; $i < $Nb; ++$i) {
                $_encryptBlock .= '$' . $e . $i . ' =

                     $sbox[ $' . $e . $i . '        & 0xff]        |

                    ($sbox[($' . $e . $i . ' >>  8) & 0xff] <<  8) |

                    ($sbox[($' . $e . $i . ' >> 16) & 0xff] << 16) |

                    ($sbox[($' . $e . $i . ' >> 24) & 0xff] << 24);' . "\n";
            }
            $_encryptBlock .= '$in = pack("N*"' . "\n";
            for ($i = 0; $i < $Nb; ++$i) {
                $_encryptBlock .= ',

                    ($' . $e . $i . ' & 0xFF000000) ^

                    ($' . $e . ($i + $c[1]) % $Nb . ' & 0x00FF0000) ^

                    ($' . $e . ($i + $c[2]) % $Nb . ' & 0x0000FF00) ^

                    ($' . $e . ($i + $c[3]) % $Nb . ' & 0x000000FF) ^

                    ' . $w[$i] . "\n";
            }
            $_encryptBlock .= ');';
//.........这里部分代码省略.........
开发者ID:Toxatoxa,项目名称:Sample-Code,代码行数:101,代码来源:rijndael.php


注:本文中的Crypt_Rijndael::get_lambda_functions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。