Logo Search packages:      
Sourcecode: ldap-account-manager version File versions

Cipher_blowfish::setKey ( key  ) 

Set the key to be used for en/decryption

Parameters:
String $key The key to use

Definition at line 317 of file blowfish.inc.

References _encryptBlock(), and _formatKey().

Referenced by decryptBlock(), and encryptBlock().

    {
        $key = $this->_formatKey($key);
        $keyPos = $keyXor = 0;

        $iMax = count($this->p);
        $keyLen = count($key);
        for ($i = 0; $i < $iMax; $i++) {
            for ($t = 0; $t < 4; $t++) {
                $keyXor = ($keyXor << 8) | (($key[$keyPos]) & 0x0ff);
                if (++$keyPos == $keyLen) {
                    $keyPos = 0;
                }
            }
            $this->p[$i] = $this->p[$i] ^ $keyXor;
        }

        $encZero = array('L' => 0, 'R' => 0);
        for ($i = 0; $i + 1 < $iMax; $i += 2) {
          $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']);
          $this->p[$i] = $encZero['L'];
          $this->p[$i + 1] = $encZero['R'];
        }

        $iMax = count($this->s1);
        for ($i = 0; $i < $iMax; $i += 2) {
          $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']);
          $this->s1[$i] = $encZero['L'];
          $this->s1[$i + 1] = $encZero['R'];
        }

        $iMax = count($this->s2);
        for ($i = 0; $i < $iMax; $i += 2) {
          $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']);
          $this->s2[$i] = $encZero['L'];
          $this->s2[$i + 1] = $encZero['R'];
        }

        $iMax = count($this->s3);
        for ($i = 0; $i < $iMax; $i += 2) {
          $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']);
          $this->s3[$i] = $encZero['L'];
          $this->s3[$i + 1] = $encZero['R'];
        }

        $iMax = count($this->s4);
        for ($i = 0; $i < $iMax; $i += 2) {
          $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']);
          $this->s4[$i] = $encZero['L'];
          $this->s4[$i + 1] = $encZero['R'];
        }

    }


Generated by  Doxygen 1.6.0   Back to index