Blowfish Cipher Tutorials - Herong's Tutorial Examples - Version 1.21, by Dr. Herong Yang
What is Crypt::CFB?
A quick introduction is provided for the Crypt::CFB Perl module, which can be used to perform encryption and decryption in the CFB (Cipher FeedBack)) operation mode with a given block cipher for any number of blocks.
What Is Crypt::CFB? Crypt::CFB is a Perl module providing CFB (Cipher FeedBack) block cipher operation mode functionality. Crypt::CFB was developed by Kees Jan Hermans.
Here is the description of Crypt::CFB on the cpan.org Web site: "Generic CFB implementation in pure Perl. The Cipher Feedback Mode module constructs a stream cipher from a block cipher or cryptographic hash function and returns it as an object. Any block cipher in the Crypt:: class can be used, as long as it supports the blocksize and keysize methods. Any hash function in the Digest:: class can be used, as long as it supports the add method."
The above description does not mention Blowfish, but Crypt::CFB can be used together with Crypt::Blowfish to encrypt and decrypt messages with Blowfish algorithm in CFB operation mode.
In case you forgot how CFB (Cipher FeedBack) works, here a shortest version of the CFB algorithm:
Input: P: The plaintext in multiple blocks K: The secret key IV: The Initialization Vector E(K,B): The block encryption function Output: C: The ciphertext in multiple blocks Algorithm - CFB (Cipher FeedBack) Operation Mode: (P[1], P[2], P[3},...) = P : Split plaintext into blocks C[1] = P[1] XOR E(K, IV) Loop i over 2,3,... Loop i over 2,3,... C[i] = P[i] XOR E(K, C[i-1]) End Loop C = (C[1], C[2], C[3},...) : Concatenate ciphertext blocks
The CBC algorithm can also be illustrated by this simple diagram:
Algorithm - CFB (Cipher FeedBack) Operation Mode: IV -----| -----| -----| E(K) / E(K) / E(K) | / | / | | / | / | P[1]--XOR / P[2]--XOR / P[3]--XOR | / | / | | / | / | C[1] C[2] C[3]
Crypt::CFB module offers the following main methods. Other methods will be discussed later as needed.
$c = Crypt::CFB->new($key, $module, $iv) - Returns a new Crypt::CFB cipher operation object with the following parameters:
$c->encrypt($plaintext) - Returns the ciphertext for the given plaintext of any size, using the cipher module specified in the cipher operation object $c. It continues with the current cache, which remembers the cipher output of the previous encrypt() call or decrypt() call.
$c->decrypt($ciphertext) - Returns the plaintext for the given ciphertext of any size, using the cipher module specified in the cipher operation object $c. It continues with the current cache, which remembers the cipher output of the previous encrypt() call or decrypt() call.
$c->reset() - Resets the cipher operation object $c to the cache to initial state. reset() must be called before starting a new encryption or decryption process.
See Crypt::CFB Web page at cpan.org for more information.
Last update: 2015.
Table of Contents
Installing Crypt::CFB 0.02 with ActivePerl
Crypt::CFB Not Requiring Padding
Crypt::CFB Operation Simulation
OpenSSL "enc -bf-ecb" for Blowfish/ECB Encryption
OpenSSL "enc -bf-cbc" for Blowfish/CBC Encryption
OpenSSL "enc -bf-cfb" for Blowfish/CFB Encryption