Crypt::CFB with Default IV

A tutorial example is provided to show that the default IV value used in the Crypt::CFB module is a string of binary zeroes 0x0000000000000000.

From the Crypt::CFB manual page, we know that the secret key is a required parameter we have to specify when creating a new Crypt::CFB object. But on the IV parameter, it says "If no IV is given, a string of zeroes is used".

The term, "string of zeroes", is not very precise. It could be a string of binary zeroes like 0x0000000000000000, or a string of ASCII code zeroes like "00000000". So I wrote the following Perl example script to find out:

#- Crypt-CFB-Blowfish-Default-IV.pl
#- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
   use Crypt::CFB;
   my ($keyHex, $ivHex, $plainHex) = @ARGV;

   print("Crypt::CFB Default IV Test - output in Hex:\n");
   $keyHex = "1122334455667788" unless $keyHex;
   $ivHex = "1111111111111111" unless $ivHex;
   $plainHex = "0123456789abcdef" unless $plainHex;
   $keyStr = pack("H*", $keyHex);
   $ivStr = pack("H*", $ivHex);
   $plainStr = pack("H*", $plainHex);
   print("   Secret Key     ($keyHex)\n");
   print("   IV             ($ivHex)\n");
   print("   IV in ASCII    ($ivStr)\n");
   print("   Plaintext      ($plainHex)\n");

   print("Creating Crypt::CFB with given IV ...\n");
   $cipher = Crypt::CFB->new($keyStr, 'Crypt::Blowfish', $ivStr);

   print("Encrypting plaintext...\n");
   $cipherStr = $cipher->encrypt($plainStr);
   $cipherHex = unpack("H*", $cipherStr);
   print("   Ciphertext     ($cipherHex)\n");

   print("Decrypting ciphertext...\n");
   $cipher->reset();
   $decryptStr = $cipher->decrypt($cipherStr);
   $decryptHex = unpack("H*", $decryptStr);
   print("   Decrypted text ($decryptHex)\n");
   
   print("Creating Crypt::CFB with default IV ...\n");
   $cipher = Crypt::CFB->new($keyStr, 'Crypt::Blowfish');

   print("Encrypting plaintext...\n");
   $cipherStr = $cipher->encrypt($plainStr);
   $cipherHex = unpack("H*", $cipherStr);
   print("   Ciphertext     ($cipherHex)\n");

   print("Decrypting ciphertext...\n");
   $cipher->reset();
   $decryptStr = $cipher->decrypt($cipherStr);
   $decryptHex = unpack("H*", $decryptStr);
   print("   Decrypted text ($decryptHex)\n");

Now run this example script with different IV values:

C:\herong>perl Crypt-CFB-Blowfish-Default-IV.pl  
   1122334455667788 3030303030303030 0123456789abcdef

Crypt::CFB Default IV Test - output in Hex:
   Secret Key     (1122334455667788)
   IV             (3030303030303030)
   IV in ASCII    (00000000)
   Plaintext      (0123456789abcdef)
Creating Crypt::CFB with given IV ...
Encrypting plaintext...
   Ciphertext     (7a9fcbbfa46f0a57)
Decrypting ciphertext...
   Decrypted text (0123456789abcdef)
Creating Crypt::CFB with default IV ...
Encrypting plaintext...
   Ciphertext     (c7de2d3fe72ea7ab)
Decrypting ciphertext...
   Decrypted text (0123456789abcdef)


C:\herong>perl Crypt-CFB-Blowfish-Default-IV.pl  
   1122334455667788 0000000000000000 0123456789abcdef
Crypt::CFB Default IV Test - output in Hex:
   Secret Key     (1122334455667788)
   IV             (0000000000000000)
   IV in ASCII    (        )
   Plaintext      (0123456789abcdef)
Creating Crypt::CFB with given IV ...
Encrypting plaintext...
   Ciphertext     (c7de2d3fe72ea7ab)
Decrypting ciphertext...
   Decrypted text (0123456789abcdef)
Creating Crypt::CFB with default IV ...
Encrypting plaintext...
   Ciphertext     (c7de2d3fe72ea7ab)
Decrypting ciphertext...
   Decrypted text (0123456789abcdef)

The output tells us that:

Last update: 2015.

Table of Contents

 About This Book

 Blowfish Cipher Algorithm

 Perl Crypt::Blowfish Module

 Perl Crypt::ECB Perl Module

 Perl Crypt::CBC Module

Perl Crypt::CFB Perl Module

 What is Crypt::CFB?

 Installing Crypt::CFB 0.02 with ActivePerl

Crypt::CFB with Default IV

 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

 OpenSSL "enc -bf-ofb" for Blowfish/OFB Encryption

 References

 PDF Printing Version