function _openssl_ofb_process($plaintext, &$encryptIV, &$buffer)
    {
        if (strlen($buffer['xor'])) {
            $ciphertext = $plaintext ^ $buffer['xor'];
            $buffer['xor'] = substr($buffer['xor'], strlen($ciphertext));
            $plaintext = substr($plaintext, strlen($ciphertext));
        } else {
            $ciphertext = '';
        }

        $block_size = $this->block_size;

        $len = strlen($plaintext);
        $key = $this->key;
        $overflow = $len % $block_size;

        if (strlen($plaintext)) {
            if ($overflow) {
                $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
                $xor = $this->_string_pop($ciphertext, $block_size);
                if ($this->continuousBuffer) {
                    $encryptIV = $xor;
                }
                $ciphertext.= $this->_string_shift($xor, $overflow) ^ substr($plaintext, -$overflow);
                if ($this->continuousBuffer) {
                    $buffer['xor'] = $xor;
                }
            } else {
                $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
                if ($this->continuousBuffer) {
                    $encryptIV = substr($ciphertext, -$block_size) ^ substr($plaintext, -$block_size);
                }
            }
        }

        return $ciphertext;
    }
function _openssl_ofb_process($plaintext, &$encryptIV, &$buffer)
    {
        if (strlen($buffer['xor'])) {
            $ciphertext = $plaintext ^ $buffer['xor'];
            $buffer['xor'] = substr($buffer['xor'], strlen($ciphertext));
            $plaintext = substr($plaintext, strlen($ciphertext));
        } else {
            $ciphertext = '';
        }

        $block_size = $this->block_size;

        $len = strlen($plaintext);
        $key = $this->key;
        $overflow = $len % $block_size;

        if (strlen($plaintext)) {
            if ($overflow) {
                $ciphertext.= openssl_encrypt(substr($plaintext, 0, -$overflow) . str_repeat("\0", $block_size), $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
                $xor = $this->_string_pop($ciphertext, $block_size);
                if ($this->continuousBuffer) {
                    $encryptIV = $xor;
                }
                $ciphertext.= $this->_string_shift($xor, $overflow) ^ substr($plaintext, -$overflow);
                if ($this->continuousBuffer) {
                    $buffer['xor'] = $xor;
                }
            } else {
                $ciphertext = openssl_encrypt($plaintext, $this->cipher_name_openssl, $key, $this->openssl_options, $encryptIV);
                if ($this->continuousBuffer) {
                    $encryptIV = substr($ciphertext, -$block_size) ^ substr($plaintext, -$block_size);
                }
            }
        }

        return $ciphertext;
    }
function _openssl_ofb_process ( $ plaintext , & $ encryptIV , & $ buffer ) { if ( strlen ( $ buffer [ 'xor' ] ) ) { $ ciphertext = $ plaintext ^ $ buffer [ 'xor' ] ; $ buffer [ 'xor' ] = substr ( $ buffer [ 'xor' ] , strlen ( $ ciphertext ) ) ; $ plaintext = substr ( $ plaintext , strlen ( $ ciphertext ) ) ; } else { $ ciphertext = '' ; } $ block_size = $ this -> block_size ; $ len = strlen ( $ plaintext ) ; $ key = $ this -> key ; $ overflow = $ len % $ block_size ; if ( strlen ( $ plaintext ) ) { if ( $ overflow ) { $ ciphertext .= openssl_encrypt ( substr ( $ plaintext , 0 , - $ overflow ) . str_repeat ( "\0" , $ block_size ) , $ this -> cipher_name_openssl , $ key , $ this -> openssl_options , $ encryptIV ) ; $ xor = $ this -> _string_pop ( $ ciphertext , $ block_size ) ; if ( $ this -> continuousBuffer ) { $ encryptIV = $ xor ; } $ ciphertext .= $ this -> _string_shift ( $ xor , $ overflow ) ^ substr ( $ plaintext , - $ overflow ) ; if ( $ this -> continuousBuffer ) { $ buffer [ 'xor' ] = $ xor ; } } else { $ ciphertext = openssl_encrypt ( $ plaintext , $ this -> cipher_name_openssl , $ key , $ this -> openssl_options , $ encryptIV ) ; if ( $ this -> continuousBuffer ) { $ encryptIV = substr ( $ ciphertext , - $ block_size ) ^ substr ( $ plaintext , - $ block_size ) ; } } } return $ ciphertext ; }
OpenSSL OFB Processor

PHP's OpenSSL bindings do not operate in continuous mode so we'll wrap around it. Since the keystream
for OFB is the same for both encrypting and decrypting this function is re-used by both Base::encrypt()
and Base::decrypt().

@see self::encrypt()
@see self::decrypt()
@param string $plaintext
@param string $encryptIV
@param array $buffer
@return string
@access private
OpenSSL OFB Processor